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-pixi-plot

v1.0.0-rc.4

Published

A React component rendering a zoomable and draggable PIXI.js scene. Intended to render 2d plots

Downloads

2

Readme

React Pixi Plot - Make interactive plots with React and WebGL

ReactPixiPlot is a Javascript library for writing PixiJS plots using React declarative style. It relies on react-pixi-fiber to render the plot

Usage

import { render } from 'react-dom';
import * as PIXI from 'pixi.js';
import React from 'react';
import countries from './countries.json';
import white_circle from './white_circle.png';
import { scaleLinear } from 'd3-scale';
import { extent } from 'd3-array';
import {
	PixiPlot, RescalingSprite,
  DraggableContainer, ZoomableContainer
} from 'react-pixi-plot';

PIXI.loader.add('circle', white_circle);
PIXI.loader.load(() => {
  const xScale = scaleLinear()
    .domain(extent(countries, (c: any) => c.NetMigration as number)).range([0, 100]);
  const yScale = scaleLinear()
    .domain(extent(countries, (c: any) => c.Literacy as number)).range([100, 0]);

  const displayObjects = countries.map((country) => {
    return <RescalingSprite
      key={country.Name}
      texture={PIXI.loader.resources.circle.texture}
      position={new PIXI.Point(xScale(country.NetMigration), yScale(country.Literacy))}
      pixelWidth={10}
      pixelHeight={10}
      tint={0xFF0000}
    />;
  });

  render(
    <div style={{
      marginLeft:'25%', marginRight:'25%', marginTop: 50, marginBottom: 50,
      border: '1px solid black', height: '100%', display: 'flex',
    }}>
      <PixiPlot
        leftAxisScale={yScale} leftLabel={'Literacy'}
        bottomAxisScale={xScale} bottomLabel={'Net Migration'}
        rendererMargins={{ left:50, right:50, top:50, bottom:50 }}
      >
        <DraggableContainer>
          <ZoomableContainer>
            {displayObjects}
          </ZoomableContainer>
        </DraggableContainer>
      </PixiPlot>
    </div>
    ,
    document.getElementById('container'));
});

Components

This library provides the following components allowing for the easy creation of an interactive plot.

<PixiPlot />

import {PixiPlot} from 'react-pixi-plot';

PixiPlot is the main component to use to render a plot. It will render a PIXI.js canvas, using the react-pixi-fiber Stage component.

Children of a PixiPlot element are rendered using react-pixi-fiber, and thus must be components from that library, one of the components below, or a customPIXIComponent.

PixiPlot allows you to render axes around the plot, using d3 scales. The following props can be given to PixiPlot:

type AnyScale =
  ScaleContinuousNumeric<number, number>
  | ScaleBand<any>
  | ScalePoint<any>;

interface PixiPlotProps {
  /**
   * A d3 scale that will be displayed along the left axis.
   * You need to specify a renderer margin to allow room for this axis
   */
  readonly leftAxisScale?: AnyScale;

  /**
   * The label for the left axis
   */
  readonly leftLabel?: string;

  /**
   * A d3 scale that will be displayed along the right axis.
   * You need to specify a renderer margin to allow room for this axis
   */
  readonly rightAxisScale?: AnyScale;

  /**
   * The label for the right axis
   */
  readonly rightLabel?: string;

  /**
   * A d3 scale that will be displayed along the top axis.
   * You need to specify a renderer margin to allow room for this axis
   */
  readonly topAxisScale?: AnyScale;

  /**
   * The label for the top axis
   */
  readonly topLabel?: string;

  /**
   * A d3 scale that will be displayed along the bottom axis.
   * You need to specify a renderer margin to allow room for this axis
   */
  readonly bottomAxisScale?: AnyScale;

  /**
   * The label for the bottom axis
   */
  readonly bottomLabel?: string;

  /**
   * The margins around the renderer, where you can display axes for instance
   */
  readonly rendererMargins?: {
    left: number, right: number, top: number, bottom: number
  };
}

<DraggableContainer />

import {DraggableContainer} from 'react-pixi-plot';

A simple PIXI container that makes the viewport draggable by using the mouse right click.

<ZoomableContainer />

import {ZoomableContainer} from 'react-pixi-plot';

A PIXI container that makes the viewport zoomable by scrolling. If used in combination with DraggableContainer, ZoomableContainer should be a child of DraggableContainer.

<SelectionContainer />

import {SelectionContainer} from 'react-pixi-plot';

A container that captures mouse interactions such as selection (left click), hovering, and brushing (click and drag). During brushing operations, an optional selection overlay can be rendered.

<RescalingSprite />

import {RescalingSprite} from 'react-pixi-plot';

To be used in combination with a ZoomableContainer, this sprite always renders with the same height and width in pixels. Useful for instance for scatterplots, allowing you to get more detail values when zooming without ending up with very large sprites.

<SVGContainer />

import {SVGContainer} from 'react-pixi-plot';

A container that will reproduce the contents of an SVG HTML element with one or more PIXI.Graphics.