Browse Source

serie as one value

merge-requests/3/head
vargburz 2 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) { export function Panel({ options, data, width, height, timeZone, timeRange, onChangeTimeRange }: Props) {
console.log('options', options); 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); console.log('series', series);
const chartwerkOptions = new Options(options).getChartwerkOptions(); const chartwerkOptions = new Options(options).getChartwerkOptions();

19
src/models/series.ts

@ -1,6 +1,8 @@
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 * as _ from 'lodash'; import * as _ from 'lodash';
// Convert Grafana options into Chartwerk options // Convert Grafana options into Chartwerk options
@ -8,17 +10,22 @@ export class Series {
private processor; private processor;
private _seriesList; 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({}); this.processor = new DataProcessor({});
const seriesList = this.processor.getSeriesList({ this._seriesList = this.processor.getSeriesList({
dataList: grafanaData.series, dataList: grafanaData.series,
range: timeRange, range: timeRange,
}); });
this._seriesList = this._updateSeriesListWithChartwerkParams(seriesList); this._seriesList = this._updateSeriesListWithChartwerkParams(this._seriesList);
} }
public getChartwerkSeries(): any[] { public getChartwerkSeries(): any[] {
return this._seriesList; return this._seriesList
} }
private _updateSeriesListWithChartwerkParams(series: any[]): any[] { 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 { export interface PanelOptions {
visualizationType: Pod; visualizationType: Pod;
gauge: { gauge: {
min: { min: ExtremumOptions;
value?: number; max: ExtremumOptions;
useMetric: false; value: ExtremumOptions;
metricName: string;
};
max: {
value?: number;
useMetric: false;
metricName: string;
};
value: {
value?: number;
useMetric: false;
metricName: string;
};
}; };
} }
export type ExtremumOptions = {
value?: number;
useMetric: false;
metricName: string;
};
export enum Pod { export enum Pod {
LINE = 'Line', LINE = 'Line',
BAR = 'Bar', BAR = 'Bar',

Loading…
Cancel
Save