From f158d74e3b181095bc0e814017a2dc0dda2c972f Mon Sep 17 00:00:00 2001 From: corpglory-dev Date: Wed, 18 Mar 2020 20:59:22 +0300 Subject: [PATCH 1/3] re-render layout --- src/module.ts | 57 ++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/module.ts b/src/module.ts index 3c52a39..1e6a093 100644 --- a/src/module.ts +++ b/src/module.ts @@ -422,23 +422,9 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { return; } - if (!this.initialized) { - const s = this.cfg.settings; - - const options = { - showLink: false, - displaylogo: false, - displayModeBar: s.displayModeBar, - modeBarButtonsToRemove: ['sendDataToCloud'], //, 'select2d', 'lasso2d'] - }; - - this.layout = this.getProcessedLayout(); - this.layout.shapes = this.annotations.shapes; - let traces = this.traces; - if (this.annotations.shapes.length > 0) { - traces = this.traces.concat(this.annotations.trace); - } - Plotly.react(this.graphDiv, traces, this.layout, options); + const isLayoutChanged = !_.isEqual(this.layout, this.getProcessedLayout()); + if (!this.initialized || isLayoutChanged) { + this.plotlyReact(); this.graphDiv.on('plotly_click', data => { if (data === undefined || data.points === undefined) { @@ -740,6 +726,26 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { return true; } + plotlyReact() { + const s = this.cfg.settings; + + const options = { + showLink: false, + displaylogo: false, + displayModeBar: s.displayModeBar, + modeBarButtonsToRemove: ['sendDataToCloud'], //, 'select2d', 'lasso2d'] + }; + + this.layout = this.getProcessedLayout(); + this.layout.shapes = this.annotations.shapes; + let traces = this.traces; + if (this.annotations.shapes.length > 0) { + traces = this.traces.concat(this.annotations.trace); + } + console.log('ConfigChanged (traces)', traces); + Plotly.react(this.graphDiv, traces, this.layout, options); + } + onConfigChanged() { // Force reloading the traces this._updateTraceData(true); @@ -762,22 +768,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { if (!this.cfg.showAnnotations) { this.annotations.clear(); } - - const s = this.cfg.settings; - const options = { - showLink: false, - displaylogo: false, - displayModeBar: s.displayModeBar, - modeBarButtonsToRemove: ['sendDataToCloud'], //, 'select2d', 'lasso2d'] - }; - this.layout = this.getProcessedLayout(); - this.layout.shapes = this.annotations.shapes; - let traces = this.traces; - if (this.annotations.shapes.length > 0) { - traces = this.traces.concat(this.annotations.trace); - } - console.log('ConfigChanged (traces)', traces); - Plotly.react(this.graphDiv, traces, this.layout, options); + this.plotlyReact(); } this.render(); // does not query again! From 2bbf7f31245a4d6c49b7c9b9b1a4a11b6c600432 Mon Sep 17 00:00:00 2001 From: corpglory-dev Date: Wed, 18 Mar 2020 21:14:03 +0300 Subject: [PATCH 2/3] plotlyReact -> createOrUpdatePlot --- src/module.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/module.ts b/src/module.ts index 1e6a093..80f96a1 100644 --- a/src/module.ts +++ b/src/module.ts @@ -424,7 +424,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { const isLayoutChanged = !_.isEqual(this.layout, this.getProcessedLayout()); if (!this.initialized || isLayoutChanged) { - this.plotlyReact(); + this.createOrUpdatePlot(); this.graphDiv.on('plotly_click', data => { if (data === undefined || data.points === undefined) { @@ -726,7 +726,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { return true; } - plotlyReact() { + createOrUpdatePlot(): void { const s = this.cfg.settings; const options = { @@ -768,7 +768,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { if (!this.cfg.showAnnotations) { this.annotations.clear(); } - this.plotlyReact(); + this.createOrUpdatePlot(); } this.render(); // does not query again! From e46dc8313025d407e7af04e345dd4a91bd70521f Mon Sep 17 00:00:00 2001 From: corpglory-dev Date: Wed, 18 Mar 2020 21:17:57 +0300 Subject: [PATCH 3/3] rm console log --- src/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module.ts b/src/module.ts index 80f96a1..a33f611 100644 --- a/src/module.ts +++ b/src/module.ts @@ -742,7 +742,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl { if (this.annotations.shapes.length > 0) { traces = this.traces.concat(this.annotations.trace); } - console.log('ConfigChanged (traces)', traces); + Plotly.react(this.graphDiv, traces, this.layout, options); }