|
From: <ai...@us...> - 2011-06-21 16:43:42
|
Revision: 11775
http://plplot.svn.sourceforge.net/plplot/?rev=11775&view=rev
Author: airwin
Date: 2011-06-21 16:43:35 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
Implement bounding box that includes both vertical and horizontal
components of numerical labelling for horizontal axes. Example 33
confirms this improvement is working properly.
ToDo: Need to implement similar functionality for exponent of
numerical label (where present), custom labels, vertical axes, and
overall colorbar label.
Modified Paths:
--------------
trunk/src/plbox.c
trunk/src/pllegend.c
Modified: trunk/src/plbox.c
===================================================================
--- trunk/src/plbox.c 2011-06-20 22:09:33 UTC (rev 11774)
+++ trunk/src/plbox.c 2011-06-21 16:43:35 UTC (rev 11775)
@@ -1369,7 +1369,11 @@
PLFLT pos, tn, tp, offset, height, just;
PLFLT factor, tstart;
const char *timefmt;
+ PLFLT default_mm, char_height_mm, height_mm;
+ PLFLT string_length_mm, pos_mm;
+ plgchr( &default_mm, &char_height_mm );
+
// Set plot options from input
ldx = plP_stsearch( xopt, 'd' );
@@ -1402,110 +1406,201 @@
vpwyma = ( vpwymax > vpwymin ) ? vpwymax : vpwymin;
// Write horizontal label(s)
- if ( plsc->if_boxbb )
+ if ( ( lmx || lnx ) && ( ltx || lxx ) )
{
- }
- else
- {
- if ( ( lmx || lnx ) && ( ltx || lxx ) )
+ PLINT xmode, xprec, xdigmax, xdigits, xscale;
+
+ plgxax( &xdigmax, &xdigits );
+ pldprec( vpwxmi, vpwxma, xtick1, lfx, &xmode, &xprec, xdigmax, &xscale );
+ timefmt = plP_gtimefmt();
+
+ if ( ldx )
{
- PLINT xmode, xprec, xdigmax, xdigits, xscale;
+ pldtfac( vpwxmi, vpwxma, &factor, &tstart );
+ tp = xtick1 * ( 1. + floor( ( vpwxmi - tstart ) / xtick1 ) ) + tstart;
+ }
+ else
+ {
+ tp = xtick1 * ( 1. + floor( vpwxmi / xtick1 ) );
+ }
+ height = lix ? 1.75 : 1.5;
+ if ( plsc->if_boxbb )
+ {
+ // Height of zero corresponds to character centred on edge
+ // so should add 0.5 to height to obtain bounding box edge
+ // in direction away from edge. However, experimentally
+ // found 0.7 gave a better looking result.
+ height_mm = ( height + 0.7 ) * char_height_mm;
+ if ( lnx )
+ plsc->boxbb_ymin = MIN( plsc->boxbb_ymin, plsc->vppymi /
+ plsc->ypmm - height_mm );
+ if ( lmx )
+ plsc->boxbb_ymax = MAX( plsc->boxbb_ymax, plsc->vppyma /
+ plsc->ypmm + height_mm );
+ }
- plgxax( &xdigmax, &xdigits );
- pldprec( vpwxmi, vpwxma, xtick1, lfx, &xmode, &xprec, xdigmax, &xscale );
- timefmt = plP_gtimefmt();
-
+ for ( tn = tp; BETW( tn, vpwxmi, vpwxma ); tn += xtick1 )
+ {
if ( ldx )
{
- pldtfac( vpwxmi, vpwxma, &factor, &tstart );
- tp = xtick1 * ( 1. + floor( ( vpwxmi - tstart ) / xtick1 ) ) + tstart;
+ strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig );
}
else
- tp = xtick1 * ( 1. + floor( vpwxmi / xtick1 ) );
- for ( tn = tp; BETW( tn, vpwxmi, vpwxma ); tn += xtick1 )
{
- if ( ldx )
+ plform( PL_X_AXIS, tn, xscale, xprec, string, STRING_LEN, llx, lfx, lox );
+ }
+ pos = ( vpwxmax > vpwxmin ) ?
+ ( tn - vpwxmi ) / ( vpwxma - vpwxmi ) :
+ ( vpwxma - tn ) / ( vpwxma - vpwxmi );
+ if ( plsc->if_boxbb )
+ {
+ string_length_mm = plstrl( string );
+ pos_mm = ( plsc->vppxmi + pos * ( plsc->vppxma - plsc->vppxmi ) ) /
+ plsc->xpmm;
+ }
+ if ( lnx )
+ {
+ // Bottom axis.
+ if ( plsc->if_boxbb )
{
- strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig );
+ plsc->boxbb_xmin = MIN( plsc->boxbb_xmin,
+ pos_mm - 0.5 * string_length_mm );
+ plsc->boxbb_xmax = MAX( plsc->boxbb_xmax,
+ pos_mm + 0.5 * string_length_mm );
}
else
{
- plform( PL_X_AXIS, tn, xscale, xprec, string, STRING_LEN, llx, lfx, lox );
+ plmtex( "b", height, pos, 0.5, string );
}
- height = lix ? 1.75 : 1.5;
- pos = ( vpwxmax > vpwxmin ) ?
- ( tn - vpwxmi ) / ( vpwxma - vpwxmi ) :
- ( vpwxma - tn ) / ( vpwxma - vpwxmi );
- if ( lnx )
- plmtex( "b", height, pos, 0.5, string );
- if ( lmx )
+ }
+ if ( lmx )
+ {
+ // Top axis.
+ if ( plsc->if_boxbb )
+ {
+ plsc->boxbb_xmin = MIN( plsc->boxbb_xmin,
+ pos_mm - 0.5 * string_length_mm );
+ plsc->boxbb_xmax = MAX( plsc->boxbb_xmax,
+ pos_mm + 0.5 * string_length_mm );
+ }
+ else
+ {
plmtex( "t", height, pos, 0.5, string );
+ }
}
- xdigits = 2;
- plsxax( xdigmax, xdigits );
+ }
+ xdigits = 2;
+ plsxax( xdigmax, xdigits );
- // Write separate exponential label if mode = 1.
+ // Write separate exponential label if mode = 1.
- if ( !llx && !ldx && !lox && xmode )
+ if ( !llx && !ldx && !lox && xmode )
+ {
+ // Assume label data is for placement of exponents if no custom
+ // label function is provided.
+ if ( plsc->label_data )
{
- // Assume label data is for placement of exponents if no custom
- // label function is provided.
- if ( plsc->label_data )
+ height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp;
+ pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos;
+ just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just;
+ }
+ else
+ {
+ height = 3.2;
+ pos = 1.0;
+ just = 0.5;
+ }
+ snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) xscale );
+ if ( lnx )
+ {
+ // Bottom axis exponent.
+ if ( plsc->if_boxbb )
{
- height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp;
- pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos;
- just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just;
+ // FIXME: Add Y bounding box calculations for
+ // exponent.
+ // FIXME: Add X bounding box calculations for
+ // exponent that slops over the end of the axis.
}
else
{
- height = 3.2;
- pos = 1.0;
- just = 0.5;
+ plmtex( "b", height, pos, just, string );
}
- snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) xscale );
- if ( lnx )
- plmtex( "b", height, pos, just, string );
- if ( lmx )
+ }
+ if ( lmx )
+ {
+ // Top axis exponent.
+ if ( plsc->if_boxbb )
+ {
+ // FIXME: Add Y bounding box calculations for
+ // exponent.
+ // FIXME: Add X bounding box calculations for
+ // exponent that slops over the end of the axis.
+ }
+ else
+ {
plmtex( "t", height, pos, just, string );
+ }
}
}
+ }
// Write vertical label(s)
- if ( ( lmy || lny ) && ( lty || lxy ) )
- {
- PLINT ymode, yprec, ydigmax, ydigits, yscale;
+ if ( ( lmy || lny ) && ( lty || lxy ) )
+ {
+ PLINT ymode, yprec, ydigmax, ydigits, yscale;
- plgyax( &ydigmax, &ydigits );
- pldprec( vpwymi, vpwyma, ytick1, lfy, &ymode, &yprec, ydigmax, &yscale );
+ plgyax( &ydigmax, &ydigits );
+ pldprec( vpwymi, vpwyma, ytick1, lfy, &ymode, &yprec, ydigmax, &yscale );
- ydigits = 0;
+ ydigits = 0;
+ if ( ldy )
+ {
+ pldtfac( vpwymi, vpwyma, &factor, &tstart );
+ tp = ytick1 * ( 1. + floor( ( vpwymi - tstart ) / ytick1 ) ) + tstart;
+ }
+ else
+ {
+ tp = ytick1 * ( 1. + floor( vpwymi / ytick1 ) );
+ }
+ for ( tn = tp; BETW( tn, vpwymi, vpwyma ); tn += ytick1 )
+ {
if ( ldy )
{
- pldtfac( vpwymi, vpwyma, &factor, &tstart );
- tp = ytick1 * ( 1. + floor( ( vpwymi - tstart ) / ytick1 ) ) + tstart;
+ strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig );
}
else
- tp = ytick1 * ( 1. + floor( vpwymi / ytick1 ) );
- for ( tn = tp; BETW( tn, vpwymi, vpwyma ); tn += ytick1 )
{
- if ( ldy )
+ plform( PL_Y_AXIS, tn, yscale, yprec, string, STRING_LEN, lly, lfy, loy );
+ }
+ pos = ( vpwymax > vpwymin ) ?
+ ( tn - vpwymi ) / ( vpwyma - vpwymi ) :
+ ( vpwyma - tn ) / ( vpwyma - vpwymi );
+ if ( lny )
+ {
+ if ( lvy )
{
- strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig );
+ // Left axis with text written perpendicular to edge.
+ if ( plsc->if_boxbb )
+ {
+ // FIXME: Add X bounding box calculations for
+ // numerical labels that slop over the end of the
+ // axis.
+ }
+ else
+ {
+ height = liy ? 1.0 : 0.5;
+ plmtex( "lv", height, pos, 1.0, string );
+ }
}
else
{
- plform( PL_Y_AXIS, tn, yscale, yprec, string, STRING_LEN, lly, lfy, loy );
- }
- pos = ( vpwymax > vpwymin ) ?
- ( tn - vpwymi ) / ( vpwyma - vpwymi ) :
- ( vpwyma - tn ) / ( vpwyma - vpwymi );
- if ( lny )
- {
- if ( lvy )
+ // Top axis.
+ if ( plsc->if_boxbb )
{
- height = liy ? 1.0 : 0.5;
- plmtex( "lv", height, pos, 1.0, string );
+ // FIXME: Add X bounding box calculations for
+ // numerical labels that slop over the end of the
+ // axis.
}
else
{
@@ -1513,52 +1608,82 @@
plmtex( "l", height, pos, 0.5, string );
}
}
- if ( lmy )
+ }
+ if ( lmy )
+ {
+ if ( lvy )
{
- if ( lvy )
+ // Top axis.
+ if ( plsc->if_boxbb )
{
+ // FIXME: Add X bounding box calculations for
+ // numerical labels that slop over the end of the
+ // axis.
+ }
+ else
+ {
height = liy ? 1.0 : 0.5;
plmtex( "rv", height, pos, 0.0, string );
}
+ }
+ else
+ {
+ // Top axis.
+ if ( plsc->if_boxbb )
+ {
+ // FIXME: Add X bounding box calculations for
+ // numerical labels that slop over the end of the
+ // axis.
+ }
else
{
height = liy ? 1.75 : 1.5;
plmtex( "r", height, pos, 0.5, string );
}
}
- ydigits = MAX( ydigits, (PLINT) strlen( string ) );
}
- if ( !lvy )
- ydigits = 2;
+ ydigits = MAX( ydigits, (PLINT) strlen( string ) );
+ }
+ if ( !lvy )
+ ydigits = 2;
- plsyax( ydigmax, ydigits );
+ plsyax( ydigmax, ydigits );
- // Write separate exponential label if mode = 1.
+ // Write separate exponential label if mode = 1.
- if ( !lly && !ldy && !loy && ymode )
+ if ( !lly && !ldy && !loy && ymode )
+ {
+ snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) yscale );
+ if ( plsc->label_data )
{
- snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) yscale );
- if ( plsc->label_data )
+ height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp;
+ pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos;
+ just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just;
+ }
+ else
+ {
+ offset = 0.02;
+ height = 2.0;
+ if ( lny )
{
- height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp;
- pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos;
- just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just;
+ pos = 0.0 - offset;
+ just = 1.0;
}
- else
+ if ( lmy )
{
- offset = 0.02;
- height = 2.0;
- if ( lny )
- {
- pos = 0.0 - offset;
- just = 1.0;
- }
- if ( lmy )
- {
- pos = 1.0 + offset;
- just = 0.0;
- }
+ pos = 1.0 + offset;
+ just = 0.0;
}
+ }
+ // Top axis.
+ if ( plsc->if_boxbb )
+ {
+ // FIXME: Add X bounding box calculations for
+ // numerical labels that slop over the end of the
+ // axis.
+ }
+ else
+ {
plmtex( "t", height, pos, just, string );
}
}
Modified: trunk/src/pllegend.c
===================================================================
--- trunk/src/pllegend.c 2011-06-20 22:09:33 UTC (rev 11774)
+++ trunk/src/pllegend.c 2011-06-21 16:43:35 UTC (rev 11775)
@@ -1177,7 +1177,7 @@
// direction of the orientation of the cap. In other words,
// cap_angle completely controls the shape of the triangle, but
// not its scale.
- PLFLT cap_angle = 90.;
+ PLFLT cap_angle = 45.;
// Ratio of length of cap in orientation direction
// to the width of the bar (and cap) in the direction
// perpendicular to the orientation in physical coordinates
@@ -1218,7 +1218,7 @@
// undecorated colorbar (where the decorations consist of external
// tick marks, numerical tick labels, or text if any of those
// exist) and the bounding box.
- PLFLT dx_subpage = 0., dy_subpage = 0.;
+ PLFLT dx_subpage, dy_subpage;
// Normalized subpage coordinates of the top left of undecorated
// colorbar,
PLFLT plot_x_subpage, plot_y_subpage;
@@ -1252,8 +1252,11 @@
// Ratio of normalized subpage coordinates to mm coordinates in
// x and y.
- PLFLT ncxpmm, ncypmm;
+ PLFLT sbxpmm, sbypmm;
+ // Decorated colorbox bounding box limits in subpage coordinates.
+ PLFLT bb_xmin, bb_xmax, bb_ymin, bb_ymax;
+
// Default position flags and sanity checks for position flags.
if ( !( position & PL_POSITION_RIGHT ) && !( position & PL_POSITION_LEFT ) && !( position & PL_POSITION_TOP ) && !( position & PL_POSITION_BOTTOM ) )
{
@@ -1342,8 +1345,8 @@
adopted_to_subpage_x( 0. );
colorbar_height = adopted_to_subpage_y( y_length ) -
adopted_to_subpage_y( 0. );
- // width and height of colorbar bounding box in normalized subpage
- // coordinates. Caps taken care of.
+ // Extent of cap in normalized subpage coordinates in either X or Y
+ // direction as appropriate.
if ( opt & PL_COLORBAR_ORIENT_RIGHT || opt & PL_COLORBAR_ORIENT_LEFT )
{
cap_extent = cap_ratio * colorbar_height / aspspp;
@@ -1397,56 +1400,40 @@
// marks + numerical tick labels) box.
draw_box( TRUE, opt, axis_opts, if_edge,
ticks, sub_ticks, n_values, values );
- ncxpmm = plsc->xpmm / ( plsc->sppxma - plsc->sppxmi );
- ncypmm = plsc->ypmm / ( plsc->sppyma - plsc->sppymi );
- colorbar_width_bb = ( plsc->boxbb_xmax - plsc->boxbb_xmin ) * ncxpmm;
- colorbar_height_bb = ( plsc->boxbb_ymax - plsc->boxbb_ymin ) * ncypmm;
- // Offsets of upper left corner relative to plvpor coordinates of that
- // point which are (0., colorbar_height), see above.
- dx_subpage += -plsc->boxbb_xmin * ncxpmm;
- dy_subpage -= plsc->boxbb_ymax * ncypmm - colorbar_height;
+ sbxpmm = plsc->xpmm / ( plsc->sppxma - plsc->sppxmi );
+ sbypmm = plsc->ypmm / ( plsc->sppyma - plsc->sppymi );
+ bb_xmin = plsc->boxbb_xmin * sbxpmm;
+ bb_xmax = plsc->boxbb_xmax * sbxpmm;
+ bb_ymin = plsc->boxbb_ymin * sbypmm;
+ bb_ymax = plsc->boxbb_ymax * sbypmm;
if ( opt & PL_COLORBAR_CAP_LOW )
{
if ( opt & PL_COLORBAR_ORIENT_RIGHT )
- {
- colorbar_width_bb += cap_extent;
- dx_subpage += cap_extent;
- }
+ bb_xmin = MIN( bb_xmin, -cap_extent );
if ( opt & PL_COLORBAR_ORIENT_TOP )
- {
- colorbar_height_bb += cap_extent;
- }
+ bb_ymin = MIN( bb_ymin, -cap_extent );
if ( opt & PL_COLORBAR_ORIENT_LEFT )
- {
- colorbar_width_bb += cap_extent;
- }
+ bb_xmax = MAX( bb_xmax, colorbar_width + cap_extent );
if ( opt & PL_COLORBAR_ORIENT_BOTTOM )
- {
- colorbar_height_bb += cap_extent;
- dy_subpage -= cap_extent;
- }
+ bb_ymax = MAX( bb_ymax, colorbar_height + cap_extent );
}
if ( opt & PL_COLORBAR_CAP_HIGH )
{
if ( opt & PL_COLORBAR_ORIENT_RIGHT )
- {
- colorbar_width_bb += cap_extent;
- }
+ bb_xmax = MAX( bb_xmax, colorbar_width + cap_extent );
if ( opt & PL_COLORBAR_ORIENT_TOP )
- {
- colorbar_height_bb += cap_extent;
- dy_subpage -= cap_extent;
- }
+ bb_ymax = MAX( bb_ymax, colorbar_height + cap_extent );
if ( opt & PL_COLORBAR_ORIENT_LEFT )
- {
- colorbar_width_bb += cap_extent;
- dx_subpage += cap_extent;
- }
+ bb_xmin = MIN( bb_xmin, -cap_extent );
if ( opt & PL_COLORBAR_ORIENT_BOTTOM )
- {
- colorbar_height_bb += cap_extent;
- }
+ bb_ymin = MIN( bb_ymin, -cap_extent );
}
+ colorbar_width_bb = bb_xmax - bb_xmin;
+ colorbar_height_bb = bb_ymax - bb_ymin;
+ // Offsets of upper left corner relative to plvpor coordinates of that
+ // point which are (0., colorbar_height), see above.
+ dx_subpage = -bb_xmin;
+ dy_subpage = colorbar_height - bb_ymax;
// Total width and height of colorbar bounding box in adopted subpage
// coordinates.
colorbar_width_vc = subpage_to_adopted_x( colorbar_width_bb ) -
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|