- cxt.xscaling = (gw->graph->points->len == 1)? 1 : (1/(maxx - minx));
- cxt.yscaling = (gw->graph->points->len == 1)? 1 : (1/(maxy - miny));
- cxt.xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
- cxt.yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
- #ifdef DEBUG
- fprintf(stderr, "minx=%g, maxx=%g, miny=%g, maxy=%g, xscaling=%g, yscaling=%g, xoffset=%g, yoffset=%g\n", minx, maxx, miny, maxy, cxt.xscaling, cxt.yscaling, cxt.xoffset, cxt.yoffset);
- fprintf(stderr, "x0=%g, y0=%g, width=%g, height=%g\n", x0, y0, height, width);
- fprintf(stderr, "translate=(%g, %g)\n", x0 + ((width>height)?(width-height)/2.0:0), y0+((width > height)?height:width) + ((height>width)?(height-width)/2.0:0));
-#endif
- double offset_height = ((width>=height)?height*INSET_PERCENT:0);;
- double offset_width = ((height>=width)?width*INSET_PERCENT:0);
- double inset_height = height - offset_height;
- double inset_width = width - offset_width;
+ /*Set up our semi-normalized scaling. The shortest direction range
+ [0, 1]; the other range depends upon the relative sizes.*/
+ double effective_height = height;
+ double effective_width = width;
+ double inset, axis_inset;
+ if((INSET_PERCENT > 0) && (INSET_PERCENT < 1.0)) {
+ inset = ((effective_height > effective_width)?effective_width:effective_height)*INSET_PERCENT;
+ effective_height -= inset;
+ effective_width -= inset;
+ }
+ if((gw->graph->xaxis != NULL) && (gw->graph->yaxis != NULL)) {
+ /*key off the smaller size.*/
+ axis_inset = ((effective_height > effective_width)?effective_width:effective_height)*TITLE_PERCENT;
+ effective_height -= axis_inset;
+ effective_width -= axis_inset;
+ }elsif(gw->graph->xaxis != NULL) {
+ effective_height -= effective_height*TITLE_PERCENT;
+ }elsif(gw->graph->yaxis != NULL) {
+ effective_width -= effective_width*TITLE_PERCENT;
+ }
+ if(effective_width > effective_height) {
+ cxt.xmax = effective_width/effective_height;
+ cxt.ymax = 1.0;
+ }else{
+ cxt.xmax = 1.0;
+ cxt.ymax = effective_height/effective_width;
+ }
+ /*Convert from data space to the semi-normalized space*/
+ double xscaling = (gw->graph->points->len == 1)? cxt.xmax : (cxt.xmax/(maxx-minx));
+ double yscaling = (gw->graph->points->len == 1)? cxt.ymax : (cxt.ymax/(maxy-miny));
+ double xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
+ double yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
+ cairo_matrix_translate(&(cxt.data_xlat), xoffset, yoffset);
+ cairo_matrix_scale(&(cxt.data_scale), xscaling, yscaling);