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

@mvarble/viewport-planar-graph

v0.1.9

Published

A Cycle.js component for managing planar graphs and interfacing them with the viewport.js API

Downloads

15

Readme

viewport-planar-graph

A Cycle.js component for managing planar graphs and interfacing them with the viewport.js API.

Example

For Blender users, this UI may look familiar. The user is able to create and drag collections of nodes around in the plane drag edges between them with ease.

viewport example

API

PlanarGraph

sink = PlanarGraph({ state, frameState, addNode, removeNode })

Manages a State

This is a component that is responsible for maintaining a state of the form:

{
  type: 'graph-frame',
  worldMatrix: [...],
  children: [
    { type: 'graph-node', key: 1, children: [...], data: {...} },
    ...
    { type: 'graph-node', key: 420, children: [...], data: {...} },
  ],
  data: { 
    graph: {
      nodes: [
        { key: 1, data: {...}, location: [x1, y1] },
        ...
        { key: 420, data: {...}, location: [x420, y420] },
      ], 
      edges: [
        { key: 1, head: 0, tail: 69 }
        ...
        { key: 666, head: 8, tail: 23 }
      ] 
    } 
  }
}

The object is intended to be a frames.js frame, capable of being parsed for clicks on the canvas. The graphFrame.data.graph serves in some sense as a redundant copy of the information in graphFrame.children, but more easily parsable by the user. Each element of graphFrame.data.nodes has a location key which encodes the coordinates of the node with respect to the coordinate system of the entire object. Each element of graphFrame.data.edges has head and tail keys, which correspond to the directed edge between the nodes of which node.key matches.

The component is designed to manage this state by taking streams of clicks from a viewport.js ViewportDriver. The state this component manages can then be embedded into the state of a Viewport component and be rendered accordingly.

Signature

The sources are:

  • frameSource: a FrameSource instance with mounted DOMSource, as outputted by the ViewportDriver; see more here.
  • state: the state source as provided by withState; see more here.
  • addNode: a stream of objects of the form { location: [x, y], data: {...} }, as one would see in an element of graphFrame.data.graph.nodes.
  • removeNode: a stream of keys corresponding to that belonging to the node we would like to remove.

The sinks are:

  • state: a stream of reducers.
  • messages: a stream of logs for the intent of the graph.

renderGraph

renderGraph(context, graphFrame, options)

This is an imperative function that is intended to be called within the render function of a Viewport component; see more here. The context is the canvas context we are using to render, the graphFrame is the state of the planar graph, and options is an (optional) object with attributes:

  • activeBorder: the color of the border of a node that is active,
  • selectedBorder: the color of the border of a node that is selected,
  • deselectedBorder: the color of the border of a node that is neither of the above.
  • fillStyle: the fill of a node.
  • inFillStyle: the fill of the little box that takes in edges.
  • outFillStyle: the fill of the little box that gives out edges.
  • toColor: the color of an edge that is not connected to anything (when dragging)
  • tailColor: the color of an edge that is connected to another node.