Multiple legends in horizontal mode overlap chart on resize from a narrow viewport to a wide one
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.3k
- Forks
- 2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Description
I am having troubles when changing from portrait mode to landscape mode as the legends overlap the x axis ticks or the chart itself.
Here is the reproducible example: https://codepen.io/bleah1/full/ZEMGVpY
Please use Inspect tools and either make the viewport narrow and then pull pretty fast to make it wide again or just go to mobile view and switch from portrait to landscape.
The legends remain in the same place when resizing from a narrow viewport to a wider one.
This behavior is not as bad on PC, because you can resize again and everything falls into place, but on mobile you can't resize the viewport/window, you can only refresh and I can't use it as it is now.
The code is pretty basic:
const plotDiv = document.getElementById('plot');
const traces = [
{x: [1,2,3], y: [2,1,4], stackgroup: 'one'},
{x: [1,2,3], y: [1,1,2], stackgroup: 'one'},
{x: [1,2,3], y: [3,0,2], stackgroup: 'one'},
{x: [1,2,3], y: [4,3,2], stackgroup: 'one'},
{x: [1,2,3], y: [5,5,2], stackgroup: 'one'},
];
const layout = {
showlegend: true,
legend: {
x: 0,
// y: 1,
orientation: "h",
traceorder: "normal",
yanchor: "top",
},
autosize: true,
margin: { pad: 10, b: 10, l: 40, r: 40, t: 80 },
}
const config = {
responsive: true
}
Plotly.newPlot('myDiv', traces, layout, config);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodePen reproduction and inspect the responsive resize path for horizontal legend placement in plotly.js. Compare narrow-to-wide resizing with a refresh, then verify that the legends no longer overlap the x-axis ticks or chart after the viewport changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100