Skip to content

Commit 0ebbbfd

Browse files
committed
Set defaults in text
1 parent 51aa8cf commit 0ebbbfd

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

Diff for: data_prototype/text.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
import numpy as np
22

3+
from matplotlib.font_manager import FontProperties
34

45
from .artist import Artist
56
from .description import Desc
6-
from .conversion_edge import Graph, CoordinateEdge
7+
from .conversion_edge import Graph, CoordinateEdge, DefaultEdge
78

89

910
class Text(Artist):
1011
def __init__(self, container, edges=None, **kwargs):
1112
super().__init__(container, edges, **kwargs)
1213

14+
scalar = Desc((), "display")
15+
1316
edges = [
1417
CoordinateEdge.from_coords(
1518
"xycoords", {"x": Desc((), "auto"), "y": Desc((), "auto")}, "data"
1619
),
20+
CoordinateEdge.from_coords("text", {"text": Desc(())}, "display"),
21+
CoordinateEdge.from_coords("color", {"color": Desc(())}, "display"),
22+
CoordinateEdge.from_coords("alpha", {"alpha": Desc(())}, "display"),
23+
CoordinateEdge.from_coords(
24+
"fontproperties", {"fontproperties": Desc(())}, "display"
25+
),
26+
CoordinateEdge.from_coords("usetex", {"usetex": Desc(())}, "display"),
27+
CoordinateEdge.from_coords("rotation", {"rotation": Desc(())}, "display"),
28+
CoordinateEdge.from_coords(
29+
"antialiased", {"antialiased": Desc(())}, "display"
30+
),
31+
DefaultEdge.from_default_value("text_def", "text", scalar, ""),
32+
DefaultEdge.from_default_value("color_def", "color", scalar, "k"),
33+
DefaultEdge.from_default_value("alpha_def", "alpha", scalar, 1),
34+
DefaultEdge.from_default_value(
35+
"fontproperties_def", "fontproperties", scalar, FontProperties()
36+
),
37+
DefaultEdge.from_default_value("usetex_def", "usetex", scalar, False),
38+
DefaultEdge.from_default_value("rotation_def", "rotation", scalar, 0),
39+
DefaultEdge.from_default_value(
40+
"antialiased_def", "antialiased", scalar, False
41+
),
1742
]
1843

1944
self._graph = self._graph + Graph(edges)
@@ -28,7 +53,7 @@ def draw(self, renderer, graph: Graph) -> None:
2853
"x": Desc((), "display"),
2954
"y": Desc((), "display"),
3055
"text": Desc((), "display"),
31-
"color": Desc((4,), "rgba"),
56+
"color": Desc((), "display"),
3257
"alpha": Desc((), "display"),
3358
"fontproperties": Desc((), "display"),
3459
"usetex": Desc((), "display"),
@@ -53,6 +78,10 @@ def draw(self, renderer, graph: Graph) -> None:
5378
x = evald["x"]
5479
y = evald["y"]
5580

81+
_, canvash = renderer.get_canvas_width_height()
82+
if renderer.flipy():
83+
y = canvash - y
84+
5685
if not np.isfinite(x) or not np.isfinite(y):
5786
# TODO: log?
5887
return

Diff for: examples/animation.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import matplotlib.pyplot as plt
1818
from matplotlib.animation import FuncAnimation
19-
from matplotlib.font_manager import FontProperties
2019

2120
from data_prototype.conversion_edge import Graph
2221
from data_prototype.description import Desc
@@ -39,12 +38,6 @@ def describe(self):
3938
"y": Desc((self.N,)),
4039
"phase": Desc(()),
4140
"time": Desc(()),
42-
"rotation": Desc((), "display"),
43-
"alpha": Desc((), "display"),
44-
"color": Desc((4,), "rgba"),
45-
"usetex": Desc((), "display"),
46-
"antialiased": Desc((), "display"),
47-
"fontproperties": Desc((), "display"),
4841
}
4942

5043
def query(
@@ -62,12 +55,6 @@ def query(
6255
"y": np.sin(th + phase),
6356
"phase": phase,
6457
"time": cur_time,
65-
"rotation": 0,
66-
"alpha": 1,
67-
"color": np.array([0, 0, 0, 1]),
68-
"usetex": False,
69-
"antialiased": True,
70-
"fontproperties": FontProperties(),
7158
}, hash(cur_time)
7259

7360

@@ -88,7 +75,7 @@ def update(frame, art):
8875
),
8976
],
9077
x=2 * np.pi,
91-
y=0,
78+
y=1,
9279
ha="right",
9380
)
9481
fig, nax = plt.subplots()

Diff for: examples/mapped.py

-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numpy as np
1212

1313
from matplotlib.colors import Normalize
14-
from matplotlib.font_manager import FontProperties
1514

1615
from data_prototype.artist import CompatibilityAxes
1716
from data_prototype.line import Line
@@ -68,12 +67,6 @@
6867
{},
6968
{"x": Desc((), "data")},
7069
),
71-
FuncEdge.from_func(
72-
"color",
73-
lambda: (0, 0, 0, 1),
74-
{},
75-
{"color": Desc((4,), "rgba")},
76-
),
7770
]
7871

7972

@@ -108,11 +101,6 @@
108101
x=2 * np.pi,
109102
# ha="right",
110103
# bbox={"facecolor": "gray", "alpha": 0.5},
111-
antialiased=False,
112-
fontproperties=FontProperties(),
113-
rotation=0,
114-
alpha=1,
115-
usetex=False,
116104
)
117105
)
118106
ax.set_xlim(0, np.pi * 2)

0 commit comments

Comments
 (0)