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

The pie arguments problem #186

Closed Benbinbin closed 2 years ago

Benbinbin commented 2 years ago

according to document

Any additional arguments are arbitrary; they are simply propagated to the pie generator’s accessor functions along with the this object.

and it should be call the pie generator like this pie(data[, arguments…])

refer to the way to call the arc generator

const arc = d3.arc();

arc({
  innerRadius: 0,
  outerRadius: 100,
  startAngle: 0,
  endAngle: Math.PI / 2
}); // "M0,-100A100,100,0,0,1,100,0L0,0Z"

I try the similar way to call the pie generator but it doesn't work

pie(data, {
  padAngle: padAngle
});

it seems like the way to treat the arguments in arc generator and pie generator is different.

which is the correct way to pass the arguments in pie generator?

Fil commented 2 years ago

It just means that if f is a function and you call pie.startAngle(f)(data, "hello", "it's me"), f will be called with the arguments (data, "hello", "it's me").

In this case, if you have

    pie = d3.pie()
      .padAngle((_, { padAngle, padAngleDegrees = 0 } = {}) =>
        padAngle === undefined ? (padAngleDegrees * Math.PI) / 180 : padAngle
      )

you might call

     pie(data, {padAngleDegrees: 1}) 

and it will compute the padAngle in radians from the value given in degrees.