Hello,
I’m trying to render Latex Legends in bokeh plots. Using an old Bokeh version (1.0.2) it worked with a custom file that extends LegendView by overriding its _draw_legend_items
function.
After upgrading to Bokeh 1.4.0, it does not work anymore.
It seems that main problem lies in the call of
initialize(options: any): void {
super.initialize(options)
this.model.orientation = "vertical"
this.overlayEl = this._parent.el.children[0].children[1]
for (const item of this.model.items) {
const labels = item.get_labels_list_from_label_prop()
for (let i = 0, end = labels.length; i < end; i++) {
const el = div({ class: 'bk-annotation-child', style: { display: "none" } })
this.overlayEl.appendChild(el)
}
}
to place the overlay at the correct position.
Especially this._parent.el.children[0].children[1]
does not work anymore, since the variable _parent
from the class View
is now set to private. Maybe this was different in old Bokeh?
Now my question is, if there is an alternative for this.
If found this._root_element
from DOMView
, but I cannot access children like in the above code.
It seems that the position of the legend items should be inside the div of class bk bk-canvas-overlays
as I can tell from F12 in the browser.
Since I don’t know Typescript/JavaScript well, I’d be glad about any advice.
Update: I’ve also tried to create it via this.plot_view.canvas_view.add_overlay(this.el)
but, it throws an error
Property ‘add_overlay’ does not exist on type ‘CanvasView’
which is very strange, since many other files in bokehjs use exactly this function and it’s obviously there in CanvasView
.
Solution:
Instead of calling the now private _parent
and its children, this is the current alternative:
this.plot_view.canvas_view.overlays_el