From: <ai...@us...> - 2011-06-20 22:09:40
|
Revision: 11774 http://plplot.svn.sourceforge.net/plplot/?rev=11774&view=rev Author: airwin Date: 2011-06-20 22:09:33 +0000 (Mon, 20 Jun 2011) Log Message: ----------- Implement infrastructure for bounding-box calculation for plbox, label_box, and label_box_custom (including decorations such as inverted tick marks and numerical tick labels). Use this infrastructure to help calculate the position of the complete colorbar (including decorations) and its bounding box. For now, the revised example 33 shows the effects of inverted tick marks on position and bounding box of the complete colorbar. ToDo: for now, I have only implemented and tested the inverted tick mark case as a proof of concept for the plbox bounding-box infrastructure. Thus, additional work needs to be done to include the numerical tick labels in the bounding box for plbox. Also, the colorbar label (if present) is independent of plbox so must be included independently into the bounding box calculation for the complete colorbar. Modified Paths: -------------- trunk/examples/c/x33c.c trunk/include/plstrm.h trunk/src/plbox.c trunk/src/pllegend.c Modified: trunk/examples/c/x33c.c =================================================================== --- trunk/examples/c/x33c.c 2011-06-20 18:03:03 UTC (rev 11773) +++ trunk/examples/c/x33c.c 2011-06-20 22:09:33 UTC (rev 11774) @@ -204,7 +204,7 @@ { if ( cont_color == 0 || cont_width == 0 ) { - axis_opts = "uwtvn"; + axis_opts = "uwtivn"; } else { @@ -215,7 +215,7 @@ { if ( cont_color == 0 || cont_width == 0 ) { - axis_opts = "uwtvm"; + axis_opts = "uwtivm"; } else { @@ -238,7 +238,7 @@ // Set interesting background colour. plscol0a( 15, 0, 0, 0, 0.20 ); plcolorbar( &colorbar_width, &colorbar_height, - opt|PL_COLORBAR_BOUNDING_BOX|PL_COLORBAR_BACKGROUND, position, + opt | PL_COLORBAR_BOUNDING_BOX | PL_COLORBAR_BACKGROUND, position, x, y, x_length, y_length, 15, 1, 1, low_cap_color, high_cap_color, Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2011-06-20 18:03:03 UTC (rev 11773) +++ trunk/include/plstrm.h 2011-06-20 22:09:33 UTC (rev 11774) @@ -796,6 +796,13 @@ // Drawing mode section PLINT dev_modeset; + + // Calculate bounding-box limits rather than plot box? + PLBOOL if_boxbb; + // Bounding box limits in mm for box including decorations + // (inverted tick marks and numerical tick labels if either is + // present). + PLFLT boxbb_xmin, boxbb_xmax, boxbb_ymin, boxbb_ymax; } PLStream; //-------------------------------------------------------------------------- Modified: trunk/src/plbox.c =================================================================== --- trunk/src/plbox.c 2011-06-20 18:03:03 UTC (rev 11773) +++ trunk/src/plbox.c 2011-06-20 22:09:33 UTC (rev 11774) @@ -156,6 +156,16 @@ vppymi = plsc->vppymi; vppyma = plsc->vppyma; + if ( plsc->if_boxbb ) + { + // Bounding-box limits for the box in mm before corrections + // for decorations are applied. + plsc->boxbb_xmin = plsc->vppxmi / plsc->xpmm; + plsc->boxbb_xmax = plsc->vppxma / plsc->xpmm; + plsc->boxbb_ymin = plsc->vppymi / plsc->ypmm; + plsc->boxbb_ymax = plsc->vppyma / plsc->ypmm; + } + // Convert world coordinates to physical xp0 = plP_wcpcx( x0 ); @@ -202,13 +212,14 @@ ytick1 = lly ? 1.0 : ytick; plP_xgvpw( &vpwxmin, &vpwxmax, &vpwymin, &vpwymax ); -// n.b. large change; vpwxmi always numerically less than vpwxma, and +// vpwxmi always numerically less than vpwxma, and // similarly for vpwymi vpwxmi = ( vpwxmax > vpwxmin ) ? vpwxmin : vpwxmax; vpwxma = ( vpwxmax > vpwxmin ) ? vpwxmax : vpwxmin; vpwymi = ( vpwymax > vpwymin ) ? vpwymin : vpwymax; vpwyma = ( vpwymax > vpwymin ) ? vpwymax : vpwymin; +// Plot axes only if they are inside viewport. lax = lax && vpwymi < y0 && y0 < vpwyma; lay = lay && vpwxmi < x0 && x0 < vpwxma; @@ -253,294 +264,309 @@ i4y = ymajor; } + if ( plsc->if_boxbb ) + { + // Carefully follow logic below (and above) for the case where + // an inverted major tick mark is written (in the X direction + // for a Y axis and vice versa). Ignore minor tick marks + // which are assumed to be smaller. Ignore axes and grids + // which are all contained within the viewport. + if ( lix && ( lbx || lux ) && ( ltx && !lxx ) ) + plsc->boxbb_ymin -= xmajor / plsc->ypmm; + if ( liy && ( lcy || lwy ) && ( lty && !lxy ) ) + plsc->boxbb_xmax += ymajor / plsc->xpmm; + if ( lix && ( lcx || lwx ) && ( ltx && !lxx ) ) + plsc->boxbb_ymax += xmajor / plsc->ypmm; + if ( liy && ( lby || luy ) && ( lty && !lxy ) ) + plsc->boxbb_xmin -= ymajor / plsc->xpmm; + } + else + { // Draw the bottom frame of the box - if ( lbx || lux ) - { - if ( !lux ) + if ( lbx || lux ) { - plP_movphy( vppxmi, vppymi ); - plP_draphy( vppxma, vppymi ); - } - if ( ltx && !lxx ) - { - if ( ldx ) + if ( !lux ) { - pldtfac( vpwxmi, vpwxma, &factor, &tstart ); - tp = xtick1 * ( floor( ( vpwxmi - tstart ) / xtick1 ) ) + tstart; + plP_movphy( vppxmi, vppymi ); + plP_draphy( vppxma, vppymi ); } - else - tp = xtick1 * floor( vpwxmi / xtick1 ); - for (;; ) + if ( ltx && !lxx ) { - tn = tp + xtick1; - if ( lsx ) + if ( ldx ) { - if ( llx ) + pldtfac( vpwxmi, vpwxma, &factor, &tstart ); + tp = xtick1 * ( floor( ( vpwxmi - tstart ) / xtick1 ) ) + tstart; + } + else + tp = xtick1 * floor( vpwxmi / xtick1 ); + for (;; ) + { + tn = tp + xtick1; + if ( lsx ) { - for ( i = 0; i <= 7; i++ ) + if ( llx ) { - temp = tp + xlog[i]; - if ( BETW( temp, vpwxmi, vpwxma ) ) - plxtik( plP_wcpcx( temp ), vppymi, i1x, i2x ); + for ( i = 0; i <= 7; i++ ) + { + temp = tp + xlog[i]; + if ( BETW( temp, vpwxmi, vpwxma ) ) + plxtik( plP_wcpcx( temp ), vppymi, i1x, i2x ); + } } - } - else - { - for ( i = 1; i <= nxsub1 - 1; i++ ) + else { - temp = tp + i * xtick1 / nxsub1; - if ( BETW( temp, vpwxmi, vpwxma ) ) - plxtik( plP_wcpcx( temp ), vppymi, i1x, i2x ); + for ( i = 1; i <= nxsub1 - 1; i++ ) + { + temp = tp + i * xtick1 / nxsub1; + if ( BETW( temp, vpwxmi, vpwxma ) ) + plxtik( plP_wcpcx( temp ), vppymi, i1x, i2x ); + } } } + if ( !BETW( tn, vpwxmi, vpwxma ) ) + break; + plxtik( plP_wcpcx( tn ), vppymi, i3x, i4x ); + tp = tn; } - if ( !BETW( tn, vpwxmi, vpwxma ) ) - break; - plxtik( plP_wcpcx( tn ), vppymi, i3x, i4x ); - tp = tn; } } - } -// Draw right-hand frame of box +// Draw the right-hand frame of box - if ( lcy || lwy ) - { - if ( !lwy ) + if ( lcy || lwy ) { - plP_movphy( vppxma, vppymi ); - plP_draphy( vppxma, vppyma ); - } - if ( lty && !lxy ) - { - if ( ldy ) + if ( !lwy ) { - pldtfac( vpwymi, vpwyma, &factor, &tstart ); - tp = ytick1 * ( floor( ( vpwymi - tstart ) / ytick1 ) ) + tstart; + plP_movphy( vppxma, vppymi ); + plP_draphy( vppxma, vppyma ); } - else - tp = ytick1 * floor( vpwymi / ytick1 ); - for (;; ) + if ( lty && !lxy ) { - tn = tp + ytick1; - if ( lsy ) + if ( ldy ) { - if ( lly ) + pldtfac( vpwymi, vpwyma, &factor, &tstart ); + tp = ytick1 * ( floor( ( vpwymi - tstart ) / ytick1 ) ) + tstart; + } + else + tp = ytick1 * floor( vpwymi / ytick1 ); + for (;; ) + { + tn = tp + ytick1; + if ( lsy ) { - for ( i = 0; i <= 7; i++ ) + if ( lly ) { - temp = tp + xlog[i]; - if ( BETW( temp, vpwymi, vpwyma ) ) - plytik( vppxma, plP_wcpcy( temp ), i2y, i1y ); + for ( i = 0; i <= 7; i++ ) + { + temp = tp + xlog[i]; + if ( BETW( temp, vpwymi, vpwyma ) ) + plytik( vppxma, plP_wcpcy( temp ), i2y, i1y ); + } } - } - else - { - for ( i = 1; i <= nysub1 - 1; i++ ) + else { - temp = tp + i * ytick1 / nysub1; - if ( BETW( temp, vpwymi, vpwyma ) ) - plytik( vppxma, plP_wcpcy( temp ), i2y, i1y ); + for ( i = 1; i <= nysub1 - 1; i++ ) + { + temp = tp + i * ytick1 / nysub1; + if ( BETW( temp, vpwymi, vpwyma ) ) + plytik( vppxma, plP_wcpcy( temp ), i2y, i1y ); + } } } + if ( !BETW( tn, vpwymi, vpwyma ) ) + break; + plytik( vppxma, plP_wcpcy( tn ), i4y, i3y ); + tp = tn; } - if ( !BETW( tn, vpwymi, vpwyma ) ) - break; - plytik( vppxma, plP_wcpcy( tn ), i4y, i3y ); - tp = tn; } } - } // Draw the top frame of the box - if ( lcx || lwx ) - { - if ( !lwx ) + if ( lcx || lwx ) { - plP_movphy( vppxma, vppyma ); - plP_draphy( vppxmi, vppyma ); - } - if ( ltx && !lxx ) - { - if ( ldx ) + if ( !lwx ) { - pldtfac( vpwxmi, vpwxma, &factor, &tstart ); - tp = xtick1 * ( floor( ( vpwxma - tstart ) / xtick1 ) + 1 ) + tstart; + plP_movphy( vppxma, vppyma ); + plP_draphy( vppxmi, vppyma ); } - else - tp = xtick1 * ( floor( vpwxma / xtick1 ) + 1 ); - for (;; ) + if ( ltx && !lxx ) { - tn = tp - xtick1; - if ( lsx ) + if ( ldx ) { - if ( llx ) + pldtfac( vpwxmi, vpwxma, &factor, &tstart ); + tp = xtick1 * ( floor( ( vpwxma - tstart ) / xtick1 ) + 1 ) + tstart; + } + else + tp = xtick1 * ( floor( vpwxma / xtick1 ) + 1 ); + for (;; ) + { + tn = tp - xtick1; + if ( lsx ) { - for ( i = 7; i >= 0; i-- ) + if ( llx ) { - temp = tn + xlog[i]; - if ( BETW( temp, vpwxmi, vpwxma ) ) - plxtik( plP_wcpcx( temp ), vppyma, i2x, i1x ); + for ( i = 7; i >= 0; i-- ) + { + temp = tn + xlog[i]; + if ( BETW( temp, vpwxmi, vpwxma ) ) + plxtik( plP_wcpcx( temp ), vppyma, i2x, i1x ); + } } - } - else - { - for ( i = nxsub1 - 1; i >= 1; i-- ) + else { - temp = tn + i * xtick1 / nxsub1; - if ( BETW( temp, vpwxmi, vpwxma ) ) - plxtik( plP_wcpcx( temp ), vppyma, i2x, i1x ); + for ( i = nxsub1 - 1; i >= 1; i-- ) + { + temp = tn + i * xtick1 / nxsub1; + if ( BETW( temp, vpwxmi, vpwxma ) ) + plxtik( plP_wcpcx( temp ), vppyma, i2x, i1x ); + } } } + if ( !BETW( tn, vpwxmi, vpwxma ) ) + break; + plxtik( plP_wcpcx( tn ), vppyma, i4x, i3x ); + tp = tn; } - if ( !BETW( tn, vpwxmi, vpwxma ) ) - break; - plxtik( plP_wcpcx( tn ), vppyma, i4x, i3x ); - tp = tn; } } - } -// Draw left-hand frame of box +// Draw the left-hand frame of box - if ( lby || luy ) - { - if ( !luy ) + if ( lby || luy ) { - plP_movphy( vppxmi, vppyma ); - plP_draphy( vppxmi, vppymi ); - } - if ( lty && !lxy ) - { - if ( ldy ) + if ( !luy ) { - pldtfac( vpwymi, vpwyma, &factor, &tstart ); - tp = ytick1 * ( floor( ( vpwymi - tstart ) / ytick1 ) + 1 ) + tstart; + plP_movphy( vppxmi, vppyma ); + plP_draphy( vppxmi, vppymi ); } - else - tp = ytick1 * ( floor( vpwyma / ytick1 ) + 1 ); - for (;; ) + if ( lty && !lxy ) { - tn = tp - ytick1; - if ( lsy ) + if ( ldy ) { - if ( lly ) + pldtfac( vpwymi, vpwyma, &factor, &tstart ); + tp = ytick1 * ( floor( ( vpwymi - tstart ) / ytick1 ) + 1 ) + tstart; + } + else + tp = ytick1 * ( floor( vpwyma / ytick1 ) + 1 ); + for (;; ) + { + tn = tp - ytick1; + if ( lsy ) { - for ( i = 7; i >= 0; i-- ) + if ( lly ) { - temp = tn + xlog[i]; - if ( BETW( temp, vpwymi, vpwyma ) ) - plytik( vppxmi, plP_wcpcy( temp ), i1y, i2y ); + for ( i = 7; i >= 0; i-- ) + { + temp = tn + xlog[i]; + if ( BETW( temp, vpwymi, vpwyma ) ) + plytik( vppxmi, plP_wcpcy( temp ), i1y, i2y ); + } } - } - else - { - for ( i = nysub1 - 1; i >= 1; i-- ) + else { - temp = tn + i * ytick1 / nysub1; - if ( BETW( temp, vpwymi, vpwyma ) ) - plytik( vppxmi, plP_wcpcy( temp ), i1y, i2y ); + for ( i = nysub1 - 1; i >= 1; i-- ) + { + temp = tn + i * ytick1 / nysub1; + if ( BETW( temp, vpwymi, vpwyma ) ) + plytik( vppxmi, plP_wcpcy( temp ), i1y, i2y ); + } } } + if ( !BETW( tn, vpwymi, vpwyma ) ) + break; + plytik( vppxmi, plP_wcpcy( tn ), i3y, i4y ); + tp = tn; } - if ( !BETW( tn, vpwymi, vpwyma ) ) - break; - plytik( vppxmi, plP_wcpcy( tn ), i3y, i4y ); - tp = tn; } } - } -// Draw the horizontal axis - - if ( lax ) - { - plP_movphy( vppxmi, (PLINT) yp0 ); - plP_draphy( vppxma, (PLINT) yp0 ); - if ( ltx && !lxx ) + // Draw the horizontal axis. + if ( lax ) { - tp = xtick1 * floor( vpwxmi / xtick1 ); - for (;; ) + plP_movphy( vppxmi, (PLINT) yp0 ); + plP_draphy( vppxma, (PLINT) yp0 ); + if ( ltx && !lxx ) { - tn = tp + xtick1; - if ( lsx ) + tp = xtick1 * floor( vpwxmi / xtick1 ); + for (;; ) { - if ( llx ) + tn = tp + xtick1; + if ( lsx ) { - for ( i = 0; i <= 7; i++ ) + if ( llx ) { - temp = tp + xlog[i]; - if ( BETW( temp, vpwxmi, vpwxma ) ) - plxtik( plP_wcpcx( temp ), (PLINT) yp0, xminor, xminor ); + for ( i = 0; i <= 7; i++ ) + { + temp = tp + xlog[i]; + if ( BETW( temp, vpwxmi, vpwxma ) ) + plxtik( plP_wcpcx( temp ), (PLINT) yp0, xminor, xminor ); + } } - } - else - { - for ( i = 1; i <= nxsub1 - 1; i++ ) + else { - temp = tp + i * xtick1 / nxsub1; - if ( BETW( temp, vpwxmi, vpwxma ) ) - plxtik( plP_wcpcx( temp ), (PLINT) yp0, xminor, xminor ); + for ( i = 1; i <= nxsub1 - 1; i++ ) + { + temp = tp + i * xtick1 / nxsub1; + if ( BETW( temp, vpwxmi, vpwxma ) ) + plxtik( plP_wcpcx( temp ), (PLINT) yp0, xminor, xminor ); + } } } + if ( !BETW( tn, vpwxmi, vpwxma ) ) + break; + plxtik( plP_wcpcx( tn ), (PLINT) yp0, xmajor, xmajor ); + tp = tn; } - if ( !BETW( tn, vpwxmi, vpwxma ) ) - break; - plxtik( plP_wcpcx( tn ), (PLINT) yp0, xmajor, xmajor ); - tp = tn; } } - } -// Draw the vertical axis - - if ( lay ) - { - plP_movphy( (PLINT) xp0, vppymi ); - plP_draphy( (PLINT) xp0, vppyma ); - if ( lty && !lxy ) + // Draw the vertical axis. + if ( lay ) { - tp = ytick1 * floor( vpwymi / ytick1 ); - for (;; ) + plP_movphy( (PLINT) xp0, vppymi ); + plP_draphy( (PLINT) xp0, vppyma ); + if ( lty && !lxy ) { - tn = tp + ytick1; - if ( lsy ) + tp = ytick1 * floor( vpwymi / ytick1 ); + for (;; ) { - if ( lly ) + tn = tp + ytick1; + if ( lsy ) { - for ( i = 0; i <= 7; i++ ) + if ( lly ) { - temp = tp + xlog[i]; - if ( BETW( temp, vpwymi, vpwyma ) ) - plytik( (PLINT) xp0, plP_wcpcy( temp ), yminor, yminor ); + for ( i = 0; i <= 7; i++ ) + { + temp = tp + xlog[i]; + if ( BETW( temp, vpwymi, vpwyma ) ) + plytik( (PLINT) xp0, plP_wcpcy( temp ), yminor, yminor ); + } } - } - else - { - for ( i = 1; i <= nysub1 - 1; i++ ) + else { - temp = tp + i * ytick1 / nysub1; - if ( BETW( temp, vpwymi, vpwyma ) ) - plytik( (PLINT) xp0, plP_wcpcy( temp ), yminor, yminor ); + for ( i = 1; i <= nysub1 - 1; i++ ) + { + temp = tp + i * ytick1 / nysub1; + if ( BETW( temp, vpwymi, vpwyma ) ) + plytik( (PLINT) xp0, plP_wcpcy( temp ), yminor, yminor ); + } } } + if ( !BETW( tn, vpwymi, vpwyma ) ) + break; + plytik( (PLINT) xp0, plP_wcpcy( tn ), ymajor, ymajor ); + tp = tn; } - if ( !BETW( tn, vpwymi, vpwyma ) ) - break; - plytik( (PLINT) xp0, plP_wcpcy( tn ), ymajor, ymajor ); - tp = tn; } } + + // Draw grids. + grid_box( xopt, xtick1, nxsub1, yopt, ytick1, nysub1 ); } -// Draw grids - - grid_box( xopt, xtick1, nxsub1, yopt, ytick1, nysub1 ); - -// Write labels - + // Write labels. label_box( xopt, xtick1, yopt, ytick1 ); // Restore the clip limits to viewport edge @@ -1368,7 +1394,7 @@ lxy = plP_stsearch( yopt, 'x' ); plP_xgvpw( &vpwxmin, &vpwxmax, &vpwymin, &vpwymax ); -// n.b. large change; vpwxmi always numerically less than vpwxma, and +// vpwxmi always numerically less than vpwxma, and // similarly for vpwymi vpwxmi = ( vpwxmax > vpwxmin ) ? vpwxmin : vpwxmax; vpwxma = ( vpwxmax > vpwxmin ) ? vpwxmax : vpwxmin; @@ -1376,160 +1402,165 @@ vpwyma = ( vpwymax > vpwymin ) ? vpwymax : vpwymin; // Write horizontal label(s) - - if ( ( lmx || lnx ) && ( ltx || lxx ) ) + if ( plsc->if_boxbb ) { - PLINT xmode, xprec, xdigmax, xdigits, xscale; + } + 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(); + plgxax( &xdigmax, &xdigits ); + pldprec( vpwxmi, vpwxma, xtick1, lfx, &xmode, &xprec, xdigmax, &xscale ); + timefmt = plP_gtimefmt(); - if ( ldx ) - { - pldtfac( vpwxmi, vpwxma, &factor, &tstart ); - tp = xtick1 * ( 1. + floor( ( vpwxmi - tstart ) / xtick1 ) ) + tstart; - } - else - tp = xtick1 * ( 1. + floor( vpwxmi / xtick1 ) ); - for ( tn = tp; BETW( tn, vpwxmi, vpwxma ); tn += xtick1 ) - { if ( ldx ) { - strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); + pldtfac( vpwxmi, vpwxma, &factor, &tstart ); + tp = xtick1 * ( 1. + floor( ( vpwxmi - tstart ) / xtick1 ) ) + tstart; } else + tp = xtick1 * ( 1. + floor( vpwxmi / xtick1 ) ); + for ( tn = tp; BETW( tn, vpwxmi, vpwxma ); tn += xtick1 ) { - plform( PL_X_AXIS, tn, xscale, xprec, string, STRING_LEN, llx, lfx, lox ); + if ( ldx ) + { + strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); + } + else + { + plform( PL_X_AXIS, tn, xscale, xprec, string, STRING_LEN, llx, lfx, lox ); + } + 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 ) + plmtex( "t", 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 ) - 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 ) - { - // Assume label data is for placement of exponents if no custom - // label function is provided. - if ( plsc->label_data ) + if ( !llx && !ldx && !lox && xmode ) { - height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp; - pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos; - just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just; + // 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 ) + plmtex( "b", height, pos, just, string ); + if ( lmx ) + plmtex( "t", height, pos, just, string ); } - else - { - height = 3.2; - pos = 1.0; - just = 0.5; - } - snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) xscale ); - if ( lnx ) - plmtex( "b", height, pos, just, string ); - if ( lmx ) - 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; - 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 ) - { + ydigits = 0; if ( ldy ) { - strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); + 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 ) { - 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 ) + if ( ldy ) { - height = liy ? 1.0 : 0.5; - plmtex( "lv", height, pos, 1.0, string ); + strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); } else { - height = liy ? 1.75 : 1.5; - plmtex( "l", height, pos, 0.5, string ); + plform( PL_Y_AXIS, tn, yscale, yprec, string, STRING_LEN, lly, lfy, loy ); } - } - if ( lmy ) - { - if ( lvy ) + pos = ( vpwymax > vpwymin ) ? + ( tn - vpwymi ) / ( vpwyma - vpwymi ) : + ( vpwyma - tn ) / ( vpwyma - vpwymi ); + if ( lny ) { - height = liy ? 1.0 : 0.5; - plmtex( "rv", height, pos, 0.0, string ); + if ( lvy ) + { + height = liy ? 1.0 : 0.5; + plmtex( "lv", height, pos, 1.0, string ); + } + else + { + height = liy ? 1.75 : 1.5; + plmtex( "l", height, pos, 0.5, string ); + } } - else + if ( lmy ) { - height = liy ? 1.75 : 1.5; - plmtex( "r", height, pos, 0.5, string ); + if ( lvy ) + { + height = liy ? 1.0 : 0.5; + plmtex( "rv", height, pos, 0.0, string ); + } + else + { + height = liy ? 1.75 : 1.5; + plmtex( "r", height, pos, 0.5, string ); + } } + ydigits = MAX( ydigits, (PLINT) strlen( string ) ); } - ydigits = MAX( ydigits, (PLINT) strlen( string ) ); - } - if ( !lvy ) - ydigits = 2; + 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 ) - { - snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) yscale ); - if ( plsc->label_data ) + if ( !lly && !ldy && !loy && ymode ) { - 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 ) + snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) yscale ); + if ( plsc->label_data ) { - pos = 0.0 - offset; - just = 1.0; + height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp; + pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos; + just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just; } - if ( lmy ) + else { - pos = 1.0 + offset; - just = 0.0; + offset = 0.02; + height = 2.0; + if ( lny ) + { + pos = 0.0 - offset; + just = 1.0; + } + if ( lmy ) + { + pos = 1.0 + offset; + just = 0.0; + } } + plmtex( "t", height, pos, just, string ); } - plmtex( "t", height, pos, just, string ); } } } @@ -1602,195 +1633,223 @@ vpwymi = ( vpwymax > vpwymin ) ? vpwymin : vpwymax; vpwyma = ( vpwymax > vpwymin ) ? vpwymax : vpwymin; + if ( plsc->if_boxbb ) + { + PLINT xmajor = MAX( ROUND( plsc->majht * plsc->ypmm ), 1 ); + PLINT ymajor = MAX( ROUND( plsc->majht * plsc->xpmm ), 1 ); + // Bounding-box limits for the box in mm before corrections + // for decorations are applied. + plsc->boxbb_xmin = plsc->vppxmi / plsc->xpmm; + plsc->boxbb_xmax = plsc->vppxma / plsc->xpmm; + plsc->boxbb_ymin = plsc->vppymi / plsc->ypmm; + plsc->boxbb_ymax = plsc->vppyma / plsc->ypmm; + // Carefully follow logic below for the case where + // an inverted major tick mark is written (in the X direction + // for a Y axis and vice versa). Ignore minor tick marks + // which are assumed to be smaller. + if ( lix && ( lmx || lnx ) && ( ltx && !lxx ) ) + { + plsc->boxbb_ymin -= xmajor / plsc->ypmm; + plsc->boxbb_ymax += xmajor / plsc->ypmm; + } + if ( liy && ( lmy || lny ) && ( lty && !lxy ) ) + { + plsc->boxbb_xmin -= ymajor / plsc->xpmm; + plsc->boxbb_xmax += ymajor / plsc->xpmm; + } + } + else + { // Write horizontal label(s) - if ( ( lmx || lnx ) && ( ltx || lxx ) ) - { - PLINT xmode, xprec, xscale; - PLFLT x_spacing, x_spacing_tmp; + if ( ( lmx || lnx ) && ( ltx || lxx ) ) + { + PLINT xmode, xprec, xscale; + PLFLT x_spacing, x_spacing_tmp; - // Determine spacing between ticks - // Use the x-size of the window - x_spacing = vpwxma - vpwxmi; - if ( n_xticks > 1 ) - { - // Use the smallest space between ticks - for ( i = 1; i < n_xticks; i++ ) + // Determine spacing between ticks + // Use the x-size of the window + x_spacing = vpwxma - vpwxmi; + if ( n_xticks > 1 ) { - x_spacing_tmp = fabs( xticks[i] - xticks[i - 1] ); - x_spacing = MIN( x_spacing, x_spacing_tmp ); + // Use the smallest space between ticks + for ( i = 1; i < n_xticks; i++ ) + { + x_spacing_tmp = fabs( xticks[i] - xticks[i - 1] ); + x_spacing = MIN( x_spacing, x_spacing_tmp ); + } } - } - plgxax( &xdigmax, &xdigits ); - pldprec( vpwxmi, vpwxma, x_spacing, lfx, &xmode, &xprec, xdigmax, &xscale ); - timefmt = plP_gtimefmt(); + plgxax( &xdigmax, &xdigits ); + pldprec( vpwxmi, vpwxma, x_spacing, lfx, &xmode, &xprec, xdigmax, &xscale ); + timefmt = plP_gtimefmt(); - // Loop through all of the tick marks - for ( i = 0; i < n_xticks; i++ ) - { - tn = xticks[i]; - if ( BETW( tn, vpwxmi, vpwxma ) ) + // Loop through all of the tick marks + for ( i = 0; i < n_xticks; i++ ) { - if ( ldx ) + tn = xticks[i]; + if ( BETW( tn, vpwxmi, vpwxma ) ) { - strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); + if ( !lxx ) + { + plwxtik( tn, vpwymin, FALSE, !lix ); + plwxtik( tn, vpwymax, FALSE, lix ); + } + if ( ldx ) + { + strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); + } + else + { + plform( PL_X_AXIS, tn, xscale, xprec, string, STRING_LEN, llx, lfx, lox ); + } + 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 ) + plmtex( "t", height, pos, 0.5, string ); } + } + xdigits = 2; + plsxax( xdigmax, xdigits ); + + // Write separate exponential label if mode = 1. + + if ( !llx && !ldx && !lox && xmode ) + { + // 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 { - plform( PL_X_AXIS, tn, xscale, xprec, string, STRING_LEN, llx, lfx, lox ); + height = 3.2; + pos = 1.0; + just = 0.5; } - height = lix ? 1.75 : 1.5; - pos = ( vpwxmax > vpwxmin ) ? - ( tn - vpwxmi ) / ( vpwxma - vpwxmi ) : - ( vpwxma - tn ) / ( vpwxma - vpwxmi ); + snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) xscale ); if ( lnx ) - plmtex( "b", height, pos, 0.5, string ); + plmtex( "b", height, pos, just, string ); if ( lmx ) - plmtex( "t", height, pos, 0.5, string ); - if ( !lxx ) - { - plwxtik( tn, vpwymin, FALSE, !lix ); - plwxtik( tn, vpwymax, FALSE, lix ); - } + plmtex( "t", height, pos, just, string ); } } - xdigits = 2; - plsxax( xdigmax, xdigits ); - // Write separate exponential label if mode = 1. +// Write vertical label(s) - if ( !llx && !ldx && !lox && xmode ) + if ( ( lmy || lny ) && ( lty || lxy ) ) { - // 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 ) - plmtex( "b", height, pos, just, string ); - if ( lmx ) - plmtex( "t", height, pos, just, string ); - } - } + PLINT ymode, yprec, yscale; + PLFLT y_spacing, y_spacing_tmp; -// Write vertical label(s) - - if ( ( lmy || lny ) && ( lty || lxy ) ) - { - PLINT ymode, yprec, yscale; - PLFLT y_spacing, y_spacing_tmp; - - // Determine spacing between ticks - // Use the y-size of the window - y_spacing = vpwyma - vpwymi; - if ( n_yticks > 1 ) - { - // Use the smallest space between ticks - for ( i = 1; i < n_yticks; i++ ) + // Determine spacing between ticks + // Use the y-size of the window + y_spacing = vpwyma - vpwymi; + if ( n_yticks > 1 ) { - y_spacing_tmp = fabs( yticks[i] - yticks[i - 1] ); - y_spacing = MIN( y_spacing, y_spacing_tmp ); + // Use the smallest space between ticks + for ( i = 1; i < n_yticks; i++ ) + { + y_spacing_tmp = fabs( yticks[i] - yticks[i - 1] ); + y_spacing = MIN( y_spacing, y_spacing_tmp ); + } } - } - plgyax( &ydigmax, &ydigits ); - pldprec( vpwymi, vpwyma, y_spacing, lfy, &ymode, &yprec, ydigmax, &yscale ); - timefmt = plP_gtimefmt(); + plgyax( &ydigmax, &ydigits ); + pldprec( vpwymi, vpwyma, y_spacing, lfy, &ymode, &yprec, ydigmax, &yscale ); + timefmt = plP_gtimefmt(); - ydigits = 0; - for ( i = 0; i < n_yticks; i++ ) - { - tn = yticks[i]; - if ( BETW( tn, vpwymi, vpwyma ) ) + ydigits = 0; + for ( i = 0; i < n_yticks; i++ ) { - if ( ldy ) + tn = yticks[i]; + if ( BETW( tn, vpwymi, vpwyma ) ) { - strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); - } - 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 ) + if ( !lxy ) { - height = liy ? 1.0 : 0.5; - plmtex( "lv", height, pos, 1.0, string ); + plwytik( vpwxmin, tn, FALSE, !liy ); + plwytik( vpwxmax, tn, FALSE, liy ); } + if ( ldy ) + { + strfqsas( string, STRING_LEN, timefmt, (double) tn, plsc->qsasconfig ); + } else { - height = liy ? 1.75 : 1.5; - plmtex( "l", height, pos, 0.5, string ); + plform( PL_Y_AXIS, tn, yscale, yprec, string, STRING_LEN, lly, lfy, loy ); } - } - if ( lmy ) - { - if ( lvy ) + pos = ( vpwymax > vpwymin ) ? + ( tn - vpwymi ) / ( vpwyma - vpwymi ) : + ( vpwyma - tn ) / ( vpwyma - vpwymi ); + if ( lny ) { - height = liy ? 1.0 : 0.5; - plmtex( "rv", height, pos, 0.0, string ); + if ( lvy ) + { + height = liy ? 1.0 : 0.5; + plmtex( "lv", height, pos, 1.0, string ); + } + else + { + height = liy ? 1.75 : 1.5; + plmtex( "l", height, pos, 0.5, string ); + } } - else + if ( lmy ) { - height = liy ? 1.75 : 1.5; - plmtex( "r", height, pos, 0.5, string ); + if ( lvy ) + { + height = liy ? 1.0 : 0.5; + plmtex( "rv", height, pos, 0.0, string ); + } + else + { + height = liy ? 1.75 : 1.5; + plmtex( "r", height, pos, 0.5, string ); + } } + ydigits = MAX( ydigits, (PLINT) strlen( string ) ); } - ydigits = MAX( ydigits, (PLINT) strlen( string ) ); - if ( !lxy ) - { - plwytik( vpwxmin, tn, FALSE, !liy ); - plwytik( vpwxmax, tn, FALSE, liy ); - } } - } - if ( !lvy ) - ydigits = 2; + 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 ) - { - snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) yscale ); - if ( plsc->label_data ) + if ( !lly && !ldy && !loy && ymode ) { - 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 ) + snprintf( string, STRING_LEN, "(x10#u%d#d)", (int) yscale ); + if ( plsc->label_data ) { - pos = 0.0 - offset; - just = 1.0; + height = ( (PLLabelDefaults *) plsc->label_data )->exp_label_disp; + pos = ( (PLLabelDefaults *) plsc->label_data )->exp_label_pos; + just = ( (PLLabelDefaults *) plsc->label_data )->exp_label_just; } - if ( lmy ) + else { - pos = 1.0 + offset; - just = 0.0; + offset = 0.02; + height = 2.0; + if ( lny ) + { + pos = 0.0 - offset; + just = 1.0; + } + if ( lmy ) + { + pos = 1.0 + offset; + just = 0.0; + } } + plmtex( "t", height, pos, just, string ); } - plmtex( "t", height, pos, just, string ); } } Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2011-06-20 18:03:03 UTC (rev 11773) +++ trunk/src/pllegend.c 2011-06-20 22:09:33 UTC (rev 11774) @@ -1012,6 +1012,64 @@ plline( 3, xs, ys ); } +static void +draw_box( PLBOOL if_bb, PLINT opt, const char *axis_opts, PLBOOL if_edge, + PLFLT ticks, PLINT sub_ticks, PLINT n_values, const PLFLT *values ) +{ + // axis option strings. + const char *edge_string; + size_t length_axis_opts = strlen( axis_opts ); + char *local_axis_opts; + + // local_axis_opts is local version that can be modified from + // const input version. + if ( ( local_axis_opts = (char *) malloc( ( length_axis_opts + 1 ) * sizeof ( char ) ) ) == NULL ) + { + plexit( "draw_box: Insufficient memory" ); + } + strcpy( local_axis_opts, axis_opts ); + + plsc->if_boxbb = if_bb; + // Draw numerical labels and tick marks if this is a shade color bar + // TODO: A better way to handle this would be to update the + // internals of plbox to support custom tick and label positions + // along an axis. + + if ( opt & PL_COLORBAR_SHADE && opt & PL_COLORBAR_SHADE_LABEL ) + { + if ( opt & PL_COLORBAR_ORIENT_RIGHT || opt & PL_COLORBAR_ORIENT_LEFT ) + label_box_custom( local_axis_opts, n_values, values, "", 0, NULL ); + else + label_box_custom( "", 0, NULL, local_axis_opts, n_values, values ); + if ( if_bb ) + { + plsc->if_boxbb = FALSE; + return; + } + // Exclude ticks for plbox call below since those tick marks and + // associated labels have already been handled in a custom way above. + remove_characters( local_axis_opts, "TtXx" ); + } + + // Draw the outline for the entire colorbar, tick marks, tick labels. + + if ( if_edge ) + edge_string = "bc"; + else + edge_string = "uw"; + if ( opt & PL_COLORBAR_ORIENT_TOP || opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + plbox( edge_string, 0.0, 0, local_axis_opts, ticks, sub_ticks ); + } + else + { + plbox( local_axis_opts, ticks, sub_ticks, edge_string, 0.0, 0 ); + } + plsc->if_boxbb = FALSE; + + free( local_axis_opts ); +} + //-------------------------------------------------------------------------- //! Plot color bar for image, shade or gradient plots. //! @@ -1183,19 +1241,19 @@ PLFLT label_offset = 0.; // For building plmtex option string. - PLINT max_opts = 25; - char opt_string[max_opts]; - char perp; + PLINT max_opts = 25; + char opt_string[max_opts]; + char perp; - // axis option strings. - const char *edge_string; - size_t length_axis_opts = strlen( axis_opts ); - char *local_axis_opts; - PLBOOL if_edge; + PLBOOL if_edge; // Character height in x and y normalized subpage coordinates. PLFLT character_height_x, character_height_y; + // Ratio of normalized subpage coordinates to mm coordinates in + // x and y. + PLFLT ncxpmm, ncypmm; + // 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 ) ) { @@ -1267,19 +1325,11 @@ opt = opt | PL_COLORBAR_ORIENT_RIGHT; } - // local_axis_opts is local version that can be modified from - // const input version. - if ( ( local_axis_opts = (char *) malloc( ( length_axis_opts + 1 ) * sizeof ( char ) ) ) == NULL ) - { - plexit( "plcolorbar: Insufficient memory" ); - } - strcpy( local_axis_opts, axis_opts ); + if_edge = plP_stsearch( axis_opts, 'b' ) && + !plP_stsearch( axis_opts, 'u' ) && + plP_stsearch( axis_opts, 'c' ) && + !plP_stsearch( axis_opts, 'w' ); - if_edge = plP_stsearch( local_axis_opts, 'b' ) && - !plP_stsearch( local_axis_opts, 'u' ) && - plP_stsearch( local_axis_opts, 'c' ) && - !plP_stsearch( local_axis_opts, 'w' ); - min_value = values[0]; max_value = values[ n_values - 1 ]; @@ -1288,14 +1338,12 @@ // Width and height of the undecorated colorbar in normalized // subpage coordinates. - colorbar_width = adopted_to_subpage_x( x_length ) - - adopted_to_subpage_x( 0. ); + colorbar_width = adopted_to_subpage_x( x_length ) - + 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. - // FIXME. Need to add inverted tickmarks + numerical tick labels + text to - // these calculations. if ( opt & PL_COLORBAR_ORIENT_RIGHT || opt & PL_COLORBAR_ORIENT_LEFT ) { cap_extent = cap_ratio * colorbar_height / aspspp; @@ -1305,27 +1353,77 @@ cap_extent = cap_ratio * colorbar_width * aspspp; } - colorbar_width_bb = colorbar_width; - colorbar_height_bb = colorbar_height; + // Specify the proper window ranges for colorbar depending on + // orientation. + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) + { + wx_min = min_value; + wx_max = max_value; + wy_min = 0.0; + wy_max = 1.0; + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { + wx_min = 0.0; + wx_max = 1.0; + wy_min = min_value; + wy_max = max_value; + } + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) + { + wx_min = max_value; + wx_max = min_value; + wy_min = 0.0; + wy_max = 1.0; + } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + wx_min = 0.0; + wx_max = 1.0; + wy_min = max_value; + wy_max = min_value; + } + else + { + plabort( "plcolorbar: Invalid PL_COLORBAR_ORIENT_* bits" ); + } + // Viewport is correct size, but has an incorrect offset compared + // to the final result, but this should not affect the bounding + // box range or offsets calculated just below. + plvpor( 0., colorbar_width, 0., colorbar_height ); + plwind( wx_min, wx_max, wy_min, wy_max ); + + // Calculate the bounding box for decorated (i.e., including tick + // 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; if ( opt & PL_COLORBAR_CAP_LOW ) { if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { colorbar_width_bb += cap_extent; - dx_subpage += cap_extent; + dx_subpage += cap_extent; } - if (opt & PL_COLORBAR_ORIENT_TOP ) + if ( opt & PL_COLORBAR_ORIENT_TOP ) { colorbar_height_bb += cap_extent; } - if (opt & PL_COLORBAR_ORIENT_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_LEFT ) { colorbar_width_bb += cap_extent; } - if (opt & PL_COLORBAR_ORIENT_BOTTOM ) + if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) { colorbar_height_bb += cap_extent; - dy_subpage -= cap_extent; + dy_subpage -= cap_extent; } } if ( opt & PL_COLORBAR_CAP_HIGH ) @@ -1334,25 +1432,25 @@ { colorbar_width_bb += cap_extent; } - if (opt & PL_COLORBAR_ORIENT_TOP ) + if ( opt & PL_COLORBAR_ORIENT_TOP ) { colorbar_height_bb += cap_extent; - dy_subpage -= cap_extent; + dy_subpage -= cap_extent; } - if (opt & PL_COLORBAR_ORIENT_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_LEFT ) { colorbar_width_bb += cap_extent; - dx_subpage += cap_extent; + dx_subpage += cap_extent; } - if (opt & PL_COLORBAR_ORIENT_BOTTOM ) + if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) { colorbar_height_bb += cap_extent; } } // Total width and height of colorbar bounding box in adopted subpage // coordinates. - colorbar_width_vc = subpage_to_adopted_x( colorbar_width_bb ) - - subpage_to_adopted_x( 0. ); + colorbar_width_vc = subpage_to_adopted_x( colorbar_width_bb ) - + subpage_to_adopted_x( 0. ); colorbar_height_vc = subpage_to_adopted_y( colorbar_height_bb ) - subpage_to_adopted_y( 0. ); *p_colorbar_width = colorbar_width_vc; @@ -1368,17 +1466,14 @@ plot_x_subpage = plot_x_subpage_bb + dx_subpage; plot_y_subpage = plot_y_subpage_bb + dy_subpage; - // Specify the proper window ranges depending on orientation. + // Specify the proper viewport ranges for colorbar depending on + // orientation. if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { vx_min = plot_x_subpage; vx_max = plot_x_subpage + colorbar_width; vy_min = plot_y_subpage - colorbar_height; vy_max = plot_y_subpage; - wx_min = min_value; - wx_max = max_value; - wy_min = 0.0; - wy_max = 1.0; } else if ( opt & PL_COLORBAR_ORIENT_TOP ) { @@ -1386,10 +1481,6 @@ vx_max = plot_x_subpage + colorbar_width; vy_min = plot_y_subpage - colorbar_height; vy_max = plot_y_subpage; - wx_min = 0.0; - wx_max = 1.0; - wy_min = min_value; - wy_max = max_value; } else if ( opt & PL_COLORBAR_ORIENT_LEFT ) { @@ -1397,10 +1488,6 @@ vx_max = plot_x_subpage + colorbar_width; vy_min = plot_y_subpage - colorbar_height; vy_max = plot_y_subpage; - wx_min = max_value; - wx_max = min_value; - wy_min = 0.0; - wy_max = 1.0; } else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) { @@ -1408,10 +1495,6 @@ vx_max = plot_x_subpage + colorbar_width; vy_min = plot_y_subpage - colorbar_height; vy_max = plot_y_subpage; - wx_min = 0.0; - wx_max = 1.0; - wy_min = max_value; - wy_max = min_value; } else { @@ -1730,12 +1813,12 @@ if ( ( opt & PL_COLORBAR_ORIENT_RIGHT && opt & PL_COLORBAR_LABEL_LEFT ) || ( opt & PL_COLORBAR_ORIENT_LEFT && opt & PL_COLORBAR_LABEL_RIGHT ) ) { - label_offset += cap_extent/character_height_x; + label_offset += cap_extent / character_height_x; } if ( ( opt & PL_COLORBAR_ORIENT_TOP && opt & PL_COLORBAR_LABEL_BOTTOM ) || ( opt & PL_COLORBAR_ORIENT_BOTTOM && opt & PL_COLORBAR_LABEL_TOP ) ) { - label_offset += cap_extent/character_height_y; + label_offset += cap_extent / character_height_y; } // Draw a filled triangle (cap/arrow) at the low end of the scale if ( opt & PL_COLORBAR_ORIENT_RIGHT ) @@ -1766,12 +1849,12 @@ if ( ( opt & PL_COLO... [truncated message content] |