Browse Source

options: remove Value input

merge-requests/4/merge
rozetko 3 years ago
parent
commit
4d9d5b4839
  1. 19
      src/models/series.ts
  2. 22
      src/module.ts
  3. 10
      src/types.ts

19
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;
}
}

22
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<PanelOptions>(Panel).setPanelOptions((builder) => {
return builder
.addRadio({
@ -29,25 +31,14 @@ export const plugin = new PanelPlugin<PanelOptions>(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<PanelOptions>(Panel).setPanelOptions((buil
category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE,
})
.addNumberInput({
path: 'gauge.max.value',
name: 'Max',

10
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',

Loading…
Cancel
Save