Latex Legend by using an overlay

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

@Matthias The entire layout system was ripped out and replaced for Bokeh 1.1, it operates on a completely different basis now. I would not expect anything using a private JS API to still function. We are only just beginning to see the light at the end of the tunnel re: BokehJS API stability. Unfortunately I don’t really know the answer to your question offhand, but I will see if I can get @mateusz to check in here.

FYI we are trying to get funding to support work to add MathJax capability built-in, tho I would not expect that work to take place until next year (and the funding is not guaranteed).

1 Like

Let’s hope for the best, built-in LaTeX support would be a very nice feature!

Meanwhile I figured out how to place the overlay.
this.plot_view.canvas_view.overlays_el does the trick.

1 Like