fix(arcs) skip generation of very small arcs #2022
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #942
Background
Issue #942 reports unexpected behavior in the sunburst chart. When the data contains an element that should produce an extremely small arc, that arc can instead "flip around" and dominate the chart.
A similar effect can occur with the pie chart.
Visualizing the above data in a donut chart produces:
Slice C should be tiny or invisible, but instead the yellow color (third color in the nivo color scheme) dominates the visualization.
https://codesandbox.io/s/stoic-cray-nfyf1n?file=/src/App.js
Fix
The cause of this effect lies in
d3-shape
. The bug only affects arcs with rounded corners. I raised an issue to let them know.The proposed fix for nivo involves setting a nonzero angle threshold in the
@nivo/arcs
package. The arc renderer can now skip rendering arcs that would be too small to see. Fixing the arcs package automatically fixes issues in@nivo/pie
and@nivo/sunburst
.The new threshold (now set to 1e-7 radians) is set via a prop
skipAngle
inArcsLayer
. The name matches a similar prop inArcLabelsLayer
andArcLinkLabelsLayer
. However, this prop is now 'hidden' inside the arcs package - there are no changes to the API for the Pie and Sunburst components. The justification for 'hiding' this threshold is that it should not have any impact on expected behavior of the chart - tiny slices are expected to be invisible, and this threshold ensures this is the case despite the bug in d3-shape.The PR also includes some unit tests for the pie and sunburst packages.