You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.1 KiB

import { ValueOptions } from 'types';
import { filterMetricListByAlias } from '../utils';
import * as _ from 'lodash';
// Convert Grafana series into Chartwerk series
export class Series {
private _seriesList;
private _selectedSerieName;
constructor(grafanaSeriesList: any, private gaugeValueOptions: ValueOptions) {
if (_.isEmpty(this.gaugeValueOptions?.metricName)) {
throw new Error(`Value: metric is not selected. [See options: Value -> Metric]`);
}
this._selectedSerieName = this.gaugeValueOptions.metricName;
const filteredSeries = filterMetricListByAlias(grafanaSeriesList, this._selectedSerieName, 'Value');
this._seriesList = this._updateSeriesListWithChartwerkParams(filteredSeries);
}
getChartwerkSeries(): any[] {
return this._seriesList;
}
private _updateSeriesListWithChartwerkParams(series: any[]): any[] {
return _.map(series, (serie: any, idx: number) => {
return {
target: serie.alias,
color: serie.color,
datapoints: _.map(serie.datapoints, (row) => _.reverse(_.clone(row))),
alias: serie.label,
};
});
}
}