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

nodal-background

v1.3.1

Published

Abstract animated nodal background JavaScript canvas library

Downloads

5

Readme

Nodal Background

Nodal Background An abstract animated nodal background JavaScript canvas library.

Features

  • Different modes of operation
    • AntiGravity produces a pleasing effect of nodes pulling away from each other.
    • Gravity creates a true n-body simulation with emerging chaotic behaviour.
    • Simple makes the simulation serene and non-distracting.
  • Fully configurable
    • Everything that could have been has been exposed as a configuration variable. Values can be changed that greatly affect the behaviour and visuals of the simulation.
    • Concrete implementations of abstract classes can be created to achieve custom behaviour.
  • Interactive
    • Nodes can be interacted with using the mouse
    • Click scrolling changes the mass of the added node

Usage

Installation

NPM Package link

npm install --save nodal-background

React

Custom wrapper

import { useNodalBackground } from "nodal-background"

export const NodalBackgroundComponent = (props: NodalBackgroundProps) => {
  const container = useRef()
  const {setContainer} = useNodalBackground({
    container: container.current,
    ...props
  })
  
  useEffect(() => {
    if (container.current) {
      setContainer(container.current)
    }
  }, [container.current])
  
  return <div ref={container}/>
}

Predefined wrapper

The wrapper above is also provided as an importable component.

import {NodalBackgroundComponent} from "nodal-background"

const YourComponent = () => <NodalBackgroundComponent>

Generic JavaScript / TypeScript

new NodalBackground({container: document.getElementById("id")})

Modes of operation

Gravity Mode

https://user-images.githubusercontent.com/5686338/139601589-d5fa1313-59cd-4112-b781-e68cad123f30.mp4

AntiGravity Mode

https://user-images.githubusercontent.com/5686338/139601633-0376d7a2-be8f-4a24-a39c-2415a0e8ce92.mp4

Configuration

All variables can be changed while the simulation is running.

Canvas is by default transparent, changing the background color below the canvas element combined with nodeColor and linkColor is an easy way to achieve a different theme.

The demonstration page can be used to interactively change the following controls.

Simulation controls

mode: NodalBackgroundMode

Controls the behaviour of the entire simulation.

  • NodalBackgroundMode.AntiGravity (default)
  • NodalBackgroundMode.Gravity
  • NodalBackgroundMode.Simple

simMaxDistance: number, default: 150

Maximum distance between two nodes for the interaction to be calculated. Higher numbers are more computationally expensive and create a more connected graph, whereas lower values produce fewer connection lines between nodes.

simMinDistance: number, default: 3

Minimum distance between two nodes for the interaction to be calculated. Lower values produce large slingshot speeds when nodes get or spawn close together. Higher values minimize the slingshot potential. Too high values will affect the perceived realism of the simulation.

simMassFactor: number, default: 1

Multiplier for node mass, affects speed and chaos.

simAttraction: number, default: 10

Multiplier for attraction, affects speed and chaos

Node controls

numberOfNodes: number, default: 100

The target number of nodes, relative to a 1200x1200 pixel area. Simulation complexity rises with O(n*log n), so higher numbers are discouraged.

preserveNumberOfNodes: boolean, default: true

Whether to delete extraneous nodes, with this disabled, the user created nodes do not disappear.

nodeColor: hex string, default: #000000

Color of the nodes.

nodeMaxInitialVelocity: number, default: 20

Node initial velocity is chosen at random from a range, this control affects that range. Higher values significantly affect the behaviour, increasing the chaos.

nodeInitialMass: number, default: 1.5

Initial mass of the nodes.

nodeInitialMassRange: number, default: 0

When greater than 0, initial mass of nodes will be randomized up to the value.

nodeMaxMass: number, default: 0

Maximum mass of the nodes, applied when merging. Value 0 sets no maximum mass.

nodeVisualSize: number, default: 0.5

Visual node size offset, does not affect the simulation apart from merging.

nodeAgeFactor: number, default: 0.5

How quickly nodes fade in after spawn.

nodeDeAgeFactor: number, default: 2

How quickly nodes fade out after leaving the area.

Link controls

linkColor: hex color, default: "#000000"

Changes the link color.

linkDash: setLineDash(segments: Array<number>), default: []

Changes the link line between nodes.

Documentation on MDN - setLineDash()

Performance

fps: number, default: 30

Sets the target FPS. Simulation is generally acceptable down to 20 fps.

fpsCounter: boolean, defaul: false

Displays the FPS counter, the current implementation of the fps counter has a negative impact on the actual fps, when bottlenecked it takes about 10fps.

Overrides

Custom simulation behaviour can be achieved by extending the base abstract classes.

For more information read the included implementing classes.

ticker: AbstractTicker

Ticker performs the simulation steps.

linker: AbstractLinker

Linker draws links between the nodes.