npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-force-gravity

v1.0.2

Published

Implement gravitational attraction (or force-field-like repulsion) using d3-force

Downloads

272

Readme

d3-force-gravity Build Status Coverage Status npm version

Implement gravitational attraction (or force-field-like repulsion) using d3-force

sample

Go here for a live demo and here for the code used in the demo

Installation

Using npm :

$ npm install --save d3-force-gravity

If you want to use this directly on your browser, use the contents of d3-force-gravity.min.js, or, include this script after the d3 library in your HTML file :

<script src="https://raw.githubusercontent.com/sohamkamani/d3-force-gravity/master/d3-force-gravity.min.js" charset="utf-8"></script>

Usage

Using npm :

const width = 200
const height = 400

//First, require the module
const forceGravity = require('d3-force-gravity')

//Add it to your d3 force simulation, just like other forces
d3.forceSimulation()
	.force('gravity', forceGravity(width/2, height/2))

Using directly in the browser :

  1. Follow installation steps above, and include the appropriate script.
  2. This force will be made available on d3.forceGravity.
  3. Be sure to include the d3 library first

Documentation

forceGravity([x, y])

Creates a new gravitational force centered on the coordinates x and y.

Defaults :

x : 0  
y : 0

Returns a new gravity force

gravity.strength([strength])

If strength is specified, sets the strength of the force to its value, and returns the force.

If it is not specified, returns the current value of the forces strength.

If the strength is negative, it will lead to replusion of all nodes from the center of the force.

Default : 10000

gravity.minRadius([minRadius])

The minimum radius outside of which this force is applied. Any node closer in distance to the center than this value, is not affected by the force. This is to prevent the enormous amount of force that would result from particles getting too close (tending to infinity at the center)

If minRadius is specified, sets the minRadius of the force to its value, and returns the force.

If it is not specified, returns the current value of the forces minRadius.

Default : 40

gravity.x([x])

Set the x coordinate of the center of the force.

If x is specified, sets the x coordinate of the force to its value, and returns the force.

If it is not specified, returns the current value of the forces x coordinate.

gravity.y([y])

Set the y coordinate of the center of the force.

If y is specified, sets the y coordinate of the force to its value, and returns the force.

If it is not specified, returns the current value of the forces y coordinate.

License

MIT © sohamkamani