d3 / d3-shape

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

Arc - Inconsistent error notification when invoked via fluent function calls vs invoking with data #173

Closed saumyatripathi closed 2 years ago

saumyatripathi commented 3 years ago

Hello contributors. Thank you for building and maintaining this amazing set of tools.

I may have found an inconsistency (and thought it might be helpful if recorded here) with how the error is reported when the .innerRadius is not supplied to the arc function when invoked in the below two ways -

  1. d3Shape .arc() .innerRadius(0) .outerRadius(50) .startAngle(Math.PI / 2) .endAngle(Math.PI * 2)() If the .innerRadius(0) is skipped, the below error is received -

    TypeError: undefined is not an object (evaluating 'd.innerRadius')

  2. d3Shape.arc().innerRadius(0).outerRadius(50)({ startAngle: 0, endAngle: Math.PI / 2, }) while the error thrown when .innerRadius(0) is skipped with this syntax is -

    Invalid number formatting character 'N' (i=44. s=M3...some numbers...NaN, NaNZ)

As seen above, while 1 is pretty clear, 2 does not really indicate the real issue. I spent a fair amount of time trying to narrow it down.

Best

mbostock commented 2 years ago

Thanks for the feedback, @saumyatripathi. We don’t plan on fixing this; many graphics APIs (such as Canvas) will ignore invalid input rather than throwing an error. Your browser will often log warnings with invalid SVG path strings that you can then investigate.