From: <ai...@us...> - 2011-04-30 18:37:34
|
Revision: 11736 http://plplot.svn.sourceforge.net/plplot/?rev=11736&view=rev Author: airwin Date: 2011-04-30 18:37:28 +0000 (Sat, 30 Apr 2011) Log Message: ----------- Put the orientation of the colorbar directly under the control of the user with the PL_COLORBAR_ORIENT_(RIGHT, TOP, LEFT, BOTTOM) orientation bits of opt. However, if the user does not specify any of these bits, then adopt a sensible orientation default which depends on position. Make all previous orientation logic (which was controlled strictly by position bits before) depend on the orientation bits instead. There are no changes to the example 33 PostScript results due to these internal changes (because of the default orientation choice noted above). ToDo: My goal here is that position should control nothing except overall position of colorbar with no cross-talk with how that colorbar object is specified except for the default value of the orientation. I have only dealt with the obvious orientation stuff for now and there is some non-position logic (e.g., label offsets, numerical label positions, and tick marks for the colorbar) that currently depends on position bits that still must be dealt with to achieve my goal. Modified Paths: -------------- trunk/src/pllegend.c Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2011-04-30 04:28:20 UTC (rev 11735) +++ trunk/src/pllegend.c 2011-04-30 18:37:28 UTC (rev 11736) @@ -1093,6 +1093,18 @@ // Draw a title char perp; + // Default orientation. + if ( !( opt & PL_COLORBAR_ORIENT_RIGHT || + opt & PL_COLORBAR_ORIENT_TOP || + opt & PL_COLORBAR_ORIENT_LEFT || + opt & PL_COLORBAR_ORIENT_BOTTOM ) ) + { + if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + opt = opt | PL_COLORBAR_ORIENT_TOP; + else + opt = opt | PL_COLORBAR_ORIENT_RIGHT; + } + min_value = values[0]; max_value = values[ n_values - 1 ]; @@ -1102,58 +1114,69 @@ plgvpsp( &xdmin_save, &xdmax_save, &ydmin_save, &ydmax_save ); plgvpw( &xwmin_save, &xwmax_save, &ywmin_save, &ywmax_save ); - // Build the proper viewport and window dimension along the requested side + // Specify the proper viewport ranges along the requested side // of the subpage if ( position & PL_POSITION_LEFT ) { vx_min = x; vy_min = y; - vx_max = vx_min + x_length; - vy_max = vy_min + y_length; - wx_min = 0.0; - wy_min = min_value; - wx_max = 1.0; - wy_max = max_value; } else if ( position & PL_POSITION_RIGHT ) { vx_min = 1.0 - x - x_length; vy_min = y; - vx_max = vx_min + x_length; - vy_max = vy_min + y_length; - wx_min = 0.0; - wy_min = min_value; - wx_max = 1.0; - wy_max = max_value; } else if ( position & PL_POSITION_TOP ) { vx_min = x; vy_min = 1.0 - y - y_length; - vx_max = vx_min + x_length; - vy_max = vy_min + y_length; - wx_min = min_value; - wy_min = 0.0; - wx_max = max_value; - wy_max = 1.0; } else if ( position & PL_POSITION_BOTTOM ) { vx_min = x; vy_min = y; - vx_max = vx_min + x_length; - vy_max = vy_min + y_length; + } + else + { + plabort( "plcolorbar: Invalid PL_POSITION_* bits" ); + } + vx_max = vx_min + x_length; + vy_max = vy_min + y_length; + + // Specify the proper window ranges depending on orientation. + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) + { wx_min = min_value; + wx_max = max_value; wy_min = 0.0; - wx_max = max_value; wy_max = 1.0; } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { + wx_min = 0.0; + wx_max = 1.0; + wy_min = min_value; + wy_max = max_value; + } + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) + { + wx_min = max_value; + wx_max = min_value; + wy_min = 0.0; + wy_max = 1.0; + } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM) + { + wx_min = 0.0; + wx_max = 1.0; + wy_min = max_value; + wy_max = min_value; + } else { - plabort( "plcolorbar: Invalid or missing side" ); + plabort( "plcolorbar: Invalid PL_COLORBAR_ORIENT_* bits" ); } - // The window used to draw the colorbar should take up the whole viewport plvpor( vx_min, vx_max, vy_min, vy_max ); plwind( wx_min, wx_max, wy_min, wy_max ); @@ -1170,8 +1193,21 @@ // TODO: Determine a better way to specify the steps here? n_steps = plsc->ncol1; step_size = ( max_value - min_value ) / (PLFLT) n_steps; - if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { + ni = n_steps; + nj = 2; + plAlloc2dGrid( &color_data, ni, nj ); + for ( i = 0; i < ni; i++ ) + { + for ( j = 0; j < nj; j++ ) + { + color_data[i][j] = min_value + (PLFLT) i * step_size; + } + } + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { ni = 2; nj = n_steps; plAlloc2dGrid( &color_data, ni, nj ); @@ -1183,7 +1219,7 @@ } } } - else if ( position & PL_POSITION_TOP || position & PL_POSITION_BOTTOM ) + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) { ni = n_steps; nj = 2; @@ -1192,13 +1228,26 @@ { for ( j = 0; j < nj; j++ ) { - color_data[i][j] = min_value + (PLFLT) i * step_size; + color_data[i][j] = max_value - (PLFLT) i * step_size; } } } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + ni = 2; + nj = n_steps; + plAlloc2dGrid( &color_data, ni, nj ); + for ( i = 0; i < ni; i++ ) + { + for ( j = 0; j < nj; j++ ) + { + color_data[i][j] = max_value - (PLFLT) j * step_size; + } + } + } else { - plabort( "plcolorbar: Invalid side" ); + plabort( "plcolorbar: Invalid orientation bits" ); } } // No interpolation - use values array as-is @@ -1206,8 +1255,21 @@ { n_steps = n_values; // Use the provided values in this case. - if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { + ni = n_steps; + nj = 2; + plAlloc2dGrid( &color_data, ni, nj ); + for ( i = 0; i < ni; i++ ) + { + for ( j = 0; j < nj; j++ ) + { + color_data[i][j] = values[i]; + } + } + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { ni = 2; nj = n_steps; plAlloc2dGrid( &color_data, ni, nj ); @@ -1219,7 +1281,7 @@ } } } - else if ( position & PL_POSITION_TOP || position & PL_POSITION_BOTTOM ) + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) { ni = n_steps; nj = 2; @@ -1228,10 +1290,23 @@ { for ( j = 0; j < nj; j++ ) { - color_data[i][j] = values[i]; + color_data[i][j] = values[ni - 1 - i]; } } } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + ni = 2; + nj = n_steps; + plAlloc2dGrid( &color_data, ni, nj ); + for ( i = 0; i < ni; i++ ) + { + for ( j = 0; j < nj; j++ ) + { + color_data[i][j] = values[nj - 1 - j]; + } + } + } else { plabort( "plcolorbar: Invalid side" ); @@ -1253,8 +1328,25 @@ PLFLT grid_axis[2] = { 0.0, 1.0 }; n_steps = n_values; // Use the provided values. - if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { + grid.xg = (PLFLT *) values; + grid.yg = grid_axis; + grid.nx = n_steps; + grid.ny = 2; + ni = n_steps; + nj = 2; + plAlloc2dGrid( &color_data, ni, nj ); + for ( i = 0; i < ni; i++ ) + { + for ( j = 0; j < nj; j++ ) + { + color_data[i][j] = values[i]; + } + } + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { grid.xg = grid_axis; grid.yg = (PLFLT *) values; grid.nx = 2; @@ -1270,7 +1362,7 @@ } } } - else if ( position & PL_POSITION_TOP || position & PL_POSITION_BOTTOM ) + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) { grid.xg = (PLFLT *) values; grid.yg = grid_axis; @@ -1283,13 +1375,30 @@ { for ( j = 0; j < nj; j++ ) { - color_data[i][j] = values[i]; + color_data[i][j] = values[ni - 1 - i]; } } } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + grid.xg = grid_axis; + grid.yg = (PLFLT *) values; + grid.nx = 2; + grid.ny = n_steps; + ni = 2; + nj = n_steps; + plAlloc2dGrid( &color_data, ni, nj ); + for ( i = 0; i < ni; i++ ) + { + for ( j = 0; j < nj; j++ ) + { + color_data[i][j] = values[nj - 1 - j]; + } + } + } else { - plabort( "plcolorbar: Invalid side" ); + plabort( "plcolorbar: Invalid orientation" ); } // Draw the color bar @@ -1311,19 +1420,25 @@ xs[3] = wx_min; ys[3] = wy_max; // Make sure the gradient runs in the proper direction - if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { - // Top to bottom + angle = 0.0; + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { angle = 90.0; } - else if ( position & PL_POSITION_TOP || position & PL_POSITION_BOTTOM ) + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) { - // Left to right - angle = 0.0; + angle = 180.0; } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + angle = 270.0; + } else { - plabort( "plcolorbar: Invalid side" ); + plabort( "plcolorbar: Invalid orientation" ); } plgradient( 4, xs, ys, angle ); } @@ -1338,50 +1453,66 @@ { // Add an extra offset for the label so it does not bump in to the // cap if the label is placed on the same side as the cap. - if ( ( ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) && - opt & PL_COLORBAR_LABEL_BOTTOM ) || - ( ( position & PL_POSITION_TOP || position & PL_POSITION_BOTTOM ) && - opt & PL_COLORBAR_LABEL_LEFT ) ) + if ( ( opt & PL_COLORBAR_ORIENT_RIGHT && opt & PL_COLORBAR_LABEL_LEFT ) || + ( opt & PL_COLORBAR_ORIENT_TOP && opt & PL_COLORBAR_LABEL_BOTTOM ) || + ( opt & PL_COLORBAR_ORIENT_LEFT && opt & PL_COLORBAR_LABEL_RIGHT ) || + ( opt & PL_COLORBAR_ORIENT_BOTTOM && opt & PL_COLORBAR_LABEL_TOP ) ) { label_offset += 2.5; } // Draw a filled triangle (cap/arrow) at the low end of the scale - if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { + draw_cap( PL_COLORBAR_ORIENT_LEFT, vx_min - cap_height, vx_min, vy_min, vy_max, low_cap_color ); + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { draw_cap( PL_COLORBAR_ORIENT_BOTTOM, vx_min, vx_max, vy_min - cap_height, vy_min, low_cap_color ); } - else if ( position & PL_POSITION_BOTTOM || position & PL_POSITION_TOP ) + else if ( opt & PL_COLORBAR_ORIENT_LEFT ) { - draw_cap( PL_COLORBAR_ORIENT_LEFT, vx_min - cap_height, vx_min, vy_min, vy_max, low_cap_color ); + draw_cap( PL_COLORBAR_ORIENT_RIGHT, vx_max, vx_max + cap_height, vy_min, vy_max, low_cap_color ); } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + draw_cap( PL_COLORBAR_ORIENT_TOP, vx_min, vx_max, vy_max, vy_max + cap_height, low_cap_color ); + } } if ( opt & PL_COLORBAR_CAP_HIGH ) { // Add an extra offset for the label so it does not bump in to the // cap if the label is placed on the same side as the cap. - if ( ( ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) && - opt & PL_COLORBAR_LABEL_TOP ) || - ( ( position & PL_POSITION_TOP || position & PL_POSITION_BOTTOM ) && - opt & PL_COLORBAR_LABEL_RIGHT ) ) + if ( ( opt & PL_COLORBAR_ORIENT_RIGHT && opt & PL_COLORBAR_LABEL_RIGHT ) || + ( opt & PL_COLORBAR_ORIENT_TOP && opt & PL_COLORBAR_LABEL_TOP ) || + ( opt & PL_COLORBAR_ORIENT_LEFT && opt & PL_COLORBAR_LABEL_LEFT ) || + ( opt & PL_COLORBAR_ORIENT_BOTTOM && opt & PL_COLORBAR_LABEL_BOTTOM ) ) { label_offset += 2.5; } // Draw a filled triangle (cap/arrow) at the high end of the scale - if ( position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT ) + if ( opt & PL_COLORBAR_ORIENT_RIGHT ) { + draw_cap( PL_COLORBAR_ORIENT_RIGHT, vx_max, vx_max + cap_height, vy_min, vy_max, high_cap_color ); + } + else if ( opt & PL_COLORBAR_ORIENT_TOP ) + { draw_cap( PL_COLORBAR_ORIENT_TOP, vx_min, vx_max, vy_max, vy_max + cap_height, high_cap_color ); } - else if ( position & PL_POSITION_BOTTOM || position & PL_POSITION_TOP ) + if ( opt & PL_COLORBAR_ORIENT_LEFT ) { - draw_cap( PL_COLORBAR_ORIENT_RIGHT, vx_max, vx_max + cap_height, vy_min, vy_max, high_cap_color ); + draw_cap( PL_COLORBAR_ORIENT_LEFT, vx_min - cap_height, vx_min, vy_min, vy_max, high_cap_color ); } + else if ( opt & PL_COLORBAR_ORIENT_BOTTOM ) + { + draw_cap( PL_COLORBAR_ORIENT_BOTTOM, vx_min, vx_max, vy_min - cap_height, vy_min, high_cap_color ); + } } tick_string = ""; if ( opt & PL_COLORBAR_LABEL_LEFT ) { - if ( position & PL_POSITION_RIGHT || position & PL_POSITION_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_TOP || opt & PL_COLORBAR_ORIENT_BOTTOM ) { if ( position & PL_POSITION_LEFT ) label_offset += 4.0; @@ -1401,7 +1532,7 @@ } else if ( opt & PL_COLORBAR_LABEL_RIGHT ) { - if ( position & PL_POSITION_RIGHT || position & PL_POSITION_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_TOP || opt & PL_COLORBAR_ORIENT_BOTTOM ) { if ( position & PL_POSITION_RIGHT ) label_offset += 4.0; @@ -1421,7 +1552,7 @@ } else if ( opt & PL_COLORBAR_LABEL_TOP ) { - if ( position & PL_POSITION_RIGHT || position & PL_POSITION_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_TOP || opt & PL_COLORBAR_ORIENT_BOTTOM ) { label_offset += 1.5; perp = '\0'; @@ -1439,7 +1570,7 @@ } else if ( opt & PL_COLORBAR_LABEL_BOTTOM ) { - if ( position & PL_POSITION_RIGHT || position & PL_POSITION_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_TOP || opt & PL_COLORBAR_ORIENT_BOTTOM ) { label_offset += 1.5; perp = '\0'; @@ -1496,26 +1627,16 @@ } // Draw the outline for the entire colorbar, tick marks, tick labels. - if ( position & PL_POSITION_LEFT ) + if ( opt & PL_COLORBAR_ORIENT_TOP || opt & PL_COLORBAR_ORIENT_BOTTOM) { snprintf( opt_string, max_opts, "bc%s%s", tick_string, axis_opts ); - plbox( "bc", ticks, sub_ticks, opt_string, ticks, sub_ticks ); - } - else if ( position & PL_POSITION_RIGHT ) - { - snprintf( opt_string, max_opts, "bc%s%s", tick_string, axis_opts ); plbox( "bc", 0.0, 0, opt_string, ticks, sub_ticks ); } - else if ( position & PL_POSITION_TOP ) + else { snprintf( opt_string, max_opts, "bc%s%s", tick_string, axis_opts ); plbox( opt_string, ticks, sub_ticks, "bc", 0.0, 0 ); } - else if ( position & PL_POSITION_BOTTOM ) - { - snprintf( opt_string, max_opts, "bc%s%s", tick_string, axis_opts ); - plbox( opt_string, ticks, sub_ticks, "bc", 0.0, 0 ); - } // Restore previous plot characteristics. plcol0( col0_save ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |