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

How to plot a horizonal sugiyama graph #112

Closed
seahurt opened this issue Aug 11, 2023 · 1 comment
Closed

How to plot a horizonal sugiyama graph #112

seahurt opened this issue Aug 11, 2023 · 1 comment

Comments

@seahurt
Copy link

seahurt commented Aug 11, 2023

I am tring to plot a horizontally placed graph, but got a little problem.

Below is the original graph from https://codepen.io/brinkbot/pen/oNQwNRv
image

After swipe the x and y by following code(change from line 144):

var { height, width } = layout(graph);



function TransNode(node){
  console.log("transform", node.data)
  let tmp = node.ux;
  node.ux = node.uy;
  node.uy = tmp;
}

function TransGraph(g){
  let tmp = width;
  width = height;
  height = tmp;
  
  for (let node of g.nodes()){
    TransNode(node);
  }
  for (let link of g.links()){
    let points = [];
    points.push([link.source.ux, link.source.uy]);
    points.push([link.target.ux, link.target.uy]);
    link.points = points;
  }
}

TransGraph(graph);

The result graph become this:
image

It seems like the path between nodes differed. But I don't known how to make it work. Could you please help me?

Or is there an option to plot horizontally placed graph directly?

@erikbrinkman
Copy link
Owner

you probably missed all of the x's and y's. Fortunately, this is now built in in the form of a tweak.

When constructing the layout function, there's a line in the example:

  .tweaks([shape]);

All you need to do is add another tweak to flip it:

  .tweaks([shape, d3dag.tweakFlip()]);

The edges will still look a bit weird due to the spline interpolation of d3. To fix that, change

const line = d3.line().curve(d3.curveMonotoneY);

to

const line = d3.line().curve(d3.curveMonotoneX);

You should then see:
image

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

2 participants