|
From: <jun...@so...> - 2006-04-08 19:05:17
|
How about the syntax below?
set size {{no}squre | ratio { center | xaxis | yaxis } <r> | noratio } {<xscale>,<yscale>}
The option "center" is default behavior same as the present.
In the option "x(y)axis", <y(x)scale> is neglected and a graph boundary
is calculated with the reference to only the length of the x(y)-axis.
Then, y(x)scale is calculated by the graph boundary and reset.
This option should resolve all the problem in multiplot,
since we can fixate the bottom left corner and know the position of
the right top one.
Patches below are just my idea and there should be more appropriate
methods to implement.
Those two feature must be very useful to put several graphs of
the same ratio and the same length of the axis in multiplot.
So, I hope such features are implemented in future gnuplot by any way.
*** gadgets.h.org Sun Apr 9 03:49:05 2006
--- gadgets.h Sun Apr 9 03:49:14 2006
***************
*** 305,310 ****
--- 305,318 ----
extern float yoffset; /* y origin setting */
extern float aspect_ratio; /* 1.0 for square */
+ /* graph position in set size ratio plot */
+ typedef enum ratio_position_type {
+ CENTER,
+ XAXIS,
+ YAXIS
+ } ratio_position_type;
+ extern enum ratio_position_type ratioposition; /* CENTER */
+
/* plot border autosizing overrides, in characters (-1: autosize) */
extern float lmargin, bmargin, rmargin, tmargin;
*** gadgets.c.org Sun Apr 9 03:47:55 2006
--- gadgets.c Sun Apr 9 03:48:17 2006
***************
*** 75,80 ****
--- 75,81 ----
float xoffset = 0.0; /* x origin */
float yoffset = 0.0; /* y origin */
float aspect_ratio = 0.0; /* don't attempt to force it */
+ enum ratio_position_type ratioposition = CENTER; /* graph position in ratio plot */
/* space between left edge and plot_bounds.xleft in chars (-1: computed) */
float lmargin = -1;
*** set.c.org Sun Apr 9 03:49:43 2006
--- set.c Sun Apr 9 03:50:14 2006
***************
*** 3452,3457 ****
--- 3452,3467 ----
++c_token;
} else if (almost_equals(c_token,"ra$tio")) {
++c_token;
+ if (almost_equals(c_token,"cen$ter")) {
+ ++c_token;
+ ratioposition = CENTER;
+ } else if (almost_equals(c_token,"x$axis")) {
+ ++c_token;
+ ratioposition = XAXIS;
+ } else if (almost_equals(c_token,"y$axis")) {
+ ++c_token;
+ ratioposition = YAXIS;
+ }
aspect_ratio = real(const_express(&s));
} else if (almost_equals(c_token, "nora$tio") || almost_equals(c_token, "nosq$uare")) {
aspect_ratio = 0.0;
*** graphics.c.org Sun Apr 9 03:49:52 2006
--- graphics.c Sun Apr 9 03:55:36 2006
***************
*** 319,324 ****
--- 319,326 ----
int xtic_height;
int ytic_width;
int y2tic_width;
+ int top_margin; /* calculated top margin */
+ int right_margin; /* calculated right margin */
int key_cols = 1; /* # columns of keys */
***************
*** 444,450 ****
plot_bounds.ytop = (int) (0.5 + (ysize + yoffset) * t->ymax);
if (tmargin < 0) {
! int top_margin = x2label_textheight + title_textheight;
if (timetop_textheight + ylabel_textheight > top_margin)
top_margin = timetop_textheight + ylabel_textheight;
--- 446,452 ----
plot_bounds.ytop = (int) (0.5 + (ysize + yoffset) * t->ymax);
if (tmargin < 0) {
! top_margin = x2label_textheight + title_textheight;
if (timetop_textheight + ylabel_textheight > top_margin)
top_margin = timetop_textheight + ylabel_textheight;
***************
*** 461,466 ****
--- 463,469 ----
plot_bounds.ytop -= top_margin;
if (plot_bounds.ytop == (int) (0.5 + (ysize + yoffset) * t->ymax)) {
/* make room for the end of rotated ytics or y2tics */
+ top_margin += (int) (t->h_char * 2);
plot_bounds.ytop -= (int) (t->h_char * 2);
}
} else
***************
*** 849,865 ****
if (rmargin < 0) {
/* plot_bounds.xright -= y2label_textwidth + y2tic_width + y2tic_textwidth; */
! plot_bounds.xright -= y2tic_width + y2tic_textwidth;
if (y2label_textwidth > 0)
! plot_bounds.xright -= y2label_textwidth;
!
if (plot_bounds.xright == (int) (0.5 + t->xmax * (xsize + xoffset))) {
/* make room for end of xtic or x2tic label */
plot_bounds.xright -= (int) (t->h_char * 2);
}
/* DBT 12-3-98 extra margin just in case */
plot_bounds.xright -= 0.5 * t->v_char;
-
} else
plot_bounds.xright -= (int) (rmargin * t->h_char);
--- 852,869 ----
if (rmargin < 0) {
/* plot_bounds.xright -= y2label_textwidth + y2tic_width + y2tic_textwidth; */
! right_margin = y2tic_width + y2tic_textwidth;
if (y2label_textwidth > 0)
! right_margin += y2label_textwidth;
! plot_bounds.xright -= right_margin;
if (plot_bounds.xright == (int) (0.5 + t->xmax * (xsize + xoffset))) {
/* make room for end of xtic or x2tic label */
+ right_margin += (int) (t->h_char * 2);
plot_bounds.xright -= (int) (t->h_char * 2);
}
/* DBT 12-3-98 extra margin just in case */
+ right_margin += 0.5 * t->v_char;
plot_bounds.xright -= 0.5 * t->v_char;
} else
plot_bounds.xright -= (int) (rmargin * t->h_char);
***************
*** 896,904 ****
if (current_aspect_ratio >= 0.01 && current_aspect_ratio <= 100.0) {
double current = ((double) (plot_bounds.ytop - plot_bounds.ybot)) / (plot_bounds.xright - plot_bounds.xleft);
double required = (current_aspect_ratio * t->v_tic) / t->h_tic;
!
! if (current > required) {
! /* too tall */
int height = plot_bounds.ytop - plot_bounds.ybot;
plot_bounds.ytop = plot_bounds.ybot + required * (plot_bounds.xright - plot_bounds.xleft);
height -= (plot_bounds.ytop - plot_bounds.ybot);
--- 900,909 ----
if (current_aspect_ratio >= 0.01 && current_aspect_ratio <= 100.0) {
double current = ((double) (plot_bounds.ytop - plot_bounds.ybot)) / (plot_bounds.xright - plot_bounds.xleft);
double required = (current_aspect_ratio * t->v_tic) / t->h_tic;
! /* CENTER */
! if (ratioposition == CENTER ) {
! if (current > required) {
! /* too tall */
int height = plot_bounds.ytop - plot_bounds.ybot;
plot_bounds.ytop = plot_bounds.ybot + required * (plot_bounds.xright - plot_bounds.xleft);
height -= (plot_bounds.ytop - plot_bounds.ybot);
***************
*** 912,917 ****
--- 917,949 ----
width /= 2;
plot_bounds.xright += width;
plot_bounds.xleft += width;
+ }
+ /* XAXIS */
+ } else if (ratioposition == XAXIS ) {
+ plot_bounds.ytop = plot_bounds.ybot + required * (plot_bounds.xright - plot_bounds.xleft);
+ if ( fabs((current-required)/required) > 0.001 ) /* for replot */
+ { /* calculate ysize */
+ if(tmargin<0) {
+ ysize = ((double) (plot_bounds.ytop + top_margin)) / ((double) (t->ymax)) + yoffset;
+ fprintf(stderr, "\tsize is set to %g,%g\n", xsize, ysize);
+ } else {
+ ysize = ((double) (plot_bounds.ytop + tmargin * t->v_char)) / ((double) (t->ymax)) + yoffset;
+ fprintf(stderr, "\tsize is set to %g,%g\n", xsize, ysize);
+ }
+ }
+ /* YAXIS */
+ } else if (ratioposition == YAXIS ) {
+ plot_bounds.xright = plot_bounds.xleft + (plot_bounds.ytop - plot_bounds.ybot) / required ;
+ if ( fabs((current-required)/required) > 0.001 ) /* for replot */
+ { /* calculate xsize */
+ if(rmargin<0) {
+ xsize = ((double) (plot_bounds.xright + right_margin)) / ((double) (t->xmax)) + xoffset;
+ fprintf(stderr, "\tsize is set to %g,%g\n", xsize, ysize);
+ } else {
+ xsize = ((double) (plot_bounds.xright + rmargin * t->h_char)) / ((double) (t->xmax)) + xoffset;
+ fprintf(stderr, "\tsize is set to %g,%g\n", xsize, ysize);
+ }
+ }
}
}
/*}}} */
|