Commit 6a42b95d by Torkel Ödegaard

feat(panels): panel refactorings

parent cb49e11e
...@@ -60,7 +60,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -60,7 +60,7 @@ class MetricsPanelCtrl extends PanelCtrl {
// if we have snapshot data use that // if we have snapshot data use that
if (this.panel.snapshotData) { if (this.panel.snapshotData) {
this.updateTimeRange(); this.updateTimeRange();
this.events.emit('load-snapshot', this.panel.snapshotData); this.events.emit('data-snapshot-load', this.panel.snapshotData);
return; return;
} }
......
...@@ -109,6 +109,7 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -109,6 +109,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.events.on('data-received', this.onDataReceived.bind(this)); this.events.on('data-received', this.onDataReceived.bind(this));
this.events.on('data-error', this.onDataError.bind(this)); this.events.on('data-error', this.onDataError.bind(this));
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));
} }
initEditMode() { initEditMode() {
...@@ -150,9 +151,9 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -150,9 +151,9 @@ class GraphCtrl extends MetricsPanelCtrl {
this.publishAppEvent('zoom-out', evt); this.publishAppEvent('zoom-out', evt);
} }
loadSnapshot(snapshotData) { onDataSnapshotLoad(snapshotData) {
this.annotationsPromise = this.annotationsSrv.getAnnotations(this.dashboard); this.annotationsPromise = this.annotationsSrv.getAnnotations(this.dashboard);
this.dataHandler(snapshotData); this.onDataReceived(snapshotData.data);
} }
onDataError(err) { onDataError(err) {
......
...@@ -56,6 +56,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -56,6 +56,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
this.events.on('data-received', this.onDataReceived.bind(this)); this.events.on('data-received', this.onDataReceived.bind(this));
this.events.on('data-error', this.onDataError.bind(this)); this.events.on('data-error', this.onDataError.bind(this));
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));
} }
initEditMode() { initEditMode() {
...@@ -71,9 +72,8 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -71,9 +72,8 @@ class SingleStatCtrl extends MetricsPanelCtrl {
this.render(); this.render();
} }
loadSnapshot(snapshotData) { onDataSnapshotLoad(snapshotData) {
// give element time to get attached and get dimensions this.onDataReceived(snapshotData.data);
this.$timeout(() => this.dataHandler(snapshotData), 50);
} }
onDataError(err) { onDataError(err) {
...@@ -284,8 +284,14 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -284,8 +284,14 @@ class SingleStatCtrl extends MetricsPanelCtrl {
function addSparkline() { function addSparkline() {
var width = elem.width() + 20; var width = elem.width() + 20;
var height = ctrl.height; if (width < 30) {
// element has not gotten it's width yet
// delay sparkline render
setTimeout(addSparkline, 30);
return;
}
var height = ctrl.height;
var plotCanvas = $('<div></div>'); var plotCanvas = $('<div></div>');
var plotCss: any = {}; var plotCss: any = {};
plotCss.position = 'absolute'; plotCss.position = 'absolute';
......
...@@ -60,6 +60,7 @@ class TablePanelCtrl extends MetricsPanelCtrl { ...@@ -60,6 +60,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
this.events.on('data-received', this.onDataReceived.bind(this)); this.events.on('data-received', this.onDataReceived.bind(this));
this.events.on('data-error', this.onDataError.bind(this)); this.events.on('data-error', this.onDataError.bind(this));
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));
} }
initEditMode() { initEditMode() {
...@@ -86,6 +87,10 @@ class TablePanelCtrl extends MetricsPanelCtrl { ...@@ -86,6 +87,10 @@ class TablePanelCtrl extends MetricsPanelCtrl {
return super.issueQueries(datasource); return super.issueQueries(datasource);
} }
onDataSnapshotLoad(data) {
this.onDataReceived(data.data);
}
onDataError(err) { onDataError(err) {
this.dataRaw = []; this.dataRaw = [];
this.render(); this.render();
...@@ -141,15 +146,13 @@ class TablePanelCtrl extends MetricsPanelCtrl { ...@@ -141,15 +146,13 @@ class TablePanelCtrl extends MetricsPanelCtrl {
var formaters = []; var formaters = [];
function getTableHeight() { function getTableHeight() {
var panelHeight = ctrl.height || ctrl.panel.height || ctrl.row.height; var panelHeight = ctrl.height;
if (_.isString(panelHeight)) {
panelHeight = parseInt(panelHeight.replace('px', ''), 10);
}
if (pageCount > 1) { if (pageCount > 1) {
panelHeight -= 28; panelHeight -= 26;
} }
return (panelHeight - 60) + 'px'; return (panelHeight - 31) + 'px';
} }
function appendTableRows(tbodyElem) { function appendTableRows(tbodyElem) {
......
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