I upgraded plotly.js recently and my app stopped working properly. I use multiple Y axes approach - the default yaxis is the only visible but has no related trace. All traces have their own yaxisN overlying the default one (yaxis). The reason is that yaxesN have autorange set on by default but user can change it and set custom range (for each trace).
The behavior in handling of multiple yaxis has changed since v1.32.0.
In v1.31.2 when I added layouts for yaxis2, yaxis3, etc using Plotly.relayout() function they were added - I could see them in _fullLayout object as properties yaxis2, yaxis3, etc.
Since v1.32.0 they are not added until there is a trace referencing them (e.g. for layout for yaxis2 there must be a trace with property yaxis: ‘y2’
). If no trace has its ‘yaxis’ set to ‘y2’, the ‘yaxis2’ property does not exist in _fullLayout. It looks like some kind of optimization.
The problem is that it works like this even for the default yaxis - i.e. if there is no trace with ‘yaxis’ property set to value of ‘y’ but there is another trace with ‘yaxis’ set to ‘y2’, the ‘yaxis’ is removed from _fullLayout despite yaxis2 is overlaying ‘y’.
Is this behavior by design?
I’m asking because I need to fix my app and need to decide how. So far I found the only solution to add empty trace (it references yaxis by default, which ensures the yaxis is not removed from layout).
In following codepen you can compare the behavior: https://codepen.io/exavier/pen/YQKmWM?editors=1010
It uses the latest plotly.js version, but if you change the reference version in HTML to v1.31.2 you can see the difference. (_fullLayout and _fullData are logged to console).