Skip to content

cthroo/d3-force-bounded-box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A D3 force. Inspired by https://bl.ocks.org/cmgiven/547658968d365bcc324f3e62e175709b

Examples:

import boundedBox from 'd3-force-bounded-box'
import { forceSimulation } from 'd3-force'

const nodeData = [
  {
    size: 52,
    x: 0,
    y: 0,
    vx: 0,
    vy: 0,
  }
]

const boxForce = boundedBox()
  .bounds([[0, 0], [width, height]])
  .size(d => [d.size, d.size]);

const simulation = forceSimulation(nodeData)
  .force('boxForce', boxForce);