Setting range in CustomJS, but being overwritten!

I’m changing the y-range on a plot in a CustomJS callback, but sometimes the original y-range comes back!

I have a complex app that’s a mix of a range tool (selecting data using a bar chart) and a line chart to show the data. In the range tool callback, I’m updating what lines to show in the line chart based on what’s selected in the range tool. On my line chart, I’m using the visible=false setting to not show lines and visible=true to show lines.

This is working great, but I need to manually change the y_range, which I can do.

I have some code in my callback that does something like this:

        let max_y = 0.0;

        loop - not showing details here. isVisible is true to show line.
            if (isVisible) {{
                max_y = Math.max(Bokeh.index.get_one_by_id(plot.renderers[i].id).bounds().y1, 
                                 max_y);
            }}

        plot.y_range.setv({{
            'start': -0.1*max_y,
            'end': 1.1*max_y
        }});

Most of the time, this works great and my line chart updates perfectly. But on some line selections, the original y-range comes back!

Bear in mind I’m using the visible value.

Has anyone any idea what I’m doing wrong?

Potentially sounds like some some sort of race condition, but that’s just speculation. Unfortunately it’s not really possible to say more without running and investigating a complete Minimal Reproducible Example directly.

I solved it. I set a fixed y_range in the figure and that cured the problem.

    plot = figure(
        title="US Govt Agency Spending Over Time",
        x_axis_label="US Govt Financial Year",
        y_axis_label="Spending (USD)",
        width=plot_width,
        height=plot_height,
        y_range=(-0.1*max_amount, 1.1*max_amount)   # CURE!!!!!
    )

I can’t really do a shorter example because this si a big project with many moving parts, but I will post the results and a link to GitHub when it’s all complete.

1 Like

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