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

@tlowerison/react-d3-graph

v1.1.0

Published

A React graph component that uses d3-force.

Downloads

6

Readme

React D3 Graph

A React component which handles converting a root object and a collection of jmespath queries into a list of nodes, links and groups.

Install

yarn add @tlowerison/react-d3-graph

Example

A small example graph with deeply nested data can be put together really quickly with the Graph component. Both plots come from the same data (shown at the end); the idea is that the root object contains information about a flight on Alaska Airlines from San Francisco International Airport (SFO) to Portland International Airport (PDX). The nested Alaska Airlines object contains a list of it five hubs, and in the PDX airport object in that hub list, there is a list of all airlines that flying out of PDX.

Display graph with a root node

import React from "react";
import { Graph, GraphLinkDirection } from "@tlowerison/react-d3-graph";
import { data } from "./data";

export const FlightGraph = () => (
  <>
    <h2>Flight: {data.code}</h2>
    <Graph
      idField="uuid"
      defaultNameField="code"
      fontSize={{ nodeName: 7 }}
      root={data}
      config={{
        name: ({ code }) => `Flight ${code}`,
        links: [
          {
            nodes: [
              {
                path: "from",
                name: ["code", (code: string) => `From: ${code}`],
              },
              {
                path: "to",
                name: ["code", (code: string) => `To: ${code}`],
              },
            ]
          },
          {
            nodes: [{
              path: "airline",
              links: [{
                direction: GraphLinkDirection.None,
                nodes: [{
                  path: "hubs",
                  links: [{
                    direction: GraphLinkDirection.None,
                    nodes: [{
                      path: "airlines",
                    }],
                  }],
                }],
              }],
            }],
          },
        ],
      }}
    />
  </>
);

Display Graph without a root node

import React from "react";
import { Graph, GraphLinkDirection } from "@tlowerison/react-d3-graph";
import { data } from "./data";

export const FlightGraph = () => (
  <>
    <h2>Flight: {data.code}</h2>
    <Graph
      idField="uuid"
      defaultNameField="code"
      fontSize={{ nodeName: 7 }}
      root={data}
      config={[
        {
          name: "Flight 3368",
          nodes: [
            {
              path: "from",
              name: ["code", (code: string) => `From: ${code}`],
            },
            {
              path: "to",
              name: ["code", (code: string) => `To: ${code}`],
            },
          ]
        },
        {
          name: "Portland Airlines",
          nodes: [{
            path: "airline",
            links: [{
              direction: GraphLinkDirection.None,
              nodes: [{
                path: "hubs",
                links: [{
                  direction: GraphLinkDirection.None,
                  nodes: [{
                    path: "airlines",
                  }],
                }],
              }],
            }],
          }],
        },
      ]}
    />
  </>
);

Example Data used above

// data.ts
export const data = {
  __typename: "Flight",
  uuid: "0000-00000-0001",
  code: "3368",
  from: {
    __typename: "Airport",
    uuid: "0000-00000-0002",
    name: "San Francisco International Airport",
    city: "San Francisco, CA, United States",
    code: "SFO",
  },
  to: {
    __typename: "Airport",
    uuid: "0000-00000-0003",
    name: "Portland International Airport",
    city: "Portland, OR, United States",
    code: "PDX",
  },
  departure: "2021-01-01T06:00:00.000Z",
  arrival: "2021-01-01T20:00:00.000Z",
  airline: {
    __typename: "Airline",
    uuid: "0000-00000-0004",
    name: "Alaska Airlines",
    code: "AS",
    hubs: [
      {
        __typename: "Airport",
        uuid: "0000-00000-0005",
        name: "Los Angeles International Airport",
        city: "Los Angeles, CA, United States",
        code: "LAX",
      },
      {
        __typename: "Airport",
        uuid: "0000-00000-0006",
        name: "Seattle-Tacoma International Airport",
        city: "Seattle, WS, United States",
        code: "SEA",
      },
      {
        __typename: "Airport",
        uuid: "0000-00000-0007",
        name: "Ted Stevens Anchorage International Airport",
        city: "Anchorage, AK, United States",
        code: "ANC",
      },
      {
        __typename: "Airport",
        uuid: "0000-00000-0002",
        name: "San Francisco International Airport",
        city: "San Francisco, CA, United States",
        code: "SFO",
      },
      {
        __typename: "Airport",
        uuid: "0000-00000-0003",
        name: "Portland International Airport",
        city: "Portland, OR, United States",
        code: "PDX",
        airlines: [
          {
            __typename: "Airline",
            uuid: "0000-00000-0004",
            name: "Alaska Airlines",
            code: "AS",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0008",
            name: "Air Canada",
            code: "AC",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0009",
            name: "Allegiant Air",
            code: "AAY",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0010",
            name: "American",
            code: "AA",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0011",
            name: "Boutique Air",
            code: "4B",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0012",
            name: "Condor",
            code: "DE",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0013",
            name: "Delta Air Lines",
            code: "DL",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0014",
            name: "Frontier Airlines",
            code: "F9",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0015",
            name: "Hawaiin",
            code: "HA",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0016",
            name: "JetBlue",
            code: "B6",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0017",
            name: "Southwest Airlines",
            code: "WN",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0018",
            name: "Spirit Airlines",
            code: "NK",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0019",
            name: "Sun Country Airlines",
            code: "SY",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0020",
            name: "United Airlines",
            code: "UA",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0021",
            name: "Volaris",
            code: "Y4",
          },
          {
            __typename: "Airline",
            uuid: "0000-00000-0022",
            name: "WestJet Encore",
            code: "WR",
          },
        ],
      },
    ],
  },
};