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

Add horizontal alignment option to Sankey layout #4

Closed
wants to merge 6 commits into from

Conversation

vasturiano
Copy link

@vasturiano
Copy link
Author

Any interest in merging this functionality into a future tag of d3-sankey?

fbreitwieser added a commit to fbreitwieser/d3-sankey that referenced this pull request Oct 19, 2016
- has several modifications from networkD3 sankey.js
- included fixes and features from unmerged pull requests:
- d3/d3-plugins#124: Fix nodesByBreadth to have proper ordering
- - d3/d3-plugins#120: Added 'l-bezier' link type
- d3/d3-plugins#74: Sort sankey target links by descending slope
- d3#4: Add horizontal alignment option to Sankey layout
- added option numberFormat, default being ",.5g" (see , fixes
christophergandrud/networkD3#147)
- added option NodePosX, fixes christophergandrud/networkD3#108
- added option to force node ordering to be alphabetical along a path
(only works well with trees with one parent for each node, but might fix
christophergandrud/networkD3#153)
fbreitwieser added a commit to fbreitwieser/sankeyD3 that referenced this pull request Oct 19, 2016
Changelog:
 - ported to D3 v4
 - based on https://github.com/d3/d3-sankey
     - added several modifications from networkD3 sankey.js
     - included fixes and features from unmerged pull requests:
       - d3/d3-plugins#124: Fix nodesByBreadth to have proper ordering
       - d3/d3-plugins#120: Added 'l-bezier' link type
       - d3/d3-plugins#74: Sort sankey target links by descending slope
       - d3/d3-sankey#4: Add horizontal alignment option to Sankey layout
 - added option numberFormat, default being ",.5g" (see , fixesristophergandrud/networkD3#147)
 - added option NodePosX, fixes christophergandrud/networkD3#108
 - added option to force node ordering to be alphabetical along a path (only works well with trees with one parent for each node, but might fix christophergandrud/networkD3#153)
@balthazar
Copy link

Sorry for the annoying bump, I'm wondering what's preventing this from being merged given @emeeks positive review. Does anyone has push access and access to the npm package?

@cirofdo
Copy link

cirofdo commented Feb 24, 2017

How can I use this? I built my Sankey based on the original one with sankey.js (the d3 v4).

I want the left aligment without the buttons choice, I want it to be like this:
sankey_goal

@vasturiano
Copy link
Author

vasturiano commented Feb 24, 2017

@thebiro to get the left alignment mode, you just need to set .align('left') on the Sankey object, i.e.:

var mySankey = d3.sankey()
    .nodeWidth(15)
    .nodePadding(10)
    .align('left')

You do need to be using the code in this PR, until it is merged into d3-sankey master.

@xaranke anything I can help with to prioritize this merge?

@vasturiano
Copy link
Author

@emeeks seems this PR is still open. Is there interest in merging this additional functionality upstream? If so, just let me know if there's anything else I can help with.

@mbostock
Copy link
Member

Neat!

The main thing this PR needs is to switch from strings to symbols to identify the alignment method. (See d3/d3-shape#23 for a long thread that led to the current design of D3 4.0.) The simplest instantiation of this would be to define opaque objects ({}) that represent the four choices: d3.sankeyLeft, d3.sankeyCenter, d3.sankeyRight, d3.sankeyJustify. Then you pass the appropriate object to sankey.align instead of a string.

What would be better than opaque objects would be to consider whether these alignment options could be represented more generally as a function that takes a node as input and returns the desired horizontal position. I think the most natural choice would be that the function returns the topological “depth” or “height” of the node, where 0 typically represents nodes with no inputs (the leftmost column in the conventional orientation), 1 represents the immediate outputs of 0 (the next column to the right in the conventional orientation), etc.

@mbostock mbostock closed this in e4475b1 Jun 13, 2017
@mbostock
Copy link
Member

Okay, this is now implemented as sankey.nodeAlign. This method takes a function, and the four alignment methods proposed by @vasturiano are implemented:

d3.sankeyCenter
align-center

d3.sankeyLeft
align-left

d3.sankeyRight
align-right

d3.sankeyJustify (default)
energy

To implement d3.sankeyRight, I also now populate a node.height field. (See d3.hierarchy for precedent.) It occurs to me that this might be useful for d3.sankeyCenter and d3.sankeyJustify…

@vasturiano
Copy link
Author

Thanks @mbostock, this is great! Much cleaner with the symbols approach.

antoinerg referenced this pull request in plotly/d3-sankey Jan 29, 2019
antoinerg referenced this pull request in plotly/d3-sankey Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants