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

bare-minimum-2d

v0.3.0

Published

An extremely lightweight React component for plotting points, lines, ellipses, and polygons on an inline SVG

Downloads

11

Readme

A Bare Minimum 2D Plotter

An extremely lightweight React component to declaratively (and elegantly) plot shapes on an inline SVG

NPM MINIFIED GZIPPED

Demo Applications

| Responsive Illustrations | On-The-Fly Animations | Interactive Applications | | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | | | | | | demo | demo | demo | | source code | source code | source code |

Install

npm install --save bare-minimum-2d

Usage

This is an example of what you can pass to a BareMinimum2d component.

You pass it like so:

import BareMinimum2d from 'bare-minimum-2d'

<div style={{ width: '100%', height: '100vh' }}>
  <BareMinimum2d {...{ data, container }} />
</div>

The component takes the dimensions of its parent and is always centered

Everything you need to know explained in two minutes

A BareMinimum2d component only has two props: container and data. container is a small object with exactly four elements. data is an array containing objects.

Example:

import BareMinimum2d from 'bare-minimum-2d'

const container = {
  color: '#0000FF',
  opacity: 0.2,
  xRange: 300,
  yRange: 500
}

const data = [{
  x: [0],
  y: [0],
  color: "#FFFFFF",
  opacity: 1.0,
  size: 10,
  type: 'points',
  id: 'center'
}]

<div style={{ width: "100%", height: "100vh" }}>
  <BareMinimum2d {...{ data, container }} />
</div>

container.color and container.opacity specifies the canvas color of BareMinimum2d.

The cartesian coordinate system of BareMinimum will follow the diagram below given container.xRange and container.yRange. Position (0, 0) will always be at the center of the rendered component.

                  yRange/2
                     |
                     |
  -xRange/2 -------(0,0)--------- xRange/2
                     |
                     |
                   -yRange/2

Please take a look at more complex example data prop to get the idea. each element of the array data should be a hash-like objectwith a type key which should have a value that is one of the following:

| points | ellipse | lines | polygon | | ------ | -------- | ------ | -------- | | plural | singular | plural | singular |

Elements of the data array will be stacked based on the order they are declared. The first element will be at the most bottom layer while the last element of the array will be at the top.

All attributes are ALWAYS required, nothing is optional because there are no default values. The id attribute must be unique for each element of the data array.

Plugins

You can add your own shapes as a plugin for example, here's an example plugin written by @fuddl


const Triangle = ({ x, y, transforms, size, color, opacity, id, i }) => {
  const cx = transforms.tx(x)
  const cy = transforms.ty(y)
  const ySize = size * 0.8626
  return (
    <polygon
      {...{
        opacity,
        id: `${id}-${i}`,
        fill: color
      }}
      points={[
        `${cx},${cy - ySize}`,
        `${cx + size},${cy + ySize}`,
        `${cx - size},${cy + ySize}`
      ].join(' ')}
    />
  )
}

const trianglesPlugin = {
  triangle: (element, transforms) => {
    const { size, color, opacity, id } = element
    return element.x.map((x, i) => (
      <Triangle
        {...{
          x,
          y: element.y[i],
          size,
          color,
          opacity,
          id,
          i,
          transforms
        }}
        key={`${id}-${i}`}
      />
    ))
  }
}

And you can use it like so:

const triangle = {
  "x": [-163.72675374383329],
  "y": [-154.33259574213795],
  "opacity": 1,
  "size": 60,
  "color": "#2196F3",
  "type": "triangles",
  "id":"points0"
}

<div style={{ width: "100%", height: "100vh" }}>
  <BareMinimum2d {...{ data: [triangle], container, plugins: [trianglesPlugin] }} />
</div>

END

Contributing

  1. Clone this repository.
  2. Add your changes
  3. You can add a demo or update the demo based on your changes somewhere here
  4. After making your change go run the following command to see if it works as you expect.
npm install && npm run build && rm -rf node_modules && cd example && npm install && npm run start

PRs welcome! Please read the contributing guidelines and the commit style guide!

License

MIT © Mithi