From: <ai...@us...> - 2010-09-11 16:32:34
|
Revision: 11167 http://plplot.svn.sourceforge.net/plplot/?rev=11167&view=rev Author: airwin Date: 2010-09-11 16:32:28 +0000 (Sat, 11 Sep 2010) Log Message: ----------- Change experimental pllegend API to add an nsymbols parameter which controls the number of symbols plotted for a particular legend line. Change the 4th standard example to use this additional capability. 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-11 04:44:06 UTC (rev 11166) +++ trunk/examples/c/x04c.c 2010-09-11 16:32:28 UTC (rev 11167) @@ -115,13 +115,13 @@ colors[1] = 3; label_colors[0] = 1; label_colors[1] = 1; - pllegend( 1.0, 0.6, 0.95, 2, label_colors, names, colors, NULL ); + pllegend( 1.0, 0.6, 0.95, 2, label_colors, names, colors, 0, NULL ); // Draw the points legend names[0] = ""; names[1] = ""; symbols[0] = -1; symbols[1] = 3; - pllegend( 1.0, 0.6, 0.95, 2, label_colors, names, colors, symbols ); + pllegend( 1.0, 0.6, 0.95, 2, label_colors, names, colors, 5, symbols ); } } Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2010-09-11 04:44:06 UTC (rev 11166) +++ trunk/include/plplot.h 2010-09-11 16:32:28 UTC (rev 11167) @@ -1207,7 +1207,7 @@ /* Routine for drawing simple line or symbol legends */ PLDLLIMPEXP void -c_pllegend( PLFLT line_length, PLFLT x, PLFLT y, PLINT n, PLINT *text_colors, char **names, PLINT *colors, PLINT *symbols ); +c_pllegend( PLFLT line_length, PLFLT x, PLFLT y, PLINT n, PLINT *text_colors, char **names, PLINT *colors, PLINT nsymbols, PLINT *symbols ); /* Sets position of the light source */ PLDLLIMPEXP void Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2010-09-11 04:44:06 UTC (rev 11166) +++ trunk/src/pllegend.c 2010-09-11 16:32:28 UTC (rev 11167) @@ -63,15 +63,17 @@ #define normalized_to_world_x(nx) ((xmin) + (nx) * ((xmax) - (xmin))) #define normalized_to_world_y(ny) ((ymin) + (ny) * ((ymax) - (ymin))) -// pllegend - Draw a legend using lines or points -// line_length: How long should the lines be/how far apart are the points +// pllegend - Draw a legend using lines (nsymbols <=1 or symbols == NULL) or +// points/symbols. +// line_length: extent of lines or extent of nsymbols points/symbols // x, y: Normalized position of the legend in the plot window // n: Number of legend entries // text_colors: Color map 0 indices of the colors to use for label text // names: Name/label for each legend entry // colors: Line/point color for each legend entry -// symbols: Symbol to draw for each legend entry (NULL for lines) -void c_pllegend(PLFLT line_length, PLFLT x, PLFLT y, PLINT n, PLINT *text_colors, char **names, PLINT *colors, PLINT *symbols) { +// nsymbols: number of points/symbols to be drawn for each line_length +// symbols: Symbol to draw for each legend entry. +void c_pllegend(PLFLT line_length, PLFLT x, PLFLT y, PLINT n, PLINT *text_colors, char **names, PLINT *colors, PLINT nsymbols, PLINT *symbols) { // Active indexed drawing color PLINT old_col0; // Viewport world-coordinate limits @@ -85,8 +87,13 @@ // y-position of the current legend entry PLFLT ty; // Positions of the legend entries - PLFLT xs[2], ys[2]; - PLINT i; + PLFLT dxs, *xs, *ys; + PLINT i, j; + // ifline is true if lines are to be drawn, false if points/symbols are + // to be drawn. + int ifline = nsymbols <= 1 || symbols == NULL; + if(symbols == NULL) nsymbols = 2; + nsymbols = MAX(2, nsymbols); old_col0 = plsc->icol0; @@ -110,22 +117,29 @@ // Starting y position for legend entries ty = text_y_world - character_height; - xs[0] = line_x_world; - xs[1] = line_x_end_world; - ys[0] = ty; - ys[1] = ty; + if ( ( ( xs = (PLFLT *) malloc( nsymbols * sizeof ( PLFLT ) ) ) == NULL ) || + ( ( ys = (PLFLT *) malloc( nsymbols * sizeof ( PLFLT ) ) ) == NULL ) ) + { + plexit( "pllegend: Insufficient memory" ); + } + dxs = (line_x_end_world - line_x_world)/(double) (nsymbols-1); + for (j=0; j<nsymbols; j++) { + xs[j] = line_x_world + dxs*(double) j; + ys[j] = ty; + } + // Draw each legend entry for (i = 0; i < n; i++) { // Line for the legend plcol0(colors[i]); - if (symbols == NULL) { + if (ifline) { // Draw lines - plline(2, xs, ys); + plline(nsymbols, xs, ys); } else { // Draw symbols - plpoin(2, xs, ys, symbols[i]); + plpoin(nsymbols, xs, ys, symbols[i]); } // Label/name for the legend @@ -133,9 +147,12 @@ plptex(text_x_world, ty, 0.0, 0.0, 0.0, names[i]); // Move to the next position ty = ty - (1.5 * character_height); - ys[0] = ty; - ys[1] = ty; + for (j=0; j<nsymbols; j++) { + ys[j] = ty; + } } + free( xs ); + free( ys ); // Restore the previously active drawing color plcol0(old_col0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |