d3 / d3-shape

Graphical primitives for visualization, such as lines and areas.
https://d3js.org/d3-shape
ISC License
2.47k stars 305 forks source link

padAngle allows data that includes 0 angle to fill #128

Closed dvnrsn closed 4 years ago

dvnrsn commented 5 years ago

https://codepen.io/devcon/pen/qMERrW

If there is data that includes a 0, the last padAngle is filled with a sliver. Is this expected behavior?

curran commented 4 years ago

What is the expected behavior?

Here's what I notice with your example:

data = [1, 1, 2, 3, 5, 8, 13];

image

data = [0, 1, 1, 2, 3, 5, 8, 13];

image

data = [0, 0, 1, 1, 2, 3, 5, 8, 13];

image

The thing that doesn't make sense to me is that if there are multiple zeroes, there's still only one sliver.

Possible options to solve this:

Which one would be preferable?

dvnrsn commented 4 years ago

Do not produce any slivers I'd say

mbostock commented 4 years ago

The problem here is that you’re using arc.padAngle, but as the documentation suggests, you should be using pie.padAngle instead. This gives you multiple slivers for multiple zeroes:

image

This can’t be fixed at the arc.padAngle level because there that padding is subtracted from the arc, and if the arc is zero-angle, there’s nothing to subtract from.