Skip to content

Commit

Permalink
Adds vectors as lines functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
CyclingNinja committed Feb 13, 2025
1 parent ee2acaa commit 2df5eb1
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion glue_jupyter/bqplot/scatter/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None):

# Vectors

self.vector_lines = lines_cls(scales=self.view.scales, x=[0.], y=[0.])
self.scale_size_vector = bqplot.LinearScale(min=0, max=1)
self.scale_color_vector = bqplot.ColorScale()
self.scale_rotation_vector = bqplot.LinearScale(min=-np.pi, max=np.pi)
Expand Down Expand Up @@ -345,6 +346,12 @@ def _update_visual_attributes(self, changed, force=False):
and self.state.vx_att is not None
and self.state.vy_att is not None
):
vector_line_coords = self._build_line_vector_points()
x_vector_coords = vector_line_coords[:,0]
y_vector_coords = vector_line_coords[:,1]
self.vector_lines.x = x_vector_coords
self.vector_lines.y = y_vector_coords
self.line_mark.colors = [color2hex(self.state.color)]

if self.state.cmap_mode == "Fixed":
breakpoint()
Expand All @@ -360,7 +367,8 @@ def _update_visual_attributes(self, changed, force=False):
self.scale_color_vector.max = float_or_none(self.state.cmap_vmax)


for mark in [self.scatter_mark, self.line_mark_gl, self.line_mark, self.vector_mark, self.density_mark]:
for mark in [self.scatter_mark, self.line_mark_gl, self.line_mark,
self.vector_mark, self.vector_lines, self.density_mark]:

if mark is None:
continue
Expand Down Expand Up @@ -447,3 +455,30 @@ def _update_zorder(self, *args):
for item in (layer.density_mark, layer.scatter_mark, layer.line_mark_gl,
layer.line_mark, layer.vector_mark)
]

def _build_line_vector_points(self):
"""
Function builds an array of coordinate pairs separated by nans for plotting individual lines
to replicate vector behaviour
"""
x = self._viewer_state.x_att
y = self._viewer_state.y_att
vx = self._viewer_state.vx_att
vy = self._viewer_state.vy_att

point_pairs = []
for row in range(0, len(x)):
x2 = x[row] + vx[row]
y2 = y[row] + yx[row]
point_1 = [x[row], y[row]]
point_pairs.append(point_1)
point_2 = [x2[row], y2[row]]
point_pairs.append(point_2)
point_3 = [np.nan, np.nan]
point_pairs.append(point_3)

return np.array(point_pairs)




0 comments on commit 2df5eb1

Please sign in to comment.