nowthis / sankeymatic

Make Beautiful Flow Diagrams
http://sankeymatic.com/build/
ISC License
841 stars 122 forks source link

Add support for [*] operator #41

Open jsstylos opened 5 years ago

jsstylos commented 5 years ago

This addresses #32 and (partially) #21, adding support for the [*] operator. This doesn't need a direction arrow because only one side can be unconstrained, so we can infer which direction; if both sides are unconstrained then the graph is unsolvable regardless.

The inference algorithm used requires that at each stage there be at least one node with a single computed/unknown edge, but this can be anywhere in the graph. This enables support for inputs where the only constraint is in the middle of the graph, such as:

A [*] B
B [*] C
C [*] D
D [100] E
E [*] F
F [*] G

More useful input would be something like:

Work [2000] Paycheck
Paycheck [600] Taxes
Paycheck [*] Take-home
Take-home [800] Rent
Take-home [200] Food
Take-home [*] Savings
Rent [*] Spending
Food [*] Spending

image

The code could use some more testing and cleaning up, and has a known bug with generating console errors when given unsolvable input, but I'm putting the code up here for @nowthis and others to play around with.

Percentages would also be possible if this seems like a direction people are interested in.

jsstylos commented 5 years ago

I put up a (temporary) web version for people to play around with and give feedback: https://jsstylos-sankeymatic.mybluemix.net

waldyrious commented 5 years ago

Tested it with the following data, that visualizes a ranked voting process:

' == ROUND 1 ==
' Candidates that move to the next round with all their votes:
Ana r1 [25] Ana r2
Ben r1 [20] Ben r2
Che r1 [16] Che r2
' Second choices for the least voted candidate:
Dan r1 [5] Ana r2
Dan r1 [4] Ben r2
Dan r1 [2] None r2

' == ROUND 2 ==
' Candidates that move to the next round with all their votes:
Ana r2 [*] Ana r3
Ben r2 [*] Ben r3
' Second choices for the least voted candidate:
Che r2 [3] Ana r3
Che r2 [11] Ben r3
Che r2 [*] None r3

(Here's a version of the script with more detailed comments explaining the numbers.)

Works quite well! Here's the result:

sankeymatic_600x600

jonz-secops commented 2 years ago

was this ever integrated? asking since the web version and this repo are not in synch so hard to tell.

GoodnessJSON commented 1 year ago

This is a great suggestion!