@@ -128,6 +128,10 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None):
128
128
129
129
# Vectors
130
130
131
+ self .vector_lines = lines_cls (scales = self .view .scales , x = [0. ], y = [0. ])
132
+ self .vector_lines .colors = [color2hex (self .state .color )]
133
+ self .vector_lines .visible = False
134
+
131
135
self .scale_size_vector = bqplot .LinearScale (min = 0 , max = 1 )
132
136
self .scale_color_vector = bqplot .ColorScale ()
133
137
self .scale_rotation_vector = bqplot .LinearScale (min = - np .pi , max = np .pi )
@@ -162,6 +166,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None):
162
166
self .line_mark_gl ,
163
167
self .line_mark ,
164
168
self .vector_mark ,
169
+ self .vector_lines ,
165
170
]
166
171
167
172
def compute_density_map (self , * args , ** kwargs ):
@@ -253,12 +258,25 @@ def _update_data(self):
253
258
self .vector_mark .size = length
254
259
self .vector_mark .rotation = angle
255
260
261
+ # maybe i need vector lines here too?
262
+ vector_line_coords = self ._build_line_vector_points ()
263
+ x_vector_coords = vector_line_coords [:,0 ]
264
+ y_vector_coords = vector_line_coords [:,1 ]
265
+ self .vector_lines .x = x_vector_coords
266
+ self .vector_lines .y = y_vector_coords
267
+ with open ('/tmp/debug.log' , 'a' ) as log :
268
+ log .write ('calculated vector lines coordinates:\n ' )
269
+ log .write (f'x vector coords : { x_vector_coords [:10 ]} \n ' )
270
+ log .write (f'y vector coords : { y_vector_coords [:10 ]} \n ' )
271
+
256
272
else :
257
273
258
274
self .vector_mark .x = []
259
275
self .vector_mark .y = []
260
276
261
277
def _update_visual_attributes (self , changed , force = False ):
278
+ with open ('/tmp/debug.log' , 'a' ) as log :
279
+ log .write ("Updateing visual attributes\n " )
262
280
263
281
if not self .enabled :
264
282
return
@@ -345,9 +363,12 @@ def _update_visual_attributes(self, changed, force=False):
345
363
and self .state .vx_att is not None
346
364
and self .state .vy_att is not None
347
365
):
366
+ with open ('/tmp/debug.log' , 'a' ) as log :
367
+ log .write ("Vector visible \n " )
368
+ self .vector_mark .visible = False
369
+ self .vector_lines .visible = True
348
370
349
371
if self .state .cmap_mode == "Fixed" :
350
- breakpoint ()
351
372
if force or "color" in changed or "cmap_mode" in changed :
352
373
self .vector_mark .color = None
353
374
self .vector_mark .colors = [color2hex (self .state .color )]
@@ -360,7 +381,8 @@ def _update_visual_attributes(self, changed, force=False):
360
381
self .scale_color_vector .max = float_or_none (self .state .cmap_vmax )
361
382
362
383
363
- for mark in [self .scatter_mark , self .line_mark_gl , self .line_mark , self .vector_mark , self .density_mark ]:
384
+ for mark in [self .scatter_mark , self .line_mark_gl , self .line_mark ,
385
+ self .vector_mark , self .vector_lines , self .density_mark ]:
364
386
365
387
if mark is None :
366
388
continue
@@ -378,7 +400,7 @@ def _update_visual_attributes(self, changed, force=False):
378
400
self .line_mark_gl .visible = self .state .visible and self .state .line_visible
379
401
self .density_mark .visible = (self .state .visible and self .state .density_map
380
402
and self .state .markers_visible )
381
- self .vector_mark .visible = self .state .visible and self .state .vector_visible
403
+ self .vector_lines .visible = self .state .visible and self .state .vector_visible
382
404
383
405
def _update_scatter (self , force = False , ** kwargs ):
384
406
@@ -387,7 +409,9 @@ def _update_scatter(self, force=False, **kwargs):
387
409
self .density_mark is None
388
410
or self .scatter_mark is None
389
411
or self .line_mark_gl is None
412
+ # TODO: check which of these are needed
390
413
or self .vector_mark is None
414
+ or self .vector_lines is None
391
415
or self ._viewer_state .x_att is None
392
416
or self ._viewer_state .y_att is None
393
417
or self .state .layer is None
@@ -447,3 +471,41 @@ def _update_zorder(self, *args):
447
471
for item in (layer .density_mark , layer .scatter_mark , layer .line_mark_gl ,
448
472
layer .line_mark , layer .vector_mark )
449
473
]
474
+
475
+ def _build_line_vector_points (self ):
476
+ """
477
+ Function builds an array of coordinate pairs separated by nans for plotting individual lines
478
+ to replicate vector behaviour
479
+
480
+ Returns: np.array
481
+ array of structure ([x1, y1], [x2, y2], [np.nan, np.nan])
482
+ """
483
+ x = self ._viewer_state .x_att
484
+ y = self ._viewer_state .y_att
485
+ vx = self ._viewer_state .vx_att
486
+ vy = self ._viewer_state .vy_att
487
+
488
+ point_pairs = []
489
+ for row in range (0 , len (x )):
490
+ length = np .sqrt (vx [row ]** 2 + vy [row ]** 2 )
491
+ angle = np .arctan2 (vy [row ], vx [row ])
492
+ x_delta = length * np .cos (angle )
493
+ y_delta = length * np .sin (angle )
494
+ x2 = x [row ] + x_delta
495
+ y2 = y [row ] + y_delta
496
+ point_1 = [x [row ], y [row ]]
497
+ point_pairs .append (point_1 )
498
+ point_2 = [x2 [row ], y2 [row ]]
499
+ point_pairs .append (point_2 )
500
+ point_3 = [np .nan , np .nan ]
501
+ point_pairs .append (point_3 )
502
+
503
+ with open ('/tmp/debug.log' , 'a' ) as f :
504
+ f .write ('Built the vectors \n ' )
505
+ f .write ('point pairs : {}\n ' .format (point_pairs ))
506
+
507
+ return np .array (point_pairs )
508
+
509
+
510
+
511
+
0 commit comments