D3 lineRadial - what is the math behind this?

Viewed 59

I am trying to make sense of this snippet

    const radialScale = d3Scale.scaleLinear()
      .domain([0, 1])
      .range([0, this.radius]);

    const line = d3Shape.lineRadial()
      .angle((d) => {
        // Angle position
        return d[0];
      })
      .radius((d) => {
        // Distance from center
        return radialScale(d[1]);
      });

that I call in

        console.log(d);
        const coors = line([[d.angle, d.radius]]).slice(1).slice(0, -1);
        console.log(coors);

with those values:

first log:
angle: 3.6215581978882336, radius: 14.3
second log:
-1122.510878774367,2156.323335456257

and my head does not wrap around the return values of the function. I my specification above it should return d[0] - i.e. 3.621.... , yet I get -1122.510878774367 ? The / A documentation I found for lineRadial states it should simply return radians, and my d[0] is a radian value.

https://www.geeksforgeeks.org/d3-js-lineradial-angle-method/

Not sure what I am getting wrong with this function...

Any ideas?

1 Answers

It was that I had the radialScale function wrong, so my radius value went out of the roof. I had to adjust that and plots now look good.

Related