From 9d961833dcd0940083b02f257a08606170999f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 3 Aug 2016 22:57:16 -0400 Subject: [PATCH] devtools: plot from hash on reload --- devtools/test_dashboard/devtools.js | 33 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/devtools/test_dashboard/devtools.js b/devtools/test_dashboard/devtools.js index c7c93cf4193..104c759d024 100644 --- a/devtools/test_dashboard/devtools.js +++ b/devtools/test_dashboard/devtools.js @@ -6,9 +6,7 @@ var Fuse = require('fuse.js'); var mocks = require('../../build/test_dashboard_mocks.json'); var credentials = require('../../build/credentials.json'); var Lib = require('@src/lib'); - -// put d3 in window scope -var d3 = window.d3 = Plotly.d3; +var d3 = Plotly.d3; // Our gracious testing object var Tabs = { @@ -140,7 +138,7 @@ var Tabs = { var interval = setInterval(function() { if(window.Plotly) { clearInterval(interval); - Tabs.setPlotConfig(); + handleOnLoad(); Tabs.onReload(); } }, 100); @@ -151,15 +149,14 @@ var Tabs = { // Bind things to the window window.Tabs = Tabs; window.Lib = Lib; +window.d3 = d3; +window.onload = handleOnLoad; setInterval(function() { window.gd = Tabs.getGraph() || Tabs.fresh(); window.fullLayout = window.gd._fullLayout; window.fullData = window.gd._fullData; }, 1000); -// Set plot config on first load -Tabs.setPlotConfig(); - // Mocks search and plotting var f = new Fuse(mocks, { keys: [{ @@ -177,14 +174,6 @@ var plotArea = document.getElementById('plots'); searchBar.addEventListener('keyup', debounce(searchMocks, 250)); -window.onload = function() { - var initialMock = window.location.hash.replace(/^#/, ''); - - if(initialMock.length > 0) { - Tabs.plotMock(initialMock); - } -}; - function debounce(func, wait, immediate) { var timeout; return function() { @@ -207,7 +196,6 @@ function searchMocks(e) { mocksList.removeChild(mocksList.firstChild); } - var results = f.search(e.target.value); results.forEach(function(r) { @@ -231,3 +219,16 @@ function searchMocks(e) { plotArea.setAttribute('style', 'width: ' + plotAreaWidth + 'px;'); }); } + +function plotFromHash() { + var initialMock = window.location.hash.replace(/^#/, ''); + + if(initialMock.length > 0) { + Tabs.plotMock(initialMock); + } +} + +function handleOnLoad() { + Tabs.setPlotConfig(); + plotFromHash(); +}