Skip to content

Commit

Permalink
Fix incorrect font for colorbar unit (#6802)
Browse files Browse the repository at this point in the history
* Fix incorrect font for colorbar unit

The label on the color bar for units was set using annotation font and offset instead of the correct label font and offset.

* Update psscale.c

* Go with the secondary bug solution

* Update the documentation on fonts

* Update psscale.c

* Update psscale.c

* Update dvc files for 100 plots
  • Loading branch information
PaulWessel authored Aug 31, 2023
1 parent a62edea commit 3f4d3b1
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 70 deletions.
4 changes: 2 additions & 2 deletions doc/examples/images.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 2ca2a3c0dadaedcec22e8acfa42dd4b1.dir
size: 35068033
- md5: 27ac0ad4e1c96b09b75e3f2d5270afca.dir
size: 35068257
nfiles: 53
path: images
9 changes: 5 additions & 4 deletions doc/rst/source/colorbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ colors) we will interpolate to give a continuous scale.
Variations in intensity due to shading/illumination may be displayed by
setting the option |-I|. Colors may be spaced according to a linear
scale, all be equal size, or by providing a file with individual tile
widths. The font used for the annotations along the scale and optional
units is specified by :term:`FONT_ANNOT_PRIMARY`.
If a label is requested, it is plotted with :term:`FONT_LABEL`. For
a full overview of CPTs, see the Cookbook section on :ref:`Color palette tables <CPT_section>`.
widths. The font used for the annotations along the scale is specified by
:term:`FONT_ANNOT_PRIMARY` while any unit placed at the side of the
bar is controlled by :term:`FONT_ANNOT_SECONDARY`. If a label along the bar
is requested, it is plotted with :term:`FONT_LABEL`. For a full overview of CPTs,
see the Cookbook section on :ref:`Color palette tables <CPT_section>`.

.. figure:: /_images/GMT_colorbar.*
:width: 500 px
Expand Down
4 changes: 2 additions & 2 deletions doc/scripts/images.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: eb4bf0527b136598cb135aed6e0a9136.dir
size: 33330006
- md5: e026fa468e0ece337e57095ec2ed1808.dir
size: 33329636
nfiles: 201
path: images
37 changes: 26 additions & 11 deletions src/psscale.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
double hor_annot_width, annot_off, label_off = 0.0, len, len2, size, x0, x1, dx, xx, dir, y_base, y_annot, y_label, xd = 0.0, yd = 0.0, xt = 0.0;
double z = 0.0, xleft, xright, inc_i, inc_j, start_val, stop_val, nan_off = 0.0, rgb[4], rrggbb[4], prev_del_z, this_del_z = 0.0, yt = 0.0;
double length = Ctrl->D.dim[GMT_X], width = Ctrl->D.dim[GMT_Y], gap = Ctrl->L.spacing, t_len, max_intens[2], xp[4], yp[4];
double *xpos = NULL, elength[2] = {0.0, 0.0}, t_angle, transp[2] = {0.0, 0.0};
double *xpos = NULL, elength[2] = {0.0, 0.0}, t_angle, transp[2] = {0.0, 0.0}, scale_down = 1.0;
struct GMT_FILL *f = NULL;
struct GMT_PLOT_AXIS *A = NULL;
struct GMT_MAP_PANEL *panel = Ctrl->F.panel; /* Shorthand */
Expand Down Expand Up @@ -1002,6 +1002,21 @@ 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 (Ctrl->D.dim[GMT_X], Ctrl->D.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;
fprintf (stderr, "scale-down = %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 Expand Up @@ -1054,8 +1069,8 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
/* u_off is width of the label placed on the right side , while v_off, if > 0, is the extra height of the label beyond the width of the bar */
size_t ylen = strlen (unit);
if (strchr (unit, '\\')) ylen = (ylen > 3) ? ylen - 3 : 0;
u_off = MAX (0.0, GMT->current.setting.map_annot_offset[GMT_PRIMARY]) + (0.5+ylen) * GMT_LET_WIDTH * GMT->current.setting.font_annot[GMT_PRIMARY].size / PSL_POINTS_PER_INCH;
v_off = 0.5 * (GMT_LET_HEIGHT * GMT->current.setting.font_annot[GMT_PRIMARY].size / PSL_POINTS_PER_INCH - width);
u_off = MAX (0.0, GMT->current.setting.map_annot_offset[GMT_SECONDARY]) + (0.5+ylen) * GMT_LET_WIDTH * GMT->current.setting.font_annot[GMT_SECONDARY].size / PSL_POINTS_PER_INCH;
v_off = 0.5 * (GMT_LET_HEIGHT * GMT->current.setting.font_annot[GMT_SECONDARY].size / PSL_POINTS_PER_INCH - width);
}
/* Adjust clearances for the panel */
if (flip & PSSCALE_FLIP_ANNOT) dim[YHI] += annot_off + v_sup_adjust; else dim[YLO] += annot_off + v_sup_adjust;
Expand Down Expand Up @@ -1101,8 +1116,8 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
/* u_off is ~half-width of the label placed on top of the vertical bar, while v_off is the extra height needed to accommodate the label */
size_t ylen = strlen (unit);
if (strchr (unit, '\\')) ylen = (ylen > 3) ? ylen - 3 : 0;
u_off = 0.5 * MAX (0.0, 1.3*ylen * GMT_LET_WIDTH * GMT->current.setting.font_annot[GMT_PRIMARY].size / PSL_POINTS_PER_INCH - width);
v_off = MAX (0.0, GMT->current.setting.map_annot_offset[GMT_PRIMARY]) + GMT->current.setting.font_annot[GMT_PRIMARY].size * GMT_LET_HEIGHT / PSL_POINTS_PER_INCH;
u_off = 0.5 * MAX (0.0, 1.3*ylen * GMT_LET_WIDTH * GMT->current.setting.font_annot[GMT_SECONDARY].size / PSL_POINTS_PER_INCH - width);
v_off = MAX (0.0, GMT->current.setting.map_annot_offset[GMT_SECONDARY]) + GMT->current.setting.font_annot[GMT_SECONDARY].size * GMT_LET_HEIGHT / PSL_POINTS_PER_INCH;
}
/* Adjust clearances for the panel */
if (flip & PSSCALE_FLIP_LABEL) dim[XLO] += label_off; else dim[XHI] += label_off;
Expand Down Expand Up @@ -1460,11 +1475,11 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
gmt_map_text (GMT, xleft + 0.5 * length, y_label, &GMT->current.setting.font_label, label, 0.0, Label_justify, form);
}
if (unit[0]) { /* Add unit label */
form = gmt_setfont (GMT, &GMT->current.setting.font_annot[GMT_PRIMARY]);
form = gmt_setfont (GMT, &GMT->current.setting.font_annot[GMT_SECONDARY]);
if (flip & PSSCALE_FLIP_UNIT) /* The y-label is on the left */
gmt_map_text (GMT, xleft - elength[XLO] - GMT->current.setting.map_annot_offset[GMT_PRIMARY], 0.5 * width, &GMT->current.setting.font_annot[GMT_PRIMARY], unit, 0.0, PSL_MR, form);
gmt_map_text (GMT, xleft - elength[XLO] - GMT->current.setting.map_annot_offset[GMT_SECONDARY], 0.5 * width, &GMT->current.setting.font_annot[GMT_SECONDARY], unit, 0.0, PSL_MR, form);
else
gmt_map_text (GMT, xright + elength[XHI] + GMT->current.setting.map_annot_offset[GMT_PRIMARY], 0.5 * width, &GMT->current.setting.font_annot[GMT_PRIMARY], unit, 0.0, PSL_ML, form);
gmt_map_text (GMT, xright + elength[XHI] + GMT->current.setting.map_annot_offset[GMT_SECONDARY], 0.5 * width, &GMT->current.setting.font_annot[GMT_SECONDARY], unit, 0.0, PSL_ML, form);
}
if (P->is_wrapping) { /* Add cyclic glyph */
if ((flip & PSSCALE_FLIP_UNIT) || unit[0] == 0) /* The y-label is on the left or not used so place cyclic glyph on right */
Expand Down Expand Up @@ -1827,11 +1842,11 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
}
}
if (unit[0]) { /* Add unit label */
form = gmt_setfont (GMT, &GMT->current.setting.font_annot[GMT_PRIMARY]);
form = gmt_setfont (GMT, &GMT->current.setting.font_annot[GMT_SECONDARY]);
if (flip & PSSCALE_FLIP_UNIT) /* The y-label is on the bottom */
gmt_map_text (GMT, xleft - GMT->current.setting.map_annot_offset[GMT_PRIMARY] - elength[XLO], 0.5 * width, &GMT->current.setting.font_annot[GMT_PRIMARY], unit, -90.0, PSL_TC, form);
gmt_map_text (GMT, xleft - GMT->current.setting.map_annot_offset[GMT_SECONDARY] - elength[XLO], 0.5 * width, &GMT->current.setting.font_annot[GMT_SECONDARY], unit, -90.0, PSL_TC, form);
else
gmt_map_text (GMT, xright + GMT->current.setting.map_annot_offset[GMT_PRIMARY] + elength[XHI], 0.5 * width, &GMT->current.setting.font_annot[GMT_PRIMARY], unit, -90.0, PSL_BC, form);
gmt_map_text (GMT, xright + GMT->current.setting.map_annot_offset[GMT_SECONDARY] + elength[XHI], 0.5 * width, &GMT->current.setting.font_annot[GMT_SECONDARY], unit, -90.0, PSL_BC, form);
}
if (P->is_wrapping) { /* Add cyclic glyph */
if ((flip & PSSCALE_FLIP_UNIT) || unit[0] == 0) /* The y-label is on the left or not used so place cyclic glyph on right */
Expand Down
4 changes: 2 additions & 2 deletions test/baseline/gmtbinstats.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 1c899bb3e42b303b91e36e4e3ba30c1e.dir
size: 758018
- md5: 3ea60b751e1a8110481f4042eac66472.dir
size: 759294
nfiles: 6
path: gmtbinstats
4 changes: 2 additions & 2 deletions test/baseline/grd2cpt.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 5f70222e0eccd0a8459ed5c79f5c7a07.dir
size: 332452
- md5: 217b3e643454f57e7bf483778758d35b.dir
size: 332316
nfiles: 2
path: grd2cpt
4 changes: 2 additions & 2 deletions test/baseline/grdblend.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 6529309a01695a8f83654062b833a383.dir
size: 316937
- md5: 45920baa4aca533105ba984d12245bb5.dir
size: 319127
nfiles: 8
path: grdblend
4 changes: 2 additions & 2 deletions test/baseline/grdclip.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: bb64bad008eb2d6c5674f47429e04dab.dir
size: 125942
- md5: 6e356ee3c759840deb7faf5d5c6df9c1.dir
size: 127366
nfiles: 1
path: grdclip
4 changes: 2 additions & 2 deletions test/baseline/grdcut.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 87b10bd2cf8cde622a46dca56307552b.dir
size: 561267
- md5: 9b894ca37d8aebb68012a7076f065cae.dir
size: 566243
nfiles: 5
path: grdcut
4 changes: 2 additions & 2 deletions test/baseline/grdedit.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: f2efeaf06b7c4632d8b9a5954378d365.dir
size: 466057
- md5: 0bed2477a1519da7cb0551a216bbc1d3.dir
size: 467294
nfiles: 3
path: grdedit
4 changes: 2 additions & 2 deletions test/baseline/grdfft.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: b948b8870df5f76c1a408827756fb9de.dir
size: 1281033
- md5: fa09d2798cb6c76a596be81bd3ddb7cc.dir
size: 1286655
nfiles: 7
path: grdfft
4 changes: 2 additions & 2 deletions test/baseline/grdfill.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: de633d11cdb21dbc1f683ffb854beb82.dir
size: 207682
- md5: e93fcb9574c5a90cfb4766435fb3f843.dir
size: 207664
nfiles: 5
path: grdfill
4 changes: 2 additions & 2 deletions test/baseline/grdfilter.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 4290a54b576aaa2c7a82b8f3b4e104fe.dir
size: 4163136
- md5: 0ba7abf18b8e5c176f5dd00400258050.dir
size: 4164823
nfiles: 6
path: grdfilter
4 changes: 2 additions & 2 deletions test/baseline/grdimage.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 660c048b84b959af239b74c69bf1a19a.dir
size: 8682493
- md5: 707d1f260c2f0d51f6a3671d747950e4.dir
size: 8665406
nfiles: 30
path: grdimage
4 changes: 2 additions & 2 deletions test/baseline/grdinterpolate.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: cf1696aa5fbea8eb926be144b334bcac.dir
size: 816505
- md5: 0322b5f03575de0e74c0c3561b4526e7.dir
size: 816472
nfiles: 6
path: grdinterpolate
4 changes: 2 additions & 2 deletions test/baseline/grdmask.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 2f7463f01e6e8fc125a3ec3f08b2b04a.dir
size: 284684
- md5: 2177ea81a6a735a299f38e647348b35c.dir
size: 274422
nfiles: 7
path: grdmask
4 changes: 2 additions & 2 deletions test/baseline/grdmath.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 391a7ce3c268c391b4805ef36430b086.dir
size: 1542005
- md5: 9c765011a0d41435a16922a2b4882de7.dir
size: 1542041
nfiles: 14
path: grdmath
4 changes: 2 additions & 2 deletions test/baseline/grdsample.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 9185a74ecf509563633e55261a093518.dir
size: 223957
- md5: c2e5e41409f36780c7e135027260c026.dir
size: 225182
nfiles: 4
path: grdsample
4 changes: 2 additions & 2 deletions test/baseline/grdview.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 7f3fbb24743938625ee3a9f254fdc857.dir
size: 6772357
- md5: a15b9b1652e49f1e0b7c9727d7c5a08d.dir
size: 6768275
nfiles: 11
path: grdview
2 changes: 1 addition & 1 deletion test/baseline/greenspline.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: f1509c2ff25cdb2b2fc09d836a3d1cf6.dir
- md5: 346061c5e8dc2a44a7fe74e6a827c4ea.dir
size: 1581934
nfiles: 8
path: greenspline
4 changes: 2 additions & 2 deletions test/baseline/makecpt.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: c4fab70f6692f7a08bc74e24ebe857dd.dir
size: 118641
- md5: 9917e66871e555f0f090780acd925896.dir
size: 123266
nfiles: 3
path: makecpt
4 changes: 2 additions & 2 deletions test/baseline/ogr.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 6964928abcec75b8cb805f8fd0ef8362.dir
size: 366042
- md5: 32c4b2ba21cb4229e89718235836d2ce.dir
size: 367284
nfiles: 3
path: ogr
4 changes: 2 additions & 2 deletions test/baseline/potential.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: f01f542a089a5978ea3fa0735f212098.dir
size: 2031912
- md5: be66debe6812a34966503fc050791b91.dir
size: 2032323
nfiles: 30
path: potential
4 changes: 2 additions & 2 deletions test/baseline/psbasemap.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: c6a5d32499e74d4a19c6978436f61e07.dir
size: 2901913
- md5: a3e3468d2d600a6b909d0f34a552e677.dir
size: 2903150
nfiles: 56
path: psbasemap
4 changes: 2 additions & 2 deletions test/baseline/pslegend.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 474181218768668c45b5e70c769c8927.dir
size: 882783
- md5: 8feb56c0d1861da696e181f9a1d32d1b.dir
size: 883406
nfiles: 20
path: pslegend
4 changes: 2 additions & 2 deletions test/baseline/psscale.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 6e0ca650ede513cd5f9082b611140a29.dir
size: 1379805
- md5: fb34c9c11ffbd59c3bb335ba51a43fa8.dir
size: 1406885
nfiles: 25
path: psscale
4 changes: 2 additions & 2 deletions test/baseline/psternary.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 6bbd7f1084d5757e528551a19cb8f448.dir
size: 131171
- md5: 5cfb1300b464b9bf2b24a64775dcb928.dir
size: 132430
nfiles: 3
path: psternary
4 changes: 2 additions & 2 deletions test/baseline/spotter.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 0b9aeea3a3620b88742e802ae2990225.dir
size: 6000729
- md5: 1d1c9d34b7681f256a68dc0c76e88abe.dir
size: 6000305
nfiles: 11
path: spotter
4 changes: 2 additions & 2 deletions test/baseline/trend2d.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 94c95069d9aa64fc7af1bf4f67da675a.dir
size: 112002
- md5: 0bb65c1c14b825e8c10172f34ac1d3db.dir
size: 115050
nfiles: 1
path: trend2d
4 changes: 2 additions & 2 deletions test/baseline/x2sys.dvc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 381e35149a4b3cba41c8e37b99e70ab0.dir
size: 3574061
- md5: d39be5a8e995afeeffbd11dd5a761abc.dir
size: 3562931
nfiles: 6
path: x2sys

0 comments on commit 3f4d3b1

Please sign in to comment.