|
@@ -17,6 +17,7 @@ export interface Props extends Themeable {
|
|
|
value: TimeSeriesValue;
|
|
value: TimeSeriesValue;
|
|
|
maxValue: number;
|
|
maxValue: number;
|
|
|
minValue: number;
|
|
minValue: number;
|
|
|
|
|
+ orientation: string;
|
|
|
prefix?: string;
|
|
prefix?: string;
|
|
|
suffix?: string;
|
|
suffix?: string;
|
|
|
decimals?: number;
|
|
decimals?: number;
|
|
@@ -28,6 +29,7 @@ export class BarGauge extends PureComponent<Props> {
|
|
|
minValue: 0,
|
|
minValue: 0,
|
|
|
value: 100,
|
|
value: 100,
|
|
|
unit: 'none',
|
|
unit: 'none',
|
|
|
|
|
+ orientation: 'horizontal',
|
|
|
thresholds: [],
|
|
thresholds: [],
|
|
|
valueMappings: [],
|
|
valueMappings: [],
|
|
|
};
|
|
};
|
|
@@ -75,35 +77,89 @@ export class BarGauge extends PureComponent<Props> {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ renderHorizontalBar(valueStyles: React.CSSProperties, valueFormatted: string, barStyles: React.CSSProperties) {
|
|
|
|
|
+ const { height, width } = this.props;
|
|
|
|
|
+
|
|
|
|
|
+ const containerStyles = {
|
|
|
|
|
+ width: `${width}px`,
|
|
|
|
|
+ height: `${height}px`,
|
|
|
|
|
+ display: 'flex',
|
|
|
|
|
+ flexDirection: 'column',
|
|
|
|
|
+ justifyContent: 'flex-end',
|
|
|
|
|
+ } as React.CSSProperties;
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div style={containerStyles}>
|
|
|
|
|
+ <div className="bar-gauge__value" style={valueStyles}>
|
|
|
|
|
+ {valueFormatted}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div style={barStyles} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderVerticalBar(valueFormatted: string, barStyles: React.CSSProperties) {
|
|
|
|
|
+ const { height, width } = this.props;
|
|
|
|
|
+ const colors = this.getColors();
|
|
|
|
|
+
|
|
|
|
|
+ const containerStyles = {
|
|
|
|
|
+ width: `${width}px`,
|
|
|
|
|
+ height: `${height}px`,
|
|
|
|
|
+ display: 'flex',
|
|
|
|
|
+ flexDirection: 'row',
|
|
|
|
|
+ alignItems: 'center',
|
|
|
|
|
+ marginBottom: '8px',
|
|
|
|
|
+ } as React.CSSProperties;
|
|
|
|
|
+
|
|
|
|
|
+ const valueStyles = this.getValueStyles(valueFormatted, colors.value);
|
|
|
|
|
+
|
|
|
|
|
+ Object.assign(valueStyles, { marginLeft: '8px' });
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div style={containerStyles}>
|
|
|
|
|
+ <div style={barStyles} />
|
|
|
|
|
+ <div className="bar-gauge__value" style={valueStyles}>
|
|
|
|
|
+ {valueFormatted}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
render() {
|
|
render() {
|
|
|
- const { height, width, maxValue, minValue, unit, decimals } = this.props;
|
|
|
|
|
|
|
+ const { height, width, maxValue, minValue, orientation, unit, decimals } = this.props;
|
|
|
|
|
|
|
|
const numericValue = this.getNumericValue();
|
|
const numericValue = this.getNumericValue();
|
|
|
const barMaxHeight = height * 0.8; // 20% for value & name
|
|
const barMaxHeight = height * 0.8; // 20% for value & name
|
|
|
|
|
+ const barMaxWidth = width * 0.8;
|
|
|
const valuePercent = numericValue / (maxValue - minValue);
|
|
const valuePercent = numericValue / (maxValue - minValue);
|
|
|
const barHeight = Math.max(valuePercent * barMaxHeight, 0);
|
|
const barHeight = Math.max(valuePercent * barMaxHeight, 0);
|
|
|
|
|
+ const barWidth = Math.max(valuePercent * barMaxWidth, 0);
|
|
|
|
|
|
|
|
const formatFunc = getValueFormat(unit);
|
|
const formatFunc = getValueFormat(unit);
|
|
|
const valueFormatted = formatFunc(numericValue, decimals);
|
|
const valueFormatted = formatFunc(numericValue, decimals);
|
|
|
const colors = this.getColors();
|
|
const colors = this.getColors();
|
|
|
-
|
|
|
|
|
- const containerStyles = { width: `${width}px`, height: `${height}px` };
|
|
|
|
|
const valueStyles = this.getValueStyles(valueFormatted, colors.value);
|
|
const valueStyles = this.getValueStyles(valueFormatted, colors.value);
|
|
|
- const barStyles = {
|
|
|
|
|
|
|
+ const vertical = orientation === 'vertical';
|
|
|
|
|
+
|
|
|
|
|
+ const horizontalBarStyles = {
|
|
|
height: `${barHeight}px`,
|
|
height: `${barHeight}px`,
|
|
|
width: `${width}px`,
|
|
width: `${width}px`,
|
|
|
backgroundColor: colors.bar,
|
|
backgroundColor: colors.bar,
|
|
|
borderTop: `1px solid ${colors.border}`,
|
|
borderTop: `1px solid ${colors.border}`,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- return (
|
|
|
|
|
- <div className="bar-gauge" style={containerStyles}>
|
|
|
|
|
- <div className="bar-gauge__value" style={valueStyles}>
|
|
|
|
|
- {valueFormatted}
|
|
|
|
|
- </div>
|
|
|
|
|
- <div style={barStyles} />
|
|
|
|
|
- </div>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const verticalBarStyles = {
|
|
|
|
|
+ height: `${height}px`,
|
|
|
|
|
+ width: `${barWidth}px`,
|
|
|
|
|
+ backgroundColor: colors.bar,
|
|
|
|
|
+ borderRight: `1px solid ${colors.border}`,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const barStyles = vertical ? verticalBarStyles : horizontalBarStyles;
|
|
|
|
|
+
|
|
|
|
|
+ return vertical
|
|
|
|
|
+ ? this.renderVerticalBar(valueFormatted, barStyles)
|
|
|
|
|
+ : this.renderHorizontalBar(valueStyles, valueFormatted, barStyles);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|