@live-codes/browser-compilers 0.4.11 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gnuplot/gnuplot.js +4675 -0
- package/dist/gnuplot/gnuplot_api.js +99 -0
- package/package.json +2 -2
- package/scripts/vendors.js +11 -0
- package/vendor-licenses.md +2 -0
- package/vendor_modules/src/gnuplot-JS/LICENSE +21 -0
- package/vendor_modules/src/gnuplot-JS/README +55 -0
- package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/em_make +7 -0
- package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/gnuplot-4.6.3.patch +13 -0
- package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/post.js +17 -0
- package/vendor_modules/src/gnuplot-JS/gnuplot-4.6.3/pre.js +62 -0
- package/vendor_modules/src/gnuplot-JS/www/gnuplot.js +4675 -0
- package/vendor_modules/src/gnuplot-JS/www/gnuplot_api.js +99 -0
- package/vendor_modules/src/gnuplot-JS/www/index.html +182 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// This is a minimal interface to the gnuplot worker. More sophisticated include virtual file-system lists and a reset function.
|
|
2
|
+
|
|
3
|
+
var Gnuplot = function (js_filename) {
|
|
4
|
+
this.worker = new Worker(js_filename);
|
|
5
|
+
this.output = [];
|
|
6
|
+
this.error = [];
|
|
7
|
+
this.isRunning = false;
|
|
8
|
+
|
|
9
|
+
// These two should be overwritten by application.
|
|
10
|
+
this.onOutput = function (text) {
|
|
11
|
+
console.log('Gnuplot output: ' + text);
|
|
12
|
+
};
|
|
13
|
+
this.onError = function (text) {
|
|
14
|
+
console.log('Gnuplot error: ' + text);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
this.transaction = 1;
|
|
18
|
+
this.callbacks = [];
|
|
19
|
+
this.postCommand = function (cmd_block, callback) {
|
|
20
|
+
var id = this.transaction; // fresh id
|
|
21
|
+
cmd_block.transaction = id; // give data object a tag
|
|
22
|
+
this.callbacks[id] = callback;
|
|
23
|
+
this.worker.postMessage(cmd_block);
|
|
24
|
+
this.transaction++;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var that = this;
|
|
28
|
+
this.worker.addEventListener(
|
|
29
|
+
'message',
|
|
30
|
+
function (e) {
|
|
31
|
+
// console.log('gnuplot: ', e.data); //enable for debug
|
|
32
|
+
var data = e.data;
|
|
33
|
+
if (data.transaction < 0) {
|
|
34
|
+
if (data.transaction == -1) {
|
|
35
|
+
that.output.push(data.content);
|
|
36
|
+
that.onOutput(data.content);
|
|
37
|
+
}
|
|
38
|
+
if (data.transaction == -2) {
|
|
39
|
+
that.error.push(data.content);
|
|
40
|
+
that.onError(data.content);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (data.content == 'FINISH') that.isRunning = false;
|
|
45
|
+
if (data.transaction && that.callbacks[data.transaction]) {
|
|
46
|
+
that.callbacks[data.transaction](data);
|
|
47
|
+
delete that.callbacks[data.transaction];
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
false,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
this.worker.postMessage({}); // supposed to do this to start the worker?
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Gnuplot.prototype.putFile = function (name_, contents, callback) {
|
|
57
|
+
var data = {
|
|
58
|
+
name: name_,
|
|
59
|
+
content: contents,
|
|
60
|
+
cmd: 'putFile',
|
|
61
|
+
};
|
|
62
|
+
this.postCommand(data, callback);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// to read output
|
|
66
|
+
Gnuplot.prototype.getFile = function (name_, callback) {
|
|
67
|
+
var data = {
|
|
68
|
+
name: name_,
|
|
69
|
+
cmd: 'getFile',
|
|
70
|
+
};
|
|
71
|
+
this.postCommand(data, callback);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
Gnuplot.prototype.getFileList = function (callback) {
|
|
75
|
+
var data = {
|
|
76
|
+
cmd: 'getFileList',
|
|
77
|
+
};
|
|
78
|
+
this.postCommand(data, callback);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
Gnuplot.prototype.removeFiles = function (files, callback) {
|
|
82
|
+
var data = {
|
|
83
|
+
name: files,
|
|
84
|
+
cmd: 'removeFiles',
|
|
85
|
+
};
|
|
86
|
+
this.postCommand(data, callback);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
Gnuplot.prototype.run = function (script, onFinish) {
|
|
90
|
+
if (this.isRunning) return false;
|
|
91
|
+
this.putFile('foo', script);
|
|
92
|
+
var data = {
|
|
93
|
+
content: ['foo'],
|
|
94
|
+
cmd: 'run',
|
|
95
|
+
};
|
|
96
|
+
this.isRunning = true;
|
|
97
|
+
this.postCommand(data, onFinish);
|
|
98
|
+
return true;
|
|
99
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-codes/browser-compilers",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"description": "Compilers that run in the browser, for use in livecodes.io",
|
|
5
5
|
"author": "Hatem Hosny",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "https://github.com/live-codes/browser-compilers"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"start": "live-server dist --cors",
|
|
12
|
+
"start": "live-server dist --port=8081 --no-browser --cors",
|
|
13
13
|
"build": "run-s clean build:vendors copy:types",
|
|
14
14
|
"build:vendors": "node ./scripts/vendors.js",
|
|
15
15
|
"copy:types": "recursive-copy vendor_modules/types dist/types",
|
package/scripts/vendors.js
CHANGED
|
@@ -238,3 +238,14 @@ fs.copyFileSync(
|
|
|
238
238
|
path.resolve(vendor_modules_src + '/turbopascal/turbopascal.js'),
|
|
239
239
|
path.resolve(targetDir + '/turbopascal/turbopascal.js'),
|
|
240
240
|
);
|
|
241
|
+
|
|
242
|
+
// gnuplot
|
|
243
|
+
mkdirp(targetDir + '/gnuplot');
|
|
244
|
+
fs.copyFileSync(
|
|
245
|
+
path.resolve(vendor_modules_src + '/gnuplot-JS/www/gnuplot.js'),
|
|
246
|
+
path.resolve(targetDir + '/gnuplot/gnuplot.js'),
|
|
247
|
+
);
|
|
248
|
+
fs.copyFileSync(
|
|
249
|
+
path.resolve(vendor_modules_src + '/gnuplot-JS/www/gnuplot_api.js'),
|
|
250
|
+
path.resolve(targetDir + '/gnuplot/gnuplot_api.js'),
|
|
251
|
+
);
|
package/vendor-licenses.md
CHANGED
|
@@ -10,6 +10,8 @@ clientside-haml-js: [MIT License](https://github.com/uglyog/clientside-haml-js/b
|
|
|
10
10
|
|
|
11
11
|
CoffeeScript: [MIT License](https://github.com/jashkenas/coffeescript/tree/07f644c39223e016aceedd2cd71b5941579b5659)
|
|
12
12
|
|
|
13
|
+
gnuplot-JS: [MIT License](https://github.com/chhu/gnuplot-JS/blob/62a3c8488ad00c97807ba48ae75738ca3af607fe/LICENSE)
|
|
14
|
+
|
|
13
15
|
JSCPP: [MIT License](https://github.com/felixhao28/JSCPP/blob/befbd6b48666007151c259c5dd291ab028ad4c04/LICENSE)
|
|
14
16
|
|
|
15
17
|
Less: [Apache License 2.0](https://github.com/less/less.js/blob/870f9b2d8136bfbcdc9e1293bb0def51b54f9276/LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Christian Huettig
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Portable JS Gnuplot
|
|
2
|
+
*******************
|
|
3
|
+
|
|
4
|
+
This is the result of compiling gnuplot with emscripten, combined with an API so it is usable straight out of the box in your browser.
|
|
5
|
+
The www directory contains the necessary files and a compiled version of gnuplot 4.6.3. The gnuplot-4.6.3 directory contains everything to
|
|
6
|
+
build the gnuplot sources with emscripten.
|
|
7
|
+
|
|
8
|
+
How to compile gnuplot
|
|
9
|
+
**********************
|
|
10
|
+
|
|
11
|
+
- Install llvm / emscripten, follow instructions at http://emscripten.org
|
|
12
|
+
- Download the gnuplot-4.6.3.tar.gz sources at http://gnuplot.info and untar.
|
|
13
|
+
- Copy the contents of this repo's gnuplot-4.6.3 into the folder where you unpacked the sources (should be the same name).
|
|
14
|
+
- [optional] adjust src/term.h and remove unneeded terminals to reduce final size
|
|
15
|
+
- [optional] patch src/axis.c with the patch file to fix axis descriptions: cd src;patch <../gnuplot-4.6.3.patch
|
|
16
|
+
- Run em_make to configure and build, you should have a gnuplot.js in your directory. WAIT at the end! The final step takes long.
|
|
17
|
+
|
|
18
|
+
How the API works
|
|
19
|
+
*****************
|
|
20
|
+
|
|
21
|
+
The gnuplot API (gnuplot_api.js) creates a worker (JS-thread) that loads gnuplot.js and handles all the work. No browser checks are done to check for HTML5 features.
|
|
22
|
+
The API lets you interact with the worker to "upload" or "download" files. Emscripten uses a mock-up for file I/O, so keep in mind that files are kept in memory as arrays
|
|
23
|
+
and that you need to push / pull any file-content to / from the fake file system within the worker. The API provides some convenience functions for this.
|
|
24
|
+
|
|
25
|
+
The demo site from the www directory is online at http://gnuplot.respawned.com
|
|
26
|
+
|
|
27
|
+
A minimal implementation should look like this (untested! see index.html for working version):
|
|
28
|
+
|
|
29
|
+
<img id="result"/>
|
|
30
|
+
<script src='gnuplot_api.js'></script>
|
|
31
|
+
<script>
|
|
32
|
+
gnuplot = new Gnuplot('gnuplot.js');
|
|
33
|
+
//gnuplot.putFile("myData.dat", "1 2 3 4 5 6 7 8 9 0"); // No callback needed here
|
|
34
|
+
gnuplot.run("my gnuplot script as a string", function(e) {
|
|
35
|
+
gnuplot.getFile('out.svg', function(e) {
|
|
36
|
+
if (!e.content) {
|
|
37
|
+
alert("Output file out.svg not found!");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var img = document.getElementById('result');
|
|
41
|
+
try {
|
|
42
|
+
var ab = new Uint8Array(e.content);
|
|
43
|
+
var blob = new Blob([ab], {"type": "image\/svg+xml"});
|
|
44
|
+
window.URL = window.URL || window.webkitURL;
|
|
45
|
+
img.src = window.URL.createObjectURL(blob);
|
|
46
|
+
} catch (err) { // in case blob / URL missing, fallback to data-uri
|
|
47
|
+
var rstr = '';
|
|
48
|
+
for (var i = 0; i < e.content.length; i++)
|
|
49
|
+
rstr += String.fromCharCode(e.content[i]);
|
|
50
|
+
img.src = 'data:image\/svg+xml;base64,' + btoa(rstr);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
</script>
|
|
55
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
emconfigure ./configure --without-readline --without-x --disable-h3d-quadtree --disable-wxwidgets
|
|
3
|
+
#emmake make clean
|
|
4
|
+
emmake make
|
|
5
|
+
rm gnuplot.o
|
|
6
|
+
mv src/gnuplot ./gnuplot.o
|
|
7
|
+
em++ -s INVOKE_RUN=0 -O2 -s ASM_JS=1 gnuplot.o -o gnuplot.js --post-js post.js --pre-js pre.js
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
--- gnuplot-4.6.3/src/axis.c 2012-11-08 18:13:08.000000000 +0100
|
|
2
|
+
+++ gnuplot-4.6.3_mod/src/axis.c 2013-05-11 11:08:08.791587160 +0200
|
|
3
|
+
@@ -467,8 +467,9 @@ copy_or_invent_formatstring(AXIS_INDEX a
|
|
4
|
+
int precision = (ceil(-log10(fabs(axmax-axmin))));
|
|
5
|
+
if ((axmin*axmax > 0) && precision > 4)
|
|
6
|
+
sprintf(ticfmt[axis],"%%.%df", (precision>14) ? 14 : precision);
|
|
7
|
+
+ else
|
|
8
|
+
+ strcpy(ticfmt[axis], "%g");
|
|
9
|
+
}
|
|
10
|
+
-
|
|
11
|
+
return ticfmt[axis];
|
|
12
|
+
}
|
|
13
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
shouldRunNow = true;
|
|
2
|
+
self['Runtime'] = Runtime;
|
|
3
|
+
self['FS'] = FS;
|
|
4
|
+
};
|
|
5
|
+
gnuplot_create();
|
|
6
|
+
// This is to avoid name mangling from closure compilers
|
|
7
|
+
self['FS'] = FS;
|
|
8
|
+
self['FS']['root'] = FS.root;
|
|
9
|
+
self['FS']['deleteFile'] = FS.deleteFile;
|
|
10
|
+
self['FS']['findObject'] = FS.findObject;
|
|
11
|
+
self['FS']['createDataFile'] = FS.createDataFile;
|
|
12
|
+
self['FS']['getFileContents'] = function(name) {
|
|
13
|
+
var file = FS.findObject(name);
|
|
14
|
+
if (!file) return null;
|
|
15
|
+
return file.contents;
|
|
16
|
+
};
|
|
17
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
self.addEventListener('message', function(e) {
|
|
2
|
+
var data = e.data;
|
|
3
|
+
if (!data) return;
|
|
4
|
+
var cmd = data['cmd'];
|
|
5
|
+
var transaction = data['transaction'];
|
|
6
|
+
var name = data['name'];
|
|
7
|
+
var content = data['content'];
|
|
8
|
+
var result = {
|
|
9
|
+
transaction: transaction
|
|
10
|
+
};
|
|
11
|
+
switch (cmd) {
|
|
12
|
+
case 'run':
|
|
13
|
+
try {
|
|
14
|
+
shouldRunNow = true;
|
|
15
|
+
if (content)
|
|
16
|
+
Module.run(content);
|
|
17
|
+
else
|
|
18
|
+
Module.run();
|
|
19
|
+
} catch(err) {
|
|
20
|
+
|
|
21
|
+
Module.printErr('Exit called, reset state.');
|
|
22
|
+
gnuplot_create();
|
|
23
|
+
};
|
|
24
|
+
result['content'] = 'FINISH';
|
|
25
|
+
self.postMessage(result);
|
|
26
|
+
break;
|
|
27
|
+
|
|
28
|
+
case 'putFile':
|
|
29
|
+
if (FS.findObject(name))
|
|
30
|
+
FS.deleteFile(name);
|
|
31
|
+
var arrc = content;
|
|
32
|
+
if (typeof(content) == "string")
|
|
33
|
+
arrc = Module['intArrayFromString'](content, true);
|
|
34
|
+
FS.createDataFile('/', name, arrc);
|
|
35
|
+
result['content'] = 'OK';
|
|
36
|
+
self.postMessage(result);
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
case 'getFile':
|
|
40
|
+
var file = FS.findObject(name);
|
|
41
|
+
result['content'] = file.contents || 0;
|
|
42
|
+
self.postMessage(result);
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
default:
|
|
46
|
+
result['content'] = 'unknown cmd';
|
|
47
|
+
self.postMessage(result);
|
|
48
|
+
};
|
|
49
|
+
}, false);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
var Module = {
|
|
53
|
+
'noInitialRun': true,
|
|
54
|
+
print: function(text) {
|
|
55
|
+
self.postMessage({'transaction': -1, 'content': text});
|
|
56
|
+
},
|
|
57
|
+
printErr: function(text) {
|
|
58
|
+
self.postMessage({'transaction': -2, 'content': text});
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
function gnuplot_create() {
|