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

graph-visualizer

v0.10.12

Published

discover nodes and edges in a flexible way

Downloads

7

Readme

Graph visualizer

Displays the nodes and edges from a dataset that the user can specify. Meant to be integrated in other applications.

Live demo

https://afasresearch.github.io/graph-visualizer/

Embedding

When loaded, this library exposes a <graph-visualizer> (GraphVisualizerElement) custom element. it has the following attributes:

  • data-url: url which can be fetched that will retrieve json in the GraphData format describing all nodes and edges
  • data-variable: global variable stored on window that contains GraphData, alternative of data-url
  • local-storage-key: when specified, the library stores its state in localstorage under this key
  • edges-to-highlight: a space separated string consisting of keys from edges that should be highlighted
  • nodes-to-highlight: a space separated string consisting of keys from nodes that should be highlighted

It also has the following properties:

  • data: can be used to programmatically set the GraphData for the graph to render. Two things are important:

    • All arrays, maps and objects in GraphData are considered immutable once they have been set on the component. Making changes to these objects will cause problems.
    • Reuse as many arrays, maps and objects from previous GraphData as possible for optimal performance.

    Changing a location programmatically can therefore be best achieved using the following code:

let data = { ...graphVisualizerElement.data, positions: [...graphVisualizerElement.data.positions] };
data.positions[2] = { nodeKey: 'a', x: 0, y: 0 }; // modifications are still allowed, because data.positions is a new array
graphVisualizerElement.data = data;

It fires the following events:

  • navigate: will be called when the user clicks on the arrow of a node to navigate to its details
  • selectionchange: will be used to notify that the user changed the selected node
  • positionschange: used to inform that the user modified/deleted/cleared the positions of one of the nodes. Detail is a PositionsChange type

Custom styling

Attributes can be placed on nodes, like typename=Event. These can be picked up in css using the following construct

graph-visualizer::part(typename\=Event) {
  --color-primary:blue;
}

Which causes the primary color to change. variables used are --color-background, --color-primary and --color-secondary.

Internals

Algorithm: pure function executed on every render:

  • input (API): NodeData + VisualizationEntry

    • config = NodeModel
  • nodeRenderers provide Dimensions to NodeModels

  • EdgeData is queried to determine visible edges, create EdgeLayouts

  • Render:

    • EdgeLayouts line
    • NodeLayouts
    • EdgeLayouts decoration
  • 'Session' state:

    • zoom, transform
    • selected node

Future plans / niceties

  • Gray out existing nodes, center on click
  • hover for long names in sidebar
  • Dark mode
  • Touch support