plotly / plotly/react-plotly.js

Margins not updating correctly in pie chart after manual resizing

Aberta
#354 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
JavaScript
Estrelas
1.1k
Forks
138
Merge médio
3d 2h
PRs com merge (30d)
4

Descrição

When dynamically updating a pie chart, I encountered an issue where the available space for the pie chart does not update properly after changing the plot size.

For my setup, the plot is rendered using Plotly in a React app. The plot state is managed using useState() and the layout updates are triggered via useEffect() whenever a user changes the settings object (for plot width, height, font, etc). The update is performed like this:

setPlot((prevPlot) => ({
  ...prevPlot,
  layout: {
    ...prevPlot.layout,
    width: displaySizes.width,
    height: displaySizes.height,
    margin: {
      ...prevPlot.layout.margin,
      t: settings.marginTop,
      b: settings.marginBottom,
      l: settings.marginLeft,
      r: settings.marginRight,
    },
    // other layout updates
  },
}));

Used versions are "plotly.js": "^3.0.0", "plotly.js-dist-min": "^3.0.1", "react-plotly.js": "^2.6.0".

Steps to reproduce the described bug:

  1. Render a pie chart with segments [39,61]
  2. Set the plot size to an incorrect size, e.g. width: 40, height: 255
  3. Correct the plot size to valid values, e.g. width: 400, height: 255

Plot, before resizing:
Image

Plot, after resizing as described:
Image

The visible margins are now way larger than what is defined in the layout and much larger than necessary, since the pie chart could take up more space (like before). Changing the margins or plot size has no effect on the margins; only randomly increasing or decreasing the text size causes the plot to reset and render correctly.
It seems like the issue is related to the segment ratio: It only occurs when the pie segments are similar (e.g. [39, 61]), but not when they differ a lot (e.g. [10, 90]).

None of the approaches I came across online (such as Plotly.Plots.resize() or using the revision prop) solved this problem.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece reproduzindo o problema em um app React com plotly.js 3.0.x e react-plotly.js 2.6.0, usando um gráfico de pizza com os segmentos [39,61]. Rastreie a atualização do layout após alterar a largura de 40 para 400 e compare-a com o caso [10,90]. Considera-se concluído quando o redimensionamento e as atualizações das margens recalcularem o espaço disponível para o gráfico de pizza sem exigir uma alteração em font-size.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript, react
Domínio
data-visualization, frontend
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.