Skip to content

Commit 95cd7ac

Browse files
Merge pull request #3850 from plotly/local-gd-for-toolpanel
Local `gd` for toolpanel
2 parents e1644a8 + 9af5db4 commit 95cd7ac

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

shelly/plotlyjs/static/plotlyjs/src/graph_obj.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ plots.getSubplotData = function getSubplotData(data, type, subplotId) {
194194

195195
// new workspace tab. Perhaps this goes elsewhere, a workspace-only file???
196196
plots.newTab = function(divid, layout) {
197-
Plotly.ToolPanel.makeMenu(document.getElementById(divid));
197+
var gd = document.getElementById(divid);
198+
var toolPanel = new Plotly.ToolPanel(Plotly, gd);
199+
200+
toolPanel.makeMenu();
201+
198202
var config = {
199203
workspace: true,
200204
editable: true,
@@ -524,7 +528,7 @@ Plotly.plot = function(gd, data, layout, config) {
524528
// Polar plots
525529
if(data && data[0] && data[0].r) return plotPolar(gd, data, layout);
526530

527-
if(gd._context.editable) Plotly.ToolPanel.tweakMenu(gd);
531+
if(gd._context.editable) gd.toolPanel.tweakMenu();
528532

529533
// so we don't try to re-call Plotly.plot from inside
530534
// legend and colorbar, if margins changed
@@ -938,7 +942,7 @@ function plotPolar(gd, data, layout) {
938942
};
939943
title.call(setContenteditable);
940944

941-
Plotly.ToolPanel.tweakMenu(gd);
945+
gd.toolPanel.tweakMenu();
942946
}
943947

944948
gd._context.setBackground(gd, gd._fullLayout.paper_bgcolor);

test-dashboard/toolpanel-dashboard/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
<link type="text/css" rel="stylesheet" href="./../../shelly/shelly/static/css/jquery-ui.css"/>
77
<link type="text/css" rel="stylesheet" href="./../../shelly/shelly/static/css/spectrum.css"/>
88
<link type="text/css" rel="stylesheet" href="./../../shelly/shelly/static/css/bootstrap-select.min.css" />
9+
<link type="text/css" rel="stylesheet" href="./../../shelly/shelly/static/css/tipsy.css" />
910

1011
<!-- ToolPanel Required Plotly CSS -->
11-
<link rel="stylesheet" type="text/css" href="style.css"/>
12+
<link rel="stylesheet" type="text/css" href="workspace-style.css"/>
1213
<link rel="stylesheet" type="text/css" href="./../../shelly/shelly/static/css/plotly.css"/>
1314
<link rel="stylesheet" type="text/css" href="./../../shelly/shelly/static/plotlycss/fonts/unified/icons.css" />
1415

1516
</head>
1617

1718
<body>
1819

20+
<div id="main"></div>
21+
1922
<!-- Dashboard Mock Stuff -->
2023
<script type"text/javascript" src="mocks.js"></script>
2124

@@ -26,6 +29,7 @@
2629

2730
<!-- ToolPanel Required Plugins' JS -->
2831
<script type="text/javascript" src="./../../shelly/shelly/static/js/plugins/jquery-ui-1.8.23.custom.min.js"></script>
32+
<script type="text/javascript" src="./../../shelly/shelly/static/js/plugins/jquery.tipsy.js"></script>
2933
<script type="text/javascript" src="./../../shelly/shelly/static/js/plugins/spectrum.js"></script>
3034
<script type="text/javascript" src="./../../shelly/shelly/static/js/plugins/bootstrap.min.js"></script>
3135
<script type="text/javascript" src="./../../shelly/shelly/static/js/plugins/bootstrap-select.min.js"></script>

test-dashboard/toolpanel-dashboard/mocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var Tabs = {
44
get: function() {
5-
return document.getElementById('yo').children[0];
5+
return document.getElementById('main').children[0];
66
},
77
fresh: function() {
88
var anchor = document.getElementById('embedded-graph'),

test-dashboard/toolpanel-dashboard/ui.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
'use strict';
22

3-
Plotly = window.Plotly;
4-
5-
(function createPlot (divId) {
3+
var Plotly = window.Plotly;
4+
var ToolPanel = window.ToolPanel;
5+
var divs = [];
66

7+
function createPlot (divId) {
8+
var containerDiv = document.getElementById('main');
79
var graphDiv = document.createElement('div');
810
graphDiv.id = divId;
9-
document.body.appendChild(graphDiv);
11+
graphDiv.style.width = '45%';
12+
graphDiv.style.display = 'inline-block';
13+
graphDiv.style.margin = '10px';
14+
graphDiv.style.position = 'relative';
15+
containerDiv.appendChild(graphDiv);
1016

1117
var trace1 = {
1218
x: [1, 2, 3, 4],
@@ -24,7 +30,15 @@ Plotly = window.Plotly;
2430

2531
Plotly.newPlot(divId, data);
2632

27-
var toolPanel = new ToolPanel({Plotly: Plotly});
28-
toolPanel.makeMenu(graphDiv);
33+
graphDiv.toolPanel = new ToolPanel(Plotly, graphDiv, {
34+
standalone: true
35+
});
36+
graphDiv.toolPanel.makeMenu(graphDiv);
37+
38+
divs.push(graphDiv);
39+
40+
}
2941

30-
})('yo');
42+
['one', 'two'].forEach(function (index) {
43+
createPlot(index);
44+
});

0 commit comments

Comments
 (0)