The example in PointDraw Stream tutorial does not seem to trigger an event on label edit. I have it here in a (hopefully) param-style, hope it is clear.
import param
import numpy as np
import pandas as pd
import holoviews as hv
import panel as pn
hv.extension('bokeh')
from holoviews.plotting.links import DataLink
columns = ["x","y","dx","dy","name"]
import logging
logger = logging.getLogger("MY")
logger.setLevel(logging.DEBUG)
def massage_df(df):
# simulates a more complex transformations
df = pd.DataFrame(df)
x_ref = df['x'].mean()
y_ref = df['y'].mean()
df['dx'] = df['x'] - x_ref
df['dy'] = df['y'] - y_ref
return df[columns]
class AnnotatorInspired(param.Parameterized):
_coords = param.DataFrame(columns = columns, doc="Dataframe containing main information")
_points_stream = param.ClassSelector(class_=hv.streams.PointDraw)
_plot = param.ClassSelector(class_=hv.Points)
_table = param.ClassSelector(class_=hv.Table)
def __init__(self, df):
self._coords = massage_df(df)
self._plot = hv.Points(self._coords, kdims=['x','y'], vdims=['name']).opts(tools=["hover"],size=10, active_tools=['point_draw'])
self._table = hv.Table(self._plot, ['x', 'y'], 'name').opts(editable=True)
DataLink(self._plot, self._table)
self._points_stream = hv.streams.PointDraw(
data=self._plot.columns(),
source=self._plot,
empty_value='',
)
super().__init__(
_coords = self._coords,
_plot = self._plot,
_table = self._table,
_points_stream = self._points_stream,
)
@param.depends("_points_stream.data",watch=True)
def _update(self):
# triggered as expected on point drags, point adds, or removes
# but not on label change
logger.debug(":::: coordinates updated")
self._coords = massage_df(self._points_stream.data)
@param.depends("_coords")
def full_view(self):
return pn.widgets.Tabulator(self._coords)
# many more methods that watch for _coords change
A = AnnotatorInspired({'x':[0.,.1],'y':[1.,.9],"name":['far','near']})
main = pn.Column(
A._table.opts(height=100),
A._plot,
A.full_view,
)
main.servable()
Interestingly, when changing the label through the table, it does change the label in the plot (I can check in the hover), but does not allow me tag other process with that.
I am aware of the Annotators, but not a clear idea how to use it in an app like this.
Any help is appreciated.
I’m in holoviews 1.15.4.