holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

'poly_draw' tool not working with holoviews 1.18.3 in combination with panel 1.4.4 #6255

Open GeoVizNow opened 4 months ago

GeoVizNow commented 4 months ago

ALL software version info

holoviews: 1.18.3 pandas: 2.2.2 bokeh: 3.4.1 panel: 1.4.4 notebook: 7.2.0 jupyter: 1.0.0 jupyterlab: 4.2.1

Description of expected behavior and the observed behavior

Expectation is that when adding option argument tools=['poly_draw'] then it is possible to edit path or polygon opjects.

It seems to be no response when trying to digitize a path.

Last configuration where I have had this working is with holoviews 1.18.3 and panel 1.3.8 I think. Not sure if others have had this challenge. Maybe some requirement alignment I am missing.

Complete, minimal, self-contained example code that reproduces the issue

# start of cell
import holoviews as hv
import bokeh
from holoviews import opts
from holoviews.streams import FreehandDraw, PolyDraw
from holoviews.streams import PolyDraw
from bokeh.models import PolyDrawTool
import panel as pn
import pandas as pd
hv.extension('bokeh')
pn.extension()

# start of cell
sample_path = []
kdims = ['xs', 'ys']

path_opts = {"line_width": 1.4}
opts.defaults(opts.Path(**path_opts))
color_list = ['blue', 'red']

def get_path_color(color):
    return hv.Path(data=sample_path, kdims=kdims,
                   # datatype=['dictionary']
                  ).opts(color=color)

path_blue = get_path_color('blue')

draw_function_options = {'PolyDraw': PolyDraw, 'FreehandDraw': FreehandDraw}
w_draw_function = pn.widgets.Select(options=draw_function_options,
                                    # value=FreehandDraw
                                    value=PolyDraw
                                   )

# start of cell
draw_function = w_draw_function.value

active_tools = {
    FreehandDraw: 'freehand_draw',
    PolyDraw: 'poly_draw'
}

active_drawing_tools = [active_tools[PolyDraw]]
display(f'{active_dawing_tools = }')

size_opts = {"frame_width": 900, "frame_height": 600}
lim_opts = {"xlim": (0, 4000), "ylim": (0, 1000)}

path_blue.opts(
    active_tools=active_drawing_tools,
    **lim_opts,
    **size_opts,
    )

Stack traceback and/or browser JavaScript console output

Error when trying to display the 'path_blue' with opts as above is: 'Tool of type 'poly_draw' could not be found and could not be activated by default.'

Screenshots or screencasts of the bug in action

hoxbro commented 3 months ago

My gut feeling is this is also related to https://github.com/bokeh/bokeh/issues/13831.

@mattpap, do you have any insight?

mattpap commented 3 months ago

My gut feeling is this is also related to https://github.com/bokeh/bokeh/issues/13831.

Definitely not, because that was local to TapTool and edit tools set selection modes (usually "replace" mode) explicitly.

'Tool of type 'poly_draw' could not be found and could not be activated by default.'

Is this at all bokeh related?

hoxbro commented 3 months ago

Is this at all bokeh related?

Yes, it is because of https://github.com/bokeh/bokeh/issues/13842. Using the example here: https://holoviews.org/reference/streams/bokeh/PolyDraw.html, I need to press long to get it to work.

Looking at https://docs.bokeh.org/en/latest/docs/user_guide/interaction/tools.html#polydrawtool, it also seems that the keyboard shortcuts do not work.