From 4d9d5b4839158679f6606095a589c27e4ca81eb6 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 4 May 2022 15:28:15 +0400 Subject: [PATCH] options: remove Value input --- src/models/series.ts | 19 ++++++------------- src/module.ts | 22 +++++++--------------- src/types.ts | 10 +++++++--- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/models/series.ts b/src/models/series.ts index 1c34f98..7949228 100644 --- a/src/models/series.ts +++ b/src/models/series.ts @@ -1,22 +1,19 @@ import { PanelData, TimeRange } from '@grafana/data'; import { DataProcessor } from '../grafana/data_processor'; -import { ExtremumOptions } from 'types'; +import { ValueOptions } from 'types'; import * as _ from 'lodash'; -// Convert Grafana options into Chartwerk options + +// Convert Grafana series into Chartwerk series export class Series { - private processor; + private processor; private _seriesList; private _selectedSerieName; - constructor(grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ExtremumOptions) { - if(this._isSerieOneValue()) { - this._seriesList = [{ datapoints: [[0, gaugeValueOptions.value]] }]; - return; - } - if(this.gaugeValueOptions.useMetric && _.isEmpty(this.gaugeValueOptions.metricName)) { + constructor(grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ValueOptions) { + if(_.isEmpty(this.gaugeValueOptions.metricName)) { throw new Error(`Value or metric is not selected.`); } @@ -52,8 +49,4 @@ export class Series { }; }); } - - private _isSerieOneValue(): boolean { - return !this.gaugeValueOptions.useMetric; - } } diff --git a/src/module.ts b/src/module.ts index 84217f1..c5c3558 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,7 +1,9 @@ -import { PanelPlugin } from '@grafana/data'; import { PanelOptions, Pod } from './types'; import { Panel } from './components/Panel'; +import { PanelPlugin } from '@grafana/data'; + + export const plugin = new PanelPlugin(Panel).setPanelOptions((builder) => { return builder .addRadio({ @@ -29,25 +31,14 @@ export const plugin = new PanelPlugin(Panel).setPanelOptions((buil ], }, }) - .addNumberInput({ - name: 'Value', - path: 'gauge.value.value', - category: ['Extremum'], - showIf: (config) => config.visualizationType === Pod.GAUGE && !config.gauge.value.useMetric, - }) + .addFieldNamePicker({ name: 'Value', path: 'gauge.value.metricName', category: ['Extremum'], - showIf: (config) => config.visualizationType === Pod.GAUGE && config.gauge.value.useMetric, - }) - .addBooleanSwitch({ - path: 'gauge.value.useMetric', - name: 'Use metric', - defaultValue: false, - category: ['Extremum'], - showIf: (config) => config.visualizationType === Pod.GAUGE, + showIf: (config) => config.visualizationType === Pod.GAUGE }) + .addNumberInput({ path: 'gauge.min.value', name: 'Min', @@ -67,6 +58,7 @@ export const plugin = new PanelPlugin(Panel).setPanelOptions((buil category: ['Extremum'], showIf: (config) => config.visualizationType === Pod.GAUGE, }) + .addNumberInput({ path: 'gauge.max.value', name: 'Max', diff --git a/src/types.ts b/src/types.ts index 22e89bb..614140d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,10 +8,14 @@ export interface PanelOptions { } export type ExtremumOptions = { - value?: number; useMetric: false; - metricName: string; -}; + value?: number; + metricName?: string; +} + +export type ValueOptions = { + metricName?: string +} export enum Pod { LINE = 'Line',