2018-02-05 11:30:18 +00:00
2018-02-02 10:07:04 +00:00
2017-11-07 21:33:16 +00:00
2017-11-07 21:33:16 +00:00
2018-02-02 12:19:17 +00:00
2018-01-31 19:28:15 +00:00
2018-02-02 10:48:48 +00:00
2018-02-02 12:17:03 +00:00

d3-spring-model

This module implements three force-directed layout algorithms to visualize high-dimensional data in 2D space.

  1. Basic spring model algorithm. In this model, every data point (node) pairs are connected with a spring that pushes or pulls, depending on the difference between 2D and high-dimensional distance. This is a tweaked version of D3's force link with functionalities removed to improve performance and lower the memory usage.
  2. Neighbour and Sampling algorithm. It uses stochastic sampling to find the best neighbours for high-dimensional data and creates the layout in 2 dimensions.
  3. Hybrid layout algorithm. It performs Neighbour and Sampling algorithm on a subset of data before interpolating the rest onto the 2D space. Neighbour and Sampling algorithm may also be run over the full dataset at the end to refine placement. During the interpolation, each node have to find a parent, a closest node that has already been plotted on the 2D space. Two methods of of finding the parents have been implemented.
    1. Bruteforce searching. This method takes more time but guaranteed that the parent found is the best one.
    2. Pivot-based searching. This method introduce a one-off pre-processing time but will make parent finding of each node faster. The parent found may not be the best one but should still be near enough to provide good results.

These algorithms are useful for producing visualizations that show relationships between the data. For instance:

Iris data set Part of Poker Hands data set

Authors

Pitchaya Boonsarngsuk

Based on d3-neighbour-sampling by Remigijus Bartasius and Matthew Chalmers under MIT license.

Based on d3-force by Mike Bostock under BSD 3-Clause license.

Reference

Usage

Download the latest release and load either the full and minified version alongside D3 4.0.

<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="d3-spring-model.min.js"></script>
<script>

var simulation = d3.forceSimulation(nodes);

</script>

File structure

  • index.js Export list of the module
  • src/ Source code of the module
  • package.json Node.js moudle descriptor with build scripts
  • img Images for this readme file
  • examples An example page running all the algorithms implemented

Building

npm run build  # Clean build folder and build the module into a single js file.
npm run minify # Minify the built js file.
npm run zip    # Zip built files and documents for release.

See package.json for more details.

API Reference

Spring Model

Neighbour and Sampling - TO REWRITE

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() <>

Initializes the Neighbour and Sampling algorithm with default parameters.

# neighbourSampling.id([id]) <>

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:

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]) <>

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:

function distance() {
  return 300;
}

# neighbourSampling.neighbourSize([neighbourSize]) <>

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]) <>

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() <>

Returns the stress of the layout.

# neighbourSampling.velocity() <>

Returns the average velocity of the iteration.

Hybrid Layout

Description
No description provided
Readme 12 MiB
2018-03-23 01:01:51 +07:00