holoviews icon indicating copy to clipboard operation
holoviews copied to clipboard

Tap tool stops working for overlay in a dynamic map

Open Cutuchiqueno opened this issue 6 years ago • 3 comments

on pyviz Gitter I was encouraged to post the following issue here

With HoloViews/Bokeh Renderer (Holoviews = 1.11.2 / Bokeh 1.0.4 via current anaconda on Windows), I want to create a layout which consist of a scatter plot and RGB image. The scatter plot shows values of light-dark contrast in 2 movies. The RGB image shows a screenshot coming from one of the movies. The goal is to be able to click on a point in the scatter plot and the image from that time stamp of that movie is loaded as RGB Image.

I have the following code:

def scatter(div=5000, thrsh=0, alpha=0.1):
    # Berechnung des Skalierungsfaktors für einen Punkt an Hand der Anzahl der Pixel in einem Bin
    il_colful1['scaler'] = (il_colful1['pixels'] / div).round(0).astype(int)
    il_colful2['scaler'] = (il_colful2['pixels'] / div).round(0).astype(int)
    # Herausfiltern aller Werte deren Pixelnzahl unterhalb des Schwellenwertes liegt
    il_colful_lim1 = il_colful1[il_colful1['pixels'] > thrsh]
    il_colful_lim2 = il_colful2[il_colful2['pixels'] > thrsh]
    points = (hv.Points(il_colful_lim1, kdims=['frame', 'bin'], vdims=['pixels', 'time', 'scaler'], label='Il Divo').opts(color='red') *
              hv.Points(il_colful_lim2, kdims=['frame', 'bin'], vdims=['pixels', 'time', 'scaler'], label='Syriana').opts(color='blue')).opts(
             'Points', tools=['tap'], width=1000, size_index='scaler', fill_alpha=alpha, line_alpha=alpha, muted_fill_alpha=0.0, muted_line_alpha=0.0)
    return points

def img(index):
    if index:
        frame = il_colful1.iloc[index[0]]['frame']
        url = './il_divo/frames/576p30/il_divo_' + '{0:05}'.format(frame) + '.png'
    else:
        url = './il_divo/frames/576p30/il_divo_00100.png'
    return hv.RGB.load_image(url).options(height=433, width=1000, xaxis=None, yaxis=None)

il_divo_sct = hv.DynamicMap(scatter, kdims=['div', 'thrsh', 'alpha']).redim.range(div=(500, 15000), thrsh=(0, 50000), alpha=(0.01, 1.0)).opts(tools=['tap'])
selected = streams.Selection1D(source=il_divo_sct)
screenshot = hv.DynamicMap(img, streams=[selected])

(screenshot + il_divo_sct).cols(1)

Unfortunately, using the two hv.Points layers for the two datasets (il_colful_lim1, il_colful_lim2) overlayed on each other with * as shown here breaks the tap functionality and no call is made to the callback function of the stream (img).

Everything works when I only use one data set on layer and ignore the other one as shown in this alternative definition of points at the end of the scatter function.

points = hv.Points(il_colful_lim1, kdims=['frame', 'bin'], vdims=['pixels', 'time', 'scaler'], label='Il Divo').opts(tools=['tap'], width=1000, color='blue', size_index='scaler', fill_alpha=alpha, line_alpha=alpha)

Is the confusion on my side or is there something not working as it should?

Cutuchiqueno avatar Feb 28 '19 11:02 Cutuchiqueno