From f72e751735d3fe62dd64990e85261264bde77ae2 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Mon, 19 Nov 2018 13:06:56 +0100 Subject: [PATCH] picker and functionaliy --- .../app/plugins/panel/gauge/GaugeOptions.tsx | 16 ------ public/app/plugins/panel/gauge/module.tsx | 53 +++++++++++++++++-- public/app/viz/Gauge.tsx | 22 ++++---- 3 files changed, 61 insertions(+), 30 deletions(-) delete mode 100644 public/app/plugins/panel/gauge/GaugeOptions.tsx diff --git a/public/app/plugins/panel/gauge/GaugeOptions.tsx b/public/app/plugins/panel/gauge/GaugeOptions.tsx deleted file mode 100644 index 23c773f963f..00000000000 --- a/public/app/plugins/panel/gauge/GaugeOptions.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React, { PureComponent } from 'react'; -import { PanelOptionsProps } from 'app/types'; - -interface Props {} - -export class GaugeOptions extends PureComponent> { - render() { - return ( -
-
-
Draw Modes
-
-
- ); - } -} diff --git a/public/app/plugins/panel/gauge/module.tsx b/public/app/plugins/panel/gauge/module.tsx index 2b536691453..f8ff4a56721 100644 --- a/public/app/plugins/panel/gauge/module.tsx +++ b/public/app/plugins/panel/gauge/module.tsx @@ -1,13 +1,30 @@ import React, { PureComponent } from 'react'; import Gauge from 'app/viz/Gauge'; -import { NullValueMode, PanelProps } from 'app/types'; +import { NullValueMode, PanelOptionsProps, PanelProps } from 'app/types'; import { getTimeSeriesVMs } from 'app/viz/state/timeSeries'; -import { GaugeOptions } from './GaugeOptions'; +import { Label } from '../../../core/components/Label/Label'; +import SimplePicker from '../../../core/components/Picker/SimplePicker'; -export interface Options {} +export interface Options { + stat: { value: string; text: string }; +} interface Props extends PanelProps {} +const statOptions = [ + { value: 'min', text: 'Min' }, + { value: 'max', text: 'Max' }, + { value: 'avg', text: 'Average' }, + { value: 'current', text: 'Current' }, + { value: 'total', text: 'Total' }, + { value: 'name', text: 'Name' }, + { value: 'first', text: 'First' }, + { value: 'delta', text: 'Delta' }, + { value: 'diff', text: 'Difference' }, + { value: 'range', text: 'Range' }, + { value: 'last_time', text: 'Time of last point' }, +]; + export class GaugePanel extends PureComponent { render() { const { timeSeries, width, height } = this.props; @@ -17,8 +34,36 @@ export class GaugePanel extends PureComponent { nullValueMode: NullValueMode.Ignore, }); + return ; + } +} + +class GaugeOptions extends PureComponent> { + onStatChange = value => { + this.props.onChange({ ...this.props.options, stat: value }); + }; + + render() { + const { stat } = this.props.options; + return ( - +
+
+
Value
+
+ + option.value === stat.value)} + width={11} + options={statOptions} + getOptionLabel={i => i.text} + getOptionValue={i => i.value} + onSelected={this.onStatChange} + value={stat} + /> +
+
+
); } } diff --git a/public/app/viz/Gauge.tsx b/public/app/viz/Gauge.tsx index 49e7dbad978..9fc706859af 100644 --- a/public/app/viz/Gauge.tsx +++ b/public/app/viz/Gauge.tsx @@ -5,13 +5,14 @@ import config from '../core/config'; interface Props { timeSeries: TimeSeriesVMs; - minValue: number; - maxValue: number; + minValue?: number; + maxValue?: number; showThresholdMarkers?: boolean; thresholds?: number[]; showThresholdLables?: boolean; width: number; height: number; + stat?: { value: string; text: string }; } const colors = ['rgba(50, 172, 45, 0.97)', 'rgba(237, 129, 40, 0.89)', 'rgba(245, 54, 54, 0.9)']; @@ -25,7 +26,7 @@ export class Gauge extends PureComponent { maxValue: 100, showThresholdMarkers: true, showThresholdLables: false, - thresholds: [], + thresholds: [0, 100], }; componentDidMount() { @@ -38,16 +39,19 @@ export class Gauge extends PureComponent { draw() { const { + timeSeries, maxValue, minValue, showThresholdLables, showThresholdMarkers, - timeSeries, thresholds, width, height, + stat, } = this.props; + console.log(stat); + const dimension = Math.min(width, height * 1.3); const backgroundColor = config.bootData.user.lightTheme ? 'rgb(230,230,230)' : 'rgb(38,38,38)'; const fontColor = config.bootData.user.lightTheme ? 'rgb(38,38,38)' : 'rgb(230,230,230)'; @@ -57,13 +61,11 @@ export class Gauge extends PureComponent { const thresholdMarkersWidth = gaugeWidth / 5; const thresholdLabelFontSize = fontSize / 2.5; - const formattedThresholds = []; - - thresholds.forEach((threshold, index) => { - formattedThresholds.push({ + const formattedThresholds = thresholds.map((threshold, index) => { + return { value: threshold, color: colors[index], - }); + }; }); const options = { @@ -94,7 +96,7 @@ export class Gauge extends PureComponent { value: { color: fontColor, formatter: () => { - return Math.round(timeSeries[0].stats.avg); + return Math.round(timeSeries[0].stats[stat.value]); }, font: { size: fontSize,