Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal legend entrywidth does not adjust to font size on initial render #312

Open
Moocowmike opened this issue Feb 16, 2023 · 1 comment

Comments

@Moocowmike
Copy link

When initially rendering the component, when set to orientation "h", the legend entries do not adjust their size correctly based on the font size set in the layout.

Example:

`
export const Test = (): ReactElement => {

  const data : Data[] =[
      {
          x: [1, 2, 3],
          y: [2, 6, 3],
          name: "my example scatter chart",
          type: 'scatter',
          mode: 'lines+markers',
          marker: {color: 'red'},
      },
      {type: 'bar', name:"my example bar chart", x: [1, 2, 3], y: [2, 5, 3]},
  ]

  const layout = {
      width: 1350,
      height: 950,
      hoverlabel: {
          bgcolor: "#555555",
          font: {
              family: "Open Sans",
              size: 14
          }
      },
      legend: {
          x: 0.25,
          y: -0.35,
          orientation: "h" as any,
          font: {
              family: 'Open Sans',
              size: 24,
              color: '#555555'
          },
          entrywidth:0,
      },
      xaxis: {
          showline: false,
          zeroline: false,
          title: {
              text: 'x',
              font: {
                  family: 'Open Sans',
                  size: 14,
                  color: '#555555'
              }
          },
      },
      yaxis: {
          showline: false,
          zeroline: false,
          title: {
              text: 'y',
              font: {
                  family: 'Open Sans',
                  size: 14,
                  color: '#555555'
              }
          }
      }
  }


  return (<Plot
      layout={layout}
      data={data}
  />)

}
`
image

If I adjust the font size property of the layout object after the initial render, it corrects itself.

image

Any guidance or help would be greatly appreciated.

@alexcjohnson
Copy link
Collaborator

Hmph, I'm not able to reproduce this in plain plotly.js, but we've definitely seen situations where rendering is attempted before the font has loaded, so we measure the size of the text for a fallback font, then the size is wrong once the right font loads. Might need to investigate font loading detection again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants