Skip to content

Commit 1f81ec3

Browse files
committed
Updates
1 parent 63c441d commit 1f81ec3

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

doc/api/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ Miscellaneous
206206
print_clib_info
207207
show_versions
208208

209+
Common Parameters
210+
-----------------
211+
212+
.. autosummary::
213+
:toctree: generated
214+
215+
params.Box
216+
217+
209218
.. currentmodule:: pygmt
210219

211220
Datasets

pygmt/params/base.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
General class for PyGMT parameters.
3+
"""
14
from __future__ import annotations
25

36
from typing import NamedTuple
@@ -6,23 +9,29 @@
69

710

811
class Alias(NamedTuple):
12+
"""
13+
Alias PyGMT long-form parameter to GMT single-letter option flag.
14+
"""
15+
916
name: str
1017
modifier: str
1118
separator: str | None = None
1219

1320

1421
class BaseParams:
1522
"""
23+
Base class for PyGMT parameters.
24+
1625
Examples
1726
--------
1827
>>> import dataclasses
1928
>>> from pygmt.params.base import BaseParams
2029
>>>
2130
>>> @dataclasses.dataclass(repr=False)
2231
... class Test(BaseParams):
23-
... attr1 : Any = None
24-
... attr2 : Any = None
25-
... attr3 : Any = None
32+
... attr1: Any = None
33+
... attr2: Any = None
34+
... attr3: Any = None
2635
...
2736
... __aliases__ = [
2837
... Alias("attr1", ""),
@@ -35,20 +44,27 @@ class BaseParams:
3544
>>> repr(var)
3645
"Test(attr1='val1')"
3746
"""
47+
3848
def __str__(self):
49+
"""
50+
String representation of the object that can be passed to GMT directly.
51+
"""
3952
values = []
4053
for alias in self.__aliases__:
4154
value = getattr(self, alias.name)
4255
if value in (None, False):
4356
continue
44-
if value is True:
57+
elif value is True:
4558
value = ""
46-
if is_nonstr_iter(value):
59+
elif is_nonstr_iter(value):
4760
value = alias.separator.join(map(str, value))
4861
values.append(f"{alias.modifier}{value}")
4962
return "".join(values)
5063

5164
def __repr__(self):
65+
"""
66+
String representation of the object.
67+
"""
5268
string = []
5369
for alias in self.__aliases__:
5470
value = getattr(self, alias.name)

pygmt/params/box.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@
1111

1212
@dataclass(repr=False)
1313
class Box(BaseParams):
14+
"""
15+
Class for the box around GMT embellishments.
16+
17+
Attributes
18+
----------
19+
clearance
20+
Set clearances between the embellishment and the box border. Can be either a
21+
scalar value or a list of two/four values.
22+
23+
- a scalar value means a uniform clearance in all four directions.
24+
- a list of two values means separate clearances in x- and y- directions.
25+
- a list of four values means separate clearances for left/right/bottom/top.
26+
fill
27+
Fill for the box. None means no fill.
28+
29+
"""
30+
1431
clearance: float | str | Sequence[float | str] | None = None
1532
fill: str | None = None
1633
innerborder: str | Sequence | None = None

0 commit comments

Comments
 (0)