Browse Source

serie as one value

merge-requests/3/head
vargburz 3 years ago
parent
commit
7359dab6c5
  1. 2
      src/components/Panel.tsx
  2. 19
      src/models/series.ts
  3. 24
      src/types.ts

2
src/components/Panel.tsx

@ -16,7 +16,7 @@ interface Props extends PanelProps<PanelOptions> {}
export function Panel({ options, data, width, height, timeZone, timeRange, onChangeTimeRange }: Props) {
console.log('options', options);
const series = new Series(data, timeRange).getChartwerkSeries();
const series = new Series(data, timeRange, options.gauge.value).getChartwerkSeries();
console.log('series', series);
const chartwerkOptions = new Options(options).getChartwerkOptions();

19
src/models/series.ts

@ -1,6 +1,8 @@
import { PanelData, TimeRange } from '@grafana/data';
import { DataProcessor } from '../grafana/data_processor';
import { ExtremumOptions } from 'types';
import * as _ from 'lodash';
// Convert Grafana options into Chartwerk options
@ -8,17 +10,22 @@ export class Series {
private processor;
private _seriesList;
constructor(private grafanaData: PanelData, timeRange: TimeRange) {
constructor(private grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ExtremumOptions) {
if(this._isSerieOneValue()) {
this._seriesList = [{ datapoints: [[0, gaugeValueOptions.value]] }];
return;
}
this.processor = new DataProcessor({});
const seriesList = this.processor.getSeriesList({
this._seriesList = this.processor.getSeriesList({
dataList: grafanaData.series,
range: timeRange,
});
this._seriesList = this._updateSeriesListWithChartwerkParams(seriesList);
this._seriesList = this._updateSeriesListWithChartwerkParams(this._seriesList);
}
public getChartwerkSeries(): any[] {
return this._seriesList;
return this._seriesList
}
private _updateSeriesListWithChartwerkParams(series: any[]): any[] {
@ -31,4 +38,8 @@ export class Series {
};
});
}
private _isSerieOneValue(): boolean {
return _.isNumber(this.gaugeValueOptions.value);
}
}

24
src/types.ts

@ -1,24 +1,18 @@
export interface PanelOptions {
visualizationType: Pod;
gauge: {
min: {
value?: number;
useMetric: false;
metricName: string;
};
max: {
value?: number;
useMetric: false;
metricName: string;
};
value: {
value?: number;
useMetric: false;
metricName: string;
};
min: ExtremumOptions;
max: ExtremumOptions;
value: ExtremumOptions;
};
}
export type ExtremumOptions = {
value?: number;
useMetric: false;
metricName: string;
};
export enum Pod {
LINE = 'Line',
BAR = 'Bar',

Loading…
Cancel
Save