Skip to content

Commit 8620c3f

Browse files
committed
Update wordspacing calculation to use the line height
1 parent 4c51b0c commit 8620c3f

10 files changed

Lines changed: 17 additions & 11 deletions

File tree

examples/.ipynb_checkpoints/3. Time Series-checkpoint.ipynb

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

examples/3. Time Series.ipynb

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.
1 KB
Loading
-1.55 KB
Loading

examples/exports/3-time-series.png

937 Bytes
Loading
0 Bytes
Binary file not shown.
2 Bytes
Binary file not shown.
200 Bytes
Binary file not shown.

multiplex/text/annotation.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, drawable):
5656
self.drawable = drawable
5757
self.lines = [ ]
5858

59-
def draw(self, annotation, x, y, wordspacing=0.005, lineheight=1.25,
59+
def draw(self, annotation, x, y, wordspacing=None, lineheight=1.25,
6060
align='left', va='top', pad=0, *args, **kwargs):
6161
"""
6262
Draw the text annotation visualization.
@@ -91,7 +91,8 @@ def draw(self, annotation, x, y, wordspacing=0.005, lineheight=1.25,
9191
:param y: The starting y-position of the annotation.
9292
:type y: float
9393
:param wordspacing: The space between words.
94-
:type wordspacing: float
94+
If `None` is given, the space is calculated based on the height of the line.
95+
:type wordspacing: float or None
9596
:param lineheight: The space between lines.
9697
:type lineheight: float
9798
:param align: The text's alignment.
@@ -267,7 +268,8 @@ def _draw_tokens(self, tokens, x, y, wordspacing, lineheight, align, va,
267268
:param y: The starting y-position of the annotation.
268269
:type y: float
269270
:param wordspacing: The space between words.
270-
:type wordspacing: float
271+
If `None` is given, the space is calculated based on the height of the line.
272+
:type wordspacing: float or None
271273
:param lineheight: The space between lines.
272274
:type lineheight: float
273275
:param align: The text's alignment.
@@ -300,6 +302,9 @@ def _draw_tokens(self, tokens, x, y, wordspacing, lineheight, align, va,
300302

301303
linespacing = util.get_linespacing(figure, axis, wordspacing, transform=transform, *args, **kwargs) * lineheight
302304

305+
if wordspacing is None:
306+
wordspacing = linespacing / 15.
307+
303308
"""
304309
Go through each token and draw it on the axis.
305310
"""

multiplex/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def get_linespacing(figure, axis, wordspacing=0, transform=None, *args, **kwargs
111111
The bbox's padding is calculated in pixels.
112112
Therefore it is transformed from the provided axis coordinates to pixels.
113113
"""
114+
wordspacing = wordspacing or 0
114115
wordspacing_px = (axis.transData.transform((wordspacing, 0))[0] -
115116
axis.transData.transform((0, 0))[0])
116117
token = axis.text(0, 0, 'None', bbox=dict(pad=wordspacing_px / 2., **bbox_kwargs),

0 commit comments

Comments
 (0)