From f1190121a76c84102748df47a111098f9b6d4cc7 Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 21 Nov 2017 12:53:49 -0800 Subject: [PATCH] Set value of new gauge thresholds to the average of the min and max values --- ui/src/dashboards/components/CellEditorOverlay.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ui/src/dashboards/components/CellEditorOverlay.js b/ui/src/dashboards/components/CellEditorOverlay.js index 5ccd04209d..6496e8734a 100644 --- a/ui/src/dashboards/components/CellEditorOverlay.js +++ b/ui/src/dashboards/components/CellEditorOverlay.js @@ -27,6 +27,8 @@ import { MAX_THRESHOLDS, DEFAULT_COLORS, GAUGE_COLORS, + COLOR_TYPE_MIN, + COLOR_TYPE_MAX, } from 'src/dashboards/constants/gaugeColors' class CellEditorOverlay extends Component { @@ -73,13 +75,20 @@ class CellEditorOverlay extends Component { handleAddThreshold = () => { const {colors} = this.state - if (colors.length < MAX_THRESHOLDS) { + if (colors.length <= MAX_THRESHOLDS) { const randomColor = Math.floor(Math.random() * GAUGE_COLORS.length) + const maxValue = Number( + colors.find(color => color.type === COLOR_TYPE_MAX).value + ) + const minValue = Number( + colors.find(color => color.type === COLOR_TYPE_MIN).value + ) + const newThreshold = { type: COLOR_TYPE_THRESHOLD, id: uuid.v4(), - value: '50', + value: String((maxValue + minValue) / 2), hex: GAUGE_COLORS[randomColor].hex, name: GAUGE_COLORS[randomColor].name, }