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

Gnuplot canvas terminal mouse coordinates

346 views
Skip to first unread message

gfl...@jpl.nasa.gov

unread,
May 3, 2012, 8:21:26 PM5/3/12
to
Hello,

I'm using the gnuplot canvas terminal, starting with some of Ethan
Merritt's demo page stuff to show some plots where the x axis goes
from, say, 3590.01 to 3590.42. (infrared spectra with wavenumber)

The returned coordinates on the canvas and in the HTML table (mb0 and
mb1) have very poor resolution, so that it only shows 3590 wherever I
move or click the mouse.

I tried hacking the gnuplot_mouse.js file by changing the
x.toPrecision( ) call, but that didn't help.
How can I increase the resolution of the returned coordinates to
something like %9.4f

Any help is greatly appreciated!

I'm using Perl 5.10.0, Gnuplot 4.4, Apache 2.2.21, Firefox 12.0 all
running on MacOS 10.6.8

sfeam

unread,
May 5, 2012, 12:16:39 PM5/5/12
to
gfl...@jpl.nasa.gov wrote:

> Hello,
>
> I'm using the gnuplot canvas terminal, starting with some of Ethan
> Merritt's demo page stuff to show some plots where the x axis goes
> from, say, 3590.01 to 3590.42. (infrared spectra with wavenumber)
>
> The returned coordinates on the canvas and in the HTML table (mb0 and
> mb1) have very poor resolution, so that it only shows 3590 wherever I
> move or click the mouse.
>
> I tried hacking the gnuplot_mouse.js file by changing the
> x.toPrecision( ) call, but that didn't help.
> How can I increase the resolution of the returned coordinates to
> something like %9.4f
>
> Any help is greatly appreciated!

I'm not sure, but possibly the problem is due to the precision used
to store the axis range limits. The mousing code calculates the
current coordinate using code equivalent to
gnuplot_x = axis_xmin + fraction * (axis_xmax - axis_xmin)
where fraction is the fractional position along the axis derived from
the pixel representation of the axis end points and the mouse position.
These values are written at the very end of the javascript output.
The code section looks like this:
gnuplot.plot_width = 523.9;
gnuplot.plot_height = 363.9;
gnuplot.plot_axis_xmin = -10;
gnuplot.plot_axis_xmax = 10;
gnuplot.plot_axis_ymin = -1.5;
gnuplot.plot_axis_ymax = 1.5;

As an experiment, you could try editing in additional decimal places to
these values in the *.js file. They needn't be _correct_ digits;
the purpose of the experiment is to see if that results in additional
precision in the mouse coordinate output. If it does, then we know
what needs to be fixed in the output code.

Ethan

gfl...@jpl.nasa.gov

unread,
May 7, 2012, 11:57:03 AM5/7/12
to
Thanks very much for the reply. The javascript output showed

-------------
// plot boundaries and axis scaling information for mousing
plot_term_xmax = 600;
plot_term_ymax = 400;
plot_xmin = 96.0;
plot_xmax = 575.9;
plot_ybot = 368.0;
plot_ytop = 30.1;
plot_width = 479.9;
plot_height = 337.9;
plot_axis_xmin = 3589.7;
plot_axis_xmax = 3590.4;
plot_axis_ymin = 0.1;
plot_axis_ymax = 1e+08;
plot_axis_x2min = "none"
plot_axis_y2min = "none"
plot_logaxis_x = 0;
plot_logaxis_y = 1;
plot_axis_width = plot_axis_xmax - plot_axis_xmin;
plot_axis_height = plot_axis_ymax - plot_axis_ymin;
------------

which look reasonable. I tried editing those values for the test with
more decimal places but it didn't change anything.
The X axis continues to report values with no decimal places.

For another clue, I just did a plot where the x axis goes from 3593.3
to 3594.2 and I noticed that along with low resolution it appears to
be mapping incorrectly.
The X values changes from 3593 to 3594 when I move around 3593.5
instead of in the neighborhood of 3594. BUT the Y values are spot
on. ???

I should mention that I do these graphs all the time with the X11
driver and the mousing resolution works fine. And, since Gnuplot is
properly labeling the canvas graph, I think it's getting the right
numbers from me.
Is there a Gnuplot-related canvas driver variable that would limit
resolution? Anything I can set/show?

Thanks again!
Greg.

Is

On May 5, 9:16 am, sfeam <sf...@users.sourceforge.net> wrote:

gfl...@jpl.nasa.gov

unread,
May 7, 2012, 12:09:42 PM5/7/12
to
Hello again. I sent a reply post, but don't see it yet, hopefully it
gets through.

Ethan, I just noticed on your demo page that the X value is always 4
significant figures. For plots that have a small X range, the
resolution is 4 sig figs (e.g. 0.04406).
For other graphs with a larger range the resolution is lower (e.g.
15.07) So, hopefully that's a variable that be can be set and not a
hard-coded printf e.g. %4e or something like that.).

Again, thanks for all the help.
Greg.

sfeam

unread,
May 7, 2012, 3:24:18 PM5/7/12
to
gfl...@jpl.nasa.gov wrote:

> I should mention that I do these graphs all the time with the X11
> driver and the mousing resolution works fine. And, since Gnuplot is
> properly labeling the canvas graph, I think it's getting the right
> numbers from me.

The mouse coordinates in X11 are calculated and printed by gnuplot itself,
which is written in C and uses C language output formats.

The mouse coordinates from the canvas terminal as displayed in a browser
are calculated and printed by the browser's javascript interpreter using
the code in gnuplot_mouse.js.

So there's no overlap in the code, and it's not so surprising that the
result is not identical.

> Is there a Gnuplot-related canvas driver variable that would limit
> resolution? Anything I can set/show?

You can change the number of decimal places that are printed by replacing,
for example, x.toPrecision(4) with x.toPrecision(8) in gnuplot_mouse.js.
However, if the underlying problem is accuracy rather than precision then
that's not going to help. It is possible, for example, that the browser
updates the mouse position in coarser increments than 1 pixel.
I know that's true for the mouse wheel, but I don't know any details about
general mouse tracking in a browser.

A similar issue was raised recently on the developer's mailing list with
regard to mouse tracking in SVG documents. There again both the number
of decimal places and the precision with which the current mouse position
is provided by the document viewer are relevant.

> The X values changes from 3593 to 3594 when I move around 3593.5
> instead of in the neighborhood of 3594.

Maybe a difference in rounding floats to ints in javascript v. C?

Ethan

gfl...@jpl.nasa.gov

unread,
May 7, 2012, 5:14:20 PM5/7/12
to

Well, I tried changing the x.toPrecision() functions again (out of
desperation) and this time it seems to work! (I had already tried
that in my first post)
My browser crashed and I had to restart it in the middle of all
this ... maybe something cached?
Anyway, things are looking good now.

Ethan thanks for your help and for making these very useful javascript
pages available.

Greg Flesch
0 new messages