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

react-graphesque

v0.1.0

Published

A library for easing development of custom graphs. React bindings. 16.3+ for now.

Downloads

7

Readme

react-graphesque

First thing’s first; why another graphing library?
The simple answer is that this library is meant to help developers make custom graphs.

If you just need a visualization framework that will take your data and a title and give you a bar graph, or a line graph, I would argue that while it is simple to accomplish here, this is probably not the library for you, and that is OK.

If, however, you have been tasked with making graphs with custom styles, custom logic, and custom behaviour, and you have grown accustomed to juggling logic for computing values, and putting data points into the graph at the right point, mixed with rendering, and flipping the y value, and all of the rest...
or, alternatively, you’ve been tasked with making a graphing library that lets people plug in data and see results...
then please do read on.

Graphesque works by first forcing you to separate your domain logic from your graphing algebra, helping you with the latter, giving you a hook for rendering, and then getting out of your way. It’s not a “graphing library” so much as it’s a graphing library library.

Install

npm install --save react-graphesque

Usage

Example 1: The Basics

To start, we need some data.

const points = [
  { x: 0.2, y: 0.8 },
  { x: 0.4, y: 0.6 },
  { x: 0.6, y: 0.4 },
  { x: 0.8, y: 0.2 },
];

Nota bene: each point has an x and a y, and each value is a fractional value. For Graphesque to do it’s job, each value for x and y must be fractional. This might seem like an arbitrary limitation, right now, but it will become empowering in the future, as you define the purpose for your graphs.

Now that we have data, we can include it in our example. For now, only SVG is available as output, so let’s work with what we have.

import {
  SVGGraph as Graph,
  SVGPlot as Plot,
  SVGPointSeries as PointSeries,
  SVGLineSeries as LineSeries
} from "react-graphesque";

const points = [
  { x: 0.2, y: 0.8 },
  { x: 0.4, y: 0.6 },
  { x: 0.6, y: 0.4 },
  { x: 0.8, y: 0.2 },
];

const Circle = ({ point }) => (
  <circle
    cx={point.x}
    cy={point.y}
    r={5} />
);

export const ExampleGraph = () => (
  <Graph>
    <Plot>
      <PointSeries points={points} renderPoint={Circle} />
    </Plot>
  </Graph>
);

If you render ExampleGraph, you should have 4 dots drawn across your screen, descending.

Let’s take this example one step further, and connect the dots.

const Circle = ({ point }) => (
  <circle
    cx={point.x}
    cy={point.y}
    r={arbitraryRadius}/>
);

const Line = ({ line: [start, end] }) => (
  <line
    x1={start.point.x}
    y1={start.point.y}
    x2={end.point.x}
    y2={end.point.y} />
);

export const ExampleGraph = () => (
  <Graph>
    <Plot>
      <LineSeries points={points} renderLine={Line} />
      <PointSeries points={points} renderPoint={Circle} />
    </Plot>
  </Graph>
);

The Points and the Lines will render just fine without a Plot, as well.

export const ExampleGraph = () => (
  <Graph>
    <LineSeries points={points} renderLine={Line} />
    <PointSeries points={points} renderPoint={Circle} />
  </Graph>
);

Though if you do this, you might notice that the points (and lines) have flipped from descending to ascending (more on that later).

TODO

  • support toggling clipping in Plot
  • add RadialSeries for pies/doughnuts/et cetera
  • add CustomSeries support
  • add TypeScript types
  • add test suite
  • add API documentation
  • add walkthroughs

Farther in the future:

  • support Canvas as the backing renderer
  • support React Native
  • support other frameworks

License

MIT © seanmay