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

curved edges/paths #305

Closed
tzookb opened this issue Jan 17, 2018 · 14 comments
Closed

curved edges/paths #305

tzookb opened this issue Jan 17, 2018 · 14 comments

Comments

@tzookb
Copy link

tzookb commented Jan 17, 2018

Tried to go over the docs and google but could not find nothing :/

the only thing similar is this:

graph.setEdge("D", "Z", {
    label: "A to zppppp",
    labelStyle: "font-style: italic; text-decoration: underline;",
    lineInterpolate: 'basis'
  });

but it didnt curved my edge, any ideas?

thanks!

@sunlisha
Copy link

sunlisha commented Jan 17, 2018

Latest version of dagre-d3 got updated to D3.js v4: See ebbb84f.

Instead of lineInterpolate: 'basis' use lineCurve: d3.curveBasis.

This took me a while to figure out also.

@lutzroeder lutzroeder reopened this Jan 17, 2018
lutzroeder added a commit that referenced this issue Jan 18, 2018
Change edge.lineCurve to edge.curve to match D3.js and update samples (#305)
@lutzroeder
Copy link
Contributor

In dagre-d3 v0.6.1 this will change to curve: d3.curveBasis and samples will be updated to use the new approach.

@tzookb
Copy link
Author

tzookb commented Jan 18, 2018

worked like a charm!

thanks guys!!

@tzookb
Copy link
Author

tzookb commented Feb 2, 2018

Hey guys

another question you probably know.

I love the above solution for the arrow, but if I want a different curved style arrow like this image:

any idea how I can achieve that?

Thanks in advance!!

aaa

@cpettitt
Copy link
Collaborator

cpettitt commented Feb 2, 2018

It looks like what you want is orthogonal routing of the edge, which is not something currently supported by dagre.

@tzookb
Copy link
Author

tzookb commented Feb 2, 2018

Thanks @cpettitt

I noticed I can pass in a function to the lineCurve
and I see the path, but can't wrap my head around of what to do with it.

like this:

{
    lineCurve: context => {
        console.log(context);
        return new d3.curveBasis(context);
    }
}
Path:
_: "M518.6015625,120.0625L518.6015625,120.0625C518.6015625,120.0625,518.6015625,120.0625,518.6015625,120.0625C518.6015625,120.0625,518.6015625,120.0625,518.6015625,120.0625L518.6015625,120.0625",
_x0: 518.6015625,
_x1: 518.6015625,
_y0: 120.0625,
_y1: 120.0625

@cpettitt
Copy link
Collaborator

cpettitt commented Feb 2, 2018 via email

@tzookb
Copy link
Author

tzookb commented Feb 2, 2018

Thanks @cpettitt

it looks great, but I want to keep using Dagre-D3

and it seems like I can pass the lineCurve

I could probably go find the points and connect them by myself, but surely there is a better way :/

@sateesh2499
Copy link

@tzookb did you find any way to create custom curves?

@tzookb
Copy link
Author

tzookb commented Jun 5, 2018

Sorry @sateesh2499

I moved from Dagre
I'm outputting a tree with d3 graph

@sateesh2499
Copy link

Okay. Thanks @tzookb

@gnganapath
Copy link

It's working at Angular 7 component mapping also. g.setEdge(sourceEdge, targetEdge, { curve: d3.curveBasis });

@herzaso
Copy link

herzaso commented Dec 25, 2019

It's a bit old but for future reference, here's how I handled it:

Create a curve function:

const BezierCurve = (context) => ({
  lineStart() {
    this.data = [];
  },

  point(x, y) {
    this.data.push([x, y]);
  },

  lineEnd() {
    const [x0, y0] = this.data[0];
    const [cp1x, cp1y] = this.data[1];
    const [cp2x, cp2y] = this.data[this.data.length - 2];
    const [x1, y1] = this.data[this.data.length - 1];
    context.moveTo(x0, y0);
    context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x1, y1);
  },
});

Assign the curve function to the edges:

g.setEdge(from, to, { curve: BezierCurve });

@hijoncon
Copy link

hijoncon commented Nov 7, 2020

@herzaso any tips or idea to convert bezierCurveTo for arcTo?

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

No branches or pull requests

8 participants