|
@@ -1,20 +1,10 @@
|
|
|
import React, { PureComponent } from 'react';
|
|
import React, { PureComponent } from 'react';
|
|
|
import $ from 'jquery';
|
|
import $ from 'jquery';
|
|
|
|
|
|
|
|
-import {
|
|
|
|
|
- ValueMapping,
|
|
|
|
|
- Threshold,
|
|
|
|
|
- ThemeName,
|
|
|
|
|
- MappingType,
|
|
|
|
|
- BasicGaugeColor,
|
|
|
|
|
- ThemeNames,
|
|
|
|
|
- ValueMap,
|
|
|
|
|
- RangeMap,
|
|
|
|
|
-} from '../../types/panel';
|
|
|
|
|
|
|
+import { ValueMapping, Threshold, ThemeName, BasicGaugeColor, ThemeNames } from '../../types/panel';
|
|
|
import { TimeSeriesVMs } from '../../types/series';
|
|
import { TimeSeriesVMs } from '../../types/series';
|
|
|
import { getValueFormat } from '../../utils/valueFormats/valueFormats';
|
|
import { getValueFormat } from '../../utils/valueFormats/valueFormats';
|
|
|
-
|
|
|
|
|
-type TimeSeriesValue = string | number | null;
|
|
|
|
|
|
|
+import { TimeSeriesValue, getMappedValue } from '../../utils/valueMappings';
|
|
|
|
|
|
|
|
export interface Props {
|
|
export interface Props {
|
|
|
decimals: number;
|
|
decimals: number;
|
|
@@ -59,70 +49,6 @@ export class Gauge extends PureComponent<Props> {
|
|
|
this.draw();
|
|
this.draw();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- addValueToTextMappingText(allValueMappings: ValueMapping[], valueToTextMapping: ValueMap, value: TimeSeriesValue) {
|
|
|
|
|
- if (!valueToTextMapping.value) {
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const valueAsNumber = parseFloat(value as string);
|
|
|
|
|
- const valueToTextMappingAsNumber = parseFloat(valueToTextMapping.value as string);
|
|
|
|
|
-
|
|
|
|
|
- if (isNaN(valueAsNumber) || isNaN(valueToTextMappingAsNumber)) {
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (valueAsNumber !== valueToTextMappingAsNumber) {
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return allValueMappings.concat(valueToTextMapping);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- addRangeToTextMappingText(allValueMappings: ValueMapping[], rangeToTextMapping: RangeMap, value: TimeSeriesValue) {
|
|
|
|
|
- if (!rangeToTextMapping.from || !rangeToTextMapping.to || !value) {
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const valueAsNumber = parseFloat(value as string);
|
|
|
|
|
- const fromAsNumber = parseFloat(rangeToTextMapping.from as string);
|
|
|
|
|
- const toAsNumber = parseFloat(rangeToTextMapping.to as string);
|
|
|
|
|
-
|
|
|
|
|
- if (isNaN(valueAsNumber) || isNaN(fromAsNumber) || isNaN(toAsNumber)) {
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (valueAsNumber >= fromAsNumber && valueAsNumber <= toAsNumber) {
|
|
|
|
|
- return allValueMappings.concat(rangeToTextMapping);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- getAllFormattedValueMappings(valueMappings: ValueMapping[], value: TimeSeriesValue) {
|
|
|
|
|
- const allFormattedValueMappings = valueMappings.reduce(
|
|
|
|
|
- (allValueMappings, valueMapping) => {
|
|
|
|
|
- if (valueMapping.type === MappingType.ValueToText) {
|
|
|
|
|
- allValueMappings = this.addValueToTextMappingText(allValueMappings, valueMapping as ValueMap, value);
|
|
|
|
|
- } else if (valueMapping.type === MappingType.RangeToText) {
|
|
|
|
|
- allValueMappings = this.addRangeToTextMappingText(allValueMappings, valueMapping as RangeMap, value);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return allValueMappings;
|
|
|
|
|
- },
|
|
|
|
|
- [] as ValueMapping[]
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- allFormattedValueMappings.sort((t1, t2) => {
|
|
|
|
|
- return t1.id - t2.id;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- return allFormattedValueMappings;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- getFirstFormattedValueMapping(valueMappings: ValueMapping[], value: TimeSeriesValue) {
|
|
|
|
|
- return this.getAllFormattedValueMappings(valueMappings, value)[0];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
formatValue(value: TimeSeriesValue) {
|
|
formatValue(value: TimeSeriesValue) {
|
|
|
const { decimals, valueMappings, prefix, suffix, unit } = this.props;
|
|
const { decimals, valueMappings, prefix, suffix, unit } = this.props;
|
|
|
|
|
|
|
@@ -131,7 +57,7 @@ export class Gauge extends PureComponent<Props> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (valueMappings.length > 0) {
|
|
if (valueMappings.length > 0) {
|
|
|
- const valueMappedValue = this.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
|
|
|
|
+ const valueMappedValue = getMappedValue(valueMappings, value);
|
|
|
if (valueMappedValue) {
|
|
if (valueMappedValue) {
|
|
|
return `${prefix} ${valueMappedValue.text} ${suffix}`;
|
|
return `${prefix} ${valueMappedValue.text} ${suffix}`;
|
|
|
}
|
|
}
|
|
@@ -139,8 +65,9 @@ export class Gauge extends PureComponent<Props> {
|
|
|
|
|
|
|
|
const formatFunc = getValueFormat(unit);
|
|
const formatFunc = getValueFormat(unit);
|
|
|
const formattedValue = formatFunc(value as number, decimals);
|
|
const formattedValue = formatFunc(value as number, decimals);
|
|
|
|
|
+ const handleNoValueValue = formattedValue || 'no value';
|
|
|
|
|
|
|
|
- return `${prefix} ${formattedValue} ${suffix}`;
|
|
|
|
|
|
|
+ return `${prefix} ${handleNoValueValue} ${suffix}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getFontColor(value: TimeSeriesValue) {
|
|
getFontColor(value: TimeSeriesValue) {
|
|
@@ -204,7 +131,7 @@ export class Gauge extends PureComponent<Props> {
|
|
|
if (timeSeries[0]) {
|
|
if (timeSeries[0]) {
|
|
|
value = timeSeries[0].stats[stat];
|
|
value = timeSeries[0].stats[stat];
|
|
|
} else {
|
|
} else {
|
|
|
- value = 'N/A';
|
|
|
|
|
|
|
+ value = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const dimension = Math.min(width, height * 1.3);
|
|
const dimension = Math.min(width, height * 1.3);
|