Skip to content

Commit 8e8f8ca

Browse files
joa-quimEsteban82
andauthored
Fix option -B+n in psscale (#8737)
This addresses one of the points raised in the Forum issue https://forum.generic-mapping-tools.org/t/colour-scheme-without-outline/5967 Now we can do `psscale -Dx6.5/1+w340p/36p+h -B+n -Ccyclic > cyclic.ps` and have no frames at all. I would like also that `-B0` did that work (a nicer syntax, IMO) and in fact, this PR also implements it but it requires that GMT is built with `-DB0_IS_NO_FRAME`. The reason for wrapping it in a `#ifdef` is that changing `-B0` to do what it originally should have been since the beginning (that is, to DO NOT PLOT ANY FRAME, ANNOTS AT ALL) is a breaking change. I would like, however, to discuss if we should do it nevertheless. Co-authored-by: Federico Esteban <[email protected]>
1 parent d708637 commit 8e8f8ca

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/gmt_init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,6 +4987,9 @@ GMT_LOCAL int gmtinit_parse5_B_option (struct GMT_CTRL *GMT, char *in) {
49874987
if (GMT->common.J.zactive) GMT->current.map.frame.drawz = true; /* Also brings z-axis into contention */
49884988
GMT->current.setting.map_frame_type = GMT_IS_PLAIN; /* Since checkerboard without intervals look stupid */
49894989
GMT->current.map.frame.set[no] = true; /* Since we want this axis drawn */
4990+
#ifdef B0_IS_NO_FRAME
4991+
GMT->current.map.frame.no_frame = true; /* Understand format '0' to mean "NO FRAME AT ALL" */
4992+
#endif
49904993
continue;
49914994
}
49924995

src/psscale.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,30 +1388,34 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
13881388

13891389
PSL_setlinecap (PSL, PSL_SQUARE_CAP); /* Square cap required for box of scale bar */
13901390

1391-
if (gap == 0.0) {
1392-
if ((flip & PSSCALE_FLIP_ANNOT) || !B_set) PSL_plotsegment (PSL, xleft, 0.0, xleft + length, 0.0);
1393-
if (!(flip & PSSCALE_FLIP_ANNOT) || !B_set) PSL_plotsegment (PSL, xleft, width, xleft + length, width);
1394-
PSL_plotsegment (PSL, xleft, 0.0, xleft, width);
1395-
PSL_plotsegment (PSL, xright, 0.0, xright, width);
1391+
if (gap == 0.0 && !GMT->current.map.frame.no_frame) {
1392+
if ((flip & PSSCALE_FLIP_ANNOT) || !B_set) PSL_plotsegment(PSL, xleft, 0.0, xleft + length, 0.0);
1393+
if (!(flip & PSSCALE_FLIP_ANNOT) || !B_set) PSL_plotsegment(PSL, xleft, width, xleft + length, width);
1394+
PSL_plotsegment(PSL, xleft, 0.0, xleft, width);
1395+
PSL_plotsegment(PSL, xright, 0.0, xright, width);
13961396
}
13971397

13981398
if (B_set) { /* Used -B */
1399-
gmt_xy_axis2 (GMT, xleft, y_base, length, start_val, stop_val, A, !(flip & PSSCALE_FLIP_ANNOT), GMT->current.map.frame.side[flip & PSSCALE_FLIP_ANNOT ? N_SIDE : S_SIDE] & PSSCALE_FLIP_LABEL, GMT->current.map.frame.side[flip & PSSCALE_FLIP_ANNOT ? N_SIDE : S_SIDE]);
1399+
if (!GMT->current.map.frame.no_frame)
1400+
gmt_xy_axis2(GMT, xleft, y_base, length, start_val, stop_val, A, !(flip & PSSCALE_FLIP_ANNOT),
1401+
GMT->current.map.frame.side[flip & PSSCALE_FLIP_ANNOT ? N_SIDE : S_SIDE] & PSSCALE_FLIP_LABEL,
1402+
GMT->current.map.frame.side[flip & PSSCALE_FLIP_ANNOT ? N_SIDE : S_SIDE]);
1403+
14001404
if (A->item[GMT_GRID_UPPER].active) {
1401-
dx = gmtlib_get_map_interval (GMT, A->type, &A->item[GMT_GRID_UPPER]);
1405+
dx = gmtlib_get_map_interval(GMT, A->type, &A->item[GMT_GRID_UPPER]);
14021406
gmt_setpen (GMT, &GMT->current.setting.map_grid_pen[GMT_PRIMARY]);
14031407
if (A->type == GMT_TIME)
1404-
gmt_plot_timex_grid (GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, GMT_GRID_UPPER);
1408+
gmt_plot_timex_grid(GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, GMT_GRID_UPPER);
14051409
else
1406-
gmt_linearx_grid (GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, dx);
1410+
gmt_linearx_grid(GMT, PSL, P->data[0].z_low, P->data[P->n_colors-1].z_high, 0.0, width, dx);
14071411
}
14081412
}
1409-
else { /* When no -B we annotate every CPT bound which may be non-equidistant, hence this code (i.e., we cannot fake a call to -B) */
1413+
else if (!GMT->current.map.frame.no_frame) { /* When no -B we annotate every CPT bound which may be non-equidistant, hence this code (i.e., we cannot fake a call to -B) */
14101414

14111415
if (!skip_lines) { /* First draw gridlines, unless skip_lines is true */
1412-
gmt_setpen (GMT, &GMT->current.setting.map_grid_pen[GMT_PRIMARY]);
1416+
gmt_setpen(GMT, &GMT->current.setting.map_grid_pen[GMT_PRIMARY]);
14131417
for (i = 0; i < n_xpos; i++)
1414-
PSL_plotsegment (PSL, xpos[i], 0.0, xpos[i], width);
1418+
PSL_plotsegment(PSL, xpos[i], 0.0, xpos[i], width);
14151419
}
14161420

14171421
/* Then draw annotation and frame tickmarks */

0 commit comments

Comments
 (0)