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/graph-viewport

v0.1.1

Published

Graph manipulation in the HTML canvas

Downloads

5

Readme

graph-viewport

This module exports a viewport.js component which allows the user to manipulate a (directed) graph in the canvas. The animation below showcases how one would maneuver the viewport and edit edge data.

viewport example

The State

The component requires @cycle/state logic as provided by the factory Cycle.js functions. The state at any given point should have the following shape.

{
  type: 'root',
  canvas: // the HTMLCanvas element
  width: // (optional) width of canvas; inherited by parent.offsetWidth,
  height: // (optional) height of canvas; inherited by parent.offsetHeight,
  children: [{
    type: 'window',
    worldMatrix: // 3x3 identity initially suggested,
    children: [{
      type: 'plane',
      worldMatrix: // [[0.1, 0, 0], [0, 0.1, 0], [0, 0, 1]] initially suggested,
      children: // Array<graph-node>
    }]
  }]
}

{
  type: 'graph-node',
  key: // unique key among siblings,
  worldMatrix: // suggested to be a function of parent's worldMatrix,
  data: {
    clickBox: [-1, -1, 1, 1],
    title: // string for printed title,
    selected: // boolean for if it is selected,
    active: // boolean for if it is active,
  },
  children: [
    inEdgeNode // in-edge-node,
    ...outEdgeNodes // Array<out-edge-node>
  ]
}

{
  type: 'in-edge-node',
  worldMatrix: // suggested to be a function of parent's worldMatrix,
  data: {
    clickBox: [-4, -4, 4, 1],
    parentKey: // parent's key,
  }
}

{
  type: 'out-edge-node',
  key: // unique key among siblings,
  worldMatrix: // suggested to be a function of parent's worldMatrix,
  data: {
    clickBox: [-4, -4, 4, 1],
    parentKey: // parent's key,
  }
}

The component is not responsible for adding/removing nodes, but this can easily be implemented outside the component by implementing the appropriate reducers, provided as discussed below.

API

GraphViewport

This is the component which is responsible for editting a graph on the canvas. The sources are as follows:

| Source | Description | |---|---| | DOM | the object provided by the factory Cycle.js DomDriver. Isolation suggested. | | props | a stream of an object with field initState which is a state like above | | state | the source that every Cycle.js app has, when mounted with withState as in @cycle/state |

The sinks are as follows:

| Sink | Description | |---|---| | DOM | the DOMObject corresponding to the canvas. | | state | the reducer stream, as requested in the @cycle/state paradigm | | viewport | the sources.state.stream | | preventDefault | a stream of events in which one should have a driver which adds a listener such that listener.next executes event.preventDefault() |

renderGraphViewport

This is a function of signature (canvas, state) => void which can be provided to the makeViewportDriver API.

appendNode

This is a reducer which adds a graph-node to the state tree.

newTree = appendNode(tree);

deleteSelectedNodes

This is a reducer which deletes all of the graph-nodes which have node.data.selected.

newTree = deleteSelectedNodes(tree);