|
From: <and...@us...> - 2013-06-07 16:03:37
|
Revision: 12374
http://sourceforge.net/p/plplot/code/12374
Author: andrewross
Date: 2013-06-07 16:03:35 +0000 (Fri, 07 Jun 2013)
Log Message:
-----------
Update lua bindings to implement latest colorbar API and update examples accordingly.
Modified Paths:
--------------
trunk/bindings/lua/plplotluac.i
trunk/bindings/swig-support/plplotcapi.i
trunk/examples/lua/x16.lua
trunk/examples/lua/x33.lua
Modified: trunk/bindings/lua/plplotluac.i
===================================================================
--- trunk/bindings/lua/plplotluac.i 2013-06-06 21:44:55 UTC (rev 12373)
+++ trunk/bindings/lua/plplotluac.i 2013-06-07 16:03:35 UTC (rev 12374)
@@ -230,7 +230,32 @@
LUA_FREE_ARRAY( $1 );
}
+// No length but remember size to check others
+%typemap( in ) const PLINT * ArrayN( int temp )
+{
+ int i;
+ $1 = (PLINT *) LUA_get_int_num_array_var( L, $input, &temp );
+ if ( !$1 )
+ SWIG_fail;
+ if (temp != Alen)
+ {
+ lua_pushfstring( L, "Tables must be of same length." );
+ SWIG_fail;
+ }
+
+ Xlen = temp;
+ Ylen = -1;
+ for ( i = 0; i < Xlen; i++ )
+ if ( $1[i] > Ylen ) Ylen = $1[i];
+
+}
+%typemap( freearg ) ( const PLINT * ArrayN )
+{
+ LUA_FREE_ARRAY( $1 );
+}
+
+
//--------------------------------------------------------------------------
// PLFLT Arrays
//--------------------------------------------------------------------------
@@ -1240,8 +1265,38 @@
}
}
+%typemap( in ) ( PLINT n, const char **Array )
+{
+ int i;
+ $1 = SWIG_table_size( L, $input );
+ Alen = $1;
+ $2 = malloc( sizeof ( char* ) * Alen );
+ for ( i = 1; i <= Alen; i++ )
+ {
+ lua_rawgeti( L, $input, i );
+ if ( lua_isstring( L, -1 ) )
+ {
+ $2[i - 1] = (char *) lua_tostring( L, -1 );
+ }
+ else
+ {
+ lua_pop( L, 1 );
+ lua_pushfstring( L, "Requires a sequence of strings." );
+ SWIG_fail;
+ }
+ lua_pop( L, 1 );
+ }
+}
+%typemap( freearg ) ( PLINT n, const char **Array )
+{
+ if ( $2 )
+ {
+ free( $2 ); $2 = NULL;
+ }
+}
+
// Process options list using current options info.
%typemap( in, checkfn = "lua_istable" ) ( int *p_argc, const char **argv )
{
@@ -1308,6 +1363,7 @@
%rename( clear ) plclear;
%rename( col0 ) plcol0;
%rename( col1 ) plcol1;
+%rename( colorbar ) plcolorbar;
%rename( configtime ) plconfigtime;
%rename( cont ) plcont;
%rename( cpstrm ) plcpstrm;
@@ -1398,6 +1454,7 @@
%rename( scmap1l ) plscmap1l;
%rename( scmap1la ) plscmap1la;
%rename( scmap1n ) plscmap1n;
+%rename( scmap1_range ) plscmap1_range;
%rename( scol0 ) plscol0;
%rename( scol0a ) plscol0a;
%rename( scolbg ) plscolbg;
Modified: trunk/bindings/swig-support/plplotcapi.i
===================================================================
--- trunk/bindings/swig-support/plplotcapi.i 2013-06-06 21:44:55 UTC (rev 12373)
+++ trunk/bindings/swig-support/plplotcapi.i 2013-06-07 16:03:35 UTC (rev 12374)
@@ -481,7 +481,6 @@
const PLINT *ArrayCkNull, const PLFLT *ArrayCkNull,
const PLINT *ArrayCkNull, const char **ArrayCk );
-#if defined ( SWIG_PYTHON ) || defined ( SWIG_JAVA ) || defined ( SWIG_OCTAVE )
void
plcolorbar( PLFLT *OUTPUT, PLFLT *OUTPUT,
PLINT opt, PLINT position, PLFLT x, PLFLT y,
@@ -493,7 +492,6 @@
PLINT n, const char **Array,
const PLFLT *ArrayCk, const PLINT *ArrayCk,
const PLINT *ArrayN, const PLFLT **MatrixCk );
-#endif
void
pllightsource( PLFLT x, PLFLT y, PLFLT z );
Modified: trunk/examples/lua/x16.lua
===================================================================
--- trunk/examples/lua/x16.lua 2013-06-06 21:44:55 UTC (rev 12373)
+++ trunk/examples/lua/x16.lua 2013-06-07 16:03:35 UTC (rev 12374)
@@ -72,7 +72,19 @@
return z<0.4 or z>0.6
end
+-- return single bit (for OR)
+function bit(x,b)
+ return ((x % 2^b) - (x % 2^(b-1)) > 0)
+end
+-- logic OR for number values
+function lor(x,y)
+ result = 0
+ for p=1,16 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
+ return result
+end
+
+
----------------------------------------------------------------------------
-- main
--
@@ -86,6 +98,14 @@
cont_color = 0
cont_width = 0.
+axis_opts = { "bcvtm" }
+num_values = {}
+values = {}
+axis_ticks = { 0.0 }
+axis_subticks = { 0 }
+label_opts = { pl.PL_COLORBAR_LABEL_BOTTOM }
+labels = { "Magnitude" }
+
-- Parse and process command line arguments
pl.parseopts(arg, pl.PL_PARSE_FULL)
@@ -169,6 +189,21 @@
pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 1)
+-- Smaller text
+pl.schr( 0.0, 0.75 )
+-- Small ticks on the vertical axis
+pl.smaj( 0.0, 0.5 )
+pl.smin( 0.0, 0.5 )
+
+num_values[1] = ns + 1
+values[1] = shedge
+colorbar_width, colorbar_height = pl.colorbar( lor(pl.PL_COLORBAR_SHADE, pl.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, num_values, values )
+
+-- Reset text and tick sizes
+pl.schr( 0.0, 1.0 )
+pl.smaj( 0.0, 1.0 )
+pl.smin( 0.0, 1.0 )
+
pl.col0(1)
pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
pl.col0(2)
@@ -193,6 +228,22 @@
pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 1, "pltr1", cgrid1)
+-- Smaller text
+pl.schr( 0.0, 0.75 )
+-- Small ticks on the vertical axis
+pl.smaj( 0.0, 0.5 )
+pl.smin( 0.0, 0.5 )
+
+num_values[1] = ns + 1
+values[1] = shedge
+
+colorbar_width, colorbar_height = pl.colorbar( lor(pl.PL_COLORBAR_SHADE, pl.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, num_values, values )
+
+-- Reset text and tick sizes
+pl.schr( 0.0, 1.0 )
+pl.smaj( 0.0, 1.0 )
+pl.smin( 0.0, 1.0 )
+
pl.col0(1)
pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
pl.col0(2)
@@ -215,6 +266,21 @@
pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 0, "pltr2", cgrid2)
+-- Smaller text
+pl.schr( 0.0, 0.75 )
+-- Small ticks on the vertical axis
+pl.smaj( 0.0, 0.5 )
+pl.smin( 0.0, 0.5 )
+
+num_values[1] = ns + 1
+values[1] = shedge
+colorbar_width, colorbar_height = pl.colorbar( lor(pl.PL_COLORBAR_SHADE, pl.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, num_values, values )
+
+-- Reset text and tick sizes
+pl.schr( 0.0, 1.0 )
+pl.smaj( 0.0, 1.0 )
+pl.smin( 0.0, 1.0 )
+
pl.col0(1)
pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
pl.col0(2)
@@ -239,6 +305,21 @@
pl.shades(z, -1, 1, -1, 1, shedge, fill_width, 2, 3., 0, "pltr2", cgrid2)
+-- Smaller text
+pl.schr( 0.0, 0.75 )
+-- Small ticks on the vertical axis
+pl.smaj( 0.0, 0.5 )
+pl.smin( 0.0, 0.5 )
+
+num_values[1] = ns + 1
+values[1] = shedge
+colorbar_width, colorbar_height = pl.colorbar( lor(pl.PL_COLORBAR_SHADE, pl.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, num_values, values )
+
+-- Reset text and tick sizes
+pl.schr( 0.0, 1.0 )
+pl.smaj( 0.0, 1.0 )
+pl.smin( 0.0, 1.0 )
+
pl.col0(1)
pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
pl.col0(2)
@@ -308,6 +389,21 @@
-- Now we can shade the interior region.
pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 0, "pltr2", cgrid2)
+-- Smaller text
+pl.schr( 0.0, 0.75 )
+-- Small ticks on the vertical axis
+pl.smaj( 0.0, 0.5 )
+pl.smin( 0.0, 0.5 )
+
+num_values[1] = ns + 1
+values[1] = shedge
+colorbar_width, colorbar_height = pl.colorbar( lor(pl.PL_COLORBAR_SHADE, pl.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, num_values, values )
+
+-- Reset text and tick sizes
+pl.schr( 0.0, 1.0 )
+pl.smaj( 0.0, 1.0 )
+pl.smin( 0.0, 1.0 )
+
-- Now we can draw the perimeter. (If do before, shade stuff may overlap.)
for i = 1, PERIMETERPTS do
t = 2*math.pi/(PERIMETERPTS-1)*(i-1)
Modified: trunk/examples/lua/x33.lua
===================================================================
--- trunk/examples/lua/x33.lua 2013-06-06 21:44:55 UTC (rev 12373)
+++ trunk/examples/lua/x33.lua 2013-06-07 16:03:35 UTC (rev 12374)
@@ -1,4 +1,4 @@
---[[ $Id: x04.lua 11667 2011-03-21 03:35:08Z airwin $
+--[[ $Id: x33.lua 11667 2011-03-21 03:35:08Z airwin $
Demonstrate most pllegend capability including unicode symbols.
@@ -24,25 +24,25 @@
-- initialise Lua bindings for PLplot examples.
dofile("plplot_examples.lua")
-----------------------------------------------------------------------------
--- plot1
---
--- Log-linear plot.
-----------------------------------------------------------------------------
-
-- return single bit (for OR)
function bit(x,b)
return ((x % 2^b) - (x % 2^(b-1)) > 0)
end
-- logic OR for number values
-
function lor(x,y)
result = 0
- for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
+ for p=1,32 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
return result
end
+-- logic AND for number values
+function land(x,y)
+ result = 0
+ for p=1,32 do result = result + (((bit(x,p) and bit(y,p)) == true) and 2^(p-1) or 0) end
+ return result
+end
+
-- Intialize pllegend arrays taking advantage of Lua's default global scope.
function initialize_pllegend_arrays(nlegend)
@@ -78,6 +78,116 @@
end
end
+function plcolorbar_example_page( kind_i, label_i, cap_i, cont_color, cont_width, n_values, values )
+ -- Parameters for the colorbars on this page
+ ticks = { 0.0 }
+ sub_ticks = { 0 }
+ axis_opts = {}
+ label_opts = { 0 }
+ n_values_array = {}
+ values_array = {}
+ label = {}
+
+ n_values_array[1] = n_values
+ values_array[1] = values
+
+ low_cap_color = 0.0
+ high_cap_color = 1.0
+
+ -- Start a new page
+ pl.adv( 0 )
+
+ -- Draw one colorbar relative to each side of the page
+ for position_i = 0,COLORBAR_POSITIONS-1 do
+ position = colorbar_position_options[position_i+1]
+ opt =
+ lor(colorbar_option_kinds[kind_i+1],
+ lor(colorbar_label_options[label_i+1],
+ colorbar_cap_options[cap_i+1]))
+
+ vertical = lor(land(position,pl.PL_POSITION_LEFT), land(position,pl.PL_POSITION_RIGHT))
+ ifn = lor(land(position, pl.PL_POSITION_LEFT), land(position, pl.PL_POSITION_BOTTOM))
+
+ -- Set the offset position on the page
+ if vertical > 0 then
+ x = 0.0
+ y = 0.0
+ x_length = 0.05
+ y_length = 0.5
+ else
+ x = 0.0
+ y = 0.0
+ x_length = 0.5
+ y_length = 0.05
+ end
+
+ -- Set appropriate labelling options.
+ if ifn > 0 then
+ if ( cont_color == 0 ) or ( cont_width == 0. ) then
+ axis_opts[1] = "uwtivn"
+ else
+ axis_opts[1] = "uwxvn"
+ end
+ else
+ if ( cont_color == 0 ) or ( cont_width == 0. ) then
+ axis_opts[1] = "uwtivm"
+ else
+ axis_opts[1] = "uwxvm"
+ end
+ end
+
+ label[1] = string.format( "%s, %s",
+ colorbar_position_option_labels[position_i+1],
+ colorbar_label_option_labels[label_i+1] )
+
+ -- Smaller text
+ pl.schr( 0.0, 0.75 )
+ -- Small ticks on the vertical axis
+ pl.smaj( 0.0, 0.5 )
+ pl.smin( 0.0, 0.5 )
+
+ pl.vpor( 0.20, 0.80, 0.20, 0.80 )
+ pl.wind( 0.0, 1.0, 0.0, 1.0 )
+ -- Set interesting background colour.
+ pl.scol0a( 15, 0, 0, 0, 0.20 );
+ colorbar_width, colorbar_height = pl.colorbar(
+ lor(opt, lor(pl.PL_COLORBAR_BOUNDING_BOX, pl.PL_COLORBAR_BACKGROUND)), position,
+ x, y, x_length, y_length,
+ 15, 1, 1,
+ low_cap_color, high_cap_color,
+ cont_color, cont_width,
+ label_opts, label,
+ axis_opts, ticks, sub_ticks,
+ n_values_array, values_array )
+
+ -- Reset text and tick sizes
+ pl.schr( 0.0, 1.0 )
+ pl.smaj( 0.0, 1.0 )
+ pl.smin( 0.0, 1.0 )
+ end
+
+ -- Draw a page title
+ title = string.format( "%s - %s",
+ colorbar_option_kind_labels[kind_i+1],
+ colorbar_cap_option_labels[cap_i+1] )
+ pl.vpor( 0.0, 1.0, 0.0, 1.0 )
+ pl.wind( 0.0, 1.0, 0.0, 1.0 )
+ pl.ptex( 0.5, 0.5, 0.0, 0.0, 0.5, title )
+end
+
+function plcolorbar_example( palette, kind_i, cont_color, cont_width, n_values, values )
+ -- Load the color palette
+ pl.spal1( palette, 1 )
+
+ for label_i = 0, COLORBAR_LABELS-1 do
+ for cap_i = 0, COLORBAR_CAPS-1 do
+ plcolorbar_example_page( kind_i, label_i, cap_i,
+ cont_color, cont_width,
+ n_values, values )
+ end
+ end
+end
+
----------------------------------------------------------------------------
-- main
----------------------------------------------------------------------------
@@ -110,6 +220,69 @@
"✦"
}
+-- plcolorbar options
+COLORBAR_KINDS = 4
+-- Colorbar type options
+colorbar_option_kinds = {
+ pl.PL_COLORBAR_SHADE,
+ lor(pl.PL_COLORBAR_SHADE, pl.PL_COLORBAR_SHADE_LABEL),
+ pl.PL_COLORBAR_IMAGE,
+ pl.PL_COLORBAR_GRADIENT
+}
+
+colorbar_option_kind_labels = {
+ "Shade colorbars",
+ "Shade colorbars with custom labels",
+ "Image colorbars",
+ "Gradient colorbars"
+}
+
+-- Which side of the page are we positioned relative to?
+COLORBAR_POSITIONS = 4
+colorbar_position_options = {
+ pl.PL_POSITION_LEFT,
+ pl.PL_POSITION_RIGHT,
+ pl.PL_POSITION_TOP,
+ pl.PL_POSITION_BOTTOM
+}
+
+colorbar_position_option_labels = {
+ "Left",
+ "Right",
+ "Top",
+ "Bottom"
+}
+
+-- Colorbar label positioning options
+COLORBAR_LABELS = 4
+colorbar_label_options = {
+ pl.PL_COLORBAR_LABEL_LEFT,
+ pl.PL_COLORBAR_LABEL_RIGHT,
+ pl.PL_COLORBAR_LABEL_TOP,
+ pl.PL_COLORBAR_LABEL_BOTTOM
+}
+colorbar_label_option_labels = {
+ "Label left",
+ "Label right",
+ "Label top",
+ "Label bottom"
+}
+
+-- Colorbar cap options
+COLORBAR_CAPS = 4
+colorbar_cap_options = {
+ pl.PL_COLORBAR_CAP_NONE,
+ pl.PL_COLORBAR_CAP_LOW,
+ pl.PL_COLORBAR_CAP_HIGH,
+ lor(pl.PL_COLORBAR_CAP_LOW, pl.PL_COLORBAR_CAP_HIGH)
+}
+colorbar_cap_option_labels = {
+ "No caps",
+ "Low cap",
+ "High cap",
+ "Low and high caps"
+}
+
-- Parse and process command line arguments
pl.parseopts(arg, pl.PL_PARSE_FULL)
@@ -612,4 +785,27 @@
symbol_colors, symbol_scales, symbol_numbers, symbols )
max_height = math.max(max_height, legend_height)
+-- Color bar examples
+values_small = { -1.0e-200, 1.0e-200 }
+values_uneven = { -1.0e-200, 2.0e-200, 2.6e-200, 3.4e-200, 6.0e-200, 7.0e-200, 8.0e-200, 9.0e-200, 10.0e-200 }
+values_even = { -2.0e-200, -1.0e-200, 0.0e-200, 1.0e-200, 2.0e-200, 3.0e-200, 4.0e-200, 5.0e-200, 6.0e-200 }
+
+-- Use unsaturated green background colour to contrast with black caps.
+pl.scolbg( 70, 185, 70 )
+-- Cut out the greatest and smallest bits of the color spectrum to
+-- leave colors for the end caps.
+pl.scmap1_range( 0.01, 0.99 )
+
+-- We can only test image and gradient colorbars with two element arrays
+for i = 2, COLORBAR_KINDS-1 do
+ plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, 2, values_small )
+end
+-- Test shade colorbars with larger arrays
+for i = 0,1 do
+ plcolorbar_example( "cmap1_blue_yellow.pal", i, 4, 2, 9, values_even )
+end
+for i = 0,1 do
+ plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, 9, values_uneven )
+end
+
pl.plend()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|