From: <and...@us...> - 2013-09-09 14:41:16
|
Revision: 12503 http://sourceforge.net/p/plplot/code/12503 Author: andrewross Date: 2013-09-09 14:41:12 +0000 (Mon, 09 Sep 2013) Log Message: ----------- Update D bindings for latest version of plcolorbar. Also add plscmap1_range and plgcmap1_range. Update example 16 to use plcolorbar as in the C version. Modified Paths: -------------- trunk/bindings/d/plplot.d trunk/examples/d/x16d.d Modified: trunk/bindings/d/plplot.d =================================================================== --- trunk/bindings/d/plplot.d 2013-09-07 08:29:45 UTC (rev 12502) +++ trunk/bindings/d/plplot.d 2013-09-09 14:41:12 UTC (rev 12503) @@ -157,6 +157,44 @@ toStringz( zopt ), toStringz( zlabel ), ztick, nsubz ); } +// Routine for drawing continous colour legends +void plcolorbar( PLFLT *p_colorbar_width, PLFLT *p_colorbar_height, + PLINT opt, PLINT position, PLFLT x, PLFLT y, + PLFLT x_length, PLFLT y_length, + PLINT bg_color, PLINT bb_color, PLINT bb_style, + PLFLT low_cap_color, PLFLT high_cap_color, + PLINT cont_color, PLFLT cont_width, + PLINT[] label_opts, string[] label, + string[] axis_opts, + PLFLT[] ticks, PLINT[] sub_ticks, + PLFLT[][] values ) +{ + PLINT n_labels = cast(PLINT) label_opts.length; + PLINT n_axes = cast(PLINT) axis_opts.length; + PLINT[] n_values = new PLINT[values.length]; + for (size_t i=0; i<values.length;i++) { + n_values[i] = cast(PLINT) values[i].length; + } + immutable( char ) * *labelz = array( map!toStringz( label ) ).ptr; + immutable( char ) * *axis_optsz = array( map!toStringz( axis_opts ) ).ptr; + assert( n_labels == label.length, "plcolorbar(): Arrays must be of same length!" ); + assert( n_labels == label_opts.length, "plcolorbar(): Arrays must be of same length!" ); + assert( n_axes == axis_opts.length, "plcolorbar(): Arrays must be of same length!" ); + assert( n_axes == ticks.length, "plcolorbar(): Arrays must be of same length!" ); + assert( n_axes == sub_ticks.length, "plcolorbar(): Arrays must be of same length!" ); + + c_plcolorbar(p_colorbar_width, p_colorbar_height, + opt, position, x, y, + x_length, y_length, + bg_color, bb_color, bb_style, + low_cap_color, high_cap_color, + cont_color, cont_width, + n_labels, label_opts.ptr, labelz, + n_axes, axis_optsz, + ticks.ptr, sub_ticks.ptr, + n_values.ptr, convert_array(values) ); +} + // Draws a contour plot from data in f(nx,ny). Is just a front-end to // plfcont, with a particular choice for f2eval and f2eval_data. // @@ -1323,6 +1361,7 @@ alias c_plclear plclear; alias c_plcol0 plcol0; alias c_plcol1 plcol1; +//alias c_plcolorbar plcolorbar; alias c_plconfigtime plconfigtime; //alias c_plcont plcont; alias c_plcpstrm plcpstrm; @@ -1413,6 +1452,7 @@ //alias c_plscmap1l plscmap1l; //alias c_plscmap1la plscmap1la; alias c_plscmap1n plscmap1n; +alias c_plscmap1_range plscmap1_range; alias c_plscol0 plscol0; alias c_plscol0a plscol0a; alias c_plscolbg plscolbg; @@ -1559,6 +1599,7 @@ // Set color, map 1. Argument is a float between 0. and 1. void c_plcol1( PLFLT col1 ); + // Configure transformation between continuous and broken-down time (and // vice versa) for current stream. void c_plconfigtime( PLFLT scale, PLFLT offset1, PLFLT offset2, PLINT ccontrol, PLBOOL ifbtime_offset, @@ -1780,10 +1821,18 @@ const PL_COLORBAR_IMAGE = 16; const PL_COLORBAR_SHADE = 32; const PL_COLORBAR_GRADIENT = 64; -const PL_COLORBAR_CAP_LOW = 128; -const PL_COLORBAR_CAP_HIGH = 256; -const PL_COLORBAR_SHADE_LABEL = 512; +const PL_COLORBAR_CAP_NONE = 128; +const PL_COLORBAR_CAP_LOW = 256; +const PL_COLORBAR_CAP_HIGH = 512; +const PL_COLORBAR_SHADE_LABEL = 1024; +const PL_COLORBAR_ORIENT_RIGHT = 2048; +const PL_COLORBAR_ORIENT_TOP = 4096; +const PL_COLORBAR_ORIENT_LEFT = 8192; +const PL_COLORBAR_ORIENT_BOTTOM = 16384; +const PL_COLORBAR_BACKGROUND = 32768; +const PL_COLORBAR_BOUNDING_BOX = 65536; + // Routine for drawing discrete line, symbol, or cmap0 legends void c_pllegend( PLFLT *p_legend_width, PLFLT *p_legend_height, PLINT opt, PLINT position, PLFLT x, PLFLT y, PLFLT plot_width, @@ -1800,6 +1849,18 @@ PLINT *symbol_colors, PLFLT *symbol_scales, PLINT *symbol_numbers, const char **symbols ); +// Routine for drawing continous colour legends +void c_plcolorbar( PLFLT *p_colorbar_width, PLFLT *p_colorbar_height, + PLINT opt, PLINT position, PLFLT x, PLFLT y, + PLFLT x_length, PLFLT y_length, + PLINT bg_color, PLINT bb_color, PLINT bb_style, + PLFLT low_cap_color, PLFLT high_cap_color, + PLINT cont_color, PLFLT cont_width, + PLINT n_labels, const PLINT *label_opts, const char **label, + PLINT n_axes, const char ** axis_opts, + const PLFLT *ticks, const PLINT *sub_ticks, + const PLINT *n_values, const PLFLT **values ); + // Sets position of the light source void c_pllightsource( PLFLT x, PLFLT y, PLFLT z ); @@ -1956,6 +2017,12 @@ // Set number of colors in cmap 1 void c_plscmap1n( PLINT ncol1 ); +// Set the color map 1 range used in continuous plots +void c_plscmap1_range( PLFLT min_color, PLFLT max_color ); + +// Get the color map 1 range used in continuous plots +void c_plgcmap1_range( PLFLT *min_color, PLFLT *max_color ); + // Set a given color from color map 0 by 8 bit RGB value void c_plscol0( PLINT icol0, PLINT r, PLINT g, PLINT b ); Modified: trunk/examples/d/x16d.d =================================================================== --- trunk/examples/d/x16d.d 2013-09-07 08:29:45 UTC (rev 12502) +++ trunk/examples/d/x16d.d 2013-09-09 14:41:12 UTC (rev 12503) @@ -22,6 +22,9 @@ // anyway, and cannot be reproduced by any // front end other than the C one. +// For now, don't show the colorbars while we are working out the API. +int colorbar = 1; + extern ( C ) { // Transformation function PLFLT[] tr; @@ -186,8 +189,33 @@ } // Plot using identity transform - PLINT fill_width = 2, cont_color = 0, cont_width = 0; + PLFLT fill_width = 2., cont_width = 0.; + PLFLT colorbar_width, colorbar_height; + PLINT cont_color = 0; + const int NUM_AXES = 1; + string[] axis_opts = [ + "bcvtm", + ]; + PLFLT[] values[NUM_AXES]; + for (size_t i = 0; i<NUM_AXES;i++) { + values[i] = new PLFLT[ns]; + } + PLFLT[] axis_ticks = [ + 0.0, + ]; + PLINT[] axis_subticks = [ + 0, + ]; + const int NUM_LABELS = 1; + PLINT label_opts[] = [ + PL_COLORBAR_LABEL_BOTTOM, + ]; + string[] labels = [ + "Magnitude", + ]; + + pladv( 0 ); plvpor( 0.1, 0.9, 0.1, 0.9 ); plwind( -1.0, 1.0, -1.0, 1.0 ); @@ -197,6 +225,30 @@ plshades( z, null, -1., 1., -1., 1., shedge, fill_width, cont_color, cont_width, 1 ); + if ( colorbar ) + { + // Smaller text + plschr( 0.0, 0.75 ); + // Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + values[0] = shedge; + plcolorbar( &colorbar_width, &colorbar_height, + PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, + axis_opts, + axis_ticks, axis_subticks, + values ); + + // Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + } + plcol0( 1 ); plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); plcol0( 2 ); @@ -219,7 +271,31 @@ plshades( z, null, -1., 1., -1., 1., shedge, fill_width, cont_color, cont_width, 1, cgrid1 ); + if ( colorbar ) + { + // Smaller text + plschr( 0.0, 0.75 ); + // Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + values[0] = shedge; + plcolorbar( &colorbar_width, &colorbar_height, + PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, + axis_opts, + axis_ticks, axis_subticks, + values ); + + // Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + } + + plcol0( 1 ); plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); plcol0( 2 ); @@ -243,6 +319,30 @@ plshades( z, null, -1., 1., -1., 1., shedge, fill_width, cont_color, cont_width, 0, cgrid2 ); + if ( colorbar ) + { + // Smaller text + plschr( 0.0, 0.75 ); + // Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + values[0] = shedge; + plcolorbar( &colorbar_width, &colorbar_height, + PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, + axis_opts, + axis_ticks, axis_subticks, + values ); + + // Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + } + plcol0( 1 ); plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); plcol0( 2 ); @@ -268,6 +368,30 @@ plshades( z, null, -1., 1., -1., 1., shedge, fill_width, 2, 3, 0, cgrid2 ); + if ( colorbar ) + { + // Smaller text + plschr( 0.0, 0.75 ); + // Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + values[0] = shedge; + plcolorbar( &colorbar_width, &colorbar_height, + PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + 2, 3., + label_opts, labels, + axis_opts, + axis_ticks, axis_subticks, + values ); + + // Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + } + plcol0( 1 ); plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); plcol0( 2 ); @@ -340,6 +464,30 @@ plshades( z, null, -1., 1., -1., 1., shedge, fill_width, cont_color, cont_width, 0, cgrid2 ); + if ( colorbar ) + { + // Smaller text + plschr( 0.0, 0.75 ); + // Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + values[0] = shedge; + plcolorbar( &colorbar_width, &colorbar_height, + PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, + axis_opts, + axis_ticks, axis_subticks, + values ); + + // Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + } + // Now we can draw the perimeter. (If do before, shade stuff may overlap.) PLFLT[PERIMETERPTS] px, py; for ( int i = 0; i < PERIMETERPTS; i++ ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |