Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions doc/rst/source/colorbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Synopsis
[ |-D|\ *refpoint* ]
[ |-F|\ *panel* ]
[ |-G|\ *zlo*\ /\ *zhi* ]
[ |-H| ]
[ |-I|\ [*max\_intens*\|\ *low_i*/*high_i*] ]
[ |-J|\ *parameters* ]
[ |-J|\ **z**\|\ **Z**\ *parameters* ]
Expand Down Expand Up @@ -54,8 +55,8 @@ widths. The font used for the annotations along the scale is specified by
bar is controlled by :term:`FONT_ANNOT_SECONDARY`. If a label along the bar is requested, it is plotted with
:term:`FONT_LABEL`. But mind you that the modern mode theme scales down the size of annotations and labels
based on the colorbar length for improved legibility. So, in modern mode scripts it might look that these
parameter settings are not working correctly. If you may want to increase font sizes to compensate the
scaling effect the solution is to use the online ``--FONT_ANNOT_PRIMARY=...`` construct.
parameter settings are not working correctly. If you want to have full control on font sizes and overcome
the auto-scaling, use option |-H|.
For a full overview of CPTs, see the Technical Reference section on :ref:`Color palette tables <CPT_section>`.

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

.. _-H:

**-H**
From GMT 6.5 on, colorbar annotation fonts are auto-scaled. Use this option to prevent that effect
and let user set fonts as they wish.

.. _-I:

**-I**\ [*max_intens*\|\ *low\_i*/*high_i*]
Expand Down
1 change: 1 addition & 0 deletions doc/rst/source/psscale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Synopsis
[ |-D|\ *refpoint* ]
[ |-F|\ *panel* ]
[ |-G|\ *zlo*\ /\ *zhi* ]
[ |-H| ]
[ |-I|\ [*max\_intens*\|\ *low_i*/*high_i*] ]
[ |-J|\ *parameters* ]
[ |-K| ]
Expand Down
47 changes: 31 additions & 16 deletions src/psscale.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ struct PSSCALE_CTRL {
bool active;
double z_low, z_high;
} G;
struct PSSCALE_H { /* -H */
bool active;
} H;
struct PSSCALE_I { /* -I[<intens>|<min_i>/<max_i>] */
bool active;
double min, max;
Expand Down Expand Up @@ -167,13 +170,13 @@ static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSSCALE_CTRL *C) { /* Deallo
gmt_M_free (GMT, C);
}

static int usage (struct GMTAPI_CTRL *API, int level) {
static int usage(struct GMTAPI_CTRL *API, int level) {
/* This displays the psscale synopsis and optionally full usage information */

const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE);
if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR);
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]] "
"[-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] "
"[-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] "
"[-S[+a<angle>][+c|n][+r][+s][+x<label>][+y<unit>]] [%s] [%s] [-W<scale>] [%s] [%s] [-Z<widthfile>] %s[%s] [%s] [%s]\n",
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,
GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, API->c_OPT, GMT_p_OPT, GMT_t_OPT, GMT_PAR_OPT);
Expand Down Expand Up @@ -210,6 +213,8 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
GMT_Usage (API, 1, "\n-G<zlo>/<zhi>");
GMT_Usage (API, -2, "Truncate incoming CPT to be limited to the z-range <zlo>/<zhi>. "
"To accept one of the incoming limits, set that limit to NaN.");
GMT_Usage (API, 1, "\n-H");
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.");
GMT_Usage (API, 1, "\n-I[<max_intens>|<low_i>/<high_i>]");
GMT_Usage (API, -2, "Add illumination for +-<max_intens> or <low_i> to <high_i> [-1.0/1.0]. "
"Alternatively, specify <lower>/<upper> intensity values.");
Expand Down Expand Up @@ -366,6 +371,9 @@ static int parse (struct GMT_CTRL *GMT, struct PSSCALE_CTRL *Ctrl, struct GMT_OP
if (!(txt_b[0] == 'N' || txt_b[0] == 'n') || !strcmp (txt_b, "-")) Ctrl->G.z_high = atof (txt_b);
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");
break;
case 'H':
n_errors += gmt_M_repeated_module_option (API, Ctrl->H.active);
break;
case 'I':
n_errors += gmt_M_repeated_module_option (API, Ctrl->I.active);
if (opt->arg[0]) {
Expand Down Expand Up @@ -993,20 +1001,27 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
}

/* Scale parameters to sqrt of the ratio of color bar length to default map dimension of 15 cm */
scale_down = sqrt (MAX (fabs (Ctrl->D.R.dim[GMT_X]), fabs (Ctrl->D.R.dim[GMT_Y])) / (15.0 / 2.54));
GMT->current.setting.font_annot[GMT_PRIMARY].size *= scale_down;
GMT->current.setting.font_annot[GMT_SECONDARY].size *= scale_down;
GMT->current.setting.font_label.size *= scale_down;
GMT->current.setting.map_frame_pen.width *= scale_down;
GMT->current.setting.map_tick_pen[GMT_PRIMARY].width *= scale_down;
GMT->current.setting.map_tick_pen[GMT_SECONDARY].width *= scale_down;
GMT->current.setting.map_tick_length[GMT_ANNOT_UPPER] *= scale_down;
GMT->current.setting.map_tick_length[GMT_TICK_UPPER] *= scale_down;
GMT->current.setting.map_annot_offset[GMT_PRIMARY] *= scale_down;
GMT->current.setting.map_annot_offset[GMT_SECONDARY] *= scale_down;
GMT->current.setting.map_label_offset[GMT_X] *= scale_down;
GMT->current.setting.map_label_offset[GMT_Y] *= scale_down;
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Color bar parameters scaled by %lg\n", scale_down);

/* The condition bellow should be changed to "if (Ctrl->H.active && strcmp(GMT->current.setting.theme, "classic"))"
because auto-scaling is not part of classic mode. But that would break not only compat with 6.5-6.6
but also a ton of CI tests, so I'm leaving this just as a comment so far.
*/
if (!Ctrl->H.active) { /* Do auto-scaling */
scale_down = sqrt(MAX(fabs(Ctrl->D.R.dim[GMT_X]), fabs(Ctrl->D.R.dim[GMT_Y])) / (15.0 / 2.54));
GMT->current.setting.font_annot[GMT_PRIMARY].size *= scale_down;
GMT->current.setting.font_annot[GMT_SECONDARY].size *= scale_down;
GMT->current.setting.font_label.size *= scale_down;
GMT->current.setting.map_frame_pen.width *= scale_down;
GMT->current.setting.map_tick_pen[GMT_PRIMARY].width *= scale_down;
GMT->current.setting.map_tick_pen[GMT_SECONDARY].width *= scale_down;
GMT->current.setting.map_tick_length[GMT_ANNOT_UPPER] *= scale_down;
GMT->current.setting.map_tick_length[GMT_TICK_UPPER] *= scale_down;
GMT->current.setting.map_annot_offset[GMT_PRIMARY] *= scale_down;
GMT->current.setting.map_annot_offset[GMT_SECONDARY] *= scale_down;
GMT->current.setting.map_label_offset[GMT_X] *= scale_down;
GMT->current.setting.map_label_offset[GMT_Y] *= scale_down;
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Color bar parameters scaled by %lg\n", scale_down);
}
/* Defeat the auto-repeat of axis info */
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;

Expand Down
Loading