Commit f064c792 authored by Muddsair Sharif's avatar Muddsair Sharif
Browse files

Initial commit

parents
Pipeline #8 canceled with stages
{
"_args": [
[
{
"raw": "d3-ease@1.0.3",
"scope": null,
"escapedName": "d3-ease",
"name": "d3-ease",
"rawSpec": "1.0.3",
"spec": "1.0.3",
"type": "version"
},
"C:\\Users\\Giuliano\\worldwind\\nasaworldwind\\node\\node_modules\\d3"
]
],
"_from": "d3-ease@1.0.3",
"_id": "d3-ease@1.0.3",
"_inCache": true,
"_location": "/d3-ease",
"_nodeVersion": "7.3.0",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/d3-ease-1.0.3.tgz_1489169213998_0.5961549214553088"
},
"_npmUser": {
"name": "mbostock",
"email": "mike@ocks.org"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"raw": "d3-ease@1.0.3",
"scope": null,
"escapedName": "d3-ease",
"name": "d3-ease",
"rawSpec": "1.0.3",
"spec": "1.0.3",
"type": "version"
},
"_requiredBy": [
"/d3",
"/d3-transition"
],
"_resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-1.0.3.tgz",
"_shasum": "68bfbc349338a380c44d8acc4fbc3304aa2d8c0e",
"_shrinkwrap": null,
"_spec": "d3-ease@1.0.3",
"_where": "C:\\Users\\Giuliano\\worldwind\\nasaworldwind\\node\\node_modules\\d3",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"bugs": {
"url": "https://github.com/d3/d3-ease/issues"
},
"dependencies": {},
"description": "Easing functions for smooth animation.",
"devDependencies": {
"eslint": "3",
"package-preamble": "0.0",
"rollup": "0.41",
"tape": "4",
"uglify-js": "^2.8.11"
},
"directories": {},
"dist": {
"shasum": "68bfbc349338a380c44d8acc4fbc3304aa2d8c0e",
"tarball": "https://registry.npmjs.org/d3-ease/-/d3-ease-1.0.3.tgz"
},
"gitHead": "f1e8d630b58f5b935b7995f0c417de257b08be52",
"homepage": "https://d3js.org/d3-ease/",
"jsnext:main": "index",
"keywords": [
"d3",
"d3-module",
"ease",
"easing",
"animation",
"transition"
],
"license": "BSD-3-Clause",
"main": "build/d3-ease.js",
"maintainers": [
{
"name": "mbostock",
"email": "mike@ocks.org"
}
],
"module": "index",
"name": "d3-ease",
"optionalDependencies": {},
"readme": "# d3-ease\n\n*Easing* is a method of distorting time to control apparent motion in animation. It is most commonly used for [slow-in, slow-out](https://en.wikipedia.org/wiki/12_basic_principles_of_animation#Slow_In_and_Slow_Out). By easing time, [animated transitions](https://github.com/d3/d3-transition) are smoother and exhibit more plausible motion.\n\nThe easing types in this module implement the [ease method](#ease_ease), which takes a normalized time *t* and returns the corresponding “eased” time *tʹ*. Both the normalized time and the eased time are typically in the range [0,1], where 0 represents the start of the animation and 1 represents the end; some easing types, such as [elastic](#easeElastic), may return eased times slightly outside this range. A good easing type should return 0 if *t* = 0 and 1 if *t* = 1. See the [easing explorer](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4) for a visual demonstration.\n\nThese easing types are largely based on work by [Robert Penner](http://robertpenner.com/easing/).\n\n## Installing\n\nIf you use NPM, `npm install d3-ease`. Otherwise, download the [latest release](https://github.com/d3/d3-ease/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-ease.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:\n\n```html\n<script src=\"https://d3js.org/d3-ease.v1.min.js\"></script>\n<script>\n\nvar ease = d3.easeCubic;\n\n</script>\n```\n\n[Try d3-ease in your browser.](https://tonicdev.com/npm/d3-ease)\n\n## API Reference\n\n<a name=\"_ease\" href=\"#_ease\">#</a> <i>ease</i>(<i>t</i>)\n\nGiven the specified normalized time *t*, typically in the range [0,1], returns the “eased” time *tʹ*, also typically in [0,1]. 0 represents the start of the animation and 1 represents the end. A good implementation returns 0 if *t* = 0 and 1 if *t* = 1. See the [easing explorer](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4) for a visual demonstration. For example, to apply [cubic](#easeCubic) easing:\n\n```js\nvar te = d3.easeCubic(t);\n```\n\nSimilarly, to apply custom [elastic](#easeElastic) easing:\n\n```js\n// Before the animation starts, create your easing function.\nvar customElastic = d3.easeElastic.period(0.4);\n\n// During the animation, apply the easing function.\nvar te = customElastic(t);\n```\n\n<a name=\"easeLinear\" href=\"#easeLinear\">#</a> d3.<b>easeLinear</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/linear.js \"Source\")\n\nLinear easing; the identity function; *linear*(*t*) returns *t*.\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/linear.png\" alt=\"linear\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#linear)\n\n<a name=\"easePolyIn\" href=\"#easePolyIn\">#</a> d3.<b>easePolyIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/poly.js#L3 \"Source\")\n\nPolynomial easing; raises *t* to the specified [exponent](#poly_exponent). If the exponent is not specified, it defaults to 3, equivalent to [cubicIn](#easeCubicIn).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/polyIn.png\" alt=\"polyIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#polyIn)\n\n<a name=\"easePolyOut\" href=\"#easePolyOut\">#</a> d3.<b>easePolyOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/poly.js#L15 \"Source\")\n\nReverse polynomial easing; equivalent to 1 - [polyIn](#easePolyIn)(1 - *t*). If the [exponent](#poly_exponent) is not specified, it defaults to 3, equivalent to [cubicOut](#easeCubicOut).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/polyOut.png\" alt=\"polyOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#polyOut)\n\n<a name=\"easePoly\" href=\"#easePoly\">#</a> d3.<b>easePoly</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/poly.js \"Source\")\n<br><a name=\"easePolyInOut\" href=\"#easePolyInOut\">#</a> d3.<b>easePolyInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/poly.js#L27 \"Source\")\n\nSymmetric polynomial easing; scales [polyIn](#easePolyIn) for *t* in [0, 0.5] and [polyOut](#easePolyOut) for *t* in [0.5, 1]. If the [exponent](#poly_exponent) is not specified, it defaults to 3, equivalent to [cubic](#easeCubic).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/polyInOut.png\" alt=\"polyInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#polyInOut)\n\n<a name=\"poly_exponent\" href=\"#poly_exponent\">#</a> <i>poly</i>.<b>exponent</b>(<i>e</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/poly.js#L1 \"Source\")\n\nReturns a new polynomial easing with the specified exponent *e*. For example, to create equivalents of [linear](#easeLinear), [quad](#easeQuad), and [cubic](#easeCubic):\n\n```js\nvar linear = d3.easePoly.exponent(1),\n quad = d3.easePoly.exponent(2),\n cubic = d3.easePoly.exponent(3);\n```\n\n<a name=\"easeQuadIn\" href=\"#easeQuadIn\">#</a> d3.<b>easeQuadIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/quad.js#L1 \"Source\")\n\nQuadratic easing; equivalent to [polyIn](#easePolyIn).[exponent](#poly_exponent)(2).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/quadIn.png\" alt=\"quadIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#quadIn)\n\n<a name=\"easeQuadOut\" href=\"#easeQuadOut\">#</a> d3.<b>easeQuadOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/quad.js#L5 \"Source\")\n\nReverse quadratic easing; equivalent to 1 - [quadIn](#easeQuadIn)(1 - *t*). Also equivalent to [polyOut](#easePolyOut).[exponent](#poly_exponent)(2).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/quadOut.png\" alt=\"quadOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#quadOut)\n\n<a name=\"easeQuad\" href=\"#easeQuad\">#</a> d3.<b>easeQuad</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/quad.js \"Source\")\n<br><a name=\"easeQuadInOut\" href=\"#easeQuadInOut\">#</a> d3.<b>easeQuadInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/quad.js#L9 \"Source\")\n\nSymmetric quadratic easing; scales [quadIn](#easeQuadIn) for *t* in [0, 0.5] and [quadOut](#easeQuadOut) for *t* in [0.5, 1]. Also equivalent to [poly](#easePoly).[exponent](#poly_exponent)(2).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/quadInOut.png\" alt=\"quadInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#quadInOut)\n\n<a name=\"easeCubicIn\" href=\"#easeCubicIn\">#</a> d3.<b>easeCubicIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/cubic.js#L1 \"Source\")\n\nCubic easing; equivalent to [polyIn](#easePolyIn).[exponent](#poly_exponent)(3).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/cubicIn.png\" alt=\"cubicIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#cubicIn)\n\n<a name=\"easeCubicOut\" href=\"#easeCubicOut\">#</a> d3.<b>easeCubicOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/cubic.js#L5 \"Source\")\n\nReverse cubic easing; equivalent to 1 - [cubicIn](#easeCubicIn)(1 - *t*). Also equivalent to [polyOut](#easePolyOut).[exponent](#poly_exponent)(3).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/cubicOut.png\" alt=\"cubicOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#cubicOut)\n\n<a name=\"easeCubic\" href=\"#easeCubic\">#</a> d3.<b>easeCubic</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/cubic.js \"Source\")\n<br><a name=\"easeCubicInOut\" href=\"#easeCubicInOut\">#</a> d3.<b>easeCubicInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/cubic.js#L9 \"Source\")\n\nSymmetric cubic easing; scales [cubicIn](#easeCubicIn) for *t* in [0, 0.5] and [cubicOut](#easeCubicOut) for *t* in [0.5, 1]. Also equivalent to [poly](#easePoly).[exponent](#poly_exponent)(3).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/cubicInOut.png\" alt=\"cubicInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#cubicInOut)\n\n<a name=\"easeSinIn\" href=\"#easeSinIn\">#</a> d3.<b>easeSinIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/sin.js#L4 \"Source\")\n\nSinusoidal easing; returns sin(*t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/sinIn.png\" alt=\"sinIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#sinIn)\n\n<a name=\"easeSinOut\" href=\"#easeSinOut\">#</a> d3.<b>easeSinOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/sin.js#L8 \"Source\")\n\nReverse sinusoidal easing; equivalent to 1 - [sinIn](#easeSinIn)(1 - *t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/sinOut.png\" alt=\"sinOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#sinOut)\n\n<a name=\"easeSin\" href=\"#easeSin\">#</a> d3.<b>easeSin</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/sin.js \"Source\")\n<br><a name=\"easeSinInOut\" href=\"#easeSinInOut\">#</a> d3.<b>easeSinInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/sin.js#L12 \"Source\")\n\nSymmetric sinusoidal easing; scales [sinIn](#easeSinIn) for *t* in [0, 0.5] and [sinOut](#easeSinOut) for *t* in [0.5, 1].\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/sinInOut.png\" alt=\"sinInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#sinInOut)\n\n<a name=\"easeExpIn\" href=\"#easeExpIn\">#</a> d3.<b>easeExpIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/exp.js#L1 \"Source\")\n\nExponential easing; raises 2 to the exponent 10 \\* (*t* - 1).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/expIn.png\" alt=\"expIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#expIn)\n\n<a name=\"easeExpOut\" href=\"#easeExpOut\">#</a> d3.<b>easeExpOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/exp.js#L5 \"Source\")\n\nReverse exponential easing; equivalent to 1 - [expIn](#easeExpIn)(1 - *t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/expOut.png\" alt=\"expOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#expOut)\n\n<a name=\"easeExp\" href=\"#easeExp\">#</a> d3.<b>easeExp</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/exp.js \"Source\")\n<br><a name=\"easeExpInOut\" href=\"#easeExpInOut\">#</a> d3.<b>easeExpInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/exp.js#L9 \"Source\")\n\nSymmetric exponential easing; scales [expIn](#easeExpIn) for *t* in [0, 0.5] and [expOut](#easeExpOut) for *t* in [0.5, 1].\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/expInOut.png\" alt=\"expInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#expInOut)\n\n<a name=\"easeCircleIn\" href=\"#easeCircleIn\">#</a> d3.<b>easeCircleIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/circle.js#L1 \"Source\")\n\nCircular easing.\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/circleIn.png\" alt=\"circleIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#circleIn)\n\n<a name=\"easeCircleOut\" href=\"#easeCircleOut\">#</a> d3.<b>easeCircleOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/circle.js#L5 \"Source\")\n\nReverse circular easing; equivalent to 1 - [circleIn](#easeCircleIn)(1 - *t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/circleOut.png\" alt=\"circleOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#circleOut)\n\n<a name=\"easeCircle\" href=\"#easeCircle\">#</a> d3.<b>easeCircle</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/circle.js \"Source\")\n<br><a name=\"easeCircleInOut\" href=\"#easeCircleInOut\">#</a> d3.<b>easeCircleInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/circle.js#L9 \"Source\")\n\nSymmetric circular easing; scales [circleIn](#easeCircleIn) for *t* in [0, 0.5] and [circleOut](#easeCircleOut) for *t* in [0.5, 1].\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/circleInOut.png\" alt=\"circleInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#circleInOut)\n\n<a name=\"easeElasticIn\" href=\"#easeElasticIn\">#</a> d3.<b>easeElasticIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/elastic.js#L5 \"Source\")\n\nElastic easing, like a rubber band. The [amplitude](#elastic_amplitude) and [period](#elastic_period) of the oscillation are configurable; if not specified, they default to 1 and 0.3, respectively.\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/elasticIn.png\" alt=\"elasticIn\" width=\"100%\" height=\"360\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#elasticIn)\n\n<a name=\"easeElastic\" href=\"#easeElastic\">#</a> d3.<b>easeElastic</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/elastic.js \"Source\")\n<br><a name=\"easeElasticOut\" href=\"#easeElasticOut\">#</a> d3.<b>easeElasticOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/elastic.js#L18 \"Source\")\n\nReverse elastic easing; equivalent to 1 - [elasticIn](#easeElasticIn)(1 - *t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/elasticOut.png\" alt=\"elasticOut\" width=\"100%\" height=\"360\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#elasticOut)\n\n<a name=\"easeElasticInOut\" href=\"#easeElasticInOut\">#</a> d3.<b>easeElasticInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/elastic.js#L31 \"Source\")\n\nSymmetric elastic easing; scales [elasticIn](#easeElasticIn) for *t* in [0, 0.5] and [elasticOut](#easeElasticOut) for *t* in [0.5, 1].\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/elasticInOut.png\" alt=\"elasticInOut\" width=\"100%\" height=\"360\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#elasticInOut)\n\n<a name=\"elastic_amplitude\" href=\"#elastic_amplitude\">#</a> <i>elastic</i>.<b>amplitude</b>(<i>a</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/elastic.js#L40 \"Source\")\n\nReturns a new elastic easing with the specified amplitude *a*.\n\n<a name=\"elastic_period\" href=\"#elastic_period\">#</a> <i>elastic</i>.<b>period</b>(<i>p</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/elastic.js#L41 \"Source\")\n\nReturns a new elastic easing with the specified period *p*.\n\n<a name=\"easeBackIn\" href=\"#easeBackIn\">#</a> d3.<b>easeBackIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/back.js#L3 \"Source\")\n\n[Anticipatory](https://en.wikipedia.org/wiki/12_basic_principles_of_animation#Anticipation) easing, like a dancer bending his knees before jumping off the floor. The degree of [overshoot](#back_overshoot) is configurable; it not specified, it defaults to 1.70158.\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/backIn.png\" alt=\"backIn\" width=\"100%\" height=\"300\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#backIn)\n\n<a name=\"easeBackOut\" href=\"#easeBackOut\">#</a> d3.<b>easeBackOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/back.js#L15 \"Source\")\n\nReverse anticipatory easing; equivalent to 1 - [backIn](#easeBackIn)(1 - *t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/backOut.png\" alt=\"backOut\" width=\"100%\" height=\"300\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#backOut)\n\n<a name=\"easeBack\" href=\"#easeBack\">#</a> d3.<b>easeBack</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/back.js \"Source\")\n<br><a name=\"easeBackInOut\" href=\"#easeBackInOut\">#</a> d3.<b>easeBackInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/back.js#L27 \"Source\")\n\nSymmetric anticipatory easing; scales [backIn](#easeBackIn) for *t* in [0, 0.5] and [backOut](#easeBackOut) for *t* in [0.5, 1].\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/backInOut.png\" alt=\"backInOut\" width=\"100%\" height=\"300\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#backInOut)\n\n<a name=\"back_overshoot\" href=\"#back_overshoot\">#</a> <i>back</i>.<b>overshoot</b>(<i>s</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/back.js#L1 \"Source\")\n\nReturns a new back easing with the specified overshoot *s*.\n\n<a name=\"easeBounceIn\" href=\"#easeBounceIn\">#</a> d3.<b>easeBounceIn</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/bounce.js#L12 \"Source\")\n\nBounce easing, like a rubber ball.\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/bounceIn.png\" alt=\"bounceIn\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#bounceIn)\n\n<a name=\"easeBounce\" href=\"#easeBounce\">#</a> d3.<b>easeBounce</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/bounce.js \"Source\")\n<br><a name=\"easeBounceOut\" href=\"#easeBounceOut\">#</a> d3.<b>easeBounceOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/bounce.js#L16 \"Source\")\n\nReverse bounce easing; equivalent to 1 - [bounceIn](#easeBounceIn)(1 - *t*).\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/bounceOut.png\" alt=\"bounceOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#bounceOut)\n\n<a name=\"easeBounceInOut\" href=\"#easeBounceInOut\">#</a> d3.<b>easeBounceInOut</b>(<i>t</i>) [<>](https://github.com/d3/d3-ease/blob/master/src/bounce.js#L20 \"Source\")\n\nSymmetric bounce easing; scales [bounceIn](#easeBounceIn) for *t* in [0, 0.5] and [bounceOut](#easeBounceOut) for *t* in [0.5, 1].\n\n[<img src=\"https://raw.githubusercontent.com/d3/d3-ease/master/img/bounceInOut.png\" alt=\"bounceInOut\" width=\"100%\" height=\"240\">](http://bl.ocks.org/mbostock/248bac3b8e354a9103c4/#bounceInOut)\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/d3/d3-ease.git"
},
"scripts": {
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../d3-ease/build/d3-ease.js d3-ease.v1.js && cp ../d3-ease/build/d3-ease.min.js d3-ease.v1.min.js && git add d3-ease.v1.js d3-ease.v1.min.js && git commit -m \"d3-ease ${npm_package_version}\" && git push && cd - && zip -j build/d3-ease.zip -- LICENSE README.md build/d3-ease.js build/d3-ease.min.js",
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-ease.js -c -m -o build/d3-ease.min.js",
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -n d3 -o build/d3-ease.js -- index.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src"
},
"version": "1.0.3"
}
var overshoot = 1.70158;
export var backIn = (function custom(s) {
s = +s;
function backIn(t) {
return t * t * ((s + 1) * t - s);
}
backIn.overshoot = custom;
return backIn;
})(overshoot);
export var backOut = (function custom(s) {
s = +s;
function backOut(t) {
return --t * t * ((s + 1) * t + s) + 1;
}
backOut.overshoot = custom;
return backOut;
})(overshoot);
export var backInOut = (function custom(s) {
s = +s;
function backInOut(t) {
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
}
backInOut.overshoot = custom;
return backInOut;
})(overshoot);
var b1 = 4 / 11,
b2 = 6 / 11,
b3 = 8 / 11,
b4 = 3 / 4,
b5 = 9 / 11,
b6 = 10 / 11,
b7 = 15 / 16,
b8 = 21 / 22,
b9 = 63 / 64,
b0 = 1 / b1 / b1;
export function bounceIn(t) {
return 1 - bounceOut(1 - t);
}
export function bounceOut(t) {
return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
}
export function bounceInOut(t) {
return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
}
export function circleIn(t) {
return 1 - Math.sqrt(1 - t * t);
}
export function circleOut(t) {
return Math.sqrt(1 - --t * t);
}
export function circleInOut(t) {
return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
}
export function cubicIn(t) {
return t * t * t;
}
export function cubicOut(t) {
return --t * t * t + 1;
}
export function cubicInOut(t) {
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
}
var tau = 2 * Math.PI,
amplitude = 1,
period = 0.3;
export var elasticIn = (function custom(a, p) {
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
function elasticIn(t) {
return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
}
elasticIn.amplitude = function(a) { return custom(a, p * tau); };
elasticIn.period = function(p) { return custom(a, p); };
return elasticIn;
})(amplitude, period);
export var elasticOut = (function custom(a, p) {
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
function elasticOut(t) {
return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
}
elasticOut.amplitude = function(a) { return custom(a, p * tau); };
elasticOut.period = function(p) { return custom(a, p); };
return elasticOut;
})(amplitude, period);
export var elasticInOut = (function custom(a, p) {
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
function elasticInOut(t) {
return ((t = t * 2 - 1) < 0
? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
: 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
}
elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
elasticInOut.period = function(p) { return custom(a, p); };
return elasticInOut;
})(amplitude, period);
export function expIn(t) {
return Math.pow(2, 10 * t - 10);
}
export function expOut(t) {
return 1 - Math.pow(2, -10 * t);
}
export function expInOut(t) {
return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
}
export function linear(t) {
return +t;
}
var exponent = 3;
export var polyIn = (function custom(e) {
e = +e;
function polyIn(t) {
return Math.pow(t, e);
}
polyIn.exponent = custom;
return polyIn;
})(exponent);
export var polyOut = (function custom(e) {
e = +e;
function polyOut(t) {
return 1 - Math.pow(1 - t, e);
}
polyOut.exponent = custom;
return polyOut;
})(exponent);
export var polyInOut = (function custom(e) {
e = +e;
function polyInOut(t) {
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
}
polyInOut.exponent = custom;
return polyInOut;
})(exponent);
export function quadIn(t) {
return t * t;
}
export function quadOut(t) {
return t * (2 - t);
}
export function quadInOut(t) {
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
}
var pi = Math.PI,
halfPi = pi / 2;
export function sinIn(t) {
return 1 - Math.cos(t * halfPi);
}
export function sinOut(t) {
return Math.sin(t * halfPi);
}
export function sinInOut(t) {
return (1 - Math.cos(pi * t)) / 2;
}
parserOptions:
sourceType: module
extends:
"eslint:recommended"
rules:
no-cond-assign: 0
*.sublime-*
build/*.zip
test/
Copyright 2010-2016 Mike Bostock
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# d3-force
This module implements a [velocity Verlet](https://en.wikipedia.org/wiki/Verlet_integration) numerical integrator for simulating physical forces on particles. The simulation is simplified: it assumes a constant unit time step Δ*t* = 1 for each step, and a constant unit mass *m* = 1 for all particles. As a result, a force *F* acting on a particle is equivalent to a constant acceleration *a* over the time interval Δ*t*, and can be simulated simply by adding to the particle’s velocity, which is then added to the particle’s position.
In the domain of information visualization, physical simulations are useful for studying [networks](http://bl.ocks.org/mbostock/ad70335eeef6d167bc36fd3c04378048) and [hierarchies](http://bl.ocks.org/mbostock/95aa92e2f4e8345aaa55a4a94d41ce37)!
[<img alt="Force Dragging III" src="https://raw.githubusercontent.com/d3/d3-force/master/img/graph.png" width="420" height="219">](http://bl.ocks.org/mbostock/ad70335eeef6d167bc36fd3c04378048)[<img alt="Force-Directed Tree" src="https://raw.githubusercontent.com/d3/d3-force/master/img/tree.png" width="420" height="219">](http://bl.ocks.org/mbostock/95aa92e2f4e8345aaa55a4a94d41ce37)
You can also simulate circles (disks) with collision, such as for [bubble charts](http://www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html) or [beeswarm plots](http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320):
[<img alt="Collision Detection" src="https://raw.githubusercontent.com/d3/d3-force/master/img/collide.png" width="420" height="219">](http://bl.ocks.org/mbostock/31ce330646fa8bcb7289ff3b97aab3f5)[<img alt="Beeswarm" src="https://raw.githubusercontent.com/d3/d3-force/master/img/beeswarm.png" width="420" height="219">](http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320)
You can even use it as a rudimentary physics engine, say to simulate cloth:
[<img alt="Force-Directed Lattice" src="https://raw.githubusercontent.com/d3/d3-force/master/img/lattice.png" width="480" height="250">](http://bl.ocks.org/mbostock/1b64ec067fcfc51e7471d944f51f1611)
To use this module, create a [simulation](#simulation) for an array of [nodes](#simulation_nodes), and compose the desired [forces](#simulation_force). Then [listen](#simulation_on) for tick events to render the nodes as they update in your preferred graphics system, such as Canvas or SVG.
## Installing
If you use NPM, `npm install d3-force`. Otherwise, download the [latest release](https://github.com/d3/d3-force/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-force.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_force` global is exported:
```html
<script src="https://d3js.org/d3-collection.v1.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v1.min.js"></script>
<script src="https://d3js.org/d3-quadtree.v1.min.js"></script>
<script src="https://d3js.org/d3-timer.v1.min.js"></script>
<script src="https://d3js.org/d3-force.v1.min.js"></script>
<script>
var simulation = d3.forceSimulation(nodes);
</script>
```
[Try d3-force in your browser.](https://tonicdev.com/npm/d3-force)
## API Reference
### Simulation
<a name="forceSimulation" href="#forceSimulation">#</a> d3.<b>forceSimulation</b>([<i>nodes</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js "Source")
Creates a new simulation with the specified array of [*nodes*](#simulation_nodes) and no [forces](#simulation_force). If *nodes* is not specified, it defaults to the empty array. The simulator [starts](#simulation_restart) automatically; use [*simulation*.on](#simulation_on) to listen for tick events as the simulation runs. If you wish to run the simulation manually instead, call [*simulation*.stop](#simulation_stop), and then call [*simulation*.tick](#simulation_tick) as desired.
<a name="simulation_restart" href="#simulation_restart">#</a> <i>simulation</i>.<b>restart</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L80 "Source")
Restarts the simulation’s internal timer and returns the simulation. In conjunction with [*simulation*.alphaTarget](#simulation_alphaTarget) or [*simulation*.alpha](#simulation_alpha), this method can be used to “reheat” the simulation during interaction, such as when dragging a node, or to resume the simulation after temporarily pausing it with [*simulation*.stop](#simulation_stop).
<a name="simulation_stop" href="#simulation_stop">#</a> <i>simulation</i>.<b>stop</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L84 "Source")
Stops the simulation’s internal timer, if it is running, and returns the simulation. If the timer is already stopped, this method does nothing. This method is useful for running the simulation manually; see [*simulation*.tick](#simulation_tick).
<a name="simulation_tick" href="#simulation_tick">#</a> <i>simulation</i>.<b>tick</b>() [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L38 "Source")
Increments the current [*alpha*](#simulation_alpha) by ([*alphaTarget*](#simulation_alphaTarget) - *alpha*) × [*alphaDecay*](#simulation_alphaDecay); then invokes each registered [force](#simulation_force), passing the new *alpha*; then decrements each [node](#simulation_nodes)’s velocity by *velocity* × [*velocityDecay*](#simulation_velocityDecay); lastly increments each node’s position by *velocity*.
This method does not dispatch [events](#simulation_on); events are only dispatched by the internal timer when the simulation is started automatically upon [creation](#forceSimulation) or by calling [*simulation*.restart](#simulation_restart). The natural number of ticks when the simulation is started is ⌈*log*([*alphaMin*](#simulation_alphaMin)) / *log*(1 - [*alphaDecay*](#simulation_alphaDecay))⌉; by default, this is 300.
This method can be used in conjunction with [*simulation*.stop](#simulation_stop) to compute a [static force layout](https://bl.ocks.org/mbostock/1667139). For large graphs, static layouts should be computed [in a web worker](https://bl.ocks.org/mbostock/01ab2e85e8727d6529d20391c0fd9a16) to avoid freezing the user interface.
<a name="simulation_nodes" href="#simulation_nodes">#</a> <i>simulation</i>.<b>nodes</b>([<i>nodes</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L88 "Source")
If *nodes* is specified, sets the simulation’s nodes to the specified array of objects, initializing their positions and velocities if necessary, and then [re-initializes](#force_initialize) any bound [forces](#simulation_force); returns the simulation. If *nodes* is not specified, returns the simulation’s array of nodes as specified to the [constructor](#forceSimulation).
Each *node* must be an object. The following properties are assigned by the simulation:
* `index` - the node’s zero-based index into *nodes*
* `x` - the node’s current *x*-position
* `y` - the node’s current *y*-position
* `vx` - the node’s current *x*-velocity
* `vy` - the node’s current *y*-velocity
The position ⟨*x*,*y*⟩ and velocity ⟨*vx*,*vy*⟩ may be subsequently modified by [forces](#forces) and by the simulation. If either *vx* or *vy* is NaN, the velocity is initialized to ⟨0,0⟩. If either *x* or *y* is NaN, the position is initialized in a [phyllotaxis arrangement](http://bl.ocks.org/mbostock/11478058), so chosen to ensure a deterministic, uniform distribution around the origin.
To fix a node in a given position, you may specify two additional properties:
* `fx` - the node’s fixed *x*-position
* `fy` - the node’s fixed *y*-position
At the end of each [tick](#simulation_tick), after the application of any forces, a node with a defined *node*.fx has *node*.x reset to this value and *node*.vx set to zero; likewise, a node with a defined *node*.fy has *node*.y reset to this value and *node*.vy set to zero. To unfix a node that was previously fixed, set *node*.fx and *node*.fy to null, or delete these properties.
If the specified array of *nodes* is modified, such as when nodes are added to or removed from the simulation, this method must be called again with the new (or changed) array to notify the simulation and bound forces of the change; the simulation does not make a defensive copy of the specified array.
<a name="simulation_alpha" href="#simulation_alpha">#</a> <i>simulation</i>.<b>alpha</b>([<i>alpha</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L92 "Source")
If *alpha* is specified, sets the current alpha to the specified number in the range [0,1] and returns this simulation. If *alpha* is not specified, returns the current alpha value, which defaults to 1.
<a name="simulation_alphaMin" href="#simulation_alphaMin">#</a> <i>simulation</i>.<b>alphaMin</b>([<i>min</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L96 "Source")
If *min* is specified, sets the minimum *alpha* to the specified number in the range [0,1] and returns this simulation. If *min* is not specified, returns the current minimum *alpha* value, which defaults to 0.001. The simulation’s internal timer stops when the current [*alpha*](#simulation_alpha) is less than the minimum *alpha*. The default [alpha decay rate](#simulation_alphaDecay) of ~0.0228 corresponds to 300 iterations.
<a name="simulation_alphaDecay" href="#simulation_alphaDecay">#</a> <i>simulation</i>.<b>alphaDecay</b>([<i>decay</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L100 "Source")
If *decay* is specified, sets the [*alpha*](#simulation_alpha) decay rate to the specified number in the range [0,1] and returns this simulation. If *decay* is not specified, returns the current *alpha* decay rate, which defaults to 0.0228… = 1 - *pow*(0.001, 1 / 300) where 0.001 is the default [minimum *alpha*](#simulation_alphaMin).
The alpha decay rate determines how quickly the current alpha interpolates towards the desired [target *alpha*](#simulation_alphaTarget); since the default target *alpha* is zero, by default this controls how quickly the simulation cools. Higher decay rates cause the simulation to stabilize more quickly, but risk getting stuck in a local minimum; lower values cause the simulation to take longer to run, but typically converge on a better layout. To have the simulation run forever at the current *alpha*, set the *decay* rate to zero; alternatively, set a [target *alpha*](#simulation_alphaTarget) greater than the [minimum *alpha*](#simulation_alphaMin).
<a name="simulation_alphaTarget" href="#simulation_alphaTarget">#</a> <i>simulation</i>.<b>alphaTarget</b>([<i>target</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L104 "Source")
If *target* is specified, sets the current target [*alpha*](#simulation_alpha) to the specified number in the range [0,1] and returns this simulation. If *target* is not specified, returns the current target alpha value, which defaults to 0.
<a name="simulation_velocityDecay" href="#simulation_velocityDecay">#</a> <i>simulation</i>.<b>velocityDecay</b>([<i>decay</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L108 "Source")
If *decay* is specified, sets the velocity decay factor to the specified number in the range [0,1] and returns this simulation. If *decay* is not specified, returns the current velocity decay factor, which defaults to 0.4. The decay factor is akin to atmospheric friction; after the application of any forces during a [tick](#simulation_tick), each node’s velocity is multiplied by 1 - *decay*. As with lowering the [alpha decay rate](#simulation_alphaDecay), less velocity decay may converge on a better solution, but risks numerical instabilities and oscillation.
<a name="simulation_force" href="#simulation_force">#</a> <i>simulation</i>.<b>force</b>(<i>name</i>[, <i>force</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L112 "Source")
If *force* is specified, assigns the [force](#forces) for the specified *name* and returns this simulation. If *force* is not specified, returns the force with the specified name, or undefined if there is no such force. (By default, new simulations have no forces.) For example, to create a new simulation to layout a graph, you might say:
```js
var simulation = d3.forceSimulation(nodes)
.force("charge", d3.forceManyBody())
.force("link", d3.forceLink(links))
.force("center", d3.forceCenter());
```
<a name="simulation_find" href="#simulation_find">#</a> <i>simulation</i>.<b>find</b>(<i>x</i>, <i>y</i>[, <i>radius</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L116 "Source")
Returns the node closest to the position ⟨*x*,*y*⟩ with the given search *radius*. If *radius* is not specified, it defaults to infinity. If there is no node within the search area, returns undefined.
<a name="simulation_on" href="#simulation_on">#</a> <i>simulation</i>.<b>on</b>(<i>typenames</i>, [<i>listener</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L139 "Source")
If *listener* is specified, sets the event *listener* for the specified *typenames* and returns this simulation. If an event listener was already registered for the same type and name, the existing listener is removed before the new listener is added. If *listener* is null, removes the current event listeners for the specified *typenames*, if any. If *listener* is not specified, returns the first currently-assigned listener matching the specified *typenames*, if any. When a specified event is dispatched, each *listener* will be invoked with the `this` context as the simulation.
The *typenames* is a string containing one or more *typename* separated by whitespace. Each *typename* is a *type*, optionally followed by a period (`.`) and a *name*, such as `tick.foo` and `tick.bar`; the name allows multiple listeners to be registered for the same *type*. The *type* must be one of the following:
* `tick` - after each tick of the simulation’s internal timer.
* `end` - after the simulation’s timer stops when *alpha* < [*alphaMin*](#simulation_alphaMin).
Note that *tick* events are not dispatched when [*simulation*.tick](#simulation_tick) is called manually; events are only dispatched by the internal timer and are intended for interactive rendering of the simulation. To affect the simulation, register [forces](#simulation_force) instead of modifying nodes’ positions or velocities inside a tick event listener.
See [*dispatch*.on](https://github.com/d3/d3-dispatch#dispatch_on) for details.
### Forces
A *force* is simply a function that modifies nodes’ positions or velocities; in this context, a *force* can apply a classical physical force such as electrical charge or gravity, or it can resolve a geometric constraint, such as keeping nodes within a bounding box or keeping linked nodes a fixed distance apart. For example, a simple positioning force that moves nodes towards the origin ⟨0,0⟩ might be implemented as:
```js
function force(alpha) {
for (var i = 0, n = nodes.length, node, k = alpha * 0.1; i < n; ++i) {
node = nodes[i];
node.vx -= node.x * k;
node.vy -= node.y * k;
}
}
```
Forces typically read the node’s current position ⟨*x*,*y*⟩ and then add to (or subtract from) the node’s velocity ⟨*vx*,*vy*⟩. However, forces may also “peek ahead” to the anticipated next position of the node, ⟨*x* + *vx*,*y* + *vy*⟩; this is necessary for resolving geometric constraints through [iterative relaxation](https://en.wikipedia.org/wiki/Relaxation_\(iterative_method\)). Forces may also modify the position directly, which is sometimes useful to avoid adding energy to the simulation, such as when recentering the simulation in the viewport.
Simulations typically compose multiple forces as desired. This module provides several for your enjoyment:
* [Centering](#centering)
* [Collision](#collision)
* [Links](#links)
* [Many-Body](#many-body)
* [Positioning](#positioning)
Forces may optionally implement [*force*.initialize](#force_initialize) to receive the simulation’s array of nodes.
<a name="_force" href="#_force">#</a> <i>force</i>(<i>alpha</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L44 "Source")
Applies this force, optionally observing the specified *alpha*. Typically, the force is applied to the array of nodes previously passed to [*force*.initialize](#force_initialize), however, some forces may apply to a subset of nodes, or behave differently. For example, [d3.forceLink](#links) applies to the source and target of each link.
<a name="force_initialize" href="#force_initialize">#</a> <i>force</i>.<b>initialize</b>(<i>nodes</i>) [<>](https://github.com/d3/d3-force/blob/master/src/simulation.js#L71 "Source")
Assigns the array of *nodes* to this force. This method is called when a force is bound to a simulation via [*simulation*.force](#simulation_force) and when the simulation’s nodes change via [*simulation*.nodes](#simulation_nodes). A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
#### Centering
The centering force translates nodes uniformly so that the mean position of all nodes (the center of mass if all nodes have equal weight) is at the given position ⟨[*x*](#center_x),[*y*](#center_y)⟩. This force modifies the positions of nodes on each application; it does not modify velocities, as doing so would typically cause the nodes to overshoot and oscillate around the desired center. This force helps keeps nodes in the center of the viewport, and unlike the [positioning force](#positioning), it does not distort their relative positions.
<a name="forceCenter" href="#forceCenter">#</a> d3.<b>forceCenter</b>([<i>x</i>, <i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js#L1 "Source")
Creates a new centering force with the specified [*x*-](#center_x) and [*y*-](#center_y) coordinates. If *x* and *y* are not specified, they default to ⟨0,0⟩.
<a name="center_x" href="#center_x">#</a> <i>center</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js#L27 "Source")
If *x* is specified, sets the *x*-coordinate of the centering position to the specified number and returns this force. If *x* is not specified, returns the current *x*-coordinate, which defaults to zero.
<a name="center_y" href="#center_y">#</a> <i>center</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/center.js#L31 "Source")
If *y* is specified, sets the *y*-coordinate of the centering position to the specified number and returns this force. If *y* is not specified, returns the current *y*-coordinate, which defaults to zero.
#### Collision
The collision force treats nodes as circles with a given [radius](#collide_radius), rather than points, and prevents nodes from overlapping. More formally, two nodes *a* and *b* are separated so that the distance between *a* and *b* is at least *radius*(*a*) + *radius*(*b*). To reduce jitter, this is by default a “soft” constraint with a configurable [strength](#collide_strength) and [iteration count](#collide_iterations).
<a name="forceCollide" href="#forceCollide">#</a> d3.<b>forceCollide</b>([<i>radius</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/collide.js "Source")
Creates a new circle collision force with the specified [*radius*](#collide_radius). If *radius* is not specified, it defaults to the constant one for all nodes.
<a name="collide_radius" href="#collide_radius">#</a> <i>collide</i>.<b>radius</b>([<i>radius</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/collide.js#L86 "Source")
If *radius* is specified, sets the radius accessor to the specified number or function, re-evaluates the radius accessor for each node, and returns this force. If *radius* is not specified, returns the current radius accessor, which defaults to:
```js
function radius() {
return 1;
}
```
The radius accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the radius of each node is only recomputed when the force is initialized or when this method is called with a new *radius*, and not on every application of the force.
<a name="collide_strength" href="#collide_strength">#</a> <i>collide</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/collide.js#L82 "Source")
If *strength* is specified, sets the force strength to the specified number in the range [0,1] and returns this force. If *strength* is not specified, returns the current strength which defaults to 0.7.
Overlapping nodes are resolved through iterative relaxation. For each node, the other nodes that are anticipated to overlap at the next tick (using the anticipated positions ⟨*x* + *vx*,*y* + *vy*⟩) are determined; the node’s velocity is then modified to push the node out of each overlapping node. The change in velocity is dampened by the force’s strength such that the resolution of simultaneous overlaps can be blended together to find a stable solution.
<a name="collide_iterations" href="#collide_iterations">#</a> <i>collide</i>.<b>iterations</b>([<i>iterations</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/collide.js#L78 "Source")
If *iterations* is specified, sets the number of iterations per application to the specified number and returns this force. If *iterations* is not specified, returns the current iteration count which defaults to 1. Increasing the number of iterations greatly increases the rigidity of the constraint and avoids partial overlap of nodes, but also increases the runtime cost to evaluate the force.
#### Links
The link force pushes linked nodes together or apart according to the desired [link distance](#link_distance). The strength of the force is proportional to the difference between the linked nodes’ distance and the target distance, similar to a spring force.
<a name="forceLink" href="#forceLink">#</a> d3.<b>forceLink</b>([<i>links</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/link.js "Source")
Creates a new link force with the specified *links* and default parameters. If *links* is not specified, it defaults to the empty array.
<a name="link_links" href="#link_links">#</a> <i>link</i>.<b>links</b>([<i>links</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/link.js#L92 "Source")
If *links* is specified, sets the array of links associated with this force, recomputes the [distance](#link_distance) and [strength](#link_strength) parameters for each link, and returns this force. If *links* is not specified, returns the current array of links, which defaults to the empty array.
Each link is an object with the following properties:
* `source` - the link’s source node; see [*simulation*.nodes](#simulation_nodes)
* `target` - the link’s target node; see [*simulation*.nodes](#simulation_nodes)
* `index` - the zero-based index into *links*, assigned by this method
For convenience, a link’s source and target properties may be initialized using numeric or string identifiers rather than object references; see [*link*.id](#link_id).
If the specified array of *links* is modified, such as when links are added to or removed from the simulation, this method must be called again with the new (or changed) array to notify the force of the change; the force does not make a defensive copy of the specified array.
<a name="link_id" href="#link_id">#</a> <i>link</i>.<b>id</b>([<i>id</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/link.js#L96 "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 default id accessor allows each link’s source and target to be specified as a zero-based index into the [nodes](#simulation_nodes) array. For example:
```js
var nodes = [
{"id": "Alice"},
{"id": "Bob"},
{"id": "Carol"}
];
var links = [
{"source": 0, "target": 1}, // Alice → Bob
{"source": 1, "target": 2} // Bob → Carol
];
```
Now consider a different id accessor that returns a string:
```js
function id(d) {
return d.id;
}
```
With this accessor, you can use named sources and targets:
```js
var nodes = [
{"id": "Alice"},
{"id": "Bob"},
{"id": "Carol"}
];
var links = [
{"source": "Alice", "target": "Bob"},
{"source": "Bob", "target": "Carol"}
];
```
This is particularly useful when representing graphs in JSON, as JSON does not allow references. See [this example](http://bl.ocks.org/mbostock/f584aa36df54c451c94a9d0798caed35).
The id accessor is invoked for each node whenever the force is initialized, as when the [nodes](#simulation_nodes) or [links](#link_links) change, being passed the node and its zero-based index.
<a name="link_distance" href="#link_distance">#</a> <i>link</i>.<b>distance</b>([<i>distance</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/link.js#L108 "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 30;
}
```
The distance accessor is invoked for each [link](#link_links), being passed the *link* and its zero-based *index*. The resulting number is then stored internally, such that the distance of each link is only recomputed when the force is initialized or when this method is called with a new *distance*, and not on every application of the force.
<a name="link_strength" href="#link_strength">#</a> <i>link</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/link.js#L104 "Source")
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each link, and returns this force. If *strength* is not specified, returns the current strength accessor, which defaults to:
```js
function strength(link) {
return 1 / Math.min(count(link.source), count(link.target));
}
```
Where *count*(*node*) is a function that returns the number of links with the given node as a source or target. This default was chosen because it automatically reduces the strength of links connected to heavily-connected nodes, improving stability.
The strength accessor is invoked for each [link](#link_links), being passed the *link* and its zero-based *index*. The resulting number is then stored internally, such that the strength of each link is only recomputed when the force is initialized or when this method is called with a new *strength*, and not on every application of the force.
<a name="link_iterations" href="#link_iterations">#</a> <i>link</i>.<b>iterations</b>([<i>iterations</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/link.js#L100 "Source")
If *iterations* is specified, sets the number of iterations per application to the specified number and returns this force. If *iterations* is not specified, returns the current iteration count which defaults to 1. Increasing the number of iterations greatly increases the rigidity of the constraint and is useful for [complex structures such as lattices](http://bl.ocks.org/mbostock/1b64ec067fcfc51e7471d944f51f1611), but also increases the runtime cost to evaluate the force.
#### Many-Body
The many-body (or *n*-body) force applies mutually amongst all [nodes](#simulation_nodes). It can be used to simulate gravity (attraction) if the [strength](#manyBody_strength) is positive, or electrostatic charge (repulsion) if the strength is negative. This implementation uses quadtrees and the [Barnes–Hut approximation](https://en.wikipedia.org/wiki/Barnes–Hut_simulation) to greatly improve performance; the accuracy can be customized using the [theta](#manyBody_theta) parameter.
Unlike links, which only affect two linked nodes, the charge force is global: every node affects every other node, even if they are on disconnected subgraphs.
<a name="forceManyBody" href="#forceManyBody">#</a> d3.<b>forceManyBody</b>() [<>](https://github.com/d3/d3-force/blob/master/src/manyBody.js "Source")
Creates a new many-body force with the default parameters.
<a name="manyBody_strength" href="#manyBody_strength">#</a> <i>manyBody</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/manyBody.js#L97 "Source")
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. A positive value causes nodes to attract each other, similar to gravity, while a negative value causes nodes to repel each other, similar to electrostatic charge. If *strength* is not specified, returns the current strength accessor, which defaults to:
```js
function strength() {
return -30;
}
```
The strength accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the strength of each node is only recomputed when the force is initialized or when this method is called with a new *strength*, and not on every application of the force.
<a name="manyBody_theta" href="#manyBody_theta">#</a> <i>manyBody</i>.<b>theta</b>([<i>theta</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/manyBody.js#L109 "Source")
If *theta* is specified, sets the Barnes–Hut approximation criterion to the specified number and returns this force. If *theta* is not specified, returns the current value, which defaults to 0.9.
To accelerate computation, this force implements the [Barnes–Hut approximation](http://en.wikipedia.org/wiki/Barnes–Hut_simulation) which takes O(*n* log *n*) per application where *n* is the number of [nodes](#simulation_nodes). For each application, a [quadtree](https://github.com/d3/d3-quadtree) stores the current node positions; then for each node, the combined force of all other nodes on the given node is computed. For a cluster of nodes that is far away, the charge force can be approximated by treating the cluster as a single, larger node. The *theta* parameter determines the accuracy of the approximation: if the ratio *w* / *l* of the width *w* of the quadtree cell to the distance *l* from the node to the cell’s center of mass is less than *theta*, all nodes in the given cell are treated as a single node rather than individually.
<a name="manyBody_distanceMin" href="#manyBody_distanceMin">#</a> <i>manyBody</i>.<b>distanceMin</b>([<i>distance</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/manyBody.js#L101 "Source")
If *distance* is specified, sets the minimum distance between nodes over which this force is considered. If *distance* is not specified, returns the current minimum distance, which defaults to 1. A minimum distance establishes an upper bound on the strength of the force between two nearby nodes, avoiding instability. In particular, it avoids an infinitely-strong force if two nodes are exactly coincident; in this case, the direction of the force is random.
<a name="manyBody_distanceMax" href="#manyBody_distanceMax">#</a> <i>manyBody</i>.<b>distanceMax</b>([<i>distance</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/manyBody.js#L105 "Source")
If *distance* is specified, sets the maximum distance between nodes over which this force is considered. If *distance* is not specified, returns the current maximum distance, which defaults to infinity. Specifying a finite maximum distance improves performance and produces a more localized layout.
#### Positioning
The [*x*](#forceX)- and [*y*](#forceY)-positioning forces push nodes towards a desired position along the given dimension with a configurable strength. The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position. While these forces can be used to position individual nodes, they are intended primarily for global forces that apply to all (or most) nodes.
<a name="forceX" href="#forceX">#</a> d3.<b>forceX</b>([<i>x</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/x.js "Source")
Creates a new positioning force along the *x*-axis towards the given position [*x*](#x_x). If *x* is not specified, it defaults to 0.
<a name="x_strength" href="#x_strength">#</a> <i>x</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/x.js#L32 "Source")
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. The *strength* determines how much to increment the node’s *x*-velocity: ([*x*](#x_x) - *node*.x) × *strength*. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current *x*-position to the target *x*-position with each application. Higher values moves nodes more quickly to the target position, often at the expense of other forces or constraints. A value outside the range [0,1] is not recommended.
If *strength* is not specified, returns the current strength accessor, which defaults to:
```js
function strength() {
return 0.1;
}
```
The strength accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the strength of each node is only recomputed when the force is initialized or when this method is called with a new *strength*, and not on every application of the force.
<a name="x_x" href="#x_x">#</a> <i>x</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/x.js#L36 "Source")
If *x* is specified, sets the *x*-coordinate accessor to the specified number or function, re-evaluates the *x*-accessor for each node, and returns this force. If *x* is not specified, returns the current *x*-accessor, which defaults to:
```js
function x() {
return 0;
}
```
The *x*-accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the target *x*-coordinate of each node is only recomputed when the force is initialized or when this method is called with a new *x*, and not on every application of the force.
<a name="forceY" href="#forceY">#</a> d3.<b>forceY</b>([<i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/y.js "Source")
Creates a new positioning force along the *y*-axis towards the given position [*y*](#y_y). If *y* is not specified, it defaults to 0.
<a name="y_strength" href="#y_strength">#</a> <i>y</i>.<b>strength</b>([<i>strength</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/y.js#L32 "Source")
If *strength* is specified, sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. The *strength* determines how much to increment the node’s *y*-velocity: ([*y*](#y_y) - *node*.y) × *strength*. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current *y*-position to the target *y*-position with each application. Higher values moves nodes more quickly to the target position, often at the expense of other forces or constraints. A value outside the range [0,1] is not recommended.
If *strength* is not specified, returns the current strength accessor, which defaults to:
```js
function strength() {
return 0.1;
}
```
The strength accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the strength of each node is only recomputed when the force is initialized or when this method is called with a new *strength*, and not on every application of the force.
<a name="y_y" href="#y_y">#</a> <i>y</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/d3/d3-force/blob/master/src/y.js#L36 "Source")
If *y* is specified, sets the *y*-coordinate accessor to the specified number or function, re-evaluates the *y*-accessor for each node, and returns this force. If *y* is not specified, returns the current *y*-accessor, which defaults to:
```js
function y() {
return 0;
}
```
The *y*-accessor is invoked for each [node](#simulation_nodes) in the simulation, being passed the *node* and its zero-based *index*. The resulting number is then stored internally, such that the target *y*-coordinate of each node is only recomputed when the force is initialized or when this method is called with a new *y*, and not on every application of the force.
// https://d3js.org/d3-force/ Version 1.0.6. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-collection'), require('d3-dispatch'), require('d3-timer')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-quadtree', 'd3-collection', 'd3-dispatch', 'd3-timer'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3));
}(this, (function (exports,d3Quadtree,d3Collection,d3Dispatch,d3Timer) { 'use strict';
var center = function(x, y) {
var nodes;
if (x == null) x = 0;
if (y == null) y = 0;
function force() {
var i,
n = nodes.length,
node,
sx = 0,
sy = 0;
for (i = 0; i < n; ++i) {
node = nodes[i], sx += node.x, sy += node.y;
}
for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
node = nodes[i], node.x -= sx, node.y -= sy;
}
}
force.initialize = function(_) {
nodes = _;
};
force.x = function(_) {
return arguments.length ? (x = +_, force) : x;
};
force.y = function(_) {
return arguments.length ? (y = +_, force) : y;
};
return force;
};
var constant = function(x) {
return function() {
return x;
};
};
var jiggle = function() {
return (Math.random() - 0.5) * 1e-6;
};
function x(d) {
return d.x + d.vx;
}
function y(d) {
return d.y + d.vy;
}
var collide = function(radius) {
var nodes,
radii,
strength = 1,
iterations = 1;
if (typeof radius !== "function") radius = constant(radius == null ? 1 : +radius);
function force() {
var i, n = nodes.length,
tree,
node,
xi,
yi,
ri,
ri2;
for (var k = 0; k < iterations; ++k) {
tree = d3Quadtree.quadtree(nodes, x, y).visitAfter(prepare);
for (i = 0; i < n; ++i) {
node = nodes[i];
ri = radii[node.index], ri2 = ri * ri;
xi = node.x + node.vx;
yi = node.y + node.vy;
tree.visit(apply);
}
}
function apply(quad, x0, y0, x1, y1) {
var data = quad.data, rj = quad.r, r = ri + rj;
if (data) {
if (data.index > node.index) {
var x = xi - data.x - data.vx,
y = yi - data.y - data.vy,
l = x * x + y * y;
if (l < r * r) {
if (x === 0) x = jiggle(), l += x * x;
if (y === 0) y = jiggle(), l += y * y;
l = (r - (l = Math.sqrt(l))) / l * strength;
node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
node.vy += (y *= l) * r;
data.vx -= x * (r = 1 - r);
data.vy -= y * r;
}
}
return;
}
return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
}
}
function prepare(quad) {
if (quad.data) return quad.r = radii[quad.data.index];
for (var i = quad.r = 0; i < 4; ++i) {
if (quad[i] && quad[i].r > quad.r) {
quad.r = quad[i].r;
}
}
}
function initialize() {
if (!nodes) return;
var i, n = nodes.length, node;
radii = new Array(n);
for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
}
force.initialize = function(_) {
nodes = _;
initialize();
};
force.iterations = function(_) {
return arguments.length ? (iterations = +_, force) : iterations;
};
force.strength = function(_) {
return arguments.length ? (strength = +_, force) : strength;
};
force.radius = function(_) {
return arguments.length ? (radius = typeof _ === "function" ? _ : constant(+_), initialize(), force) : radius;
};
return force;
};
function index(d) {
return d.index;
}
function find(nodeById, nodeId) {
var node = nodeById.get(nodeId);
if (!node) throw new Error("missing: " + nodeId);
return node;
}
var link = function(links) {
var id = index,
strength = defaultStrength,
strengths,
distance = constant(30),
distances,
nodes,
count,
bias,
iterations = 1;
if (links == null) links = [];
function defaultStrength(link) {
return 1 / Math.min(count[link.source.index], count[link.target.index]);
}
function force(alpha) {
for (var k = 0, n = links.length; k < iterations; ++k) {
for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
link = links[i], source = link.source, target = link.target;
x = target.x + target.vx - source.x - source.vx || jiggle();
y = target.y + target.vy - source.y - source.vy || jiggle();
l = Math.sqrt(x * x + y * y);
l = (l - distances[i]) / l * alpha * strengths[i];
x *= l, y *= l;
target.vx -= x * (b = bias[i]);
target.vy -= y * b;
source.vx += x * (b = 1 - b);
source.vy += y * b;
}
}
}
function initialize() {
if (!nodes) return;
var i,
n = nodes.length,
m = links.length,
nodeById = d3Collection.map(nodes, id),
link;
for (i = 0, count = new Array(n); i < m; ++i) {
link = links[i], link.index = i;
if (typeof link.source !== "object") link.source = find(nodeById, link.source);
if (typeof link.target !== "object") link.target = find(nodeById, link.target);
count[link.source.index] = (count[link.source.index] || 0) + 1;
count[link.target.index] = (count[link.target.index] || 0) + 1;
}
for (i = 0, bias = new Array(m); i < m; ++i) {
link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
}
strengths = new Array(m), initializeStrength();
distances = new Array(m), initializeDistance();
}
function initializeStrength() {
if (!nodes) return;
for (var i = 0, n = links.length; i < n; ++i) {
strengths[i] = +strength(links[i], i, links);
}
}
function initializeDistance() {
if (!nodes) return;
for (var i = 0, n = links.length; i < n; ++i) {
distances[i] = +distance(links[i], i, links);
}
}
force.initialize = function(_) {
nodes = _;
initialize();
};
force.links = function(_) {
return arguments.length ? (links = _, initialize(), force) : links;
};
force.id = function(_) {
return arguments.length ? (id = _, force) : id;
};
force.iterations = function(_) {
return arguments.length ? (iterations = +_, force) : iterations;
};
force.strength = function(_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initializeStrength(), force) : strength;
};
force.distance = function(_) {
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
};
return force;
};
function x$1(d) {
return d.x;
}
function y$1(d) {
return d.y;
}
var initialRadius = 10;
var initialAngle = Math.PI * (3 - Math.sqrt(5));
var simulation = function(nodes) {
var simulation,
alpha = 1,
alphaMin = 0.001,
alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
alphaTarget = 0,
velocityDecay = 0.6,
forces = d3Collection.map(),
stepper = d3Timer.timer(step),
event = d3Dispatch.dispatch("tick", "end");
if (nodes == null) nodes = [];
function step() {
tick();
event.call("tick", simulation);
if (alpha < alphaMin) {
stepper.stop();
event.call("end", simulation);
}
}
function tick() {
var i, n = nodes.length, node;
alpha += (alphaTarget - alpha) * alphaDecay;
forces.each(function(force) {
force(alpha);
});
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
if (node.fy == null) node.y += node.vy *= velocityDecay;
else node.y = node.fy, node.vy = 0;
}
}
function initializeNodes() {
for (var i = 0, n = nodes.length, node; i < n; ++i) {
node = nodes[i], node.index = i;
if (isNaN(node.x) || isNaN(node.y)) {
var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
node.x = radius * Math.cos(angle);
node.y = radius * Math.sin(angle);
}
if (isNaN(node.vx) || isNaN(node.vy)) {
node.vx = node.vy = 0;
}
}
}
function initializeForce(force) {
if (force.initialize) force.initialize(nodes);
return force;
}
initializeNodes();
return simulation = {
tick: tick,
restart: function() {
return stepper.restart(step), simulation;
},
stop: function() {
return stepper.stop(), simulation;
},
nodes: function(_) {
return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
},
alpha: function(_) {
return arguments.length ? (alpha = +_, simulation) : alpha;
},
alphaMin: function(_) {
return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
},
alphaDecay: function(_) {
return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
},
alphaTarget: function(_) {
return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
},
velocityDecay: function(_) {
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
},
force: function(name, _) {
return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
},
find: function(x, y, radius) {
var i = 0,
n = nodes.length,
dx,
dy,
d2,
node,
closest;
if (radius == null) radius = Infinity;
else radius *= radius;
for (i = 0; i < n; ++i) {
node = nodes[i];
dx = x - node.x;
dy = y - node.y;
d2 = dx * dx + dy * dy;
if (d2 < radius) closest = node, radius = d2;
}
return closest;
},
on: function(name, _) {
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
}
};
};
var manyBody = function() {
var nodes,
node,
alpha,
strength = constant(-30),
strengths,
distanceMin2 = 1,
distanceMax2 = Infinity,
theta2 = 0.81;
function force(_) {
var i, n = nodes.length, tree = d3Quadtree.quadtree(nodes, x$1, y$1).visitAfter(accumulate);
for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
}
function initialize() {
if (!nodes) return;
var i, n = nodes.length, node;
strengths = new Array(n);
for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
}
function accumulate(quad) {
var strength = 0, q, c, x$$1, y$$1, i;
// For internal nodes, accumulate forces from child quadrants.
if (quad.length) {
for (x$$1 = y$$1 = i = 0; i < 4; ++i) {
if ((q = quad[i]) && (c = q.value)) {
strength += c, x$$1 += c * q.x, y$$1 += c * q.y;
}
}
quad.x = x$$1 / strength;
quad.y = y$$1 / strength;
}
// For leaf nodes, accumulate forces from coincident quadrants.
else {
q = quad;
q.x = q.data.x;
q.y = q.data.y;
do strength += strengths[q.data.index];
while (q = q.next);
}
quad.value = strength;
}
function apply(quad, x1, _, x2) {
if (!quad.value) return true;
var x$$1 = quad.x - node.x,
y$$1 = quad.y - node.y,
w = x2 - x1,
l = x$$1 * x$$1 + y$$1 * y$$1;
// Apply the Barnes-Hut approximation if possible.
// Limit forces for very close nodes; randomize direction if coincident.
if (w * w / theta2 < l) {
if (l < distanceMax2) {
if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1;
if (y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
node.vx += x$$1 * quad.value * alpha / l;
node.vy += y$$1 * quad.value * alpha / l;
}
return true;
}
// Otherwise, process points directly.
else if (quad.length || l >= distanceMax2) return;
// Limit forces for very close nodes; randomize direction if coincident.
if (quad.data !== node || quad.next) {
if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1;
if (y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
}
do if (quad.data !== node) {
w = strengths[quad.data.index] * alpha / l;
node.vx += x$$1 * w;
node.vy += y$$1 * w;
} while (quad = quad.next);
}
force.initialize = function(_) {
nodes = _;
initialize();
};
force.strength = function(_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
};
force.distanceMin = function(_) {
return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
};
force.distanceMax = function(_) {
return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
};
force.theta = function(_) {
return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
};
return force;
};
var x$2 = function(x) {
var strength = constant(0.1),
nodes,
strengths,
xz;
if (typeof x !== "function") x = constant(x == null ? 0 : +x);
function force(alpha) {
for (var i = 0, n = nodes.length, node; i < n; ++i) {
node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
}
}
function initialize() {
if (!nodes) return;
var i, n = nodes.length;
strengths = new Array(n);
xz = new Array(n);
for (i = 0; i < n; ++i) {
strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
}
}
force.initialize = function(_) {
nodes = _;
initialize();
};
force.strength = function(_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
};
force.x = function(_) {
return arguments.length ? (x = typeof _ === "function" ? _ : constant(+_), initialize(), force) : x;
};
return force;
};
var y$2 = function(y) {
var strength = constant(0.1),
nodes,
strengths,
yz;
if (typeof y !== "function") y = constant(y == null ? 0 : +y);
function force(alpha) {
for (var i = 0, n = nodes.length, node; i < n; ++i) {
node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
}
}
function initialize() {
if (!nodes) return;
var i, n = nodes.length;
strengths = new Array(n);
yz = new Array(n);
for (i = 0; i < n; ++i) {
strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
}
}
force.initialize = function(_) {
nodes = _;
initialize();
};
force.strength = function(_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
};
force.y = function(_) {
return arguments.length ? (y = typeof _ === "function" ? _ : constant(+_), initialize(), force) : y;
};
return force;
};
exports.forceCenter = center;
exports.forceCollide = collide;
exports.forceLink = link;
exports.forceManyBody = manyBody;
exports.forceSimulation = simulation;
exports.forceX = x$2;
exports.forceY = y$2;
Object.defineProperty(exports, '__esModule', { value: true });
})));
// https://d3js.org/d3-force/ Version 1.0.6. Copyright 2017 Mike Bostock.
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-collection"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-collection","d3-dispatch","d3-timer"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,i){"use strict";function u(n){return n.x+n.vx}function o(n){return n.y+n.vy}function f(n){return n.index}function a(n,t){var e=n.get(t);if(!e)throw new Error("missing: "+t);return e}function c(n){return n.x}function l(n){return n.y}var h=function(n,t){function e(){var e,i,u=r.length,o=0,f=0;for(e=0;e<u;++e)i=r[e],o+=i.x,f+=i.y;for(o=o/u-n,f=f/u-t,e=0;e<u;++e)i=r[e],i.x-=o,i.y-=f}var r;return null==n&&(n=0),null==t&&(t=0),e.initialize=function(n){r=n},e.x=function(t){return arguments.length?(n=+t,e):n},e.y=function(n){return arguments.length?(t=+n,e):t},e},v=function(n){return function(){return n}},d=function(){return 1e-6*(Math.random()-.5)},y=function(n){function e(){function n(n,t,e,r,i){var u=n.data,o=n.r,f=x+o;{if(!u)return t>v+f||r<v-f||e>y+f||i<y-f;if(u.index>h.index){var a=v-u.x-u.vx,l=y-u.y-u.vy,s=a*a+l*l;s<f*f&&(0===a&&(a=d(),s+=a*a),0===l&&(l=d(),s+=l*l),s=(f-(s=Math.sqrt(s)))/s*c,h.vx+=(a*=s)*(f=(o*=o)/(g+o)),h.vy+=(l*=s)*f,u.vx-=a*(f=1-f),u.vy-=l*f)}}}for(var e,i,h,v,y,x,g,s=f.length,p=0;p<l;++p)for(i=t.quadtree(f,u,o).visitAfter(r),e=0;e<s;++e)h=f[e],x=a[h.index],g=x*x,v=h.x+h.vx,y=h.y+h.vy,i.visit(n)}function r(n){if(n.data)return n.r=a[n.data.index];for(var t=n.r=0;t<4;++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}function i(){if(f){var t,e,r=f.length;for(a=new Array(r),t=0;t<r;++t)e=f[t],a[e.index]=+n(e,t,f)}}var f,a,c=1,l=1;return"function"!=typeof n&&(n=v(null==n?1:+n)),e.initialize=function(n){f=n,i()},e.iterations=function(n){return arguments.length?(l=+n,e):l},e.strength=function(n){return arguments.length?(c=+n,e):c},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:v(+t),i(),e):n},e},x=function(n){function t(n){return 1/Math.min(y[n.source.index],y[n.target.index])}function r(t){for(var e=0,r=n.length;e<M;++e)for(var i,u,o,f,a,h,v,y=0;y<r;++y)i=n[y],u=i.source,o=i.target,f=o.x+o.vx-u.x-u.vx||d(),a=o.y+o.vy-u.y-u.vy||d(),h=Math.sqrt(f*f+a*a),h=(h-l[y])/h*t*c[y],f*=h,a*=h,o.vx-=f*(v=x[y]),o.vy-=a*v,u.vx+=f*(v=1-v),u.vy+=a*v}function i(){if(h){var t,r,i=h.length,f=n.length,v=e.map(h,g);for(t=0,y=new Array(i);t<f;++t)r=n[t],r.index=t,"object"!=typeof r.source&&(r.source=a(v,r.source)),"object"!=typeof r.target&&(r.target=a(v,r.target)),y[r.source.index]=(y[r.source.index]||0)+1,y[r.target.index]=(y[r.target.index]||0)+1;for(t=0,x=new Array(f);t<f;++t)r=n[t],x[t]=y[r.source.index]/(y[r.source.index]+y[r.target.index]);c=new Array(f),u(),l=new Array(f),o()}}function u(){if(h)for(var t=0,e=n.length;t<e;++t)c[t]=+s(n[t],t,n)}function o(){if(h)for(var t=0,e=n.length;t<e;++t)l[t]=+p(n[t],t,n)}var c,l,h,y,x,g=f,s=t,p=v(30),M=1;return null==n&&(n=[]),r.initialize=function(n){h=n,i()},r.links=function(t){return arguments.length?(n=t,i(),r):n},r.id=function(n){return arguments.length?(g=n,r):g},r.iterations=function(n){return arguments.length?(M=+n,r):M},r.strength=function(n){return arguments.length?(s="function"==typeof n?n:v(+n),u(),r):s},r.distance=function(n){return arguments.length?(p="function"==typeof n?n:v(+n),o(),r):p},r},g=10,s=Math.PI*(3-Math.sqrt(5)),p=function(n){function t(){u(),p.call("tick",a),c<l&&(x.stop(),p.call("end",a))}function u(){var t,e,r=n.length;for(c+=(v-c)*h,y.each(function(n){n(c)}),t=0;t<r;++t)e=n[t],null==e.fx?e.x+=e.vx*=d:(e.x=e.fx,e.vx=0),null==e.fy?e.y+=e.vy*=d:(e.y=e.fy,e.vy=0)}function o(){for(var t,e=0,r=n.length;e<r;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=g*Math.sqrt(e),u=e*s;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function f(t){return t.initialize&&t.initialize(n),t}var a,c=1,l=.001,h=1-Math.pow(l,1/300),v=0,d=.6,y=e.map(),x=i.timer(t),p=r.dispatch("tick","end");return null==n&&(n=[]),o(),a={tick:u,restart:function(){return x.restart(t),a},stop:function(){return x.stop(),a},nodes:function(t){return arguments.length?(n=t,o(),y.each(f),a):n},alpha:function(n){return arguments.length?(c=+n,a):c},alphaMin:function(n){return arguments.length?(l=+n,a):l},alphaDecay:function(n){return arguments.length?(h=+n,a):+h},alphaTarget:function(n){return arguments.length?(v=+n,a):v},velocityDecay:function(n){return arguments.length?(d=1-n,a):1-d},force:function(n,t){return arguments.length>1?(null==t?y.remove(n):y.set(n,f(t)),a):y.get(n)},find:function(t,e,r){var i,u,o,f,a,c=0,l=n.length;for(null==r?r=1/0:r*=r,c=0;c<l;++c)f=n[c],i=t-f.x,u=e-f.y,(o=i*i+u*u)<r&&(a=f,r=o);return a},on:function(n,t){return arguments.length>1?(p.on(n,t),a):p.on(n)}}},M=function(){function n(n){var e,a=u.length,h=t.quadtree(u,c,l).visitAfter(r);for(f=n,e=0;e<a;++e)o=u[e],h.visit(i)}function e(){if(u){var n,t,e=u.length;for(a=new Array(e),n=0;n<e;++n)t=u[n],a[t.index]=+h(t,n,u)}}function r(n){var t,e,r,i,u,o=0;if(n.length){for(r=i=u=0;u<4;++u)(t=n[u])&&(e=t.value)&&(o+=e,r+=e*t.x,i+=e*t.y);n.x=r/o,n.y=i/o}else{t=n,t.x=t.data.x,t.y=t.data.y;do{o+=a[t.data.index]}while(t=t.next)}n.value=o}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-o.x,u=n.y-o.y,c=r-t,l=i*i+u*u;if(c*c/g<l)return l<x&&(0===i&&(i=d(),l+=i*i),0===u&&(u=d(),l+=u*u),l<y&&(l=Math.sqrt(y*l)),o.vx+=i*n.value*f/l,o.vy+=u*n.value*f/l),!0;if(!(n.length||l>=x)){(n.data!==o||n.next)&&(0===i&&(i=d(),l+=i*i),0===u&&(u=d(),l+=u*u),l<y&&(l=Math.sqrt(y*l)));do{n.data!==o&&(c=a[n.data.index]*f/l,o.vx+=i*c,o.vy+=u*c)}while(n=n.next)}}var u,o,f,a,h=v(-30),y=1,x=1/0,g=.81;return n.initialize=function(n){u=n,e()},n.strength=function(t){return arguments.length?(h="function"==typeof t?t:v(+t),e(),n):h},n.distanceMin=function(t){return arguments.length?(y=t*t,n):Math.sqrt(y)},n.distanceMax=function(t){return arguments.length?(x=t*t,n):Math.sqrt(x)},n.theta=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n},q=function(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vx+=(u[e]-t.x)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+o(r[t],t,r)}}var r,i,u,o=v(.1);return"function"!=typeof n&&(n=v(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:v(+n),e(),t):o},t.x=function(r){return arguments.length?(n="function"==typeof r?r:v(+r),e(),t):n},t},w=function(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vy+=(u[e]-t.y)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+o(r[t],t,r)}}var r,i,u,o=v(.1);return"function"!=typeof n&&(n=v(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(o="function"==typeof n?n:v(+n),e(),t):o},t.y=function(r){return arguments.length?(n="function"==typeof r?r:v(+r),e(),t):n},t};n.forceCenter=h,n.forceCollide=y,n.forceLink=x,n.forceManyBody=M,n.forceSimulation=p,n.forceX=q,n.forceY=w,Object.defineProperty(n,"__esModule",{value:!0})});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment