|
From: Allin C. <cot...@wf...> - 2007-12-26 22:05:55
|
On Tue, 25 Dec 2007, Ethan A Merritt wrote:
> On Wednesday 19 December 2007 08:16, Allin Cottrell wrote:
> > I'm attaching a new .tgz file with 3 small patches, to
> > term/cairo.trm, src/eval.c and src/term_api.h. Jointly these
> > implement the writing of plot pixel bounds, with a possible scale
> > factor, using a new scalar variable rather than a new function
> > pointer.
>
> I like the idea, but unfortunately this code isn't working.
> If you look closely, you will find that the y coordinates being
> reported by this code are off by 17 pixels in the default 640x480
> ouput from either 'set term png' or 'set term pngcairo'...
Hmm, could you explain how you're coming to that judgment?
The way I'm testing this is (in my program, gretl) is by
displaying the PNG (at present, produced by the pngcairo term) in
a GTK window, with a mouse-over feedback mechanism that prints the
data coordinates.
This is similar to the mechanism in gnuplot itself (e.g. for the
X11 or wxt terminals), except that in my version the coordinates
readback goes blank if you move the pointer outside of the
actual plot area (which incidentally enables you to see easily if
that area is correctly registered).
Anyway, I find that the readback is perfectly accurate: the data
coordinates seem right and they kick out just at the very edge of
the plot. I've tried this with plots of 640x480 and 680x400.
Here's the function I'm using to compute the data coordinates,
given integer x and y as reported by GTK from the mouse pointer,
relative to the window holding the PNG:
static void get_data_xy (png_plot *plot, int x, int y,
double *data_x, double *data_y)
{
double dx, dy;
*data_x = plot->xmin + ((double) x - plot->pixel_xmin) /
(plot->pixel_xmax - plot->pixel_xmin) *
(plot->xmax - plot->xmin);
*data_y = ymax - ((double) y - plot->pixel_ymin) /
(plot->pixel_ymax - plot->pixel_ymin) *
(plot->ymax - plot->ymin);
}
where the relevant members of the my png_plot structure have the
following relationships with gnuplot variables (as read from an
auxiliary test file produced using gnuplot's print command):
plot->pixel_xmin <- TERM_XMIN
plot->pixel_xmax <- TERM_XMAX
plot->pixel_ymin <- plot->pixel_height - TERM_YMIN
plot->pixel_ymax <- plot->pixel_height - TERM_YMAX
plot->xmin <- GPVAL_X_MIN
plot->xmax <- GPVAL_X_MAX
plot->ymin <- GPVAL_Y_MIN
plot->ymax <- GPVAL_Y_MAX
plot->pixel_height is, e.g. 480 for a 640x480 PNG, as you might
expect!
Allin Cottrell
|