Fix issue where `visible` property of one legend was affecting another by emilykl · Pull Request #7574 · plotly/plotly.js
Closes #7559
Fixes issue where setting layout.legend3.visible to false caused both legend and legend3 to disappear.
Also adds a Jasmine test to prevent regression.
It seems this bug was because legend._id was not being added to the processed legend object during the defaults step if visible was false. This DID cause the legend not to be drawn (desirable), but it had the side effect of causing the plot step to "assume" the legend _id to be legend if not available, which caused the visibility setting to also be applied to the first legend (undesirable).
Note that the only actual logic change is on line 242 of src/components/legend/defaults.js; the other changes in that file are just auto-formatting changes.
To test
- Open @my-tien 's codepen linked in [BUG]: legend3.visible = false affects visibility of other legend #7559
- Replace the Plotly.js CDN link with the link to the CircleCI build for this branch: https://output.circle-artifacts.com/output/job/aff93db6-865a-4e06-a4c6-816483ea13b4/artifacts/0/dist/plotly.js
- In the plot definition, change
layout.legend3.visiblefromtruetofalseand make sure that neither of the other two legends disappear. (legend3is not visible in any case becauseshowlegendis set tofalseat the trace level and there's only one trace in that legend)