Skip to content

Plot from hash on test dashboard reload #824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions devtools/test_dashboard/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -140,7 +138,7 @@ var Tabs = {
var interval = setInterval(function() {
if(window.Plotly) {
clearInterval(interval);
Tabs.setPlotConfig();
handleOnLoad();
Tabs.onReload();
}
}, 100);
Expand All @@ -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: [{
Expand All @@ -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() {
Expand All @@ -207,7 +196,6 @@ function searchMocks(e) {
mocksList.removeChild(mocksList.firstChild);
}


var results = f.search(e.target.value);

results.forEach(function(r) {
Expand All @@ -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();
}