From dbba523d3b5b8782ca7b1e364e192054e5fb81e5 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Wed, 12 Dec 2018 16:16:05 +0100 Subject: [PATCH] mixing color when --- public/app/plugins/panel/gauge/Thresholds.tsx | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/public/app/plugins/panel/gauge/Thresholds.tsx b/public/app/plugins/panel/gauge/Thresholds.tsx index 9e9856b137b..ed2d947e268 100644 --- a/public/app/plugins/panel/gauge/Thresholds.tsx +++ b/public/app/plugins/panel/gauge/Thresholds.tsx @@ -1,5 +1,6 @@ import React, { PureComponent } from 'react'; import classNames from 'classnames/bind'; +import tinycolor from 'tinycolor2'; import { ColorPicker } from 'app/core/components/colorpicker/ColorPicker'; import { OptionModuleProps } from './module'; import { Threshold } from 'app/types'; @@ -21,7 +22,7 @@ export default class Thresholds extends PureComponent this.state = { thresholds: this.props.options.thresholds || [ { index: 0, label: 'Min', value: 0, canRemove: false, color: BasicGaugeColor.Green }, - { index: 1, label: 'Max', value: 100, canRemove: false }, + { index: 1, label: 'Max', value: 100, canRemove: false, color: BasicGaugeColor.Red }, ], }; } @@ -39,12 +40,13 @@ export default class Thresholds extends PureComponent // Setting value to a value between the new threshold. const value = newThresholds[index].value - (newThresholds[index].value - newThresholds[index - 1].value) / 2; + const color = tinycolor.mix(thresholds[index - 1].color, thresholds[index].color, 50).toRgbString(); this.setState( { thresholds: this.sortThresholds([ ...newThresholds, - { index: index, label: '', value: value, canRemove: true, color: BasicGaugeColor.Orange }, + { index: index, label: '', value: value, canRemove: true, color: color }, ]), }, () => this.updateGauge() @@ -127,7 +129,6 @@ export default class Thresholds extends PureComponent const { thresholds } = this.state; const min = thresholds[0]; - const max = thresholds[1]; return [
@@ -154,18 +155,6 @@ export default class Thresholds extends PureComponent
Add new threshold by clicking the line.
, -
-
-
- this.onChangeThresholdValue(event, max)} - value={max.value} - /> -
{max.label}
-
-
, ]; } @@ -173,6 +162,10 @@ export default class Thresholds extends PureComponent const { thresholds } = this.state; return thresholds.map((threshold, index) => { + if (index === thresholds.length - 1) { + return null; + } + const rowStyle = classNames({ 'threshold-row': true, 'threshold-row-min': index === 0, @@ -183,14 +176,15 @@ export default class Thresholds extends PureComponent
- {threshold.color && ( -
- this.onChangeThresholdColor(threshold, color)} - /> -
- )} + {threshold.color && + index !== thresholds.length - 1 && ( +
+ this.onChangeThresholdColor(threshold, color)} + /> +
+ )}
render() { const { thresholds } = this.state; + const max = thresholds[thresholds.length - 1]; return (
@@ -296,6 +291,18 @@ export default class Thresholds extends PureComponent
{this.renderIndicator()}
{thresholds.length > 2 ? this.renderThresholds() : this.renderNoThresholds()} +
+
+
+ this.onChangeThresholdValue(event, max)} + value={max.value} + /> +
{max.label}
+
+