-
Notifications
You must be signed in to change notification settings - Fork 27
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
Added custom yOrderComparator function for vertical ordering of nodes #16
Conversation
Thanks for the contribution @bragil-massoud , I think that's a useful feature! |
You're welcome! Thanks for the package, I will use it a lot going forward. |
Hi Simon, could you provide a quick demonstration how to use the |
An example would be the following function - it simply prioritizes nodes with a specific name and the sorts as the default (with orderByPath = false) would.
|
Hi, sorry I am late and also afraid I still don't understand. links <- data.frame(
source = c(0, 0, 0, 1, 2, 3, 4, 4),
target = c(1, 2, 3, 4, 4, 4, 5, 6),
value = c(2, 3, 4, 2, 3 , 4, 4, 5)
)
nodes <- data.frame(
label = c("A1", "B1", "B3", "B2", "C1", "D1", "D2"),
yOrder = c(1, 1, 3, 2, 1, 1, 2)
)
sankeyD3::sankeyNetwork(
Links = links,
Nodes = nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "label",
# yOrderComparator = ?,
fontFamily = "Arial",
numberFormat = ",.1s",
fontSize = 12) As you can see I have a |
Hi @SchmidtPaul , I would use however I am not entirely sure I understand the expected order of the B* components in the reprex correctly. Does this work for you? Cheers, |
Hi @simon-tietze thanks for replying! However, it seems it still does not work as I intended. While B1 is now on top, B3 is not on the bottom? ...then again D1 and D2 are correct. I feel like I missing something here. links <- data.frame(
source = c(0, 0, 0, 1, 2, 3, 4, 4),
target = c(1, 2, 3, 4, 4, 4, 5, 6),
value = c(2, 3, 4, 2, 3 , 4, 4, 5)
)
nodes <- data.frame(
label = c("A1", "B1", "B3", "B2", "C1", "D1", "D2"),
yOrder = c(1, 1, 3, 2, 1, 1, 2)
)
sankeyD3::sankeyNetwork(
Links = links,
Nodes = nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "label",
yOrderComparator = htmlwidgets::JS("function(a, b) { return a.yOrder - b.yOrder; }"),
fontFamily = "Arial",
numberFormat = ",.1s",
fontSize = 12) |
Added a parameter to pass a custom node comparator function down to sankey-d3. Also had to change the included sankey-d3 code to actually use the comparator function.
Could help #2 and #6 if I understand them correctly.