GithubHelp home page GithubHelp logo

vasturiano / d3-force-pod Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 1.0 265 KB

Component to automatically draw nodes/links in a D3 force simulation according to a set of forces

Home Page: https://vasturiano.github.io/d3-force-pod/example/column/

License: MIT License

JavaScript 81.59% HTML 18.41%
force d3-force-simulation d3js

d3-force-pod's Introduction

d3-force-pod

NPM package Build Size NPM Downloads

Component that runs a D3 force simulation and automatically draws circles/lines to an SVG canvas according to a configurable set of nodes, links and forces.

Nodes are prevented from escaping by hard-limiting the coordinates to the boundaries of the canvas.

Quick start

import d3ForcePod from 'd3-force-pod';

or using a script tag

<script src="//unpkg.com/d3-force-pod/dist/d3-force-pod.min.js"></script>

then

d3ForcePod()
    .genNodes()
    .addForce(d3.forceManyBody())
    (<myDOMElement>);

API reference

Method Description Default
width([number]) Getter/setter for the canvas width. window.innerWidth
height([number]) Getter/setter for the canvas height. window.innerHeight
nodes([array]) Getter/setter for the list of nodes. Each node should be an object with the following optional properties: { x, y, vx, vy, r }. []
links([array]) Getter/setter for the list of lines to draw between node pairs. Each link should follow the syntax: {source: <node index or node obj>, target: <node index or node obj>}. []
genNodes([object]) Convenience method for randomly generating nodes. See below for input options and defaults.
addForce(fn) Method to register a D3 force in the system.
simulation() Getter for the underlying simulation object. Can be used as an escape hatch to modify simulation parameters such as alphaDecay. d3.forceSimulation().alphaDecay(0).velocityDecay(0)
nodeColor([string or fn]) Getter/setter for the color accessor of the node circles #900C3F
linkColor([string or fn]) Getter/setter for the color accessor of the link lines #00008B

genNodes(options) defaults:

{
    density: 0.00025,             // nodes/px
    xRange: [0, width],           // px
    yRange: [0, height],          // px
    radiusRange: [1, 18],         // px
    velocityRange: [0, 4],        // px/tick
    velocityAngleRange: [0, 360]  // 0=right, 90=down
}

d3-force-pod's People

Contributors

dependabot[bot] avatar vasturiano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

w0lramd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.