# d3-spring-model This module implements Chalmers' 1996 Neighbour and Sampling algorithm for drawing the force-directed layouts. It is a linear time algorithm that uses stochastic sampling to find the best neighbours for high-dimensional data and creates the layout in 2 dimensions. Neighbour and Sampling algorithm is useful for producing visualizations that show relationships between the data. For instance: ![fsmvis data set](https://raw.githubusercontent.com/sReeper/d3-neighbour-sampling/master/img/chalmers-fsmvis.PNG)![Poker Hands data set](https://raw.githubusercontent.com/sReeper/d3-neighbour-sampling/master/img/chalmers-poker.PNG) ### Authors Remigijus Bartasius and Matthew Chalmers ### Reference - Chalmers, Matthew. ["A linear iteration time layout algorithm for visualising high-dimensional data."](http://dl.acm.org/citation.cfm?id=245035) Proceedings of the 7th conference on Visualization'96. IEEE Computer Society Press, 1996. ## Usage Download the [latest release](https://git.win32exe.tech/brian/d3-spring-model/releases) and load one of Javascript file alongside [D3 4.0](https://github.com/d3/d3). ```html ``` ## API Reference #### NeighbourSampling The Neighbour and Sampling algorithm tries to group the nodes based on the distance between them. If the nodes have a low distance, then the force attracts them to each other. If the nodes have a high distance, then the repulsive force pushes them further apart from each other. In order for it to work properly, a distance function should be specified. # d3.forceNeighbourSampling() [<>](src/neighbourSampling.js "Source") Initializes the Neighbour and Sampling algorithm with default parameters. # neighbourSampling.id([id]) [<>](src/neighbourSampling.js#L218 "Source") If *id* is specified, sets the node id accessor to the specified function and returns this force. If *id* is not specified, returns the current node id accessor, which defaults to the numeric *node*.index: ```js function id(d) { return d.index; } ``` The id accessor is invoked for each node whenever the force is initialized, as when the nodes change, being passed the node and its zero-based index. # neighbourSampling.distance([distance]) [<>](https://github.com/sReeper/d3-neighbour-sampling/blob/master/src/neighbourSampling.js#L230 "Source") If *distance* is specified, sets the distance accessor to the specified number or function, re-evaluates the distance accessor for each link, and returns this force. If *distance* is not specified, returns the current distance accessor, which defaults to: ```js function distance() { return 300; } ``` # neighbourSampling.neighbourSize([neighbourSize]) [<>](src/neighbourSampling.js#L222 "Source") If *neighbourSize* is specified, sets the neighbour set size to the specified number and returns this force. If *neighbourSize* is not specified, returns the current value, which defaults to 6. # neighbourSampling.sampleSize([sampleSize]) [<>](https://github.com/sReeper/d3-neighbour-sampling/blob/master/src/neighbourSampling.js#L226 "Source") If *sampleSize* is specified, sets the sample set size to the specified number and returns this force. If *sampleSize* is not specified, returns the current value, which defaults to 3. # neighbourSampling.stress() [<>](https://github.com/sReeper/d3-neighbour-sampling/blob/master/src/neighbourSampling.js#L234 "Source") Returns the stress of the layout. # neighbourSampling.velocity() [<>](https://github.com/sReeper/d3-neighbour-sampling/blob/master/src/neighbourSampling.js#L238 "Source") Returns the average velocity of the iteration.