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

Support custom X-axis positioning of the nodes #78

Open
dcupif opened this issue Aug 20, 2020 · 5 comments
Open

Support custom X-axis positioning of the nodes #78

dcupif opened this issue Aug 20, 2020 · 5 comments

Comments

@dcupif
Copy link

dcupif commented Aug 20, 2020

Hi, thank you for this great library.

For a specific use case, we'd need to position nodes on the X-axis according to a D3 time scale. It does not seem possible as of now considering the horizontal positioning of the nodes is governed by the nodes' depth.

Would it be in the scope of this library to support such use case? If not, would you have any hints/suggestions towards implementing a solution?

We are willing to help working on a solution. 😃

@dcupif
Copy link
Author

dcupif commented Aug 20, 2020

@bella-kpler fyi

@mvdobrinin
Copy link

mvdobrinin commented Oct 4, 2020

@dcupif Can you use custom align function?

const i = Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x))));

This should control the X axis positioning of the nodes based on columns that they belong to.

@kayecandy
Copy link

@dcupif Can you use custom align function?

const i = Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x))));

This should control the X axis positioning of the nodes based on columns that they belong to.

Thanks for the advice! To add to this answer, this is how I did it:

sankey = d3.sankey()
  /* ... */
  .nodeAlign((node, n)=>{
      return node.customX ? node.customX : d3.sankeyJustify(node, n) // sankeyJustify can be changed to any nodeAlign() functions
  })
  /* ... */

@NPC
Copy link

NPC commented Feb 4, 2021

Unfortunatelly it doesn't seem to work if your custom scale for whatever reason extends beyond the already calculated max depth (passed as “n” into the alignment function).

I'll keep experimenting, but seems like at the very least after the alignment is done max depth should be updated for the chart to be drawn properly. This would provide more flexibility to the calling code.

@NoPodi
Copy link

NoPodi commented Apr 27, 2021

@dcupif Can you use custom align function?

const i = Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x))));

This should control the X axis positioning of the nodes based on columns that they belong to.

Thanks for the advice! To add to this answer, this is how I did it:

sankey = d3.sankey()
  /* ... */
  .nodeAlign((node, n)=>{
      return node.customX ? node.customX : d3.sankeyJustify(node, n) // sankeyJustify can be changed to any nodeAlign() functions
  })
  /* ... */

node.customX ? could lead to an issue because if node.customX = 0 then this would jump into the else branch too

var x = 0; x === true; ==> false

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

5 participants