d3 / d3-shape

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

Create unclosed arc #76

Closed techniq closed 8 years ago

techniq commented 8 years ago

Is it possible to declare an arc should not be closed? Currently it appears L0,0Z is always appended to the end of the path data and I'm resorting to stripping this off.

const arc = d3.arc();

const d = arc({
  innerRadius: 0,
  outerRadius: 100,
  startAngle: 0,
  endAngle: 270 * (Math.PI/180)
}).split('L')[0]

document.getElementById('arc1')
  .setAttribute('d', d);

Produces:

M6.123233995736766e-15,-100A100,100,0,1,1,-100,1.2246467991473532e-14L0,0Z

Example: http://codepen.io/techniq/pen/QEkKOm?editors=1010

mbostock commented 8 years ago

You’ve specified an innerRadius of 0, so you’re producing a circular segment like a slice of a pie chart. If you just want to stroke the circumference of the circle, try setting the innerRadius and the outerRadius to same value (e.g., 100).

techniq commented 8 years ago

👍 Thanks, I figured it was something I was overlooking.

I noticed the path curve draws back on top of itself for the inner radius, but it doesn't produce any artifacts (just extra/unnecessary path data)

M6.123233995736766e-15,-100A100,100,0,1,1,-100,1.2246467991473532e-14A100,100,0,1,0,6.123233995736766e-15,-100Z

when the following would be sufficient

M6.123233995736766e-15,-100A100,100,0,1,1,-100,1.2246467991473532e-14
mbostock commented 8 years ago

These shapes are intended to be filled. If D3 didn’t draw the path back, and you fill the arc, then you’ll see a straight line from the start to the end of the arc.

techniq commented 8 years ago

Understood. I was using stroke and setting fill to none, but I understand now with the intended purpose be to fill the arc (not stroke). Setting innerRadius and outerRadius equal gave me my desired result (updated the codepen linked above). Thanks again.