|
7 | 7 |
|
8 | 8 | from packaging.version import Version
|
9 | 9 | from pygmt._typing import AnchorCode
|
| 10 | +from pygmt.alias import Alias, AliasSystem |
10 | 11 | from pygmt.clib import Session, __gmt_version__
|
11 |
| -from pygmt.helpers import build_arg_list, kwargs_to_strings |
| 12 | +from pygmt.helpers import build_arg_list |
12 | 13 |
|
13 | 14 | __doctest_skip__ = ["timestamp"]
|
14 | 15 |
|
15 | 16 |
|
16 |
| -@kwargs_to_strings(offset="sequence") |
17 | 17 | def timestamp(
|
18 | 18 | self,
|
19 | 19 | text: str | None = None,
|
@@ -78,39 +78,42 @@ def timestamp(
|
78 | 78 | """
|
79 | 79 | self._activate_figure()
|
80 | 80 |
|
81 |
| - # Build the options passed to the "plot" module |
82 |
| - kwdict: dict = {"T": True, "U": ""} |
83 |
| - if label is not None: |
84 |
| - kwdict["U"] += f"{label}" |
85 |
| - kwdict["U"] += f"+j{justify}" |
| 81 | + if text is not None and len(str(text)) > 64: |
| 82 | + msg = ( |
| 83 | + "Parameter 'text' expects a string no longer than 64 characters. " |
| 84 | + "The given text string will be truncated to 64 characters." |
| 85 | + ) |
| 86 | + warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) |
| 87 | + text = str(text)[:64] |
86 | 88 |
|
87 |
| - # TODO(GMT>=6.5.0): Remove the patch for upstream bug fixed in GMT 6.5.0. |
88 |
| - if Version(__gmt_version__) < Version("6.5.0") and "/" not in str(offset): |
89 |
| - # Giving a single offset doesn't work in GMT < 6.5.0. |
90 |
| - # See https://github.com/GenericMappingTools/gmt/issues/7107. |
91 |
| - offset = f"{offset}/{offset}" |
92 |
| - kwdict["U"] += f"+o{offset}" |
| 89 | + # TODO(GMT>=6.5.0): Remove the patch for upstream "offset" bug fixed in GMT 6.5.0. |
| 90 | + # TODO(GMT>=6.5.0): Remove the workaround for the '+t' modifier added in GMT 6.5.0. |
| 91 | + # Related issues: |
| 92 | + # - https://github.com/GenericMappingTools/gmt/issues/7107 |
| 93 | + # - https://github.com/GenericMappingTools/gmt/pull/7127 |
| 94 | + if Version(__gmt_version__) < Version("6.5.0"): |
| 95 | + if "/" not in str(offset): # Giving a single offset doesn't work in GMT<6.5.0 |
| 96 | + offset = f"{offset}/{offset}" |
| 97 | + if text is not None: |
| 98 | + # Workaround for GMT<6.5.0 by overriding the 'timefmt' parameter and |
| 99 | + # unsetting 'text'. |
| 100 | + timefmt = str(text) |
| 101 | + text = None |
93 | 102 |
|
94 |
| - # The +t modifier was added in GMT 6.5.0. |
95 |
| - # See https://github.com/GenericMappingTools/gmt/pull/7127. |
96 |
| - if text is not None: |
97 |
| - if len(str(text)) > 64: |
98 |
| - msg = ( |
99 |
| - "Argument of 'text' must be no longer than 64 characters. " |
100 |
| - "The given text string will be truncated to 64 characters." |
101 |
| - ) |
102 |
| - warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) |
103 |
| - # TODO(GMT>=6.5.0): Remove the workaround for the new '+t' modifier. |
104 |
| - if Version(__gmt_version__) < Version("6.5.0"): |
105 |
| - # Workaround for GMT<6.5.0 by overriding the 'timefmt' parameter |
106 |
| - timefmt = text[:64] |
107 |
| - else: |
108 |
| - kwdict["U"] += f"+t{text}" |
| 103 | + aliasdict = AliasSystem( |
| 104 | + U=[ |
| 105 | + Alias(label, name="label"), |
| 106 | + Alias(justify, name="justify", prefix="+j"), |
| 107 | + Alias(offset, name="offset", prefix="+o", sep="/", size=2), |
| 108 | + Alias(text, name="text", prefix="+t"), |
| 109 | + ] |
| 110 | + ) |
| 111 | + aliasdict["T"] = "" # Add '-T' to the "plot" module. |
109 | 112 |
|
110 | 113 | with Session() as lib:
|
111 | 114 | lib.call_module(
|
112 | 115 | module="plot",
|
113 | 116 | args=build_arg_list(
|
114 |
| - kwdict, confdict={"FONT_LOGO": font, "FORMAT_TIME_STAMP": timefmt} |
| 117 | + aliasdict, confdict={"FONT_LOGO": font, "FORMAT_TIME_STAMP": timefmt} |
115 | 118 | ),
|
116 | 119 | )
|
0 commit comments