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

vnodes

v1.3.3

Published

Vue components to create svg interactive graphs, diagrams or node visual tools.

Downloads

563

Readme

vnodes

Vue components to create svg interactive graphs, diagrams or node visual tools.

Demo

https://tiagolr.github.io/vnodes/

Install

npm install vnodes

Get started

<template>
  <screen ref="screen">
    <edge v-for="edge in graph.edges" :data="edge" :nodes="graph.nodes" :key="edge.id">
    </edge>

    <!-- html can be placed inside node, defaults to <div>{{node.id}}</div> -->
    <node v-for="node in graph.nodes" :data="node" :key="node.id">
    </node>
  </screen>
</template>
import { Screen, Node, Edge, graph } from 'vnodes'
export default {
  components: {
     Screen,
     Node,
     Edge
  }
  data () {
    return {
      graph: new graph()
    }
  }
  created () {
    this.graph.createNode('a')
    this.graph.createNode('b')
    this.graph.createEdge('a', 'b')
    this.graph.graphNodes()
  }
}

Components

Components are independent and can be imported separately.

Screen

Svg wrapper with zoom, panning and other features.

<screen>
  <circle cx="50" cy="50" r="50" fill="red"/>
</screen>

Screen Options

Screen component uses svg-pan-zoom under the hood and screen takes options prop like this

<screen :options="options">
  <circle cx="50" cy="50" r="50" fill="red"/>
</screen>

you can refer to available options here

{
  viewportSelector: string,
  panEnabled: boolean,
  controlIconsEnabled: boolean,
  zoomEnabled: boolean,
  dblClickZoomEnabled: boolean,
  mouseWheelZoomEnabled: boolean,
  preventMouseEventsDefault: boolean,
  zoomScaleSensitivity: number,
  minZoom: number,
  maxZoom: number,
  fit: boolean,
  contain: boolean,
  center: boolean,
  refreshRate: 'auto',
  beforeZoom: function(){},
  onZoom: function(){},
  beforePan: function(){},
  onPan: function(){},
  onUpdatedCTM: function(){},
  customEventsHandler: {},
  eventsListenerElement: null
}

Node

Html wrapper for svg with additional features like, dragging and fitting contents.

<svg width="500" height="500">
  <node :data="{
    id: 'test',
    x: 100,
    y: 100,
    width: 250,
    height: 150}">
      <h1>My First Node!</h1>
  </node>
</svg>

Edge

Connects nodes using svg lines

<edge :data="{
  from: { x: 0, y: 0},
  to: { x: 100, y: 100}}"
></edge>

Edges require node references { from: id|Object, to: String|Object }, if nodes are refered by id(String) an array nodes must be passed:

<edge
  :data="{from: 'A', to: 'B'}"
  :nodes="[{id: 'A' ... ]">
</edge>

Edges can take anchor information to offset their position relative to a node,

<edge :data="{
  from: nodes[0],
  to: nodes[1],
  fromAnchor: 'center',
  toAnchor: 'top-left',
}">

anchors format can be:

  • String 'center', 'left', 'right', 'top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'cirlce', 'rect'
  • Object { x?:Number|String, y?: Number|String, align?: String, snap?: String }

Examples of valid anchors:

null
{ x: 0, y: 0}
{ x: 10, y: 10 }
{ x: '50%', '50%' }
{ x: '50%', '50%', snap: 'rect' }
{ align: 'bottom-right' }
'center'
'top-left'
'circle'   // snaps offset to circle with radius node.width/2
'rect'     // snaps offset to node rectangle

Group

Surrounds a group of nodes with a rectangle, allows dragging multiple nodes.

<group :nodes="nodes">
  <h1>Group Label</h1>
</group>

Port

Placed inside a node, automatically offsets edges to a their position inside the nodes html [Ports demo].

Label

Create a label node that is positioned along an edge

<v-label :edge="graph.edges[0]" :perc="50" :offset="{x: 0, y: -50}">
  <h4>Content</h4>
</v-label>

graph.js

Can be used to store edges and nodes. Contains utility methods to build graphs, layouts, remove and create nodes, edges and so on.

Styling

The simplest way to style nodes and edges is using CSS

<style>
svg .node .content {
  border-radius: 50%;
  background-color: red;
}

svg .edge {
  stroke-width: 10;
  stroke: blue;
  marker-start: url(#arrow-start);
}
</style>

Markers

TODO routing orth manh metro https://resources.jointjs.com/demos/routing theme apply demo markers demo groups demo edge api review graph tools, nodes containing edge refs or adj list etc graph layouts https://www.yworks.com/products/yfiles/features#layout layered layouts https://github.com/erikbrinkman/d3-dag layered layouts https://www.yworks.com/pages/layered-graph-layout css animations demo/theme https://www.yworks.com/products/yfiles/features https://www.edrawmax.com/online/en/ https://js.cytoscape.org/