Browse Source

options: remove Value input

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

17
src/models/series.ts

@ -1,22 +1,19 @@
import { PanelData, TimeRange } from '@grafana/data'; import { PanelData, TimeRange } from '@grafana/data';
import { DataProcessor } from '../grafana/data_processor'; import { DataProcessor } from '../grafana/data_processor';
import { ExtremumOptions } from 'types'; import { ValueOptions } from 'types';
import * as _ from 'lodash'; import * as _ from 'lodash';
// Convert Grafana options into Chartwerk options
// Convert Grafana series into Chartwerk series
export class Series { export class Series {
private processor; private processor;
private _seriesList; private _seriesList;
private _selectedSerieName; private _selectedSerieName;
constructor(grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ExtremumOptions) { constructor(grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ValueOptions) {
if(this._isSerieOneValue()) { if(_.isEmpty(this.gaugeValueOptions.metricName)) {
this._seriesList = [{ datapoints: [[0, gaugeValueOptions.value]] }];
return;
}
if(this.gaugeValueOptions.useMetric && _.isEmpty(this.gaugeValueOptions.metricName)) {
throw new Error(`Value or metric is not selected.`); 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 { PanelOptions, Pod } from './types';
import { Panel } from './components/Panel'; import { Panel } from './components/Panel';
import { PanelPlugin } from '@grafana/data';
export const plugin = new PanelPlugin<PanelOptions>(Panel).setPanelOptions((builder) => { export const plugin = new PanelPlugin<PanelOptions>(Panel).setPanelOptions((builder) => {
return builder return builder
.addRadio({ .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({ .addFieldNamePicker({
name: 'Value', name: 'Value',
path: 'gauge.value.metricName', path: 'gauge.value.metricName',
category: ['Extremum'], category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE && config.gauge.value.useMetric, showIf: (config) => config.visualizationType === Pod.GAUGE
})
.addBooleanSwitch({
path: 'gauge.value.useMetric',
name: 'Use metric',
defaultValue: false,
category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE,
}) })
.addNumberInput({ .addNumberInput({
path: 'gauge.min.value', path: 'gauge.min.value',
name: 'Min', name: 'Min',
@ -67,6 +58,7 @@ export const plugin = new PanelPlugin<PanelOptions>(Panel).setPanelOptions((buil
category: ['Extremum'], category: ['Extremum'],
showIf: (config) => config.visualizationType === Pod.GAUGE, showIf: (config) => config.visualizationType === Pod.GAUGE,
}) })
.addNumberInput({ .addNumberInput({
path: 'gauge.max.value', path: 'gauge.max.value',
name: 'Max', name: 'Max',

10
src/types.ts

@ -8,10 +8,14 @@ export interface PanelOptions {
} }
export type ExtremumOptions = { export type ExtremumOptions = {
value?: number;
useMetric: false; useMetric: false;
metricName: string; value?: number;
}; metricName?: string;
}
export type ValueOptions = {
metricName?: string
}
export enum Pod { export enum Pod {
LINE = 'Line', LINE = 'Line',

Loading…
Cancel
Save