Multiline with CDSView and legend

I am plotting many (up to 100s) lines as multilines using a ColumnarDataSource. I filter the lines via a CDSView which is working fine. I use a column from the CDS as legend_field, but when displaying a legend, all lines appear in the legend despite changes to the filter applied.
The issue is similar to Issue #9878.

I have a patch for LegendItem.get_labels_list_from_label_prop I would like to test, but I cannot figure out how to inject the js and monkey patch the method.

I am using the plot in a panel pn.pane.Bokeh()

Any suggestions? (maybe @MarcSkovMadsen?)

The (untested) monkey patched method would be

    LegendItem.prototype.get_labels_list_from_label_prop = function() {
        if (!this.visible)
            return [];
        if ((0, vectorization_1.isValue)(this.label)) {
            const { value } = this.label;
            return value != null ? [value] : [];
        }
        const field = this.get_field_from_label_prop();
        if (field != null) {
            let source;
            if (this.renderers[0] && this.renderers[0].data_source != null)
                source = this.renderers[0].data_source;
            else
                return ["No source found"];
    
            if (source instanceof columnar_data_source_1.ColumnarDataSource) {
                let data;
                if (this.renderers[0].view != null) {
                    const indices = this.renderers[0].view.indices;
                    data = source.data[field][indices];
                } else {
                    data = source.get_column(field);
                }
                if (data != null)
                    return (0, array_1.uniq)(Array.from(data));
                else
                    return ["Invalid field"];
            }
        }
        return [];
    }

You’ll need to build BokehJS locally with your changes, and then use “inline” resources to use the local version you built. Contributor setup instructions are here:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.