Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gnuplot running in your browser (compiled with emscripten)

854 views
Skip to first unread message

Christ H

unread,
Jan 1, 2013, 3:39:38 PM1/1/13
to
Hi,
just as an xmas project I tried to compile gnuplot with emscripten and it worked amazingly well. Had to patch some little things, nothing dramatic. Only issue: hidden surface removal is broken (crashes), which might be due to int64 usage. Appreciate feedback. Feel free to have fun with this, no install required, just a modern browser.

Cheers,
Christian

http://gnuplot.respawned.com

sfeam

unread,
Jan 1, 2013, 8:00:31 PM1/1/13
to
Christ H wrote:

> Hi,
> just as an xmas project I tried to compile gnuplot with emscripten and
> it worked amazingly well. Had to patch some little things, nothing
> dramatic. Only issue: hidden surface removal is broken (crashes),
> which might be due to int64 usage. Appreciate feedback. Feel free to
> have fun with this, no install required, just a modern browser.
>
> http://gnuplot.respawned.com

What a great holiday project!
Some thoughts after a quick trial run:

2.5MB is pretty small already, but I think you could cut that down
further by trimming the number of terminal drivers in the build.
I can't see much point in context/corel/mif/pslatex/tektronix support.

Aside from the problem with hidden3d, I notice that NaN and infinities
are not handled correctly. You can see this by running imageNAN.dem or
by typing "print NaN".

I get an error page saying
"error on line 80 at column 36: Encoding error"
if there are UTF-8 characters in the input script.
It's not clear what level of the processing stack is involved;
this is not an error from gnuplot per se.

I would have thought that modifying the script to use
set term svg enhanced size 1000,700 mouse \
jsdir "http://gnuplot.sourceforge.net/demo_svg_4.6/"
would be sufficient to enable mousing, but it isn't. This
could be due to sandboxing by the browser (chrome), but I didn't
pursue it further. Clearly it should work to include the mousing
support scripts with the rest of the downloaded code, however
in order to play with the mousing script it would be easier if it
lived in a separate editable location. Which brings me to...

The obvious next step is to extend the mousing code so that you
get true 3D interactive rotation and zoom.
That would be spectacular!

3D mouse support would be easier to do using the canvas terminal
instead of svg because that way there needn't be an intermediate
file (svg.out) in local storage.
Either way the amount of new code required would be small;
so far as I can see, the only thing required is to add hooks so
that mouse events trigger a call back into the existing
gp_exec_event() routine. It could well be that no change is
needed to the core gnuplot code at all, only to the separate
mousing scripts and the wrapping HTML on the web page.

Please send me, or upload to the SourceForge site, whatever
code changes you needed to "patch some little things".
I'd be happy to shepherd them into the current CVS version.

Happy New Year,

Ethan

>
> Cheers,
> Christian
>
> http://gnuplot.respawned.com

Christ H

unread,
Jan 2, 2013, 6:37:24 AM1/2/13
to sf...@users.sourceforge.net
Hi Ethan,

thanks for the feedback! I am a researcher and was trying to run my fluid-dynamics code in the browser, which worked surprisingly well too, so the next thing was visualizing the results, where gnuplot is superior than any other JS libraries out there to plot things. My goal was to produce nice printable plots, which is why I focused on svg and not so much on mousing.
You clearly tested this already more than I did. :)

> 2.5MB is pretty small already, but I think you could cut that down
> further by trimming the number of terminal drivers in the build.
> I can't see much point in context/corel/mif/pslatex/tektronix support.
Great idea! I removed X support via configure options already. Where would I need to start? Or is this possible with more config options?


> Aside from the problem with hidden3d, I notice that NaN and infinities
> are not handled correctly. You can see this by running imageNAN.dem or
> by typing "print NaN".
I see, that might be a tough one, although JS handles infinity, NaN etc properly...

> I get an error page saying
> "error on line 80 at column 36: Encoding error"
> if there are UTF-8 characters in the input script.
> It's not clear what level of the processing stack is involved;
> this is not an error from gnuplot per se.
Agreed, I am not sure how encoding is handled for HTML elements. What did you do? I tried to include a German umlaut character in the label, I don't get an error but the svg is corrupted or not created.

>
> I would have thought that modifying the script to use
> set term svg enhanced size 1000,700 mouse \
> jsdir "http://gnuplot.sourceforge.net/demo_svg_4.6/"
> would be sufficient to enable mousing, but it isn't. This
> could be due to sandboxing by the browser (chrome), but I didn't
> pursue it further. Clearly it should work to include the mousing
> support scripts with the rest of the downloaded code, however
> in order to play with the mousing script it would be easier if it
> lived in a separate editable location. Which brings me to...
I don't understand the mousing support, does gnuplot produce an additional js?

>
> The obvious next step is to extend the mousing code so that you
> get true 3D interactive rotation and zoom.
> That would be spectacular!
... and tough! ;) You are thinking of a simple feedback of new rotation parameters to the script? Even then you would need something like a cube that the user rotates to illustrate the new rotation position...


>
> 3D mouse support would be easier to do using the canvas terminal
> instead of svg because that way there needn't be an intermediate
> file (svg.out) in local storage.
>
> Either way the amount of new code required would be small;
> so far as I can see, the only thing required is to add hooks so
> that mouse events trigger a call back into the existing
> gp_exec_event() routine. It could well be that no change is
> needed to the core gnuplot code at all, only to the separate
> mousing scripts and the wrapping HTML on the web page.
>
Regarding 3D, I would love to see features like volume-rendering, iso-surface and slices. I could not find an open-source tool that can do this, but I understand that's a whole new level.

> Please send me, or upload to the SourceForge site, whatever
> code changes you needed to "patch some little things".
> I'd be happy to shepherd them into the current CVS version.
Great! I needed the most time testing what configure options work. Disabling readline was important, and I think the only patch in the src was in gnprintf(), because the emscripten printf does not understand "% g" so I compacted it with a simple else-statement in the if (???=="% g") branch when nothing happens with the string. Maybe there is even more trouble with formatting... I am happy to share the pre/post JS files needed and the compile script, and the little API I wrote. It is possible to host all this at sourceforge as well as my web server simply serves static files here... You cannot see the pre/post js files as they are "compiled" with gnuplot itself.


>
> Happy New Year,
To you too!

>
>
>
> Ethan
>

sfeam

unread,
Jan 2, 2013, 2:45:45 PM1/2/13
to
Christ H wrote:

>>
>> The obvious next step is to extend the mousing code so that you
>> get true 3D interactive rotation and zoom.
>> That would be spectacular!
> ... and tough! ;) You are thinking of a simple feedback of new rotation
> parameters to the script? Even then you would need something like a cube
> that the user rotates to illustrate the new rotation position...

I don't see why it would need to be any different from the 3D mousing
support we have had for ages in the interactive terminals win/x11/wxt/qt.
Since you have created a javascript version of all the core routines,
the only missing bit is to attach a call to the emscriptened gp_exec_event()
routine as an action to be triggered on mouse events.

I'll send a more detailed reply off-line.

Ethan

Christ H

unread,
Jan 4, 2013, 9:13:14 AM1/4/13
to
Quick heads-up:
- I could fix the UTF8 issue. That was related to the virtual file system and how a JS string is converted to an array (all files are arrays of bytes).
- Unnecessary terminals are out, JS reduced to 1.7MB, gzip'd 460kB.
- IE10 & iOS6 compatible now.

Christ H

unread,
Jan 14, 2013, 7:29:36 AM1/14/13
to
Mousing works now too.
Still working on hidden surface bug...

C

Christ H

unread,
Jan 16, 2013, 6:36:53 AM1/16/13
to
Unfortunately mousing has some serious scaling issues, and it prevents the user from right-click, save-as... option. I'm thinking of reverting back to <img> tag.

sfeam

unread,
Jan 16, 2013, 6:36:29 PM1/16/13
to
Christ H wrote:

> Unfortunately mousing has some serious scaling issues,

I noticed that. But I'm sure it's fixable.
It might be due to the SVG element being embedded in a
separate frame?

> and it prevents the user from right-click, save-as... option.

I don't see that here. gnuplot's SVG mousing code ignores right-click.
I don't have any problems with right-click + save-as in either chrome
or firefox. What browser are you having trouble with?

> I'm thinking of reverting back to <img> tag.
>>
>> Still working on hidden surface bug...

You might try

./configure --disable-h3d-quadtree --enable-h3d-gridbox

That selects a different hidden surface algorithm.
No promises, but at least you'd be executing a different code path.

Ethan

>>
>>
>> C
>>

>> > > http://gnuplot.respawned.com

yasasvi....@gmail.com

unread,
Jun 24, 2019, 2:34:50 AM6/24/19
to
Hey Christian, I too am trying to port gnuplot, but currently, I keep getting an error "out.svg not found", after dealing with a few other errors, this seems to be where i'm getting stuck, it could be great if you could share any details regarding this!

>Regards,
>Yasasvi
0 new messages