Skip to content

Commit

Permalink
Implemented support for data in table format.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurla committed Nov 4, 2018
1 parent ef177b7 commit 3b09fef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -63,7 +63,7 @@ onHandleMetric(ctrl: MetricsPanelCtrl, svgnode: HTMLElement)
```

`ctrl` passes a grafana `MetricsPanelCtrl` object. This object contains all relevant data pertainig the current panel.
You may want to use the `ctrl.series` array property to access the current measurement data.
You may want to use the `ctrl.series` or `ctrl.tables` array property to access the current measurement data.

`svgnode` passes the HTMLElement of the svg object on the panel. You can access the elements of the svg itself by using the integrated Snap Library. ([http://snapsvg.io/](http://snapsvg.io/))

Expand All @@ -81,7 +81,7 @@ onHandleMetric(ctrl: MetricsPanelCtrl, svgnode: HTMLElement)
```

`ctrl` passes a grafana `MetricsPanelCtrl` object. This object contains all relevant data pertainig the current panel.
You may want to use the `ctrl.series` array property to access the current measurement data.
You may want to use the `ctrl.series` or `ctrl.tables` array property to access the current measurement data.

`svgnode` passes the HTMLElement of the svg object on the panel. You can access the elements of the svg itself by using the integrated Snap Library. ([http://snapsvg.io/](http://snapsvg.io/))

Expand Down
26 changes: 25 additions & 1 deletion src/svg_ctrl.js
Expand Up @@ -239,7 +239,13 @@ export class SVGCtrl extends MetricsPanelCtrl {
}

onDataReceived(dataList) {
this.series = dataList.map(this.seriesHandler.bind(this));

if (dataList.length > 0 && dataList[0].type === 'table') {
this.tables = dataList.map(this.tableHandler.bind(this));
} else {
this.series = dataList.map(this.seriesHandler.bind(this));
}

this.render();
}

Expand All @@ -256,6 +262,24 @@ export class SVGCtrl extends MetricsPanelCtrl {
series.flotpairs = series.getFlotPairs(this.panel.nullPointMode);
return series;
}

tableHandler(tableData) {

const columnNames = tableData.columns.map(column => column.text);

const rows = tableData.rows.map(row => {
const datapoint = {};

row.forEach((value, columnIndex) => {
const key = columnNames[columnIndex];
datapoint[key] = value;
});

return datapoint;
});

return { columnNames: columnNames, rows: rows };
}

getSeriesIdByAlias(aliasName) {
for (var i = 0; i < this.series.length; i++) {
Expand Down

0 comments on commit 3b09fef

Please sign in to comment.