GithubHelp home page GithubHelp logo

hhogg / sysplot Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 72 KB

A library that systematically generates a plane for plotting shapes, with a variety of algorithms to choose from.

License: MIT License

JavaScript 100.00%
plotting archimedes concentric fermat ulam vogel

sysplot's Introduction

SysPlot

A library that systematically generates a plane for plotting shapes, with a variety of algorithms to choose from.

Install

$ yarn add sysplot

Usage

SysPlot is used for generating XY coordinates for placing shapes. It is agnostic about the approach used for the visualisation, be it HTML, SVG, Canvas, WebGL.. etc.

Positions will be given starting from the center and will attempt to fill as much space as possible.

import SysPlot, { VogelSpiral /* any provided algorithm */ } from 'sysplot';

const sysPlot = new SysPlot();

sysPlot.setConfig({
  algorithm: VogelSpiral,
  cover: true,
  padding: 10,
  proportional: true,
  spread: 0.25,
});

sysPlot.setBounds(1000, 500);

const shapes = [{
  radius: 20,
}, {
  width: 30,
  height: 50,
}]

/** Give it the shapes to calculate the position for. */
sysPlot.setShape(shapes);

/** Get the positions for those shapes */
const positions = sysPlot.getPositions();

/** Shapes that were unable to be placed will have no position */
const shapesWithValidPositions = zip(positions, shapes).filter(([, p]) => p);

Algorithms

ArchimedesSpiral

The Archimedean spiral (also known as the arithmetic spiral) is a spiral named after the 3rd century BC Greek mathematician Archimedes. It is the locus of points corresponding to the locations over time of a point moving away from a fixed point with a constant speed along a line which rotates with constant angular velocity.

Wikipedia - Archimedes Spiral

ConcentricCircles

In geometry, two or more objects are said to be concentric, coaxal, or coaxial when they share the same center or axis.

Wikipedia - Concentric Circles

FermatSpiral

Fermat's spiral (also known as a parabolic spiral) was first discovered by Pierre de Fermat. It is a type of Archimedean spiral

Wikipedia - Fermat Spiral

UlamSpiral

The Ulam spiral or prime spiral (in other languages also called the Ulam cloth) is a graphical depiction of the set of prime numbers... It is constructed by writing the positive integers in a square spiral and specially marking the prime numbers.

Wikipedia - Ulam Spiral

VogelSpiral

In disc phyllotaxis, as in the sunflower and daisy, the mesh of spirals occurs in Fibonacci numbers because divergence (angle of succession in a single spiral arrangement) approaches the golden ratio.

Wikipedia - Vogel Spiral

API

Config Object

const config = {
  /**
   * One of the exported algorithm functions mentioned above.
   *
   * Defaults: ArchimedesSpiral
   */
  algorithm: Function,

  /**
   * An explicit aspect ratio, irrespective of the given bounds, for
   * plotting the vectors.
   *
   * Defaults: 1
   */
  aspectRatio: Number,

  /**
   * Specifies to generate as many vector points needed to cover the entire
   * area give.
   *
   * Defaults: true
   */
  cover: Boolean

  /**
   * The amount of padding to be used around the shapes when
   * positioning.
   *
   * Defaults: 10
   */
  padding: Number,

  /**
   * Retains the aspect ratio (taking from the bounds) for plotting the vector points.
   *
   * Defaults: false
   */
  proportional: Boolean,

  /**
   * A number between 0.1 and 1 that affects the density of the
   * vector points. 0.1 being very dense and 1 being very spread
   * apart.
   *
   * Defaults: 0.25
   */
  spread: Number,
}

SysPlot()

The main class for storing the environment and generating vectors and positions.

new SysPlot();

Sysplot.setConfig(configObject)

Updates the config and sets a flag to regenerate the plotting vectors and/or the positions on next getPositions() call.

sysPlot.setConfig(configObject);

SysPlot.setBounds(width, height)

Sets the bounds to generate the plotting vectors for.

const width = 1000;
const height = 500;

sysPlot.setBounds(width, height);

SysPlot.setShapes(shapes)

Sets the shapes and sets a flag to regenerate positions on next getPositions() call.

const shapes = [{
  radius: 20,
}, {
  width: 30,
  height: 50,
}]

sysPlot.setShapes(shapes);

SysPlot.getPositions()

Gets the positions for the set shapes. Returns XY coordinates in order of the shapes that were set. Any shapes they were unable to be positioned will be null.

const shapes = [...];
const positions = sysPlot.getPositions();

const shapesWithValidPositions = zip(positions, shapes).filter(([, p]) => p);

SysPlot.getVectors()

Gets the vector points used for positioning (as XY coordinates) that the algorithm generated, radiating out from the center.

sysPlot.getVectors(); // [[x, y], [x, y] ...etc]

Performance

Generating the vector points and positioning the shapes can be intensive depending on the algorithm used, the number of shapes and the spread option. SysPlot will only generate new vectors and positions if it needs to, which is determined when certain parts of the config, bounds or shapes change.

Use the setBounds, setConfig and setShapes methods when the environment changes.

sysplot's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

andy-polhill

sysplot's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

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.