|
@@ -82,14 +82,14 @@ export class Gauge extends PureComponent<Props> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(value)) {
|
|
if (isNaN(value)) {
|
|
|
- return '-';
|
|
|
|
|
|
|
+ return value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return `${prefix} ${formattedValue} ${suffix}`;
|
|
return `${prefix} ${formattedValue} ${suffix}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getFontColor(value) {
|
|
|
|
|
- const { maxValue, thresholds } = this.props;
|
|
|
|
|
|
|
+ getFontColor(value: string | number) {
|
|
|
|
|
+ const { thresholds } = this.props;
|
|
|
|
|
|
|
|
if (thresholds.length === 1) {
|
|
if (thresholds.length === 1) {
|
|
|
return thresholds[0].color;
|
|
return thresholds[0].color;
|
|
@@ -98,12 +98,11 @@ export class Gauge extends PureComponent<Props> {
|
|
|
const atThreshold = thresholds.filter(threshold => value < threshold.value);
|
|
const atThreshold = thresholds.filter(threshold => value < threshold.value);
|
|
|
|
|
|
|
|
if (atThreshold.length > 0) {
|
|
if (atThreshold.length > 0) {
|
|
|
- return atThreshold[0].color;
|
|
|
|
|
- } else if (value <= maxValue) {
|
|
|
|
|
- return BasicGaugeColor.Red;
|
|
|
|
|
|
|
+ const nearestThreshold = atThreshold.sort((t1, t2) => t1.value - t2.value)[0];
|
|
|
|
|
+ return nearestThreshold.color;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return '';
|
|
|
|
|
|
|
+ return BasicGaugeColor.Red;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
draw() {
|
|
draw() {
|
|
@@ -136,16 +135,16 @@ export class Gauge extends PureComponent<Props> {
|
|
|
const thresholdMarkersWidth = gaugeWidth / 5;
|
|
const thresholdMarkersWidth = gaugeWidth / 5;
|
|
|
const thresholdLabelFontSize = fontSize / 2.5;
|
|
const thresholdLabelFontSize = fontSize / 2.5;
|
|
|
|
|
|
|
|
- // const formattedThresholds = [
|
|
|
|
|
- // { value: minValue, color: BasicGaugeColor.Green },
|
|
|
|
|
- // ...thresholds.map((threshold, index) => {
|
|
|
|
|
- // return {
|
|
|
|
|
- // value: threshold.value,
|
|
|
|
|
- // color: index === 0 ? threshold.color : thresholds[index].color,
|
|
|
|
|
- // };
|
|
|
|
|
- // }),
|
|
|
|
|
- // { value: maxValue, color: thresholds.length > 0 ? BasicGaugeColor.Red : baseColor },
|
|
|
|
|
- // ];
|
|
|
|
|
|
|
+ const formattedThresholds = [
|
|
|
|
|
+ { value: minValue, color: thresholds.length === 1 ? thresholds[0].color : BasicGaugeColor.Green },
|
|
|
|
|
+ ...thresholds.map((threshold, index) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ value: threshold.value,
|
|
|
|
|
+ color: thresholds[index].color,
|
|
|
|
|
+ };
|
|
|
|
|
+ }),
|
|
|
|
|
+ { value: maxValue, color: thresholds.length === 1 ? thresholds[0].color : BasicGaugeColor.Red },
|
|
|
|
|
+ ];
|
|
|
|
|
|
|
|
const options = {
|
|
const options = {
|
|
|
series: {
|
|
series: {
|
|
@@ -163,7 +162,7 @@ export class Gauge extends PureComponent<Props> {
|
|
|
layout: { margin: 0, thresholdWidth: 0 },
|
|
layout: { margin: 0, thresholdWidth: 0 },
|
|
|
cell: { border: { width: 0 } },
|
|
cell: { border: { width: 0 } },
|
|
|
threshold: {
|
|
threshold: {
|
|
|
- values: thresholds,
|
|
|
|
|
|
|
+ values: formattedThresholds,
|
|
|
label: {
|
|
label: {
|
|
|
show: showThresholdLabels,
|
|
show: showThresholdLabels,
|
|
|
margin: thresholdMarkersWidth + 1,
|
|
margin: thresholdMarkersWidth + 1,
|