dash icon indicating copy to clipboard operation
dash copied to clipboard

[BUG] dash>=2.12.0 caused regression in multiple legends (legend2, legend3, ...)

Open pfbuxton opened this issue 1 year ago • 0 comments

Multiple legends are great!

However, I have found an edge case where since dash=2.12.0 if legend isn't used then legend2, legend3 stop working.

Expected behaviour: when you click a legend on/off the plot turns on/off.

dash version worked ?
2.11.0 worked as expected ✔️
2.11.1 worked as expected ✔️
2.12.0 not working ❌
2.12.1 not working ❌

As a workaround you can make certain that you always use legend.

Here is an example where legend is not used, but legend2 and legend3 are used, you will find that clicking the legends will not turn them on/off:

import dash
from dash import dcc, html
import numpy as np
import plotly.graph_objs as go


x = np.linspace(0.0, 20.0, 100)

# Make example traces
traces = []
# Ensure that "Plot1" is visiable
traces.append(go.Scatter(
    x=np.full([1], np.nan),
    y=np.full([1], np.nan),
    xaxis='x',
    yaxis='y',
))
traces.append(go.Scatter(
    x=x,
    y=x**2,
    xaxis='x',
    yaxis='y2',
    name='y = x**2',
    hoverinfo='skip',
    legend='legend2'
))
traces.append(go.Scatter(
    x=x,
    y=x**3,
    xaxis='x',
    yaxis='y2',
    name='y = x**3',
    legend='legend2'
))
traces.append(go.Scatter(
    x=x,
    y=np.sin(x),
    xaxis='x',
    yaxis='y3',
    name='y = sin(x)',
    legend='legend3'
))
traces.append(go.Scatter(
    x=x,
    y=np.cos(x),
    xaxis='x',
    yaxis='y3',
    name='y = cos(x)',
    legend='legend3'
))

# Layout with multiple legends
layout = go.Layout(
    xaxis=dict(
        title='x',
    ),
    yaxis=dict(
        title='Plot 1',
        domain=[0.0000, 0.32],
    ),
    yaxis2=dict(
        title='Plot 2',
        domain=[0.34, 0.65]
    ),
    yaxis3=dict(
        title='Plot 3',
        domain=[0.67, 1.0]
    ),
    legend=dict(
        x=0.99,
        y=0.33,
        xanchor='right',
        yanchor='top',
        visible=True
    ),
    legend2=dict(
        x=0.99,
        y=0.66,
        xanchor='right',
        yanchor='top',
        visible=True
    ),
    legend3=dict(
        x=0.99,
        y=0.99,
        xanchor='right',
        yanchor='top',
        visible=True
    ),
)

figure = go.Figure(
    data=traces,
    layout=layout
)

app = dash.Dash(__name__)
app.layout = html.Div(
    children=[
        html.H1(
            children="when clicked, \"legends\" don't turn plots on/off"
        ),
        dcc.Graph(
            figure=figure
        )
    ]
)

if __name__ == '__main__':
    app.run_server(debug=True)

multiple_legend_example

pfbuxton avatar Sep 28 '23 12:09 pfbuxton