|
From: <hez...@us...> - 2011-04-17 22:01:59
|
Revision: 11711
http://plplot.svn.sourceforge.net/plplot/?rev=11711&view=rev
Author: hezekiahcarty
Date: 2011-04-17 22:01:53 +0000 (Sun, 17 Apr 2011)
Log Message:
-----------
Add a large number of plcolorbar example pages to C example 33
These pages should exercise plcolorbar pretty heavily and are hopefully
simple to extend.
The plcolorbar API is still a work in progress, so these pages should not
be propagated to other languages at this time.
Modified Paths:
--------------
trunk/examples/c/x33c.c
Modified: trunk/examples/c/x33c.c
===================================================================
--- trunk/examples/c/x33c.c 2011-04-17 22:01:24 UTC (rev 11710)
+++ trunk/examples/c/x33c.c 2011-04-17 22:01:53 UTC (rev 11711)
@@ -60,6 +60,66 @@
"✦"
};
+// plcolorbar options
+
+// Colorbar type options
+#define COLORBAR_KINDS 4
+static PLINT colorbar_option_kinds[COLORBAR_KINDS] = {
+ PL_COLORBAR_SHADE,
+ PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL,
+ PL_COLORBAR_IMAGE,
+ PL_COLORBAR_GRADIENT
+};
+static const char *colorbar_option_kind_labels[COLORBAR_KINDS] = {
+ "Shade colorbars",
+ "Shade colorbars with custom labels",
+ "Image colorbars",
+ "Gradient colorbars"
+};
+
+// Which side of the page are we positioned relative to?
+#define COLORBAR_POSITIONS 4
+static PLINT colorbar_position_options[COLORBAR_POSITIONS] = {
+ PL_POSITION_LEFT,
+ PL_POSITION_RIGHT,
+ PL_POSITION_TOP,
+ PL_POSITION_BOTTOM
+};
+static const char *colorbar_position_option_labels[COLORBAR_POSITIONS] = {
+ "Left",
+ "Right",
+ "Top",
+ "Bottom"
+};
+
+// Colorbar label positioning options
+#define COLORBAR_LABELS 4
+static PLINT colorbar_label_options[COLORBAR_LABELS] = {
+ PL_COLORBAR_LABEL_LEFT,
+ PL_COLORBAR_LABEL_RIGHT,
+ PL_COLORBAR_LABEL_TOP,
+ PL_COLORBAR_LABEL_BOTTOM
+};
+static const char *colorbar_label_option_labels[COLORBAR_LABELS] = {
+ "Label left",
+ "Label right",
+ "Label top",
+ "Label bottom"
+};
+
+// Colorbar cap options
+#define COLORBAR_CAPS 3
+static PLINT colorbar_cap_options[COLORBAR_CAPS] = {
+ PL_COLORBAR_CAP_LOW,
+ PL_COLORBAR_CAP_HIGH,
+ PL_COLORBAR_CAP_LOW | PL_COLORBAR_CAP_HIGH
+};
+static const char *colorbar_cap_option_labels[COLORBAR_CAPS] = {
+ "Low cap",
+ "High cap",
+ "Low and high caps"
+};
+
static int colorbar = 0; // By default do not plot plcolorbar pages
// for now while we are working out the API.
static PLOptionTable options[] = {
@@ -86,171 +146,119 @@
const char *notes[] = { "Make sure you get it right!", NULL };
void
-plcolorbar_example_1( PLINT bar_type, PLINT cont_color, PLINT cont_width, PLFLT ticks, PLINT sub_ticks, PLINT n, PLFLT *values, const char *title )
+plcolorbar_example_page( int kind_i, int label_i, int cap_i, PLINT cont_color, PLINT cont_width, PLINT n_values, PLFLT *values )
{
- PLFLT colors[n];
- int i;
- PLFLT color_step, color_offset;
- PLINT position, opt;
- const char *axis_opts_1, *axis_opts_2;
+ // Parameters for the colorbars on this page
+ PLINT position_i, position, opt;
+ PLFLT x, y, length, width;
+ PLFLT ticks;
+ PLINT sub_ticks;
+ PLFLT low_cap_color, high_cap_color;
+ PLINT vertical;
+ const char *axis_opts;
+ char label[200];
+ char title[200];
+
+ length = 0.5;
+ width = 0.05;
+
+ ticks = 0.0;
+ sub_ticks = 0;
+
+ low_cap_color = 0.0;
+ high_cap_color = 1.0;
+
+ // Start a new page
pladv( 0 );
- // Setup color palette 1
- plspal1( "cmap1_blue_red.pal", 1 );
- color_step = 1.0 / (PLFLT) ( n - 1 );
- for ( i = 0; i < n; i++ )
+ // Draw one colorbar relative to each side of the page
+ for ( position_i = 0; position_i < COLORBAR_POSITIONS; position_i ++ )
{
- colors[i] = color_offset + color_step * (PLFLT) ( i );
- }
+ position = colorbar_position_options[position_i];
+ opt =
+ colorbar_option_kinds[kind_i] |
+ colorbar_label_options[label_i] |
+ colorbar_cap_options[cap_i];
- position = PL_POSITION_LEFT;
- opt = bar_type | PL_COLORBAR_LABEL_LEFT | PL_COLORBAR_CAP_HIGH;
+ vertical = position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT;
- if ( bar_type & PL_COLORBAR_SHADE_LABEL )
- {
- axis_opts_1 = "iv";
- axis_opts_2 = "i";
- }
- else
- {
- if ( sub_ticks != 0 )
+ // Set the offset position on the page
+ if ( vertical )
{
- axis_opts_1 = "stv";
- axis_opts_2 = "st";
+ x = 0.1;
+ y = 0.25;
}
else
{
- axis_opts_1 = "tv";
- axis_opts_2 = "t";
+ x = 0.25;
+ y = 0.1;
}
- }
- plcolorbar( position, opt, 0.1, 0.1, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_1, "Test label - Left, High Cap",
- n, colors, values );
+ // Set appropriate labeling options
+ if ( opt & PL_COLORBAR_SHADE_LABEL )
+ {
+ if ( vertical )
+ axis_opts = "iv";
+ else
+ axis_opts = "i";
+ }
+ else
+ {
+ if ( sub_ticks != 0 )
+ {
+ if ( vertical )
+ axis_opts = "stv";
+ else
+ axis_opts = "st";
+ }
+ else
+ {
+ if ( vertical )
+ axis_opts = "tv";
+ else
+ axis_opts = "t";
+ }
+ }
- position = PL_POSITION_RIGHT;
- opt = bar_type | PL_COLORBAR_LABEL_RIGHT | PL_COLORBAR_CAP_LOW;
+ sprintf( label, "%s, %s",
+ colorbar_position_option_labels[position_i],
+ colorbar_label_option_labels[label_i] );
- plcolorbar( position, opt, 0.1, 0.4, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_1, "Test label - Right, Low Cap",
- n, colors, values );
+ plcolorbar( position, opt,
+ x, y, length, width,
+ low_cap_color, high_cap_color,
+ cont_color, cont_width,
+ ticks, sub_ticks,
+ axis_opts, label,
+ n_values, values );
+ }
- position = PL_POSITION_TOP;
- opt = bar_type | PL_COLORBAR_LABEL_TOP | PL_COLORBAR_CAP_HIGH;
-
- plcolorbar( position, opt, 0.1, 0.1, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_2, "Test label - Top, High Cap",
- n, colors, values );
-
- position = PL_POSITION_BOTTOM;
- opt = bar_type | PL_COLORBAR_LABEL_BOTTOM | PL_COLORBAR_CAP_LOW;
-
- plcolorbar( position, opt, 0.4, 0.1, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_2, "Test label - Bottom, Low Cap",
- n, colors, values );
-
+ // Draw a page title
+ sprintf( title, "%s - %s",
+ colorbar_option_kind_labels[kind_i],
+ colorbar_cap_option_labels[cap_i] );
plvpor( 0.0, 1.0, 0.0, 1.0 );
plwind( 0.0, 1.0, 0.0, 1.0 );
plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title );
}
void
-plcolorbar_example_2( PLINT bar_type, PLINT cont_color, PLINT cont_width, PLFLT ticks, PLFLT sub_ticks, PLINT n, PLFLT *values, const char *title )
+plcolorbar_example( const char *palette, int kind_i, PLINT cont_color, PLINT cont_width, PLINT n_values, PLFLT *values )
{
- PLFLT colors[n];
- int i;
- PLFLT color_step, color_offset;
- PLINT position, opt;
- const char *axis_opts_1, *axis_opts_2;
- pladv( 0 );
- // Setup color palette 1
- plspal1( "cmap1_blue_yellow.pal", 1 );
+ int label_i, cap_i;
- color_step = 1.0 / (PLFLT) ( n - 1 );
- for ( i = 0; i < n; i++ )
- {
- if ( i == 0 )
- {
- color_offset = 0.01;
- }
- else if ( i == n - 1 )
- {
- color_offset = -0.01;
- }
- else
- {
- color_offset = 0.0;
- }
- colors[i] = color_offset + color_step * (PLFLT) ( i );
- }
+ // Load the color palette
+ plspal1( palette, 1 );
- position = PL_POSITION_LEFT;
- opt = bar_type | PL_COLORBAR_LABEL_LEFT | PL_COLORBAR_CAP_LOW;
-
- if ( bar_type == PL_COLORBAR_SHADE_LABEL )
+ for ( label_i = 0; label_i < COLORBAR_LABELS; label_i++ )
{
- axis_opts_1 = "";
- axis_opts_2 = "";
- }
- else
- {
- if ( sub_ticks != 0 )
+ for ( cap_i = 0; cap_i < COLORBAR_CAPS; cap_i++ )
{
- axis_opts_1 = "stv";
- axis_opts_2 = "st";
+ plcolorbar_example_page( kind_i, label_i, cap_i,
+ cont_color, cont_width,
+ n_values, values );
}
- else
- {
- axis_opts_1 = "tv";
- axis_opts_2 = "t";
- }
}
-
- plcolorbar( position, opt, 0.1, 0.1, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_1, "Test label - Left, Low Cap",
- n, colors, values );
-
- position = PL_POSITION_RIGHT;
- opt = bar_type | PL_COLORBAR_LABEL_RIGHT | PL_COLORBAR_CAP_HIGH;
-
- plcolorbar( position, opt, 0.1, 0.4, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_1, "Test label - Right, High Cap",
- n, colors, values );
-
- position = PL_POSITION_TOP;
- opt = bar_type | PL_COLORBAR_LABEL_TOP | PL_COLORBAR_CAP_LOW;
-
- plcolorbar( position, opt, 0.1, 0.1, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_2, "Test label - Top, Low Cap",
- n, colors, values );
-
- position = PL_POSITION_BOTTOM;
- opt = bar_type | PL_COLORBAR_LABEL_BOTTOM | PL_COLORBAR_CAP_HIGH;
-
- plcolorbar( position, opt, 0.4, 0.1, 0.5, 0.1,
- cont_color, cont_width,
- ticks, sub_ticks,
- axis_opts_2, "Test label - Bottom, High Cap",
- n, colors, values );
-
- plvpor( 0.0, 1.0, 0.0, 1.0 );
- plwind( 0.0, 1.0, 0.0, 1.0 );
- plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title );
}
//--------------------------------------------------------------------------
@@ -817,20 +825,25 @@
PLFLT values_small[2] = { 0.0, 1.0 };
PLFLT values_uneven[9] = { 0.0, 2.0, 2.6, 3.4, 6.0, 7.0, 8.0, 9.0, 10.0 };
PLFLT values_even[9] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
- plcolorbar_example_1( PL_COLORBAR_IMAGE, 0, 0, 0.0, 0, 2, values_small, "Image Color Bars" );
- plcolorbar_example_2( PL_COLORBAR_IMAGE, 0, 0, 0.0, 0, 2, values_small, "Image Color Bars" );
- plcolorbar_example_1( PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0, 0, 0.0, 0, 9, values_uneven,
- "Shade Color Bars - Uneven Steps" );
- plcolorbar_example_2( PL_COLORBAR_SHADE, 0, 0, 3.0, 3, 9, values_even,
- "Shade Color Bars - Even Steps" );
- plcolorbar_example_1( PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 2, 1, 0.0, 0, 9, values_uneven,
- "Shade Color Bars - Uneven Steps, Contours" );
- plcolorbar_example_2( PL_COLORBAR_SHADE, 2, 3, 3.0, 3, 9, values_even,
- "Shade Color Bars - Even Steps, Contours" );
- plcolorbar_example_1( PL_COLORBAR_GRADIENT, 0, 0, 0.5, 5, 2, values_small,
- "Gradient Color Bars" );
- plcolorbar_example_2( PL_COLORBAR_GRADIENT, 0, 0, 0.5, 5, 2, values_small,
- "Gradient Color Bars" );
+
+ // Cut out the greatest and smallest bits of the color spectrum to
+ // leave colors for the end caps.
+ plscmap1_range( 0.01, 0.99 );
+
+ // We can only test image and gradient colorbars with two element arrays
+ for ( i = 2; i < COLORBAR_KINDS; i ++ )
+ {
+ plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, 2, values_small );
+ }
+ // Test shade colorbars with larger arrays
+ for ( i = 0; i < 2; i++ )
+ {
+ plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, 9, values_even );
+ }
+ for ( i = 0; i < 2; i++ )
+ {
+ plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, 9, values_uneven );
+ }
}
plend();
exit( 0 );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|