From 0ec5b2eaab12a423f7ad1285d86cf3cae8dc86ef Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Mon, 26 Apr 2021 11:01:12 -0500 Subject: [PATCH] Add buttons for saving loading camera views --- .../widgets/PlotlyGraph/PlotlyGraphWidget.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/visualizers/widgets/PlotlyGraph/PlotlyGraphWidget.js b/src/visualizers/widgets/PlotlyGraph/PlotlyGraphWidget.js index 411ded0..065b0e8 100644 --- a/src/visualizers/widgets/PlotlyGraph/PlotlyGraphWidget.js +++ b/src/visualizers/widgets/PlotlyGraph/PlotlyGraphWidget.js @@ -88,6 +88,37 @@ define([ json.layout.plot_bgcolor = PLOT_BG_COLOR; json.layout.paper_bgcolor = PLOT_BG_COLOR; + const icon1 = { + 'width': 500, + 'height': 600, + 'path': 'M224 512c35.32 0 63.97-28.65 63.97-64H160.03c0 35.35 28.65 64 63.97 64zm215.39-149.71c-19.32-20.76-55.47-51.99-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32c0-17.67-14.32-32-31.98-32s-31.98 14.33-31.98 32v20.84C118.56 68.1 64.08 130.3 64.08 208c0 102.3-36.15 133.53-55.47 154.29-6 6.45-8.66 14.16-8.61 21.71.11 16.4 12.98 32 32.1 32h383.8c19.12 0 32-15.6 32.1-32 .05-7.55-2.61-15.27-8.61-21.71z' + }; + json.config = { + modeBarButtonsToAdd: [ + { + name: 'save camera', + icon: icon1, + click: function(gd) { + var scene = gd._fullLayout.scene._scene; + const layout = {}; + scene.saveLayout(layout); + localStorage['camera'] = JSON.stringify(layout.scene); + } + }, + { + name: 'reset camera', + icon: icon1, + click: function(gd) { + var scene = gd._fullLayout.scene._scene; + if (localStorage['camera']) { + const cameraView = JSON.parse(localStorage['camera']); + scene.setViewport(cameraView); + } + } + } + ], + modeBarButtonsToRemove: ['pan2d','select2d','lasso2d','resetScale2d','zoomOut2d'] + }; Plotly.newPlot(plotlyDiv[0], json); this.plots.push(plotlyDiv); this.$el.append(plotlyDiv);