From: <ai...@us...> - 2010-09-25 21:11:12
|
Revision: 11212 http://plplot.svn.sourceforge.net/plplot/?rev=11212&view=rev Author: airwin Date: 2010-09-25 21:11:06 +0000 (Sat, 25 Sep 2010) Log Message: ----------- Really do have an indexed nsymbols (rather than overall) to specify the number of symbols per legend line. Tweak legend in example to make it look a bit better. Modified Paths: -------------- trunk/examples/c/x04c.c trunk/include/plplot.h trunk/src/pllegend.c Modified: trunk/examples/c/x04c.c =================================================================== --- trunk/examples/c/x04c.c 2010-09-25 20:33:17 UTC (rev 11211) +++ trunk/examples/c/x04c.c 2010-09-25 21:11:06 UTC (rev 11212) @@ -51,7 +51,7 @@ PLINT line_colors[2]; PLINT line_styles[2]; PLINT line_widths[2]; - PLINT symbol_colors[2], symbols[2]; + PLINT nsymbols[2], symbol_colors[2], symbols[2]; PLFLT symbol_scales[2]; pladv( 0 ); @@ -119,23 +119,25 @@ line_colors[0] = 2; line_colors[1] = 3; line_styles[0] = 1; - line_styles[1] = 2; + line_styles[1] = 1; line_widths[0] = 1; line_widths[1] = 1; symbol_colors[0] = 3; symbol_colors[1] = 3; - symbol_scales[0] = 1.; + symbol_scales[0] = 1.2; symbol_scales[1] = 1.; - symbols[0] = 9; + nsymbols[0] = 3; + nsymbols[1] = 4; + symbols[0] = 3; symbols[1] = 3; - plscol0a( 15, 255, 255, 255, 0.2 ); + plscol0a( 15, 128, 128, 128, 0.2 ); pllegend( PL_LEGEND_BACKGROUND, 0.1, 0.6, 0.95, 15, opt_array, 2, 1., 1.0, 2.0, 0., 1, text, line_colors, line_styles, line_widths, - 5, symbol_colors, symbol_scales, symbols, + nsymbols, symbol_colors, symbol_scales, symbols, 0., NULL, NULL ); } } Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2010-09-25 20:33:17 UTC (rev 11211) +++ trunk/include/plplot.h 2010-09-25 21:11:06 UTC (rev 11212) @@ -1223,7 +1223,7 @@ PLFLT text_offset, PLFLT text_scale, PLFLT text_spacing, PLINT text_justification, PLINT text_color, char **text, PLINT *line_colors, PLINT *line_styles, PLINT *line_widths, - PLINT nsymbols, PLINT *symbol_colors, + PLINT *nsymbols, PLINT *symbol_colors, PLFLT *symbol_scales, PLINT *symbols, PLFLT cmap0_height, PLINT *cmap0_colours, PLINT *cmap0_patterns ); Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2010-09-25 20:33:17 UTC (rev 11211) +++ trunk/src/pllegend.c 2010-09-25 21:11:06 UTC (rev 11212) @@ -85,7 +85,7 @@ PLFLT text_offset, PLFLT text_scale, PLFLT text_spacing, PLINT text_justification, PLINT text_color, char **text, PLINT *line_colors, PLINT *line_styles, PLINT *line_widths, - PLINT nsymbols, PLINT *symbol_colors, + PLINT *nsymbols, PLINT *symbol_colors, PLFLT *symbol_scales, PLINT *symbols, PLFLT cmap0_height, PLINT *cmap0_colours, PLINT *cmap0_patterns ) @@ -110,7 +110,8 @@ symbol_scale_save = plsc->symht / plsc->symdef; PLFLT x_world_per_mm, y_world_per_mm, text_width = 0.; PLFLT total_width, total_height; - PLINT some_lines = 0, some_symbols = 0, some_cmap0s; + PLINT some_lines = 0, some_symbols = 0, some_cmap0s; + PLINT max_nsymbols = 0; plschr( 0., text_scale ); @@ -119,7 +120,10 @@ if ( opt_array[i] & PL_LEGEND_LINE ) some_lines = 1; if ( opt_array[i] & PL_LEGEND_SYMBOL ) + { + max_nsymbols = MAX( max_nsymbols, nsymbols[i] ); some_symbols = 1; + } if ( opt_array[i] & PL_LEGEND_CMAP0 ) some_cmap0s = 1; } @@ -196,9 +200,9 @@ if ( some_symbols ) { - nsymbols = MAX( 2, nsymbols ); - if ( ( ( xs = (PLFLT *) malloc( nsymbols * sizeof ( PLFLT ) ) ) == NULL ) || - ( ( ys = (PLFLT *) malloc( nsymbols * sizeof ( PLFLT ) ) ) == NULL ) ) + max_nsymbols = MAX( 2, max_nsymbols ); + if ( ( ( xs = (PLFLT *) malloc( max_nsymbols * sizeof ( PLFLT ) ) ) == NULL ) || + ( ( ys = (PLFLT *) malloc( max_nsymbols * sizeof ( PLFLT ) ) ) == NULL ) ) { plexit( "pllegend: Insufficient memory" ); } @@ -210,11 +214,6 @@ // Factor should be unity. symbol_width = 0.5 * get_character_or_symbol_height( 0 ) * fabs( ( xmax - xmin ) / ( ymax - ymin ) ); - dxs = ( plot_x_end_world - plot_x_world - symbol_width ) / (double) ( nsymbols - 1 ); - for ( j = 0; j < nsymbols; j++ ) - { - xs[j] = plot_x_world + 0.5 * symbol_width + dxs * (double) j; - } } ty = text_y_world + 0.5 * text_spacing * character_height; @@ -242,11 +241,13 @@ { plcol0( symbol_colors[i] ); plssym( 0., symbol_scales[i] ); - for ( j = 0; j < nsymbols; j++ ) + dxs = ( plot_x_end_world - plot_x_world - symbol_width ) / (double) ( MAX( nsymbols[i], 2 ) - 1 ); + for ( j = 0; j < nsymbols[i]; j++ ) { + xs[j] = plot_x_world + 0.5 * symbol_width + dxs * (double) j; ys[j] = ty; } - plpoin( nsymbols, xs, ys, symbols[i] ); + plpoin( nsymbols[i], xs, ys, symbols[i] ); } } if ( some_symbols ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |