Skip to content

Commit 7710153

Browse files
authored
Merge pull request #824 from plotly/better-dashboard-reload
Plot from hash on test dashboard reload
2 parents a979e55 + 9d96183 commit 7710153

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

devtools/test_dashboard/devtools.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ var Fuse = require('fuse.js');
66
var mocks = require('../../build/test_dashboard_mocks.json');
77
var credentials = require('../../build/credentials.json');
88
var Lib = require('@src/lib');
9-
10-
// put d3 in window scope
11-
var d3 = window.d3 = Plotly.d3;
9+
var d3 = Plotly.d3;
1210

1311
// Our gracious testing object
1412
var Tabs = {
@@ -140,7 +138,7 @@ var Tabs = {
140138
var interval = setInterval(function() {
141139
if(window.Plotly) {
142140
clearInterval(interval);
143-
Tabs.setPlotConfig();
141+
handleOnLoad();
144142
Tabs.onReload();
145143
}
146144
}, 100);
@@ -151,15 +149,14 @@ var Tabs = {
151149
// Bind things to the window
152150
window.Tabs = Tabs;
153151
window.Lib = Lib;
152+
window.d3 = d3;
153+
window.onload = handleOnLoad;
154154
setInterval(function() {
155155
window.gd = Tabs.getGraph() || Tabs.fresh();
156156
window.fullLayout = window.gd._fullLayout;
157157
window.fullData = window.gd._fullData;
158158
}, 1000);
159159

160-
// Set plot config on first load
161-
Tabs.setPlotConfig();
162-
163160
// Mocks search and plotting
164161
var f = new Fuse(mocks, {
165162
keys: [{
@@ -177,14 +174,6 @@ var plotArea = document.getElementById('plots');
177174

178175
searchBar.addEventListener('keyup', debounce(searchMocks, 250));
179176

180-
window.onload = function() {
181-
var initialMock = window.location.hash.replace(/^#/, '');
182-
183-
if(initialMock.length > 0) {
184-
Tabs.plotMock(initialMock);
185-
}
186-
};
187-
188177
function debounce(func, wait, immediate) {
189178
var timeout;
190179
return function() {
@@ -207,7 +196,6 @@ function searchMocks(e) {
207196
mocksList.removeChild(mocksList.firstChild);
208197
}
209198

210-
211199
var results = f.search(e.target.value);
212200

213201
results.forEach(function(r) {
@@ -231,3 +219,16 @@ function searchMocks(e) {
231219
plotArea.setAttribute('style', 'width: ' + plotAreaWidth + 'px;');
232220
});
233221
}
222+
223+
function plotFromHash() {
224+
var initialMock = window.location.hash.replace(/^#/, '');
225+
226+
if(initialMock.length > 0) {
227+
Tabs.plotMock(initialMock);
228+
}
229+
}
230+
231+
function handleOnLoad() {
232+
Tabs.setPlotConfig();
233+
plotFromHash();
234+
}

0 commit comments

Comments
 (0)