Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8590b8d

Browse filesBrowse files
authored
add vertex, edge, and fill color properties (#664)
* add vertex, edge, and fill color properties * update api docs * lint * requested changes * add doc strings, fix linear selector
1 parent f7a9cca commit 8590b8d
Copy full SHA for 8590b8d

File tree

7 files changed

+131
-20
lines changed
Filter options

7 files changed

+131
-20
lines changed

‎docs/source/api/selectors/LinearRegionSelector.rst

Copy file name to clipboardExpand all lines: docs/source/api/selectors/LinearRegionSelector.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Properties
2424
LinearRegionSelector.axis
2525
LinearRegionSelector.block_events
2626
LinearRegionSelector.deleted
27+
LinearRegionSelector.edge_color
2728
LinearRegionSelector.event_handlers
29+
LinearRegionSelector.fill_color
2830
LinearRegionSelector.limits
2931
LinearRegionSelector.name
3032
LinearRegionSelector.offset
@@ -33,6 +35,7 @@ Properties
3335
LinearRegionSelector.rotation
3436
LinearRegionSelector.selection
3537
LinearRegionSelector.supported_events
38+
LinearRegionSelector.vertex_color
3639
LinearRegionSelector.visible
3740
LinearRegionSelector.world_object
3841

‎docs/source/api/selectors/LinearSelector.rst

Copy file name to clipboardExpand all lines: docs/source/api/selectors/LinearSelector.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Properties
2424
LinearSelector.axis
2525
LinearSelector.block_events
2626
LinearSelector.deleted
27+
LinearSelector.edge_color
2728
LinearSelector.event_handlers
29+
LinearSelector.fill_color
2830
LinearSelector.limits
2931
LinearSelector.name
3032
LinearSelector.offset
@@ -33,6 +35,7 @@ Properties
3335
LinearSelector.rotation
3436
LinearSelector.selection
3537
LinearSelector.supported_events
38+
LinearSelector.vertex_color
3639
LinearSelector.visible
3740
LinearSelector.world_object
3841

‎docs/source/api/selectors/RectangleSelector.rst

Copy file name to clipboardExpand all lines: docs/source/api/selectors/RectangleSelector.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Properties
2424
RectangleSelector.axis
2525
RectangleSelector.block_events
2626
RectangleSelector.deleted
27+
RectangleSelector.edge_color
2728
RectangleSelector.event_handlers
29+
RectangleSelector.fill_color
2830
RectangleSelector.limits
2931
RectangleSelector.name
3032
RectangleSelector.offset
@@ -33,6 +35,7 @@ Properties
3335
RectangleSelector.rotation
3436
RectangleSelector.selection
3537
RectangleSelector.supported_events
38+
RectangleSelector.vertex_color
3639
RectangleSelector.visible
3740
RectangleSelector.world_object
3841

‎fastplotlib/graphics/selectors/_base_selector.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/selectors/_base_selector.py
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from functools import partial
44

55
import numpy as np
6+
import pygfx
67

78
from pygfx import WorldObject, Line, Mesh, Points
89

@@ -40,6 +41,70 @@ class BaseSelector(Graphic):
4041
def axis(self) -> str:
4142
return self._axis
4243

44+
@property
45+
def fill_color(self) -> pygfx.Color:
46+
"""Returns the fill color of the selector, ``None`` if selector has no fill."""
47+
return self._fill_color
48+
49+
@fill_color.setter
50+
def fill_color(self, color: str | Sequence[float]):
51+
"""
52+
Set the fill color of the selector.
53+
54+
Parameters
55+
----------
56+
color : str | Sequence[float]
57+
String or sequence of floats that gets converted into a ``pygfx.Color`` object.
58+
"""
59+
color = pygfx.Color(color)
60+
for fill in self._fill:
61+
fill.material.color = color
62+
self._original_colors[fill] = color
63+
self._fill_color = color
64+
65+
@property
66+
def vertex_color(self) -> pygfx.Color:
67+
"""Returns the vertex color of the selector, ``None`` if selector has no vertices."""
68+
return self._vertex_color
69+
70+
@vertex_color.setter
71+
def vertex_color(self, color: str | Sequence[float]):
72+
"""
73+
Set the vertex color of the selector.
74+
75+
Parameters
76+
----------
77+
color : str | Sequence[float]
78+
String or sequence of floats that gets converted into a ``pygfx.Color`` object.
79+
"""
80+
color = pygfx.Color(color)
81+
for vertex in self._vertices:
82+
vertex.material.color = color
83+
vertex.material.edge_color = color
84+
self._original_colors[vertex] = color
85+
self._vertex_color = color
86+
87+
@property
88+
def edge_color(self) -> pygfx.Color:
89+
"""Returns the edge color of the selector"""
90+
return self._edge_color
91+
92+
@edge_color.setter
93+
def edge_color(self, color: str | Sequence[float]):
94+
"""
95+
Set the edge color of the selector.
96+
97+
Parameters
98+
----------
99+
color : str | Sequence[float]
100+
String or sequence of floats that gets converted into a ``pygfx.Color`` object.
101+
"""
102+
color = pygfx.Color(color)
103+
for edge in self._edges:
104+
edge.material.color = color
105+
self._original_colors[edge] = color
106+
self._edge_color = color
107+
43108
def __init__(
44109
self,
45110
edges: Tuple[Line, ...] = None,

‎fastplotlib/graphics/selectors/_linear.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/selectors/_linear.py
+27-3Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ def limits(self, values: tuple[float, float]):
4747
) # if values are close to zero things get weird so round them
4848
self.selection._limits = self._limits
4949

50+
@property
51+
def edge_color(self) -> pygfx.Color:
52+
"""Returns the color of the linear selector."""
53+
return self._edge_color
54+
55+
@edge_color.setter
56+
def edge_color(self, color: str | Sequence[float]):
57+
"""
58+
Set the color of the linear selector.
59+
60+
Parameters
61+
----------
62+
color : str | Sequence[float]
63+
String or sequence of floats that gets converted into a ``pygfx.Color`` object.
64+
"""
65+
color = pygfx.Color(color)
66+
# only want to change inner line color
67+
self._edges[0].material.color = color
68+
self._original_colors[self._edges[0]] = color
69+
self._edge_color = color
70+
5071
# TODO: make `selection` arg in graphics data space not world space
5172
def __init__(
5273
self,
@@ -56,7 +77,7 @@ def __init__(
5677
center: float,
5778
axis: str = "x",
5879
parent: Graphic = None,
59-
color: str | Sequence[float] | np.ndarray = "w",
80+
edge_color: str | Sequence[float] | np.ndarray = "w",
6081
thickness: float = 2.5,
6182
arrow_keys_modifier: str = "Shift",
6283
name: str = None,
@@ -92,13 +113,16 @@ def __init__(
92113
thickness: float, default 2.5
93114
thickness of the selector
94115
95-
color: str | tuple | np.ndarray, default "w"
116+
edge_color: str | tuple | np.ndarray, default "w"
96117
color of the selector
97118
98119
name: str, optional
99120
name of linear selector
100121
101122
"""
123+
self._fill_color = None
124+
self._edge_color = pygfx.Color(edge_color)
125+
self._vertex_color = None
102126

103127
if len(limits) != 2:
104128
raise ValueError("limits must be a tuple of 2 integers, i.e. (int, int)")
@@ -134,7 +158,7 @@ def __init__(
134158
line_inner = pygfx.Line(
135159
# self.data.feature_data because data is a Buffer
136160
geometry=pygfx.Geometry(positions=line_data),
137-
material=material(thickness=thickness, color=color, pick_write=True),
161+
material=material(thickness=thickness, color=edge_color, pick_write=True),
138162
)
139163

140164
self.line_outer = pygfx.Line(

‎fastplotlib/graphics/selectors/_linear_region.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/selectors/_linear_region.py
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def __init__(
114114
name of this selector graphic
115115
116116
"""
117+
self._edge_color = pygfx.Color(edge_color)
118+
self._fill_color = pygfx.Color(fill_color)
119+
self._vertex_color = None
117120

118121
# lots of very close to zero values etc. so round them, otherwise things get weird
119122
if not len(selection) == 2:
@@ -134,13 +137,17 @@ def __init__(
134137
if axis == "x":
135138
mesh = pygfx.Mesh(
136139
pygfx.box_geometry(1, size, 1),
137-
pygfx.MeshBasicMaterial(color=pygfx.Color(fill_color), pick_write=True),
140+
pygfx.MeshBasicMaterial(
141+
color=pygfx.Color(self.fill_color), pick_write=True
142+
),
138143
)
139144

140145
elif axis == "y":
141146
mesh = pygfx.Mesh(
142147
pygfx.box_geometry(size, 1, 1),
143-
pygfx.MeshBasicMaterial(color=pygfx.Color(fill_color), pick_write=True),
148+
pygfx.MeshBasicMaterial(
149+
color=pygfx.Color(self.fill_color), pick_write=True
150+
),
144151
)
145152
else:
146153
raise ValueError("`axis` must be one of 'x' or 'y'")
@@ -179,15 +186,15 @@ def __init__(
179186
positions=init_line_data.copy()
180187
), # copy so the line buffer is isolated
181188
pygfx.LineMaterial(
182-
thickness=edge_thickness, color=edge_color, pick_write=True
189+
thickness=edge_thickness, color=self.edge_color, pick_write=True
183190
),
184191
)
185192
line1 = pygfx.Line(
186193
pygfx.Geometry(
187194
positions=init_line_data.copy()
188195
), # copy so the line buffer is isolated
189196
pygfx.LineMaterial(
190-
thickness=edge_thickness, color=edge_color, pick_write=True
197+
thickness=edge_thickness, color=self.edge_color, pick_write=True
191198
),
192199
)
193200

‎fastplotlib/graphics/selectors/_rectangle.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/selectors/_rectangle.py
+19-13Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ def __init__(
117117

118118
xmin, xmax, ymin, ymax = selection
119119

120+
self._fill_color = pygfx.Color(fill_color)
121+
self._edge_color = pygfx.Color(edge_color)
122+
self._vertex_color = pygfx.Color(vertex_color)
123+
120124
width = xmax - xmin
121125
height = ymax - ymin
122126

@@ -125,7 +129,9 @@ def __init__(
125129

126130
self.fill = pygfx.Mesh(
127131
pygfx.box_geometry(width, height, 1),
128-
pygfx.MeshBasicMaterial(color=pygfx.Color(fill_color), pick_write=True),
132+
pygfx.MeshBasicMaterial(
133+
color=pygfx.Color(self.fill_color), pick_write=True
134+
),
129135
)
130136

131137
self.fill.world.position = (0, 0, -2)
@@ -142,7 +148,7 @@ def __init__(
142148

143149
left_line = pygfx.Line(
144150
pygfx.Geometry(positions=left_line_data.copy()),
145-
pygfx.LineMaterial(thickness=edge_thickness, color=edge_color),
151+
pygfx.LineMaterial(thickness=edge_thickness, color=self.edge_color),
146152
)
147153

148154
# position data for the right edge line
@@ -155,7 +161,7 @@ def __init__(
155161

156162
right_line = pygfx.Line(
157163
pygfx.Geometry(positions=right_line_data.copy()),
158-
pygfx.LineMaterial(thickness=edge_thickness, color=edge_color),
164+
pygfx.LineMaterial(thickness=edge_thickness, color=self.edge_color),
159165
)
160166

161167
# position data for the left edge line
@@ -168,7 +174,7 @@ def __init__(
168174

169175
bottom_line = pygfx.Line(
170176
pygfx.Geometry(positions=bottom_line_data.copy()),
171-
pygfx.LineMaterial(thickness=edge_thickness, color=edge_color),
177+
pygfx.LineMaterial(thickness=edge_thickness, color=self.edge_color),
172178
)
173179

174180
# position data for the right edge line
@@ -181,7 +187,7 @@ def __init__(
181187

182188
top_line = pygfx.Line(
183189
pygfx.Geometry(positions=top_line_data.copy()),
184-
pygfx.LineMaterial(thickness=edge_thickness, color=edge_color),
190+
pygfx.LineMaterial(thickness=edge_thickness, color=self.edge_color),
185191
)
186192

187193
self.edges: Tuple[pygfx.Line, pygfx.Line, pygfx.Line, pygfx.Line] = (
@@ -207,9 +213,9 @@ def __init__(
207213
pygfx.PointsMarkerMaterial(
208214
marker="square",
209215
size=vertex_thickness,
210-
color=vertex_color,
216+
color=self.vertex_color,
211217
size_mode="vertex",
212-
edge_color=vertex_color,
218+
edge_color=self.vertex_color,
213219
),
214220
)
215221

@@ -218,9 +224,9 @@ def __init__(
218224
pygfx.PointsMarkerMaterial(
219225
marker="square",
220226
size=vertex_thickness,
221-
color=vertex_color,
227+
color=self.vertex_color,
222228
size_mode="vertex",
223-
edge_color=vertex_color,
229+
edge_color=self.vertex_color,
224230
),
225231
)
226232

@@ -231,9 +237,9 @@ def __init__(
231237
pygfx.PointsMarkerMaterial(
232238
marker="square",
233239
size=vertex_thickness,
234-
color=vertex_color,
240+
color=self.vertex_color,
235241
size_mode="vertex",
236-
edge_color=vertex_color,
242+
edge_color=self.vertex_color,
237243
),
238244
)
239245

@@ -244,9 +250,9 @@ def __init__(
244250
pygfx.PointsMarkerMaterial(
245251
marker="square",
246252
size=vertex_thickness,
247-
color=vertex_color,
253+
color=self.vertex_color,
248254
size_mode="vertex",
249-
edge_color=vertex_color,
255+
edge_color=self.vertex_color,
250256
),
251257
)
252258

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.