Commit 854c360d by bergquist

Merge branch 'plopp-master'

parents fa99a674 0cbb95ed
......@@ -14,6 +14,41 @@ export function exportSeriesListToCsv(seriesList) {
saveSaveBlob(text, 'grafana_data_export.csv');
};
export function exportSeriesListToCsvColumns(seriesList) {
var text = 'Time;';
// add header
_.each(seriesList, function(series) {
text += series.alias + ';';
});
text = text.substring(0,text.length-1);
text += '\n';
// process data
var dataArr = [[]];
var sIndex = 1;
_.each(seriesList, function(series) {
var cIndex = 0;
dataArr.push([]);
_.each(series.datapoints, function(dp) {
dataArr[0][cIndex] = new Date(dp[1]).toISOString();
dataArr[sIndex][cIndex] = dp[0];
cIndex++;
});
sIndex++;
});
// make text
for (var i = 0; i < dataArr[0].length; i++) {
text += dataArr[0][i] + ';';
for (var j = 1; j < dataArr.length; j++) {
text += dataArr[j][i] + ';';
}
text = text.substring(0,text.length-1);
text += '\n';
}
saveSaveBlob(text, 'grafana_data_export.csv');
};
export function exportTableDataToCsv(table) {
var text = '';
// add header
......
......@@ -125,7 +125,8 @@ class GraphCtrl extends MetricsPanelCtrl {
getExtendedMenu() {
var menu = super.getExtendedMenu();
menu.push({text: 'Export CSV', click: 'ctrl.exportCsv()'});
menu.push({text: 'Export CSV (series as rows)', click: 'ctrl.exportCsv()'});
menu.push({text: 'Export CSV (series as columns)', click: 'ctrl.exportCsvColumns()'});
menu.push({text: 'Toggle legend', click: 'ctrl.toggleLegend()'});
return menu;
}
......@@ -295,6 +296,10 @@ class GraphCtrl extends MetricsPanelCtrl {
exportCsv() {
fileExport.exportSeriesListToCsv(this.seriesList);
}
exportCsvColumns() {
fileExport.exportSeriesListToCsvColumns(this.seriesList);
}
}
export {GraphCtrl, GraphCtrl as PanelCtrl}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment