plotly / plotly/react-plotly.js
Margins not updating correctly in pie chart after manual resizing
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 1.1k
- Forks
- 138
- Merge moyen
- 3 j 2 h
- PR mergées (30 j)
- 4
Description
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:
- Render a pie chart with segments [39,61]
- Set the plot size to an incorrect size, e.g. width: 40, height: 255
- Correct the plot size to valid values, e.g. width: 400, height: 255
Plot, before resizing:
Plot, after resizing as described:
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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire le problème dans une application React avec plotly.js 3.0.x et react-plotly.js 2.6.0, en utilisant un diagramme circulaire avec les segments [39,61]. Suivez la mise à jour du layout après avoir modifié la largeur de 40 à 400 et comparez-la au cas [10,90]. C’est terminé lorsque le redimensionnement et les mises à jour des marges recalculent l’espace disponible pour le diagramme circulaire sans nécessiter de modification de font-size.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, react
- Domaine
- data-visualization, frontend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100