d3.force-link-status
A very small module so you can stop thinking about certain repetetive
operations while managing d3js force directed graphs force.links()
array.
Example
Setup
Status
is designed to work with d3, although it should work for anything which
imnplements a similar API, meaning the force argument has a force#links
method which returns an incidince list of the edges in the graph. In any event,
you need a few things before we can et started:
var Status = d3 = /* A few parameters */var loops = false // node cannot link to itself directed = false // link from A to B == link from B to A multiedge = false // at most one link between nodes A and B. var s = loops directed multiedge var force = d3layout /* Supposing you've defined links and nodes somewhere. */force linkslinks_array var one_link = // a link another_link = // another link /* start the layout -- this gives the nodes an index. although their positions * wont update until the first tick. */forcestart
Checks
Checking for equality will respect your settings:
s
A method to easily find the index of the link in the force. Mimics the api of Array#indexOf api.
s
There is a convenient membership check:
s // -> true or false
And finally a method to count the number of times a link appears (useful when
multiedge == true
.
s
Literate source
Is very short and available here