From: <ai...@us...> - 2011-02-13 21:07:05
|
Revision: 11565 http://plplot.svn.sourceforge.net/plplot/?rev=11565&view=rev Author: airwin Date: 2011-02-13 21:06:58 +0000 (Sun, 13 Feb 2011) Log Message: ----------- Implement honoring of PL_POSITION_VIEWPORT and PL_POSITION_SUBPAGE bits of position argument for plllegend. (Note, this is not an API change for pllegend.) Use the PL_POSITION_SUBPAGE bit to make page 3 of example 33 slightly more convenient to implement. N.B. I have left it to Hez to deal with the OCaml change to example 33 because I don't grok OCaml. However, my examples changes are consistent for all our other languages where example 33 is currently implemented. Modified Paths: -------------- trunk/examples/c/x33c.c trunk/examples/c++/x33.cc trunk/examples/f77/x33f.fm4 trunk/examples/f95/x33f.f90 trunk/examples/java/x33.java trunk/examples/octave/x33c.m trunk/examples/python/xw33.py trunk/src/pllegend.c Modified: trunk/examples/c/x33c.c =================================================================== --- trunk/examples/c/x33c.c 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/c/x33c.c 2011-02-13 21:06:58 UTC (rev 11565) @@ -469,16 +469,16 @@ // Third page demonstrating legend alignment pladv( 0 ); - plvpor( 0., 1., 0., 1. ); + plvpor( 0.0, 1.0, 0.0, 0.9 ); plwind( 0.0, 1.0, 0.0, 1.0 ); plsfont( PL_FCI_SANS, -1, -1 ); - plmtex( "t", -2.0, 0.5, 0.5, "Demonstrate legend alignment" ); + plmtex( "t", 2.0, 0.5, 0.5, "Demonstrate legend alignment" ); x = 0.1; y = 0.1; nturn = 4; nlegend = 0; - position = PL_POSITION_TOP | PL_POSITION_LEFT; + position = PL_POSITION_TOP | PL_POSITION_LEFT | PL_POSITION_SUBPAGE; opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX; opt = opt_base; for ( i = 0; i < 9; i++ ) @@ -521,7 +521,7 @@ if ( i == nturn ) { - position = PL_POSITION_TOP | PL_POSITION_RIGHT; + position = PL_POSITION_TOP | PL_POSITION_RIGHT | PL_POSITION_SUBPAGE; opt = opt_base; x = 1. - x; y += legend_height; Modified: trunk/examples/c++/x33.cc =================================================================== --- trunk/examples/c++/x33.cc 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/c++/x33.cc 2011-02-13 21:06:58 UTC (rev 11565) @@ -458,16 +458,16 @@ // Third page demonstrating legend alignment pls->adv( 0 ); - pls->vpor( 0., 1., 0., 1. ); + pls->vpor( 0.0, 1.0, 0.0, 0.9 ); pls->wind( 0.0, 1.0, 0.0, 1.0 ); pls->sfont( PL_FCI_SANS, -1, -1 ); - pls->mtex( "t", -2.0, 0.5, 0.5, "Demonstrate legend alignment" ); + pls->mtex( "t", 2.0, 0.5, 0.5, "Demonstrate legend alignment" ); x = 0.1; y = 0.1; nturn = 4; nlegend = 0; - position = PL_POSITION_TOP | PL_POSITION_LEFT; + position = PL_POSITION_TOP | PL_POSITION_LEFT | PL_POSITION_SUBPAGE; opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX; opt = opt_base; for ( i = 0; i < 9; i++ ) @@ -510,7 +510,7 @@ if ( i == nturn ) { - position = PL_POSITION_TOP | PL_POSITION_RIGHT; + position = PL_POSITION_TOP | PL_POSITION_RIGHT | PL_POSITION_SUBPAGE; opt = opt_base; x = 1. - x; y += legend_height; Modified: trunk/examples/f77/x33f.fm4 =================================================================== --- trunk/examples/f77/x33f.fm4 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/f77/x33f.fm4 2011-02-13 21:06:58 UTC (rev 11565) @@ -311,17 +311,18 @@ c Third page demonstrating legend alignment call pladv( 0 ) - call plvpor( 0.d0, 1.d0, 0.d0, 1.d0 ) + call plvpor( 0.0d0, 1.0d0, 0.0d0, 0.9d0 ) call plwind( 0.0d0, 1.0d0, 0.0d0, 1.0d0 ) call plsfont( PL_FCI_SANS, -1, -1 ) - call plmtex( 't', -2.0d0, 0.5d0, 0.5d0, + call plmtex( 't', 2.0d0, 0.5d0, 0.5d0, & 'Demonstrate legend alignment' ) x = 0.1d0 y = 0.1d0 nturn = 5 nlegend = 0 - position = PL_POSITION_TOP + PL_POSITION_LEFT + position = PL_POSITION_TOP + PL_POSITION_LEFT + + & PL_POSITION_SUBPAGE opt_base = PL_LEGEND_BACKGROUND + PL_LEGEND_BOUNDING_BOX opt = opt_base do 140 i = 1,9 @@ -369,7 +370,8 @@ & symbol_colors, symbol_scales, symbol_numbers, symbols ) if ( i .eq. nturn ) then - position = PL_POSITION_TOP + PL_POSITION_RIGHT + position = PL_POSITION_TOP + PL_POSITION_RIGHT + + & PL_POSITION_SUBPAGE opt = opt_base x = 1.d0 - x y = y + legend_height Modified: trunk/examples/f95/x33f.f90 =================================================================== --- trunk/examples/f95/x33f.f90 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/f95/x33f.f90 2011-02-13 21:06:58 UTC (rev 11565) @@ -291,17 +291,17 @@ ! Third page demonstrating legend alignment call pladv( 0 ) - call plvpor( 0._plflt, 1._plflt, 0._plflt, 1._plflt ) + call plvpor( 0.0_plflt, 1.0_plflt, 0.0_plflt, 0.9_plflt ) call plwind( 0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt ) call plsfont( PL_FCI_SANS, -1, -1 ) - call plmtex( 't', -2.0_plflt, 0.5_plflt, 0.5_plflt, & + call plmtex( 't', 2.0_plflt, 0.5_plflt, 0.5_plflt, & 'Demonstrate legend alignment' ) x = 0.1_plflt y = 0.1_plflt nturn = 5 nlegend = 0 - position = PL_POSITION_TOP + PL_POSITION_LEFT + position = PL_POSITION_TOP + PL_POSITION_LEFT + PL_POSITION_SUBPAGE opt_base = PL_LEGEND_BACKGROUND + PL_LEGEND_BOUNDING_BOX opt = opt_base do i = 1,9 @@ -349,7 +349,7 @@ symbol_colors, symbol_scales, symbol_numbers, symbols ) if ( i .eq. nturn ) then - position = PL_POSITION_TOP + PL_POSITION_RIGHT + position = PL_POSITION_TOP + PL_POSITION_RIGHT + PL_POSITION_SUBPAGE opt = opt_base x = 1._plflt - x y = y + legend_height Modified: trunk/examples/java/x33.java =================================================================== --- trunk/examples/java/x33.java 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/java/x33.java 2011-02-13 21:06:58 UTC (rev 11565) @@ -458,17 +458,17 @@ // Third page demonstrating legend alignment pls.adv( 0 ); - pls.vpor( 0., 1., 0., 1. ); + pls.vpor( 0.0, 1.0, 0.0, 0.9 ); pls.wind( 0.0, 1.0, 0.0, 1.0 ); pls.sfont( PLStream.PL_FCI_SANS, -1, -1 ); - pls.mtex( "t", -2.0, 0.5, 0.5, "Demonstrate legend alignment" ); + pls.mtex( "t", 2.0, 0.5, 0.5, "Demonstrate legend alignment" ); x = 0.1; y = 0.1; nturn = 4; nlegend = 0; opt_base = PLStream.PL_LEGEND_BACKGROUND | PLStream.PL_LEGEND_BOUNDING_BOX; - position = PLStream.PL_POSITION_TOP | PLStream.PL_POSITION_LEFT; + position = PLStream.PL_POSITION_TOP | PLStream.PL_POSITION_LEFT | PLStream.PL_POSITION_SUBPAGE; opt = opt_base; for ( i = 0; i < 9; i++ ) { @@ -525,7 +525,7 @@ if ( i == nturn ) { - position = PLStream.PL_POSITION_TOP | PLStream.PL_POSITION_RIGHT; + position = PLStream.PL_POSITION_TOP | PLStream.PL_POSITION_RIGHT | PLStream.PL_POSITION_SUBPAGE; opt = opt_base; x = 1. - x; y = y + legend_height[0]; Modified: trunk/examples/octave/x33c.m =================================================================== --- trunk/examples/octave/x33c.m 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/octave/x33c.m 2011-02-13 21:06:58 UTC (rev 11565) @@ -177,7 +177,7 @@ ## Initialize plplot ## set global attributes for PLplot variables used in this function. global PL_FCI_SANS PL_FCI_MONO PL_LEGEND_NONE PL_LEGEND_COLOR_BOX PL_LEGEND_LINE PL_LEGEND_SYMBOL PL_LEGEND_TEXT_LEFT PL_LEGEND_BACKGROUND PL_LEGEND_BOUNDING_BOX PL_LEGEND_ROW_MAJOR - global PL_POSITION_LEFT PL_POSITION_RIGHT PL_POSITION_TOP PL_POSITION_BOTTOM PL_POSITION_INSIDE PL_POSITION_OUTSIDE + global PL_POSITION_LEFT PL_POSITION_RIGHT PL_POSITION_TOP PL_POSITION_BOTTOM PL_POSITION_INSIDE PL_POSITION_OUTSIDE PL_POSITION_SUBPAGE global PL_COLORBAR_IMAGE PL_COLORBAR_SHADE PL_COLORBAR_GRADIENT PL_COLORBAR_SHADE_LABEL global position_options special_symbols plinit(); @@ -423,16 +423,16 @@ ## Third page demonstrating legend alignment pladv(0); - plvpor(0., 1., 0., 1.); + plvpor(0.0, 1.0, 0.0, 0.9); plwind(0.0, 1.0, 0.0, 1.0); plsfont(PL_FCI_SANS, -1, -1); - plmtex("t", -2.0, 0.5, 0.5, "Demonstrate legend alignment"); + plmtex("t", 2.0, 0.5, 0.5, "Demonstrate legend alignment"); x = 0.1; y = 0.1; nturn = 4; nlegend = 0; - position = bitor(PL_POSITION_LEFT, PL_POSITION_TOP); + position = bitor(bitor(PL_POSITION_LEFT, PL_POSITION_TOP), PL_POSITION_SUBPAGE); opt_base = bitor(PL_LEGEND_BACKGROUND, PL_LEGEND_BOUNDING_BOX); opt = opt_base; for i=0:8 @@ -511,7 +511,7 @@ line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); if(i == nturn) - position = bitor(PL_POSITION_RIGHT, PL_POSITION_TOP); + position = bitor(bitor(PL_POSITION_RIGHT, PL_POSITION_TOP), PL_POSITION_SUBPAGE); opt = opt_base; x = 1. - x; y += legend_height; Modified: trunk/examples/python/xw33.py =================================================================== --- trunk/examples/python/xw33.py 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/examples/python/xw33.py 2011-02-13 21:06:58 UTC (rev 11565) @@ -363,16 +363,16 @@ # Third page demonstrating legend alignment pladv(0) - plvpor(0., 1., 0., 1.) + plvpor(0.0, 1.0, 0.0, 0.9) plwind(0.0, 1.0, 0.0, 1.0) plsfont(PL_FCI_SANS, -1, -1) - plmtex("t", -2.0, 0.5, 0.5, "Demonstrate legend alignment") + plmtex("t", 2.0, 0.5, 0.5, "Demonstrate legend alignment") x = 0.1 y = 0.1 nturn = 4 nlegend = 0 - position = PL_POSITION_TOP | PL_POSITION_LEFT + position = PL_POSITION_TOP | PL_POSITION_LEFT | PL_POSITION_SUBPAGE opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX opt = opt_base for i in range(9): @@ -426,7 +426,7 @@ line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ) if i == nturn: - position = PL_POSITION_TOP | PL_POSITION_RIGHT + position = PL_POSITION_TOP | PL_POSITION_RIGHT | PL_POSITION_SUBPAGE opt = opt_base x = 1. - x y += legend_height Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2011-02-13 20:55:15 UTC (rev 11564) +++ trunk/src/pllegend.c 2011-02-13 21:06:58 UTC (rev 11565) @@ -309,7 +309,7 @@ //! @param nx External normalized viewport X coordinate. //! -#define viewport_to_subpage_x( nx ) ( ( xdmin_save ) + ( nx ) * ( ( xdmax_save ) - ( xdmin_save ) ) ) +#define viewport_to_subpage_x( nx ) ( ( xdmin_adopted ) + ( nx ) * ( ( xdmax_adopted ) - ( xdmin_adopted ) ) ) //-------------------------------------------------------------------------- //! Convert from normalized subpage X coordinate to external normalized @@ -318,7 +318,7 @@ //! @param nx Normalized subpage X coordinate. //! -#define subpage_to_viewport_x( nx ) ( ( nx - xdmin_save ) / ( ( xdmax_save ) - ( xdmin_save ) ) ) +#define subpage_to_viewport_x( nx ) ( ( nx - xdmin_adopted ) / ( ( xdmax_adopted ) - ( xdmin_adopted ) ) ) //-------------------------------------------------------------------------- //! Convert from external normalized viewport Y coordinate to normalized @@ -327,7 +327,7 @@ //! @param ny External normalized viewport Y coordinate. //! -#define viewport_to_subpage_y( ny ) ( ( ydmin_save ) + ( ny ) * ( ( ydmax_save ) - ( ydmin_save ) ) ) +#define viewport_to_subpage_y( ny ) ( ( ydmin_adopted ) + ( ny ) * ( ( ydmax_adopted ) - ( ydmin_adopted ) ) ) //-------------------------------------------------------------------------- //! Convert from normalized subpage Y coordinate to external normalized @@ -336,7 +336,7 @@ //! @param ny Normalized subpage Y coordinate. //! -#define subpage_to_viewport_y( ny ) ( ( ny - ydmin_save ) / ( ( ydmax_save ) - ( ydmin_save ) ) ) +#define subpage_to_viewport_y( ny ) ( ( ny - ydmin_adopted ) / ( ( ydmax_adopted ) - ( ydmin_adopted ) ) ) //-------------------------------------------------------------------------- //! Plot discrete annotated legend using filled boxes, lines, and/or symbols. @@ -495,7 +495,12 @@ // Saved external world coordinates of viewport. PLFLT xwmin_save, xwmax_save, ywmin_save, ywmax_save; // Saved external normalized coordinates of viewport. + // (These are actual values used only for the restore.) PLFLT xdmin_save, xdmax_save, ydmin_save, ydmax_save; + // Saved external normalized coordinates of viewport. + // (These are adopted values used to calculate all coordinate + // transformations.) + PLFLT xdmin_adopted, xdmax_adopted, ydmin_adopted, ydmax_adopted; PLFLT x_subpage_per_mm, y_subpage_per_mm, text_width0 = 0., text_width; PLFLT width_border, column_separation, @@ -546,10 +551,33 @@ return; } - // xdmin_save, etc., are the external relative viewport - // coordinates within the current sub-page. + if ( !( position & PL_POSITION_VIEWPORT ) && !( position & PL_POSITION_SUBPAGE ) ) + { + position = position | PL_POSITION_VIEWPORT; + } + else if ( ( position & PL_POSITION_VIEWPORT ) && ( position & PL_POSITION_SUBPAGE ) ) + { + plabort( "pllegend: PL_POSITION_VIEWPORT and PL_POSITION_SUBPAGE cannot be simultaneously set." ); + return; + } + + // xdmin_save, etc., are the actual external relative viewport + // coordinates within the current sub-page used only for + // restoration at the end. plgvpd( &xdmin_save, &xdmax_save, &ydmin_save, &ydmax_save ); + if ( position & PL_POSITION_SUBPAGE ) + plvpor( 0., 1., 0., 1. ); + // xdmin_adopted, etc., are the adopted external relative viewport + // coordinates within the current sub-page used for all coordinate + // transformations. + // If position & PL_POSITION_VIEWPORT is true, these coordinates + // are the external relative viewport coordinates. + // If position & PL_POSITION_SUBPAGE is true, these + // coordinates are the relative subpage coordinates. + + plgvpd( &xdmin_adopted, &xdmax_adopted, &ydmin_adopted, &ydmax_adopted ); + // xwmin_save, etc., are the external world coordinates corresponding // to the external viewport boundaries. plgvpw( &xwmin_save, &xwmax_save, &ywmin_save, &ywmax_save ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |