├── .babelrc ├── .eslintrc ├── .gitignore ├── .npmignore ├── .nvmrc ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── lib └── forceCluster.js ├── package.json ├── rollup.config.js └── test └── forceCluster-test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "es2015" ] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "eslint:recommended", 4 | "env": { 5 | "node": true, 6 | "mocha": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | coverage 3 | node_modules 4 | npm_debug.log 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | coverage 3 | node_modules 4 | npm_debug.log 5 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 5.11.1 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 5.11.1 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Eric Socolofsky 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of contributors may be used to 15 | endorse or promote products derived from this software without specific prior 16 | written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # d3-force-cluster 2 | 3 | Modular force for use with D3's [`forceSimulation`](https://github.com/d3/d3-force#forceSimulation). 4 | 5 | Pulls nodes toward a set of cluster center nodes / points. Works well with a [collision force](https://github.com/d3/d3-force/blob/master/README.md#collision) to pack nodes together in clusters with no overlap. 6 | 7 | Adapted from Mike Bostock's [Clustered Force Layout III](https://bl.ocks.org/mbostock/7881887). 8 | 9 | [![Build Status](https://travis-ci.org/ericsoco/d3-force-cluster.svg?branch=master)](https://travis-ci.org/ericsoco/d3-force-cluster) 10 | 11 | 12 | ## Installing 13 | 14 | #### npm 15 | 16 | `npm install d3-force-cluster` 17 | 18 | #### CDN ([UNPKG](https://unpkg.com/)), via `` 21 | 22 | #### Local, via `` 27 | 28 | 29 | ## Usage 30 | 31 | ### Accessing the module 32 | 33 | The install method you use determines the syntax for accessing the module in your code: 34 | 35 | #### npm 36 | 37 | Import the `forceCluster()` method and use it in a `forceSimulation`. 38 | 39 | ``` 40 | import { forceCluster } from 'd3-force-cluster' 41 | // ... 42 | d3.forceSimulation 43 | .force('cluster', forceCluster()); 44 | ``` 45 | 46 | #### via `