From: <and...@us...> - 2011-01-11 15:51:14
|
Revision: 11478 http://plplot.svn.sourceforge.net/plplot/?rev=11478&view=rev Author: andrewross Date: 2011-01-11 15:51:08 +0000 (Tue, 11 Jan 2011) Log Message: ----------- Add in support for plstring3, pllegend and plcolorbar to java. Update examples accordingly. Modified Paths: -------------- trunk/bindings/java/PLStream.java trunk/bindings/java/plplotjavac.i trunk/bindings/swig-support/plplotcapi.i trunk/examples/java/x04.java trunk/examples/java/x18.java trunk/examples/java/x26.java trunk/examples/java/x27.java Modified: trunk/bindings/java/PLStream.java =================================================================== --- trunk/bindings/java/PLStream.java 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/bindings/java/PLStream.java 2011-01-11 15:51:08 UTC (rev 11478) @@ -528,6 +528,42 @@ plplotjavac.pllab( xlabel, ylabel, tlabel ); } + public void legend( double[] p_legend_width, double[] p_legend_height, + int opt, double x, double y, double plot_width, + int bg_color, int bb_color, int bb_style, + int nrow, int ncolumn, int[] opt_array, + double text_offset, double text_scale, + double text_spacing, double text_justification, + int[] text_colors, String[] text, + int[] box_colors, int[] box_patterns, + double[] box_scales, int[] box_line_widths, + int[] line_colors, int[] line_styles, + int[] line_widths, + int[] symbol_colors, double[]symbol_scales, + int[] symbol_numbers, String[] symbols ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pllegend( p_legend_width, p_legend_height, + opt, x, y, plot_width, bg_color, bb_color, + bb_style, nrow, ncolumn, opt_array, + text_offset, text_scale, text_spacing, + text_justification, text_colors, text, + box_colors, box_patterns, box_scales, + box_line_widths, line_colors, line_styles, + line_widths, symbol_colors, symbol_scales, + symbol_numbers, symbols ); + } + + public void colorbar( int opt, double x, double y, double length, + double width, double ticks, double subticks, + String axis_opts, String label, + double[] colors, double[] values ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plcolorbar( opt, x, y, length, width, ticks, subticks, + axis_opts, label, colors, values ); + } + public void lightsource( double x, double y, double z ) { if ( set_stream() == -1 ) return; @@ -1001,6 +1037,12 @@ plplotjavac.plstring( x, y, string ); } + public void string3( double[] x, double[] y, double[] z, String string ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstring3( x, y, z, string ); + } + public void stripa( int id, int pen, double x, double y ) { if ( set_stream() == -1 ) return; Modified: trunk/bindings/java/plplotjavac.i =================================================================== --- trunk/bindings/java/plplotjavac.i 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/bindings/java/plplotjavac.i 2011-01-11 15:51:08 UTC (rev 11478) @@ -321,6 +321,7 @@ Naming rules: Array (sets Alen to dim[0]) ArrayCk (tests that dim[0] == Alen) + ArrayCkNull (tests that dim[0] == Alen or array is null) ArrayX (sets Xlen to dim[0] ArrayCkX (tests dim[0] == Xlen) ArrayY (sets Ylen to dim[1]) @@ -398,6 +399,33 @@ return $jnicall; } +/* no count but check consistency with previous or is null */ +%typemap(in) PLINT *ArrayCkNull { + if ( $input != NULL ) { + jint *jydata = (*jenv)->GetIntArrayElements( jenv, $input, 0 ); + if((*jenv)->GetArrayLength( jenv, $input ) != Alen) { + printf("Vectors must be same length.\n"); + return; + } + setup_array_1d_i( &$1, jydata, Alen); + (*jenv)->ReleaseIntArrayElements( jenv, $input, jydata, 0 ); + } + else { + $1 == NULL; + } +} +%typemap(freearg) PLINT *ArrayCkNull { + if ($1 != NULL) + free($1); +} +%typemap(jni) PLINT *ArrayCkNull "jintArray" +%typemap(jtype) PLINT *ArrayCkNull "int[]" +%typemap(jstype) PLINT *ArrayCkNull "int[]" +%typemap(javain) PLINT *ArrayCkNull "$javainput" +%typemap(javaout) PLINT *ArrayCkNull { + return $jnicall; +} + /* Weird case to allow argument to be one shorter than others */ /* This case is used both for PLBOOL and PLINT. Define PLBOOL version * first. (AWI thinks this may be necessary because of the above @@ -610,6 +638,33 @@ return $jnicall; } +/* no count, but check consistency with previous or NULL */ +%typemap(in) PLFLT *ArrayCkNull { + if ( $input != NULL ) { + jPLFLT *jydata = (*jenv)->GetPLFLTArrayElements( jenv, $input, 0 ); + if((*jenv)->GetArrayLength( jenv, $input ) != Alen) { + printf("Vectors must be same length.\n"); + return; + } + setup_array_1d_PLFLT( &$1, jydata, Alen ); + (*jenv)->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 ); + } + else { + $1 = NULL; + } +} +%typemap(freearg) PLFLT *ArrayCkNull { + if ($1 != NULL) + free($1); +} +%typemap(jni) PLFLT *ArrayCkNull jPLFLTArray +%typemap(jtype) PLFLT *ArrayCkNull jPLFLTbracket +%typemap(jstype) PLFLT *ArrayCkNull jPLFLTbracket +%typemap(javain) PLFLT *ArrayCkNull "$javainput" +%typemap(javaout) PLFLT *ArrayCkNull{ + return $jnicall; +} + /* set X length for later consistency checking */ %typemap(in) (PLFLT *ArrayX, PLINT nx) { jPLFLT *jxdata = (*jenv)->GetPLFLTArrayElements( jenv, $input, 0 ); @@ -1720,6 +1775,47 @@ free($1); } +%typemap(jni) (char **ArrayCk) "jobjectArray" +%typemap(jtype) (char **ArrayCk) "String[]" +%typemap(jstype) (char **ArrayCk) "String[]" +%typemap(javain) (char **ArrayCk) "$javainput" +%typemap(javaout) (char **ArrayCk) { + return $jnicall; +} +%typemap(in) (char **ArrayCk) { + int i = 0; + if ($input != NULL) { + int size = (*jenv)->GetArrayLength(jenv, $input); + if (size != Alen) { + printf("Arrays must be the same length\n"); + return; + } + $1 = (char **) malloc(Alen*sizeof(char *)); + /* make a copy of each string */ + for (i = 0; i<Alen; i++) { + jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, $input, i); + const char * c_string = (char *) (*jenv)->GetStringUTFChars(jenv, j_string, 0); + $1[i] = malloc((strlen(c_string)+1)*sizeof(const char *)); + strcpy($1[i], c_string); + (*jenv)->ReleaseStringUTFChars(jenv, j_string, c_string); + (*jenv)->DeleteLocalRef(jenv, j_string); + } + } + else { + $1 = NULL; + } +} + +/* This cleans up the memory we malloc'd before the function call */ +%typemap(freearg) (char **ArrayCk) { + int i; + if ($1 != NULL) { + for (i=0; i<Alen; i++) + free($1[i]); + free($1); + } +} + #if 0 %typemap(in) PLGraphicsIn *gin (PLGraphicsIn tmp) { if(!PySequence_Check($input) || PySequence_Size($input) != 2) { @@ -1739,8 +1835,5 @@ } #endif -// Not implemented yet. -%ignore pllegend; - /* swig compatible PLplot API definitions from here on. */ %include plplotcapi.i Modified: trunk/bindings/swig-support/plplotcapi.i =================================================================== --- trunk/bindings/swig-support/plplotcapi.i 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/bindings/swig-support/plplotcapi.i 2011-01-11 15:51:08 UTC (rev 11478) @@ -554,17 +554,17 @@ PLFLT text_offset, PLFLT text_scale, PLFLT text_spacing, PLFLT text_justification, const PLINT *ArrayCk, const char **ArrayCk, - const PLINT *ArrayCk, const PLINT *ArrayCk, - const PLFLT *ArrayCk, const PLINT *ArrayCk, - const PLINT *ArrayCk, const PLINT *ArrayCk, - const PLINT *ArrayCk, - const PLINT *ArrayCk, const PLFLT *ArrayCk, - const PLINT *ArrayCk, const char **ArrayCk ); + const PLINT *ArrayCkNull, const PLINT *ArrayCkNull, + const PLFLT *ArrayCkNull, const PLINT *ArrayCkNull, + const PLINT *ArrayCkNull, const PLINT *ArrayCkNull, + const PLINT *ArrayCkNull, + const PLINT *ArrayCkNull, const PLFLT *ArrayCkNull, + const PLINT *ArrayCkNull, const char **ArrayCk ); %feature( "docstring", "Create a continous colorbar using an image, shade, or gradient with an optional axis label." ) plcolorbar; void plcolorbar( PLINT opt, PLFLT x, PLFLT y, PLFLT length, PLFLT width, - PLFLT ticks, PLINT sub_ticks, + PLFLT ticks, PLFLT sub_ticks, const char *axis_opts, const char *label, PLINT n, PLFLT *Array, PLFLT *ArrayCk ); Modified: trunk/examples/java/x04.java =================================================================== --- trunk/examples/java/x04.java 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/examples/java/x04.java 2011-01-11 15:51:08 UTC (rev 11478) @@ -69,6 +69,19 @@ double[] ampl = new double[101]; double[] phase = new double[101]; double f0, freq; + int nlegend; + String[] text; + String[] symbols; + int[] opt_array; + int[] text_colors; + int[] line_colors; + int[] line_styles; + int[] line_widths; + int[] symbol_numbers; + int[] symbol_colors; + double[] symbol_scales; + double[] legend_width = new double[1]; + double[] legend_height = new double[1]; pls.adv( 0 ); @@ -104,7 +117,7 @@ pls.col0( 2 ); pls.line( freql, ampl ); - pls.col0( 1 ); + pls.col0( 2 ); pls.ptex( 1.6, -30.0, 1.0, -20.0, 0.5, "-20 dB/decade" ); // Put labels on. @@ -114,6 +127,7 @@ pls.mtex( "t", 2.0, 0.5, 0.5, "Single Pole Low-Pass Filter" ); pls.col0( 2 ); pls.mtex( "l", 5.0, 0.5, 0.5, "Amplitude (dB)" ); + nlegend = 1; // For the gridless case, put phase vs freq on same plot. @@ -127,7 +141,61 @@ pls.string( freql, phase, "*" ); pls.col0( 3 ); pls.mtex( "r", 5.0, 0.5, 0.5, "Phase shift (degrees)" ); + nlegend = 2; } + text = new String[nlegend]; + symbols = new String[nlegend]; + opt_array = new int[nlegend]; + text_colors = new int[nlegend]; + line_colors = new int[nlegend]; + line_styles = new int[nlegend]; + line_widths = new int[nlegend]; + symbol_numbers = new int[nlegend]; + symbol_colors = new int[nlegend]; + symbol_scales = new double[nlegend]; + + // Draw a legend + // First legend entry. + opt_array[0] = PLStream.PL_LEGEND_LINE; + text_colors[0] = 2; + text[0] = "Amplitude"; + line_colors[0] = 2; + line_styles[0] = 1; + line_widths[0] = 1; + // note from the above opt_array the first symbol (and box) indices + // do not have to be specified EXCEPT for symbols. + // Although this is unused, it can't be undefined as the String + // array is copied as part of the java bindings. + symbols[0] = " "; + + // Second legend entry. + if (nlegend == 2) { + opt_array[1] = PLStream.PL_LEGEND_LINE | PLStream.PL_LEGEND_SYMBOL; + text_colors[1] = 3; + text[1] = "Phase shift"; + line_colors[1] = 3; + line_styles[1] = 1; + line_widths[1] = 1; + symbol_colors[1] = 3; + symbol_scales[1] = 1.; + symbol_numbers[1] = 4; + symbols[1] = "*"; + } + + // from the above opt_arrays we can completely ignore everything + // to do with boxes. + + pls.scol0a( 15, 32, 32, 32, 0.70 ); + pls.legend( legend_width, legend_height, + PLStream.PL_LEGEND_BACKGROUND | PLStream.PL_LEGEND_BOUNDING_BOX, + 0.0, 0.0, 0.1, 15, + 1, 1, 0, 0, opt_array, + 1.0, 1.0, 2.0, + 1., text_colors, text, + null, null, null, null, + line_colors, line_styles, line_widths, + symbol_colors, symbol_scales, symbol_numbers, symbols ); + } } Modified: trunk/examples/java/x18.java =================================================================== --- trunk/examples/java/x18.java 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/examples/java/x18.java 2011-01-11 15:51:08 UTC (rev 11478) @@ -167,7 +167,8 @@ if ( opt[k] > 0 ) pls.line3( x, y, z ); else - pls.poin3( x, y, z, 1 ); + // U+22C5 DOT OPERATOR. + pls.string3( x, y, z, "⋅" ); pls.col0( 3 ); String title = "#frPLplot Example 18 - Alt=" + Modified: trunk/examples/java/x26.java =================================================================== --- trunk/examples/java/x26.java 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/examples/java/x26.java 2011-01-11 15:51:08 UTC (rev 11478) @@ -85,6 +85,12 @@ "Фазовый сдвиг (градусы)" }; + // Short rearranged versions of y_label and alty_label. + static String[][] legend_text = { + { "Amplitude", "Phase shift"}, + { "Амплитуда", "Фазовый сдвиг" } + }; + static String[] title_label = { "Single Pole Low-Pass Filter", "Однополюсный Низко-Частотный Фильтр" @@ -126,8 +132,8 @@ for ( i = 0; i < nlang; i++ ) { - plot1( 0, x_label[i], y_label[i], alty_label[i], title_label[i], - line_label[i] ); + plot1( 0, x_label[i], y_label[i], alty_label[i], + legend_text[i], title_label[i], line_label[i] ); } pls.end(); @@ -136,13 +142,25 @@ // Log-linear plot. void plot1( int type, String x_label, String y_label, String alty_label, - String title_label, String line_label ) + String[] legend_text, String title_label, String line_label ) { int i; double[] freql = new double[101]; double[] ampl = new double[101]; double[] phase = new double[101]; double f0, freq; + int nlegend = 2; + int[] opt_array = new int[2]; + int[] text_colors = new int[2]; + int[] line_colors = new int[2]; + int[] line_styles = new int[2]; + int[] line_widths = new int[2]; + int[] symbol_numbers = new int[2]; + int[] symbol_colors = new int[2]; + double[] symbol_scales = new double[2]; + String[] symbols = new String[2]; + double[] legend_width = new double[1]; + double[] legend_height = new double[1]; pls.adv( 0 ); @@ -178,7 +196,7 @@ pls.col0( 2 ); pls.line( freql, ampl ); - pls.col0( 1 ); + pls.col0( 2 ); pls.ptex( 1.6, -30.0, 1.0, -20.0, 0.5, line_label ); // Put labels on. @@ -202,6 +220,43 @@ pls.col0( 3 ); pls.mtex( "r", 5.0, 0.5, 0.5, alty_label ); } + // Draw a legend + // First legend entry. + opt_array[0] = PLStream.PL_LEGEND_LINE; + text_colors[0] = 2; + line_colors[0] = 2; + line_styles[0] = 1; + line_widths[0] = 1; + // note from the above opt_array the first symbol (and box) indices + // do not have to be specified EXCEPT for symbols. + // Although this is unused, it can't be undefined as the String + // array is copied as part of the java bindings. + symbols[0] = ""; + + // Second legend entry. + opt_array[1] = PLStream.PL_LEGEND_LINE | PLStream.PL_LEGEND_SYMBOL; + text_colors[1] = 3; + line_colors[1] = 3; + line_styles[1] = 1; + line_widths[1] = 1; + symbol_colors[1] = 3; + symbol_scales[1] = 1.; + symbol_numbers[1] = 4; + symbols[1] = "*"; + // from the above opt_arrays we can completely ignore everything + // to do with boxes. + + pls.scol0a( 15, 32, 32, 32, 0.70 ); + pls.legend( legend_width, legend_height, + PLStream.PL_LEGEND_BACKGROUND | PLStream.PL_LEGEND_BOUNDING_BOX, + 0.0, 0.0, 0.10, 15, + 1, 1, 0, 0, opt_array, + 1.0, 1.0, 2.0, + 1., text_colors, legend_text, + null, null, null, null, + line_colors, line_styles, line_widths, + symbol_colors, symbol_scales, symbol_numbers, symbols ); + } } Modified: trunk/examples/java/x27.java =================================================================== --- trunk/examples/java/x27.java 2011-01-11 08:22:48 UTC (rev 11477) +++ trunk/examples/java/x27.java 2011-01-11 15:51:08 UTC (rev 11478) @@ -61,6 +61,7 @@ { 20.0, -13.0, 20.0, 20.0 } }; int i; + boolean fill; // plplot initialization @@ -77,11 +78,12 @@ // First an overview, then all curves one by one pls.ssub( 3, 3 ); // Three by three window + fill = false; for ( i = 0; i < 9; i++ ) { pls.adv( 0 ); pls.vpor( 0.0, 1.0, 0.0, 1.0 ); - spiro( params[i] ); + spiro( params[i], fill ); } pls.adv( 0 ); @@ -91,9 +93,22 @@ { pls.adv( 0 ); pls.vpor( 0.0, 1.0, 0.0, 1.0 ); - spiro( params[i] ); + spiro( params[i], fill ); } + // Fill the curves + fill = true; + + pls.adv( 0 ); + pls.ssub( 1, 1 ); // One window per curve + + for ( i = 0; i < 9; i++ ) + { + pls.adv( 0 ); + pls.vpor( 0.0, 1.0, 0.0, 1.0 ); + spiro( params[i], fill ); + } + pls.end(); } @@ -106,7 +121,7 @@ // =============================================================== - void spiro( double params[] ) + void spiro( double params[], boolean fill ) { int NPNT = 20000; double xcoord[]; @@ -167,7 +182,11 @@ pls.wind( xmin, xmax, ymin, ymax ); pls.col0( 1 ); - pls.line( xcoord, ycoord ); + + if ( fill ) + pls.fill( xcoord, ycoord ); + else + pls.line( xcoord, ycoord ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |