-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_drawers.py
222 lines (179 loc) · 7.8 KB
/
basic_drawers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
from __future__ import annotations
from typing import TYPE_CHECKING, Any, ClassVar, Never
from basic_data import ColorData
from drawer import MPLDrawer
from tree import CBaseNode, CNormalNode, CRealNode, CZeroNode
if TYPE_CHECKING:
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from util import MPLColor, RealNumber
class ColorDrawer(MPLDrawer[Never]):
fig: Figure
ax: Axes
draw_zero: bool
radius: RealNumber
def choose_triangle_color(self, /, node: CRealNode[Never]) -> MPLColor:
raise NotImplementedError
def choose_negative_triangle_color(
self, /, node: CNormalNode[Never],
) -> MPLColor:
raise NotImplementedError
def choose_horizontal_arc_color(
self, /, node: CNormalNode[Never]
) -> MPLColor:
raise NotImplementedError
def choose_vertical_arc_color(
self, /, node: CNormalNode[Never]
) -> MPLColor:
raise NotImplementedError
def choose_base_left_arc_color(
self, /, node: CBaseNode[Never],
) -> MPLColor:
raise NotImplementedError
def choose_base_right_arc_color(
self, /, node: CBaseNode[Never],
) -> MPLColor:
raise NotImplementedError
def choose_segment_color(
self, /, node: CZeroNode[Never] | CBaseNode[Never],
) -> MPLColor:
raise NotImplementedError
def draw_triangle(self, /, node: CRealNode[Never]) -> None:
self.ax.fill(*node.shapes.triangle.draw_coords,
facecolor=self.choose_triangle_color(node))
def draw_negative_triangle(self, /, node: CNormalNode[Never]) -> None:
self.ax.fill(*node.shapes.negative_triangle.draw_coords,
facecolor=self.choose_negative_triangle_color(node))
def draw_horizontal_arc(self, /, node: CNormalNode[Never]) -> None:
self.ax.fill(*node.shapes.horizontal_arc.draw_coords,
facecolor=self.choose_horizontal_arc_color(node))
def draw_vertical_arc(self, /, node: CNormalNode[Never]) -> None:
self.ax.fill(*node.shapes.vertical_arc.draw_coords,
facecolor=self.choose_vertical_arc_color(node))
def draw_base_left_arc(self, /, node: CBaseNode[Never]) -> None:
self.ax.fill(*node.shapes.left_arc.draw_coords,
facecolor=self.choose_base_left_arc_color(node))
def draw_base_right_arc(self, /, node: CBaseNode[Never]) -> None:
self.ax.fill(*node.shapes.right_arc.draw_coords,
facecolor=self.choose_base_right_arc_color(node))
def draw_segment(
self, /, node: CBaseNode[Never] | CZeroNode[Never],
) -> None:
self.ax.fill(*node.shapes.segment.draw_coords,
facecolor=self.choose_segment_color(node))
class ColorDataDrawer(MPLDrawer[ColorData[Any]]):
fig: Figure
ax: Axes
draw_zero: bool
radius: RealNumber
triangle_data_index: ClassVar[int] = 0
negative_triangle_data_index: ClassVar[int] = 1
vertical_arc_data_index: ClassVar[int] = 1
horizontal_arc_data_index: ClassVar[int] = 1
base_left_arc_data_index: ClassVar[int] = 1
base_right_arc_data_index: ClassVar[int] = 1
segment_data_index: ClassVar[int] = 1
def draw_triangle(self, /, node: CRealNode[ColorData[Any]]) -> None:
index = self.triangle_data_index % len(node.data)
self.ax.fill(*node.shapes.triangle.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_negative_triangle(
self, /, node: CNormalNode[ColorData[Any]],
) -> None:
index = self.negative_triangle_data_index % len(node.data)
self.ax.fill(*node.shapes.negative_triangle.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_horizontal_arc(
self, /, node: CNormalNode[ColorData[Any]],
) -> None:
index = self.horizontal_arc_data_index % len(node.data)
self.ax.fill(*node.shapes.horizontal_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_vertical_arc(
self, /, node: CNormalNode[ColorData[Any]],
) -> None:
index = self.vertical_arc_data_index % len(node.data)
self.ax.fill(*node.shapes.vertical_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_base_left_arc(
self, /, node: CBaseNode[ColorData[Any]],
) -> None:
index = self.base_left_arc_data_index % len(node.data)
self.ax.fill(*node.shapes.left_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_base_right_arc(
self, /, node: CBaseNode[ColorData[Any]],
) -> None:
index = self.base_right_arc_data_index % len(node.data)
self.ax.fill(*node.shapes.right_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_segment(
self, /,
node: CBaseNode[ColorData[Any]] | CZeroNode[ColorData[Any]],
) -> None:
assert node.shapes.segment is not None
index = self.segment_data_index % len(node.data)
self.ax.fill(*node.shapes.segment.draw_coords,
facecolor=node.data[index].color.to_hex())
class AlternatingColorDataDrawer(MPLDrawer[ColorData[Any]]):
fig: Figure
ax: Axes
draw_zero: bool
radius: RealNumber
triangle_offset: ClassVar[int] = 0
negative_triangle_offset: ClassVar[int] = 1
vertical_arc_offset: ClassVar[int] = 1
horizontal_arc_offset: ClassVar[int] = 1
base_left_arc_offset: ClassVar[int] = 1
base_right_arc_offset: ClassVar[int] = 1
segment_offset: ClassVar[int] = 1
def draw_triangle(
self, /, node: CRealNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.triangle_offset
index %= len(node.data)
self.ax.fill(*node.shapes.triangle.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_negative_triangle(
self, /, node: CNormalNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.negative_triangle_offset
index %= len(node.data)
self.ax.fill(*node.shapes.negative_triangle.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_horizontal_arc(
self, /, node: CNormalNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.horizontal_arc_offset
index %= len(node.data)
self.ax.fill(*node.shapes.horizontal_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_vertical_arc(
self, /, node: CNormalNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.vertical_arc_offset
index %= len(node.data)
self.ax.fill(*node.shapes.vertical_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_base_left_arc(
self, /, node: CBaseNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.base_left_arc_offset
index %= len(node.data)
self.ax.fill(*node.shapes.left_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_base_right_arc(
self, /, node: CBaseNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.base_right_arc_offset
index %= len(node.data)
self.ax.fill(*node.shapes.right_arc.draw_coords,
facecolor=node.data[index].color.to_hex())
def draw_segment(
self, /,
node: CBaseNode[ColorData[Any]] | CZeroNode[ColorData[Any]],
) -> None:
index = sum(node.identifier.parts) + self.segment_offset
index %= len(node.data)
self.ax.fill(*node.shapes.segment.draw_coords,
facecolor=node.data[index].color.to_hex())