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
5 changes: 4 additions & 1 deletion doc/rst/source/explain_-L_scale.rst_
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**-L**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ **+w**\ *length*\ [**e**\|\ **f**\|\ **k**\|\
**-L**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ [*refpoint*]\ **+w**\ *length*\ [**e**\|\ **f**\|\ **k**\|\
**M**\|\ **n**\|\ **u**]\ [**+a**\ *align*]\ [**+c**\ [[*slon*/]\ *slat*]]\ [**+f**]\ [**+j**\ *justify*]\ [**+l**\
[*label*]\ ]\ [**+o**\ *dx*\ [/*dy*]]\ [**+u**][**+v**]

Expand All @@ -8,6 +8,9 @@

.. include:: explain_refpoint.rst_

If *refpoint* is omitted, the map scale is placed by default in the lower-left corner of the map
(using **+jBL+o0.2c/0.4c**), nudged slightly inward so it does not sit flush against the map frame.

The following modifiers can be appended to |-L| (**+w** is required), with additional explanation and
examples provided in the :ref:`placing-map-scales` cookbook section. For Cartesian projection, the modifier
**+c** is not allowed and no units should be appended in **+w**.
Expand Down
1 change: 1 addition & 0 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -8925,6 +8925,7 @@ void gmt_mapscale_syntax (struct GMT_CTRL *GMT, char option, char *string) {
GMT_Usage (API, 1, "\n-%c%s", option, GMT_SCALE);
GMT_Usage (API, -2, "%s", string);
gmt_refpoint_syntax (GMT, "L", NULL, GMT_ANCHOR_MAPSCALE, 3);
GMT_Usage (API, -2, "If <refpoint> is omitted, the scale defaults to the bottom-left corner inside the map frame, nudged slightly inward (using +jBL+o0.2/0.4c).");
GMT_Usage (API, -2, "Set required scale via +w<length>, and (for geographic projection) append a unit from %s [km]. Other scale modifiers are optional:",
GMT_LEN_UNITS2_DISPLAY);
GMT_Usage (API, 3, "+a Append label alignment (choose among l(eft), r(ight), t(op), and b(ottom)) [t].");
Expand Down
20 changes: 18 additions & 2 deletions src/gmt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -14128,7 +14128,8 @@ int gmt_getinset (struct GMT_CTRL *GMT, char option, char *in_text, struct GMT_M

int gmt_getscale (struct GMT_CTRL *GMT, char option, char *text, struct GMT_MAP_SCALE *ms) {
/* This function parses the -L map scale syntax:
* -L[g|j|J|n|x]<refpoint>+c[/<slon>]/<slat>+w<length>[e|f|M|n|k|u][+a<align>][+f][+j<just>][+l<label>][+u]
* -L[g|j|J|n|x][<refpoint>]+c[/<slon>]/<slat>+w<length>[e|f|M|n|k|u][+a<align>][+f][+j<just>][+l<label>][+u]
* If <refpoint> (and its g|j|J|n|x code) is entirely omitted, we default to jBL+o0.2c/0.4c (Bottom-Left plus a small nudge)
* If the required +w is not present we call the backwards compatible parsert for the previous map scale syntax.
* An optional background panel is handled by a separate option (typically -F). */

Expand All @@ -14149,7 +14150,22 @@ int gmt_getscale (struct GMT_CTRL *GMT, char option, char *text, struct GMT_MAP_
ms->measure = 'k'; /* Default distance unit is km */
ms->alignment = (vertical) ? 'r' : 't'; /* Default label placement is on top for map scale and right for vertical scale */

if ((ms->refpoint = gmt_get_refpoint (GMT, text, option)) == NULL) {
/* Inject default reference point (jBL+o0.2c/0.4c) if omitted by user --- */
char refpoint_str[GMT_LEN256];
char *parse_text = text;
/* If the user omitted the reference point (e.g., -L+w100k), inject a default one (jBL = Bottom-Left inside), plus a small inward
* offset of 0.2 cm horizontally and 0.4 cm vertically (+o0.2c/0.4c) so the scale does not sit flush against the map frame.
* If the user already gave their own +o modifier, leave it untouched. */
if (text[0] == '+') {
char dummy[GMT_LEN256] = {""};
if (gmt_get_modifier (text, 'o', dummy)) /* User already specified +o<dx>/<dy>; do not override */
snprintf (refpoint_str, GMT_LEN256-1, "jBL%s", text);
else
snprintf (refpoint_str, GMT_LEN256-1, "jBL+o0.2c/0.4c%s", text);
parse_text = refpoint_str;
}

if ((ms->refpoint = gmt_get_refpoint (GMT, parse_text, option)) == NULL) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Scale reference point was not accepted\n", option);
gmt_refpoint_syntax (GMT, "L", NULL, GMT_ANCHOR_MAPSCALE, 3);
return (1); /* Failed basic parsing */
Expand Down
Loading