On Wed, Sep 29, 2010 at 9:40 PM, Hezekiah M. Carty
<hezekiahca...@users.sourceforge.net> wrote:
> On Tue, Sep 28, 2010 at 6:46 PM, Alan W. Irwin
> <ir...@beluga.phys.uvic.ca> wrote:
>> On 2010-09-28 14:30-0700 Alan W. Irwin wrote:
>>
>>> For the "simplest is best" reasons [...], I am going to drop cmap1
>>> from pllegend. I will try to finish that by late this afternoon.
>>
>> Done as of revision 11231.
>>
>
> While working on the OCaml interface to pllegend, I came up with a
> potential improvement to the C interface:
>
<snip>
>
> I'm willing to make an attempt at implementation if you think it is
> worth considering.
>
I gave the change a shot. I don't want to commit without getting some
feedback, so I have attached a test patch for pllegend.c and x04c.c
for your consideration. I think the result is positive overall.
Thoughts?
Hez
diff --git a/examples/c/x04c.c b/examples/c/x04c.c
index c3abc75..13621c1 100644
--- a/examples/c/x04c.c
+++ b/examples/c/x04c.c
@@ -129,26 +129,24 @@ plot1( int type )
line_styles[1] = 1;
line_widths[0] = 1;
line_widths[1] = 1;
- symbol_colors[0] = 2;
- symbol_colors[1] = 3;
- symbol_scales[0] = 1.2;
- symbol_scales[1] = 1.;
- symbol_numbers[0] = 3;
- symbol_numbers[1] = 4;
+ symbol_colors[0] = 3;
+ symbol_scales[0] = 1.;
+ symbol_numbers[0] = 4;
symbols[0] = 3;
- symbols[1] = 3;
+ /*
box_colors[0] = 2;
box_colors[1] = 3;
box_patterns[0] = 0;
box_patterns[1] = 3;
box_scales[0] = 0.5;
box_scales[1] = 0.5;
+ */
plscol0a( 15, 32, 32, 32, 0.90 );
pllegend( PL_LEGEND_BACKGROUND, 0.57, 0.85, 0.06, 15,
nlegend, opt_array,
1.0, 1.0, 2.0,
1., text_colors, text,
- box_colors, box_patterns, box_scales,
+ NULL, NULL, NULL,
line_colors, line_styles, line_widths,
symbol_colors, symbol_scales, symbol_numbers, symbols );
}
diff --git a/src/pllegend.c b/src/pllegend.c
index dc664a4..5888264 100644
--- a/src/pllegend.c
+++ b/src/pllegend.c
@@ -199,6 +199,9 @@ c_pllegend( PLINT opt, PLFLT x, PLFLT y, PLFLT plot_width, PLINT bg_color,
// Saved normalized coordinates of viewport.
PLFLT xdmin_save, xdmax_save, ydmin_save, ydmax_save;
+ // Counters to keep track of where we are in the legend progression
+ PLINT box_index = 0, line_index = 0, symbol_index = 0;
+
PLFLT x_world_per_mm, y_world_per_mm, text_width0 = 0., text_width;
PLFLT total_width_border, total_width, total_height;
@@ -342,37 +345,43 @@ c_pllegend( PLINT opt, PLFLT x, PLFLT y, PLFLT plot_width, PLINT bg_color,
{
if ( opt_array[i] & PL_LEGEND_COLOR_BOX )
{
- plcol0( box_colors[i] );
- plpsty( box_patterns[i] );
- ybox[0] = ty + 0.5 * dty * box_scales[i];
- ybox[1] = ty - 0.5 * dty * box_scales[i];
- ybox[2] = ty - 0.5 * dty * box_scales[i];
- ybox[3] = ty + 0.5 * dty * box_scales[i];
+ plcol0( box_colors[box_index] );
+ plpsty( box_patterns[box_index] );
+ ybox[0] = ty + 0.5 * dty * box_scales[box_index];
+ ybox[1] = ty - 0.5 * dty * box_scales[box_index];
+ ybox[2] = ty - 0.5 * dty * box_scales[box_index];
+ ybox[3] = ty + 0.5 * dty * box_scales[box_index];
plfill( 4, xbox, ybox );
+ // Increment the box index counter
+ box_index++;
}
if ( opt_array[i] & PL_LEGEND_LINE )
{
- plcol0( line_colors[i] );
- pllsty( line_styles[i] );
- plwid( line_widths[i] );
+ plcol0( line_colors[line_index] );
+ pllsty( line_styles[line_index] );
+ plwid( line_widths[line_index] );
yl[0] = ty;
yl[1] = ty;
plline( 2, xl, yl );
pllsty( line_style_save );
plwid( line_width_save );
+ // Increment the line index counter
+ line_index++;
}
if ( opt_array[i] & PL_LEGEND_SYMBOL )
{
- plcol0( symbol_colors[i] );
- plssym( 0., symbol_scales[i] );
- dxs = ( plot_x_end_world - plot_x_world - symbol_width ) / (double) ( MAX( symbol_numbers[i], 2 ) - 1 );
- for ( j = 0; j < symbol_numbers[i]; j++ )
+ plcol0( symbol_colors[symbol_index] );
+ plssym( 0., symbol_scales[symbol_index] );
+ dxs = ( plot_x_end_world - plot_x_world - symbol_width ) / (double) ( MAX( symbol_numbers[symbol_index], 2 ) - 1 );
+ for ( j = 0; j < symbol_numbers[symbol_index]; j++ )
{
xs[j] = plot_x_world + 0.5 * symbol_width + dxs * (double) j;
ys[j] = ty;
}
- plpoin( symbol_numbers[i], xs, ys, symbols[i] );
+ plpoin( symbol_numbers[symbol_index], xs, ys, symbols[symbol_index] );
+ // Increment the symbol index counter
+ symbol_index++;
}
}
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel