Skip to content

Commit df3760b

Browse files
authored
Add a new option, -H, that will stop the annotations auto-scale. (#8810)
* Add a new option, -H, that will stop the annotations auto-scale. See discussion at #8796 (comment) This applies to both modern and classic mode. Sadly the change to the auto-scaling behavior did not let an escape route to the situations where user to have full control of font sizes. Not even in classic mode, where auto-scaling is not supposed to happen. This new option restores that _power_. * Update docs for the new -H option
1 parent 65461bd commit df3760b

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

doc/rst/source/colorbar.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Synopsis
1818
[ |-D|\ *refpoint* ]
1919
[ |-F|\ *panel* ]
2020
[ |-G|\ *zlo*\ /\ *zhi* ]
21+
[ |-H| ]
2122
[ |-I|\ [*max\_intens*\|\ *low_i*/*high_i*] ]
2223
[ |-J|\ *parameters* ]
2324
[ |-J|\ **z**\|\ **Z**\ *parameters* ]
@@ -54,8 +55,8 @@ widths. The font used for the annotations along the scale is specified by
5455
bar is controlled by :term:`FONT_ANNOT_SECONDARY`. If a label along the bar is requested, it is plotted with
5556
:term:`FONT_LABEL`. But mind you that the modern mode theme scales down the size of annotations and labels
5657
based on the colorbar length for improved legibility. So, in modern mode scripts it might look that these
57-
parameter settings are not working correctly. If you may want to increase font sizes to compensate the
58-
scaling effect the solution is to use the online ``--FONT_ANNOT_PRIMARY=...`` construct.
58+
parameter settings are not working correctly. If you want to have full control on font sizes and overcome
59+
the auto-scaling, use option |-H|.
5960
For a full overview of CPTs, see the Technical Reference section on :ref:`Color palette tables <CPT_section>`.
6061

6162
.. figure:: /_images/GMT_colorbar.*
@@ -162,6 +163,12 @@ Optional Arguments
162163
we leave that end of the CPT alone. The truncation takes place
163164
before the plotting.
164165

166+
.. _-H:
167+
168+
**-H**
169+
From GMT 6.5 on, colorbar annotation fonts are auto-scaled. Use this option to prevent that effect
170+
and let user set fonts as they wish.
171+
165172
.. _-I:
166173

167174
**-I**\ [*max_intens*\|\ *low\_i*/*high_i*]

doc/rst/source/psscale.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Synopsis
1818
[ |-D|\ *refpoint* ]
1919
[ |-F|\ *panel* ]
2020
[ |-G|\ *zlo*\ /\ *zhi* ]
21+
[ |-H| ]
2122
[ |-I|\ [*max\_intens*\|\ *low_i*/*high_i*] ]
2223
[ |-J|\ *parameters* ]
2324
[ |-K| ]

src/psscale.c

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ struct PSSCALE_CTRL {
101101
bool active;
102102
double z_low, z_high;
103103
} G;
104+
struct PSSCALE_H { /* -H */
105+
bool active;
106+
} H;
104107
struct PSSCALE_I { /* -I[<intens>|<min_i>/<max_i>] */
105108
bool active;
106109
double min, max;
@@ -167,13 +170,13 @@ static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSSCALE_CTRL *C) { /* Deallo
167170
gmt_M_free (GMT, C);
168171
}
169172

170-
static int usage (struct GMTAPI_CTRL *API, int level) {
173+
static int usage(struct GMTAPI_CTRL *API, int level) {
171174
/* This displays the psscale synopsis and optionally full usage information */
172175

173176
const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE);
174177
if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR);
175178
GMT_Usage (API, 0, "usage: %s [%s] [-C<cpt>] [-D%s[+w<length>[/<width>]][+e[b|f][<length>]][+h|v][+j<justify>][+ma|c|l|u][+n|N[<txt>]]%s[+r]] "
176-
"[-F%s] [-G<zlo>/<zhi>] [-I[<max_intens>|<low_i>/<high_i>]] [%s] %s[-L[i|I][<gap>]] [-M] [-N[p|<dpi>]] %s%s[-Q] [%s] "
179+
"[-F%s] [-G<zlo>/<zhi>] [-H] [-I[<max_intens>|<low_i>/<high_i>]] [%s] %s[-L[i|I][<gap>]] [-M] [-N[p|<dpi>]] %s%s[-Q] [%s] "
177180
"[-S[+a<angle>][+c|n][+r][+s][+x<label>][+y<unit>]] [%s] [%s] [-W<scale>] [%s] [%s] [-Z<widthfile>] %s[%s] [%s] [%s]\n",
178181
name, GMT_B_OPT, GMT_XYANCHOR, GMT_OFFSET, GMT_PANEL, GMT_J_OPT, API->K_OPT, API->O_OPT, API->P_OPT, GMT_Rgeoz_OPT,
179182
GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, API->c_OPT, GMT_p_OPT, GMT_t_OPT, GMT_PAR_OPT);
@@ -210,6 +213,8 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
210213
GMT_Usage (API, 1, "\n-G<zlo>/<zhi>");
211214
GMT_Usage (API, -2, "Truncate incoming CPT to be limited to the z-range <zlo>/<zhi>. "
212215
"To accept one of the incoming limits, set that limit to NaN.");
216+
GMT_Usage (API, 1, "\n-H");
217+
GMT_Usage (API, -2, "From GMT 6.5 on, colorbar annotation fonts are auto-scaled. Use this option to prevent that and let user set them as they wish.");
213218
GMT_Usage (API, 1, "\n-I[<max_intens>|<low_i>/<high_i>]");
214219
GMT_Usage (API, -2, "Add illumination for +-<max_intens> or <low_i> to <high_i> [-1.0/1.0]. "
215220
"Alternatively, specify <lower>/<upper> intensity values.");
@@ -366,6 +371,9 @@ static int parse (struct GMT_CTRL *GMT, struct PSSCALE_CTRL *Ctrl, struct GMT_OP
366371
if (!(txt_b[0] == 'N' || txt_b[0] == 'n') || !strcmp (txt_b, "-")) Ctrl->G.z_high = atof (txt_b);
367372
n_errors += gmt_M_check_condition (GMT, gmt_M_is_dnan (Ctrl->G.z_low) && gmt_M_is_dnan (Ctrl->G.z_high), "Option -G: Both of zlo/zhi cannot be NaN\n");
368373
break;
374+
case 'H':
375+
n_errors += gmt_M_repeated_module_option (API, Ctrl->H.active);
376+
break;
369377
case 'I':
370378
n_errors += gmt_M_repeated_module_option (API, Ctrl->I.active);
371379
if (opt->arg[0]) {
@@ -993,20 +1001,27 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
9931001
}
9941002

9951003
/* Scale parameters to sqrt of the ratio of color bar length to default map dimension of 15 cm */
996-
scale_down = sqrt (MAX (fabs (Ctrl->D.R.dim[GMT_X]), fabs (Ctrl->D.R.dim[GMT_Y])) / (15.0 / 2.54));
997-
GMT->current.setting.font_annot[GMT_PRIMARY].size *= scale_down;
998-
GMT->current.setting.font_annot[GMT_SECONDARY].size *= scale_down;
999-
GMT->current.setting.font_label.size *= scale_down;
1000-
GMT->current.setting.map_frame_pen.width *= scale_down;
1001-
GMT->current.setting.map_tick_pen[GMT_PRIMARY].width *= scale_down;
1002-
GMT->current.setting.map_tick_pen[GMT_SECONDARY].width *= scale_down;
1003-
GMT->current.setting.map_tick_length[GMT_ANNOT_UPPER] *= scale_down;
1004-
GMT->current.setting.map_tick_length[GMT_TICK_UPPER] *= scale_down;
1005-
GMT->current.setting.map_annot_offset[GMT_PRIMARY] *= scale_down;
1006-
GMT->current.setting.map_annot_offset[GMT_SECONDARY] *= scale_down;
1007-
GMT->current.setting.map_label_offset[GMT_X] *= scale_down;
1008-
GMT->current.setting.map_label_offset[GMT_Y] *= scale_down;
1009-
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Color bar parameters scaled by %lg\n", scale_down);
1004+
1005+
/* The condition bellow should be changed to "if (Ctrl->H.active && strcmp(GMT->current.setting.theme, "classic"))"
1006+
because auto-scaling is not part of classic mode. But that would break not only compat with 6.5-6.6
1007+
but also a ton of CI tests, so I'm leaving this just as a comment so far.
1008+
*/
1009+
if (!Ctrl->H.active) { /* Do auto-scaling */
1010+
scale_down = sqrt(MAX(fabs(Ctrl->D.R.dim[GMT_X]), fabs(Ctrl->D.R.dim[GMT_Y])) / (15.0 / 2.54));
1011+
GMT->current.setting.font_annot[GMT_PRIMARY].size *= scale_down;
1012+
GMT->current.setting.font_annot[GMT_SECONDARY].size *= scale_down;
1013+
GMT->current.setting.font_label.size *= scale_down;
1014+
GMT->current.setting.map_frame_pen.width *= scale_down;
1015+
GMT->current.setting.map_tick_pen[GMT_PRIMARY].width *= scale_down;
1016+
GMT->current.setting.map_tick_pen[GMT_SECONDARY].width *= scale_down;
1017+
GMT->current.setting.map_tick_length[GMT_ANNOT_UPPER] *= scale_down;
1018+
GMT->current.setting.map_tick_length[GMT_TICK_UPPER] *= scale_down;
1019+
GMT->current.setting.map_annot_offset[GMT_PRIMARY] *= scale_down;
1020+
GMT->current.setting.map_annot_offset[GMT_SECONDARY] *= scale_down;
1021+
GMT->current.setting.map_label_offset[GMT_X] *= scale_down;
1022+
GMT->current.setting.map_label_offset[GMT_Y] *= scale_down;
1023+
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Color bar parameters scaled by %lg\n", scale_down);
1024+
}
10101025
/* Defeat the auto-repeat of axis info */
10111026
if (!strcmp (GMT->current.map.frame.axis[GMT_X].label, GMT->current.map.frame.axis[GMT_Y].label)) GMT->current.map.frame.axis[GMT_Y].label[0] = 0;
10121027

0 commit comments

Comments
 (0)