What are you trying to do?
I have a line glyph/renderer and I want the line’s legend label to follow a CustomJSTransform, in my simple MRE it should read “My Custom Label”.
What have you tried that did NOT work as expected?
I looked at legend instantiation here → Annotations — Bokeh 3.6.0 Documentation
and it looks like I can mimic what assigning ‘legend_field’ to renderer instantiation does by assigning a transform to the label argument when instantiating an explicit LegendItem. However, this does produce the desired behavior, as my CustomJSTransform assigned to the transform is ignored and it just does the usual legend_field thing instead.
MRE:
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, CustomJSTransform, Legend, LegendItem
from bokeh.transform import transform
src = ColumnDataSource({'x':[1,2,3],'y':[2,3,1]})
f = figure()
r = f.line(x='x',y='y',source=src)
ctr = CustomJSTransform(func='''
return 'My Custom Label'
''')
legend = Legend(items=[
LegendItem(label="my label", renderers=[r]),
#???
LegendItem(label=transform(field_name='x',transform=ctr),renderers=[r],index=0)
])
f.add_layout(legend)
show(f)
Thanks…