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

Changing stack order #9

Closed
dpanster opened this issue Nov 19, 2020 · 8 comments · Fixed by #18
Closed

Changing stack order #9

dpanster opened this issue Nov 19, 2020 · 8 comments · Fixed by #18
Labels
enhancement New feature or request

Comments

@dpanster
Copy link

Hi,

is there a possibility to force a custom stack ordering at a vertical bar group? For example: Set an priority index within a dataset property property?
Like this (with the result, that "Oil" is on top, middle "Coal", bottom "Natural Gas" in the left bar. With highest priority number is on top.):
Unbenannt


Currently the element with the highest value is at the top.

Btw: Very cool library. Good work.

@kurkle
Copy link
Owner

kurkle commented Nov 19, 2020

This would probably be quite useful feature and should not be too hard to implement.
I think that's all that would need to be altered (in addition to reading the options):

export function sortFlows(nodeArray) {
nodeArray.forEach(node => {
let addY = 0;
node.from.sort((a, b) => (a.node.y + a.node.out / 2) - (b.node.y + b.node.out / 2)).forEach(flow => {
flow.addY = addY;
addY += flow.flow;
});
addY = 0;
node.to.sort((a, b) => (a.node.y + a.node.in / 2) - (b.node.y + b.node.in / 2)).forEach(flow => {
flow.addY = addY;
addY += flow.flow;
});
});
}

Btw: Very cool library. Good work.

Thanks ❤️

@kurkle kurkle added the enhancement New feature or request label Nov 19, 2020
@kurkle
Copy link
Owner

kurkle commented Nov 19, 2020

No, I'm actually wrong, its not that simple.

The current layout process starts by finding the largest node (bar). And that is placed at y=0. Then it starts iterating the flows left and right, ordering by node count behind each flow. Finally it places anything that was not yet placed in similar manner. After bars are placed, flows from/to each bar are ordered by the above sortFlows.

I think it would be better and easier to implement another layout mode for this.

@dpanster
Copy link
Author

Thanks for your quick response and for trying to implement this feature. Have a nice day.

@musicaldoctor
Copy link

+1 (I think)

We're doing this sankey chart on COVID-19 to track counties and their risk tiers through lockdowns:

image

And we're not being able to make sure the green bar always stays on top on the fourth iteration, and make sure we control the order of all those stacks on each iteration. Also, can't figure out how to change labels (without changing the JSON source file that feeds the chart).

@kurkle
Copy link
Owner

kurkle commented Feb 10, 2021

Initial implementation released in v0.3.0

// the y-order of nodes, smaller = higher
var priority = {
  Oil: 1,
  'Narural Gas': 2,
  Coal: 3,
  'Fossil Fuels': 1,
  Electricity: 2,
  Energy: 1
};

image

@musicaldoctor
Copy link

musicaldoctor commented Feb 11, 2021

awesome! is it possible to hide those labels or change them through some sort of callback? if so, how? thanks

EDIT: and also, is it possible to remover that black border from the stacks?

image

@kurkle
Copy link
Owner

kurkle commented Feb 11, 2021

@musicaldoctor added labels (similar to priority), borderWidth and borderColor. These are released in v0.3.2.

Edit: Forgot to mention nodeWidth. This one is not tested though :). Default is 10.

@dpanster
Copy link
Author

Well done. Thank You :)

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

Successfully merging a pull request may close this issue.

3 participants