@@ -141,108 +141,6 @@ def yz(self) -> Grid:
141
141
return self ._yz
142
142
143
143
144
- class Ruler (pygfx .Ruler ):
145
- def __init__ (self , ** kwargs ):
146
- super ().__init__ (** kwargs )
147
- self .tick_text_mapper = None
148
- self .font_size = 14
149
-
150
- def _update_sub_objects (self , ticks , tick_auto_step ):
151
- """Update the sub-objects to show the given ticks."""
152
- assert isinstance (ticks , dict )
153
-
154
- tick_size = 5
155
- min_n_slots = 8 # todo: can be (much) higher when we use a single text object!
156
-
157
- # Load config
158
- start_pos = self ._start_pos
159
- end_pos = self ._end_pos
160
- start_value = self ._start_value
161
- end_value = self .end_value
162
-
163
- # Derive some more variables
164
- length = end_value - start_value
165
- vec = end_pos - start_pos
166
- if length :
167
- vec /= length
168
-
169
- # Get array to store positions
170
- n_slots = self .points .geometry .positions .nitems
171
- n_positions = len (ticks ) + 2
172
- if n_positions <= n_slots <= max (min_n_slots , 2 * n_positions ):
173
- # Re-use existing buffers
174
- positions = self .points .geometry .positions .data
175
- sizes = self .points .geometry .sizes .data
176
- self .points .geometry .positions .update_range ()
177
- self .points .geometry .sizes .update_range ()
178
- else :
179
- # Allocate new buffers
180
- new_n_slots = max (min_n_slots , int (n_positions * 1.2 ))
181
- positions = np .zeros ((new_n_slots , 3 ), np .float32 )
182
- sizes = np .zeros ((new_n_slots ,), np .float32 )
183
- self .points .geometry .positions = pygfx .Buffer (positions )
184
- self .points .geometry .sizes = pygfx .Buffer (sizes )
185
- # Allocate text objects
186
- while len (self ._text_object_pool ) < new_n_slots :
187
- ob = pygfx .Text (
188
- pygfx .TextGeometry ("" , screen_space = True , font_size = self .font_size ),
189
- pygfx .TextMaterial (aa = False ),
190
- )
191
- self ._text_object_pool .append (ob )
192
- self ._text_object_pool [new_n_slots :] = []
193
- # Reset children
194
- self .clear ()
195
- self .add (self ._line , self ._points , * self ._text_object_pool )
196
-
197
- def define_text (pos , text ):
198
- if self .tick_text_mapper is not None and text != "" :
199
- text = self .tick_text_mapper (text )
200
-
201
- ob = self ._text_object_pool [index ]
202
- ob .geometry .anchor = self ._text_anchor
203
- ob .geometry .anchor_offset = self ._text_anchor_offset
204
- ob .geometry .set_text (text )
205
- ob .local .position = pos
206
-
207
- # Apply start point
208
- index = 0
209
- positions [0 ] = start_pos
210
- if self ._ticks_at_end_points :
211
- sizes [0 ] = tick_size
212
- define_text (start_pos , f"{ self ._start_value :0.4g} " )
213
- else :
214
- sizes [0 ] = 0
215
- define_text (start_pos , f"" )
216
-
217
- # Collect ticks
218
- index += 1
219
- for value , text in ticks .items ():
220
- pos = start_pos + vec * (value - start_value )
221
- positions [index ] = pos
222
- sizes [index ] = tick_size
223
- define_text (pos , text )
224
- index += 1
225
-
226
- # Handle end point, and nullify remaining slots
227
- positions [index :] = end_pos
228
- sizes [index :] = 0
229
- for ob in self ._text_object_pool [index :]:
230
- ob .geometry .set_text ("" )
231
-
232
- # Show last tick?
233
- if self ._ticks_at_end_points :
234
- sizes [index ] = tick_size
235
- define_text (end_pos , f"{ end_value :0.4g} " )
236
-
237
- # Hide the ticks close to the ends?
238
- if self ._ticks_at_end_points and ticks :
239
- tick_values = list (ticks .keys ())
240
- if abs (tick_values [0 ] - start_value ) < 0.5 * tick_auto_step :
241
- self ._text_object_pool [1 ].geometry .set_text ("" )
242
- if abs (tick_values [- 1 ] - end_value ) < 0.5 * tick_auto_step :
243
- self ._text_object_pool [index - 1 ].geometry .set_text ("" )
244
-
245
-
246
144
class Axes :
247
145
def __init__ (
248
146
self ,
@@ -283,9 +181,9 @@ def __init__(
283
181
}
284
182
285
183
# create ruler for each dim
286
- self ._x = Ruler (** x_kwargs )
287
- self ._y = Ruler (** y_kwargs )
288
- self ._z = Ruler (** z_kwargs )
184
+ self ._x = pygfx . Ruler (** x_kwargs )
185
+ self ._y = pygfx . Ruler (** y_kwargs )
186
+ self ._z = pygfx . Ruler (** z_kwargs )
289
187
290
188
self ._offset = offset
291
189
@@ -400,17 +298,17 @@ def offset(self, value: np.ndarray):
400
298
self ._offset = value
401
299
402
300
@property
403
- def x (self ) -> Ruler :
301
+ def x (self ) -> pygfx . Ruler :
404
302
"""x axis ruler"""
405
303
return self ._x
406
304
407
305
@property
408
- def y (self ) -> Ruler :
306
+ def y (self ) -> pygfx . Ruler :
409
307
"""y axis ruler"""
410
308
return self ._y
411
309
412
310
@property
413
- def z (self ) -> Ruler :
311
+ def z (self ) -> pygfx . Ruler :
414
312
"""z axis ruler"""
415
313
return self ._z
416
314
0 commit comments