From: <ai...@us...> - 2010-09-26 00:56:33
|
Revision: 11216 http://plplot.svn.sourceforge.net/plplot/?rev=11216&view=rev Author: airwin Date: 2010-09-26 00:56:26 +0000 (Sun, 26 Sep 2010) Log Message: ----------- Put small left and right border change on legend to make better-looking background result. API change.... Implement separate text colours for each legend line and use that feature for the 4th example. 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 23:28:07 UTC (rev 11215) +++ trunk/examples/c/x04c.c 2010-09-26 00:56:26 UTC (rev 11216) @@ -48,6 +48,7 @@ PLFLT f0, freq; char *text[2]; PLINT opt_array[2]; + PLINT text_colors[2]; PLINT line_colors[2]; PLINT line_styles[2]; PLINT line_widths[2]; @@ -114,6 +115,8 @@ // Draw a legend opt_array[0] = PL_LEGEND_LINE; opt_array[1] = PL_LEGEND_LINE | PL_LEGEND_SYMBOL; + text_colors[0] = 2; + text_colors[1] = 3; text[0] = "Amplitude"; text[1] = "Phase shift"; line_colors[0] = 2; @@ -134,8 +137,8 @@ pllegend( PL_LEGEND_BACKGROUND, 0.1, 0.6, 0.95, 15, opt_array, 2, - 1., 1.0, 2.0, - 0., 1, text, + 1.0, 1.0, 2.0, + 0., text_colors, text, line_colors, line_styles, line_widths, nsymbols, symbol_colors, symbol_scales, symbols, 0., NULL, NULL ); Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2010-09-25 23:28:07 UTC (rev 11215) +++ trunk/include/plplot.h 2010-09-26 00:56:26 UTC (rev 11216) @@ -1221,7 +1221,7 @@ PLFLT x, PLFLT y, PLINT bg_color, PLINT *opt_array, PLINT nlegend, PLFLT text_offset, PLFLT text_scale, PLFLT text_spacing, - PLINT text_justification, PLINT text_color, char **text, + PLINT text_justification, PLINT *text_colors, char **text, PLINT *line_colors, PLINT *line_styles, PLINT *line_widths, PLINT *nsymbols, PLINT *symbol_colors, PLFLT *symbol_scales, PLINT *symbols, Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2010-09-25 23:28:07 UTC (rev 11215) +++ trunk/src/pllegend.c 2010-09-26 00:56:26 UTC (rev 11216) @@ -83,7 +83,7 @@ PLFLT x, PLFLT y, PLINT bg_color, PLINT *opt_array, PLINT nlegend, PLFLT text_offset, PLFLT text_scale, PLFLT text_spacing, - PLINT text_justification, PLINT text_color, char **text, + PLINT text_justification, PLINT *text_colors, char **text, PLINT *line_colors, PLINT *line_styles, PLINT *line_widths, PLINT *nsymbols, PLINT *symbol_colors, PLFLT *symbol_scales, PLINT *symbols, @@ -109,7 +109,7 @@ PLFLT text_scale_save = plsc->chrht / plsc->chrdef, symbol_scale_save = plsc->symht / plsc->symdef; PLFLT x_world_per_mm, y_world_per_mm, text_width = 0.; - PLFLT total_width, total_height; + PLFLT total_width_border, total_width, total_height; PLINT some_lines = 0, some_symbols = 0, some_cmap0s; PLINT max_nsymbols = 0; @@ -166,9 +166,13 @@ text_width = MAX( text_width, plstrl( text[i] ) ); } get_world_per_mm( &x_world_per_mm, &y_world_per_mm ); - text_width = x_world_per_mm * text_width + text_offset * character_width; - total_width = text_width + ( xmax - xmin ) * plot_width; - total_height = nlegend * text_spacing * character_height; + text_width = x_world_per_mm * text_width + text_offset * character_width; + // make small border area where only the background is plotted + // for left and right of legend. 0.4 seems to be a reasonable factor + // that gives a good-looking result. + total_width_border = 0.4 * character_width; + total_width = 2. * total_width_border + text_width + ( xmax - xmin ) * plot_width; + total_height = nlegend * text_spacing * character_height; if ( opt & PL_LEGEND_BACKGROUND ) { @@ -192,6 +196,11 @@ plcol0( col0_save ); } + // adjust for border after background is drawn. + plot_x_world += total_width_border; + plot_x_end_world += total_width_border; + text_x_world += total_width_border; + if ( some_lines ) { xl[0] = plot_x_world; @@ -223,7 +232,7 @@ // y position of text, lines, symbols, and/or centre of cmap0 box. ty = ty - ( text_spacing * character_height ); // Label/name for the legend - plcol0( text_color ); + plcol0( text_colors[i] ); plptex( text_x_world, ty, 0.0, 0.0, 0.0, text[i] ); if ( opt_array[i] & PL_LEGEND_LINE ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |