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

tree and gradient #1978

Open
Fil opened this issue Jan 30, 2024 · 0 comments
Open

tree and gradient #1978

Fil opened this issue Jan 30, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Fil
Copy link
Contributor

Fil commented Jan 30, 2024

Using Plot.tree with a gradient stroke fails on links that are purely horizontal:

Capture d’écran 2024-01-30 à 13 35 38

The bug (reported by @Pixflowave) is due to the infamous browser issue that an horizontal path has height 0, and thus the gradient is optimized out. (This issue is also often hitting d3-sankey users, d3/d3-sankey#28.)

A way to fix this is to always add some points in any path, to guarantee that the bounding-box’s area is not 0.

For example, one could use: curve: bbCurve(d3.curveBumpX)

where:

function bbCurve (curve) {
  return (context) => {
    const c = curve(context);
    const { point, lineEnd } = c;
    let x0, y0;
    return Object.assign(c, {
      point(x, y) {
        point.call(this, (x0 = x), (y0 = y));
      },
      lineEnd() {
        this._context.moveTo(x0 - 0.1, y0);
        this._context.moveTo(x0, y0 + 0.1);
        lineEnd.call(this);
      }
    });
  };
}

Capture d’écran 2024-01-30 à 13 35 52

Not sure if this should be done in Plot, as an option of d3 curves, or somewhere else?

@Fil Fil added the enhancement New feature or request label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant