|
|
|
@ -9,23 +9,37 @@ import * as _ from 'lodash';
|
|
|
|
|
export class Series { |
|
|
|
|
private processor;
|
|
|
|
|
private _seriesList; |
|
|
|
|
private _selectedSerieName; |
|
|
|
|
|
|
|
|
|
constructor(private grafanaData: PanelData, timeRange: TimeRange, private gaugeValueOptions: ExtremumOptions) { |
|
|
|
|
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)) { |
|
|
|
|
throw new Error(`Value or metric is not selected.`); |
|
|
|
|
} |
|
|
|
|
this._selectedSerieName = this.gaugeValueOptions.metricName; |
|
|
|
|
this.processor = new DataProcessor({}); |
|
|
|
|
this._seriesList = this.processor.getSeriesList({ |
|
|
|
|
dataList: grafanaData.series, |
|
|
|
|
const series = grafanaData.series; |
|
|
|
|
const seriesList = this.processor.getSeriesList({ |
|
|
|
|
dataList: series, |
|
|
|
|
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[] { |
|
|
|
|
return this._seriesList |
|
|
|
|
return this._seriesList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private _updateSeriesListWithChartwerkParams(series: any[]): any[] { |
|
|
|
@ -40,6 +54,6 @@ export class Series {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private _isSerieOneValue(): boolean { |
|
|
|
|
return _.isNumber(this.gaugeValueOptions.value); |
|
|
|
|
return !this.gaugeValueOptions.useMetric; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|