first commit
This commit is contained in:
55
tools/qalc/flaviut/gnuplot-worker.js
Normal file
55
tools/qalc/flaviut/gnuplot-worker.js
Normal file
@@ -0,0 +1,55 @@
|
||||
let pendingRequests = [];
|
||||
|
||||
self.addEventListener('message', ({ data }) => {
|
||||
if (pendingRequests) {
|
||||
// gnuplot not loaded yet
|
||||
pendingRequests.push(data);
|
||||
} else {
|
||||
doPlot(data);
|
||||
}
|
||||
});
|
||||
|
||||
var Module = {
|
||||
noInitialRun: true,
|
||||
postRun: () => {
|
||||
shouldRunNow = true;
|
||||
pendingRequests.forEach(doPlot);
|
||||
pendingRequests = null;
|
||||
},
|
||||
print: (s) => {
|
||||
console.log('GNUPLOT LOG: ' + s);
|
||||
},
|
||||
printErr: (s) => {
|
||||
console.warn('GNUPLOT ERR: ' + s);
|
||||
},
|
||||
};
|
||||
|
||||
function doPlot({
|
||||
fix_cmd = true,
|
||||
data_files = {},
|
||||
commands,
|
||||
id,
|
||||
// TODO: do something with these...?
|
||||
extra_commandline,
|
||||
persist,
|
||||
}) {
|
||||
const files = Object.keys(data_files);
|
||||
for (const [file, data] of Object.entries(data_files)) {
|
||||
FS.writeFile(file, data);
|
||||
}
|
||||
const cmd = fix_cmd
|
||||
? commands.replace(
|
||||
'set terminal pop',
|
||||
"set terminal svg; set output '/output'"
|
||||
)
|
||||
: commands;
|
||||
FS.writeFile('/commands', cmd);
|
||||
callMain(['/commands']);
|
||||
const output = FS.readFile('/output', { encoding: 'utf8' });
|
||||
for (const file of ['/commands', '/output', ...files]) {
|
||||
FS.unlink(file);
|
||||
}
|
||||
self.postMessage({ id, output });
|
||||
}
|
||||
|
||||
importScripts('gnuplot.js');
|
||||
Reference in New Issue
Block a user