From 9ec0af73ecb0cb5fe1bde5fc1c94bac5cd2348d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 21 Nov 2018 11:38:15 +0100 Subject: [PATCH] fixed issue with new legend not checking if panel.legend.show (cherry picked from commit cab92f88afb6374eee354667c62dae6b9df5c6c4) --- public/app/plugins/panel/graph/graph.ts | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index c5f98792568..ff248d68201 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -58,15 +58,7 @@ class GraphElement { // panel events this.ctrl.events.on('panel-teardown', this.onPanelTeardown.bind(this)); - - /** - * Split graph rendering into two parts. - * First, calculate series stats in buildFlotPairs() function. Then legend rendering started - * (see ctrl.events.on('render') in legend.ts). - * When legend is rendered it emits 'legend-rendering-complete' and graph rendered. - */ this.ctrl.events.on('render', this.onRender.bind(this)); - this.ctrl.events.on('legend-rendering-complete', this.onLegendRenderingComplete.bind(this)); // global events appEvents.on('graph-hover', this.onGraphHover.bind(this), scope); @@ -85,11 +77,20 @@ class GraphElement { if (!this.data) { return; } + this.annotations = this.ctrl.annotations || []; this.buildFlotPairs(this.data); const graphHeight = this.elem.height(); updateLegendValues(this.data, this.panel, graphHeight); + if (!this.panel.legend.show) { + if (this.legendElem.hasChildNodes()) { + ReactDOM.unmountComponentAtNode(this.legendElem); + } + this.renderPanel(); + return; + } + const { values, min, max, avg, current, total } = this.panel.legend; const { alignAsTable, rightSide, sideWidth, sort, sortDesc, hideEmpty, hideZero } = this.panel.legend; const legendOptions = { alignAsTable, rightSide, sideWidth, sort, sortDesc, hideEmpty, hideZero }; @@ -104,12 +105,9 @@ class GraphElement { onColorChange: this.ctrl.onColorChange, onToggleAxis: this.ctrl.onToggleAxis, }; - const legendReactElem = React.createElement(Legend, legendProps); - ReactDOM.render(legendReactElem, this.legendElem, () => this.onLegendRenderingComplete()); - } - onLegendRenderingComplete() { - this.render_panel(); + const legendReactElem = React.createElement(Legend, legendProps); + ReactDOM.render(legendReactElem, this.legendElem, () => this.renderPanel()); } onGraphHover(evt) { @@ -281,7 +279,7 @@ class GraphElement { } // Function for rendering panel - render_panel() { + renderPanel() { this.panelWidth = this.elem.width(); if (this.shouldAbortRender()) { return;