Browse Source

get series from options

merge-requests/3/head
vargburz 3 years ago
parent
commit
302f509425
  1. 1
      src/components/Panel.tsx
  2. 28
      src/models/series.ts

1
src/components/Panel.tsx

@ -1,4 +1,3 @@
import { DataProcessor } from '../grafana/data_processor';
import { Options } from '../models/options'; import { Options } from '../models/options';
import { Series } from '../models/series'; import { Series } from '../models/series';

28
src/models/series.ts

@ -9,23 +9,37 @@ import * as _ from 'lodash';
export class Series { export class Series {
private processor; private processor;
private _seriesList; private _seriesList;
private _selectedSerieName;
constructor(private grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ExtremumOptions) { constructor(grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ExtremumOptions) {
if(this._isSerieOneValue()) { if(this._isSerieOneValue()) {
this._seriesList = [{ datapoints: [[0, gaugeValueOptions.value]] }]; this._seriesList = [{ datapoints: [[0, gaugeValueOptions.value]] }];
return; return;
} }
if(this.gaugeValueOptions.useMetric && _.isEmpty(this.gaugeValueOptions.metricName)) {
throw new Error(`Value or metric is not selected.`);
}
this._selectedSerieName = this.gaugeValueOptions.metricName;
this.processor = new DataProcessor({}); this.processor = new DataProcessor({});
this._seriesList = this.processor.getSeriesList({ const series = grafanaData.series;
dataList: grafanaData.series, const seriesList = this.processor.getSeriesList({
dataList: series,
range: timeRange, range: timeRange,
}); });
this._seriesList = this._updateSeriesListWithChartwerkParams(this._seriesList); console.log('_seriesList', seriesList);
const filteredSeries = _.filter(seriesList, serie => serie.alias === this._selectedSerieName);
if(filteredSeries.length === 0) {
throw new Error(`Can't find metric for ${this._selectedSerieName} name`);
}
if(filteredSeries.length > 1) {
throw new Error(`Get ${filteredSeries.length} metrics for ${this._selectedSerieName} name. Please choose one`);
}
console.log('filteredSeries', filteredSeries);
this._seriesList = this._updateSeriesListWithChartwerkParams(filteredSeries);
} }
public getChartwerkSeries(): any[] { public getChartwerkSeries(): any[] {
return this._seriesList return this._seriesList;
} }
private _updateSeriesListWithChartwerkParams(series: any[]): any[] { private _updateSeriesListWithChartwerkParams(series: any[]): any[] {
@ -40,6 +54,6 @@ export class Series {
} }
private _isSerieOneValue(): boolean { private _isSerieOneValue(): boolean {
return _.isNumber(this.gaugeValueOptions.value); return !this.gaugeValueOptions.useMetric;
} }
} }

Loading…
Cancel
Save