vargburz
3 years ago
3 changed files with 72 additions and 39 deletions
@ -0,0 +1,27 @@
|
||||
import { PanelOptions } from 'types'; |
||||
|
||||
// Convert Grafana options into Chartwerk options
|
||||
export class Options { |
||||
constructor(private grafanaOptions: PanelOptions) {} |
||||
|
||||
public getChartwerkOptions(): any { |
||||
return { |
||||
maxValue: this.grafanaOptions.gauge.max.value || 0, |
||||
minValue: this.grafanaOptions.gauge.min.value || 0, |
||||
valueFormatter: (val: any) => val.toFixed(2), |
||||
defaultColor: 'green', |
||||
stops: [ |
||||
{ |
||||
color: 'green', |
||||
value: 100, |
||||
}, |
||||
{ |
||||
color: 'orange', |
||||
value: 140, |
||||
}, |
||||
], |
||||
// @ts-ignore
|
||||
icons: [{ src: 'https://cityhost.ua/upload_img/blog5ef308ea5529c_trash2-01.jpg', position: 'middle', size: 30 }], |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
import { PanelData, TimeRange } from '@grafana/data'; |
||||
import { DataProcessor } from '../grafana/data_processor'; |
||||
|
||||
import * as _ from 'lodash'; |
||||
|
||||
// Convert Grafana options into Chartwerk options
|
||||
export class Series { |
||||
private processor;
|
||||
private _seriesList; |
||||
|
||||
constructor(private grafanaData: PanelData, timeRange: TimeRange) { |
||||
this.processor = new DataProcessor({}); |
||||
const seriesList = this.processor.getSeriesList({ |
||||
dataList: grafanaData.series, |
||||
range: timeRange, |
||||
}); |
||||
this._seriesList = this._updateSeriesListWithChartwerkParams(seriesList); |
||||
} |
||||
|
||||
public 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(row)), |
||||
alias: serie.label, |
||||
}; |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue