Skip to content

Commit aec12ef

Browse files
committed
removed unused code in codegen tooling, and made it auto exit when complete
1 parent ac4f861 commit aec12ef

File tree

2 files changed

+16
-122
lines changed

2 files changed

+16
-122
lines changed

devtools/regl_codegen/devtools.js

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,13 @@
22

33
/* global Plotly:false */
44

5-
var Fuse = require('fuse.js/dist/fuse.common.js');
65
var mocks = require('../../build/test_dashboard_mocks.json');
76
var reglTraces = require('../../build/regl_traces.json');
8-
var credentials = require('../../build/credentials.json');
97
var Lib = require('@src/lib');
108

119
// Our gracious testing object
1210
var Tabs = {
1311

14-
// Set plot config options
15-
setPlotConfig: function() {
16-
Plotly.setPlotConfig({
17-
18-
// use local topojson files
19-
topojsonURL: '../../node_modules/sane-topojson/dist/',
20-
21-
// register mapbox access token
22-
// run `npm run preset` if you haven't yet
23-
mapboxAccessToken: credentials.MAPBOX_ACCESS_TOKEN,
24-
25-
// show all logs in console
26-
logging: 2
27-
});
28-
},
29-
3012
// Return the specified plot container (or default one)
3113
getGraph: function(id) {
3214
id = id || 'graph';
@@ -86,74 +68,6 @@ var Tabs = {
8668
};
8769
})
8870
},
89-
90-
// Save a png snapshot and display it below the plot
91-
snapshot: function(id) {
92-
var gd = Tabs.getGraph(id);
93-
94-
if(!gd._fullLayout || !gd._fullData) {
95-
console.error('no graph with id ' + id + ' found.');
96-
return;
97-
}
98-
99-
var image = new Image();
100-
101-
Plotly.Snapshot.toImage(gd, { format: 'png' }).on('success', function(img) {
102-
image.src = img;
103-
104-
var imageDiv = document.getElementById('snapshot');
105-
imageDiv.appendChild(image);
106-
107-
console.warn('Snapshot complete!');
108-
});
109-
},
110-
111-
// Remove all plots and snapshots from the page
112-
purge: function() {
113-
var plots = document.getElementsByClassName('dashboard-plot');
114-
var images = document.getElementById('snapshot');
115-
116-
while(images.firstChild) {
117-
images.removeChild(images.firstChild);
118-
}
119-
120-
for(var i = 0; i < plots.length; i++) {
121-
Plotly.purge(plots[i]);
122-
}
123-
},
124-
125-
// Specify what to do after each plotly.js script reload
126-
onReload: function() {
127-
return;
128-
},
129-
130-
// Refreshes the plotly.js source without needing to refresh the page
131-
reload: function() {
132-
var source = document.getElementById('source');
133-
var reloaded = document.getElementById('reload-time');
134-
135-
source.remove();
136-
137-
window.Plotly = null;
138-
139-
source = document.createElement('script');
140-
source.id = 'source';
141-
source.src = '../../build/plotly.js';
142-
143-
document.body.appendChild(source);
144-
145-
var reloadTime = new Date().toLocaleTimeString();
146-
console.warn('plotly.js reloaded at ' + reloadTime);
147-
reloaded.textContent = 'last reload at ' + reloadTime;
148-
149-
var interval = setInterval(function() {
150-
if(window.Plotly) {
151-
clearInterval(interval);
152-
handleOnLoad();
153-
Tabs.onReload();
154-
}
155-
}, 100);
156-
}
15771
};
15872

15973

@@ -167,43 +81,7 @@ setInterval(function() {
16781
window.fullData = window.gd._fullData;
16882
}, 1000);
16983

170-
// Mocks search and plotting
171-
var fuse = new Fuse(mocks, {
172-
// isCaseSensitive: false,
173-
// includeScore: false,
174-
// shouldSort: true,
175-
// includeMatches: false,
176-
// findAllMatches: false,
177-
// minMatchCharLength: 1,
178-
// location: 0,
179-
// threshold: 0.6,
180-
// distance: 100,
181-
// useExtendedSearch: false,
182-
keys: [{
183-
name: 'name',
184-
weight: 0.7
185-
}, {
186-
name: 'keywords',
187-
weight: 0.3
188-
}]
189-
});
190-
191-
var transformInput = document.getElementById('css-transform');
192-
var mockInput = document.getElementById('mocks-search');
19384
var mocksList = document.getElementById('mocks-list');
194-
var plotArea = document.getElementById('plots');
195-
196-
function getNameFromHash() {
197-
return window.location.hash.replace(/^#/, '');
198-
}
199-
200-
function plotFromHash() {
201-
var initialMock = getNameFromHash();
202-
203-
if(initialMock.length > 0) {
204-
Tabs.plotMock(initialMock);
205-
}
206-
}
20785

20886
async function handleOnLoad() {
20987
var mocksByReglTrace = {};
@@ -260,4 +138,8 @@ async function handleOnLoad() {
260138
body
261139
});
262140
}
141+
142+
// close
143+
await fetch("/api/codegen-done");
144+
window.close();
263145
}

devtools/regl_codegen/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var minimist = require('minimist');
99
var constants = require('../../tasks/util/constants');
1010
var makeWatchifiedBundle = require('../../tasks/util/watchified_bundle');
1111
var shortcutPaths = require('../../tasks/util/shortcut_paths');
12+
const { exit } = require('process');
1213

1314
var args = minimist(process.argv.slice(2), {});
1415
var PORT = args.port || 3000;
@@ -21,6 +22,9 @@ var static = ecstatic({
2122
gzip: true,
2223
cors: true
2324
})
25+
26+
var tracesReceived = [];
27+
2428
var server = http.createServer(function (req, res) {
2529
if (req.method === 'POST' && req.url === '/api/submit-code') {
2630
var body = '';
@@ -30,10 +34,18 @@ var server = http.createServer(function (req, res) {
3034
req.on('end', function () {
3135
var data = JSON.parse(body);
3236

37+
tracesReceived.push(data.trace);
3338
handleCodegen(data);
3439
res.statusCode = 200;
3540
res.end();
3641
})
42+
} else if (req.method === 'GET' && req.url === '/api/codegen-done') {
43+
console.log('Codegen complete');
44+
console.log('Traces received:', tracesReceived);
45+
46+
res.statusCode = 200;
47+
res.end();
48+
setTimeout(() => exit(), 1000);
3749
} else {
3850
static(req, res);
3951
}

0 commit comments

Comments
 (0)