Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startPadAngle and endPadAngle #207

Open
cittadhammo opened this issue May 20, 2023 · 4 comments
Open

startPadAngle and endPadAngle #207

cittadhammo opened this issue May 20, 2023 · 4 comments

Comments

@cittadhammo
Copy link

Dear All,

I would like to implement two optional parameters for the function arc().

At the moment arc().padAngle(x) create a symetric padding on each side of the arc sector. I have posted on d3 slack about my issue and I think it would be worth implement a solution at the source level. (notice the last comment on this stakOverflow post that bumped into the same problem).

Basically, I would like to modify the arc.js of d3-shape to be able to specify something like :

const arc = d3.arc()
    .innerRadius(0)
    .outerRadius(100)
    .startAngle(0)
    .endAngle(Math.PI / 2)
    .startPadAngle(0.03)
    .endPadAngle(0)

by default startPadAngle and endPadAngle should be equal to padAngle if not specified.

I have been giving a quick try in the source code here for exemple, but I don't understand all the mathematics... any help ?

Thanks!

@cittadhammo
Copy link
Author

For anyone interested, this modif works in arc.js https://github.com/cittadhammo/d3-shape/blob/main/src/arc.js

main new code:


 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
      if (rp > epsilon) {
        var p0s = asin(rp / r0 * sin(aps)),
            p0e = asin(rp / r0 * sin(ape)),
            p1s = asin(rp / r1 * sin(aps)),
            p1e = asin(rp / r1 * sin(ape));
        if ((da0 -= p0s+p0e) > epsilon) p0s *= (cw ? 1 : -1), a00 += p0s, a10 -= p0e;
        else da0 = 0, a00 = a10 = (a0 + a1) / 2;
        if ((da1 -= p1s+p1e) > epsilon) p1s *= (cw ? 1 : -1), a01 += p1s, a11 -= p1e;
        else da1 = 0, a01 = a11 = (a0 + a1) / 2;
      }

compiled d3.js with the modif here and a test page here,

@curran
Copy link
Contributor

curran commented May 25, 2023

Very nice!

@cittadhammo
Copy link
Author

@curran Do you think it is worth a Pull Request ?

@curran
Copy link
Contributor

curran commented May 25, 2023

Personally, I think so! This would make a nice addition to the library, and it seems to be a non-breaking change.

I'm not able to merge PRs as I'm not a maintainer here, but happy to review it and provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants