Hi,
I am trying to make a canvas where I can draw with different colors using the same stream. I want to first select color from a drop-down or using buttons and then to draw to populate a dynamic map with that specific color. Then I want to be able to change to a different color and draw with that.
Currently my color drop-down is modifying all paths in the plot at once, I kind of see why, but am in doubt what is an elegant way of dealing with this.
Here is the current code:
from holoviews import opts
from holoviews.streams import FreehandDraw
hv.extension('bokeh')
kdims = ['xs', 'ys']
sample_path = []
path_generic = hv.Path(data=sample_path, kdims=kdims).opts(color='brown', line_width=3)
stream_generic = FreehandDraw(source=path_generic, tooltip='generic', name='generic')
def get_paths(data, color):
# import pdb; pdb.set_trace()
try:
for key, paths_1d in data.items():
transformed_data = [
(xs, ys, [color] * len(xs))
for xs, ys # col
in zip(data['xs'], data['ys'])
]
paths = [hv.Path(data=(x, y, c), kdims=['x', 'y'], vdims='c').opts(color='c', line_width=3) for x, y, c in transformed_data]
return hv.Overlay(paths)
except:
return hv.Overlay([hv.Path([])])
color_dim = hv.Dimension(('color', 'Color'), values=['blue', 'red'], default='red' )
dmap_generic = hv.DynamicMap(get_paths, kdims=[color_dim], streams=[stream_generic])
size_opts = dict(frame_width=500, frame_height=600)
overlay = path_generic * dmap_generic
overlay.opts(**size_opts)
I would be happy to hear about proposed ways of dealing with this. Also I think there might be more concise ways of fetching streams data that could replace my current way.
An image of the result below: