|
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,41 @@ 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 | + "Argument of 'text' must be 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, text = str(text), None |
93 | 101 |
|
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}" |
| 102 | + aliasdict = AliasSystem( |
| 103 | + U=[ |
| 104 | + Alias(label, name="label"), |
| 105 | + Alias(justify, name="justify", prefix="+j"), |
| 106 | + Alias(offset, name="offset", prefix="+o", separator="/"), |
| 107 | + Alias(text, name="text", prefix="+t"), |
| 108 | + ] |
| 109 | + ) |
| 110 | + aliasdict["T"] = True # Add '-T' to the "plot" module. |
109 | 111 |
|
110 | 112 | with Session() as lib: |
111 | 113 | lib.call_module( |
112 | 114 | module="plot", |
113 | 115 | args=build_arg_list( |
114 | | - kwdict, confdict={"FONT_LOGO": font, "FORMAT_TIME_STAMP": timefmt} |
| 116 | + aliasdict, confdict={"FONT_LOGO": font, "FORMAT_TIME_STAMP": timefmt} |
115 | 117 | ), |
116 | 118 | ) |
0 commit comments