plotly / plotly/plotly.js

Multiple legends in horizontal mode overlap chart on resize from a narrow viewport to a wide one

Open
#6,492 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.