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

leaflet-network

v0.5.4

Published

Leaflet plugin to visualise arbitrary network connectivity between spatial data points

Downloads

7

Readme

leaflet-network NPM version NPM Downloads

ALPHA leaflet plugin to visualise (weighted) network connectivity between spatial data points. It uses d3.js v4 to visualise the network connections on a L.SVG layer.

There is an interactive notebook example here: https://beta.observablehq.com/@danwild/network-connectivity-template

Node connectivity weights can be represented:

  • GLOBAL: node connection weights are scaled against all other connections in the matrix (only SOURCE / downstream displayMode supported).
  • LOCAL: node connection weights are scaled to only the connections of the selected target.
  • NONE: connection weights are ignored, simplified display.

This plugin only supports Leaflet ^v1.0.0.

Screenshot

install, build

  • install: npm install leaflet-network
  • build: gulp

usage

Init plugin with map and data (see gh-pages branch for full demo):

// create a basemap
var canvas = L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
	attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
	subdomains: 'abcd',
	maxZoom: 19
});

// setup our leaflet map
var map = L.map('map', {
	layers: [ canvas ],
	center: L.latLng(-25, 134),
	zoom: 5
});

// create a layer control so we can show/hide network layer
var layerControl = L.control.layers();
layerControl.addTo(map);

// init the network layer
var networkLayer = L.networkLayer({

	// optional pane to add the layer, defaults to 'overlayPane'
	// note that the elem must be tagged with a unique id
	pane: {
		name: 'myPane', // the leaflet pane name
		elem: '<HTMLElement>'
	},

	// see expected data format below
	data: data,

	// One of:
	// - SOURCE: visualise connections that are downstream from the target node
	// - SINK:   visualise connections that are upstream from the target node
	// - ANY:    visualise any connections related to the target node (useful if not concerned with SOURCE/SINKs)
	// - BOTH:   visualise connections that are upstream or downstream from the target node, differs to ANY as it
	//   keeps SOURCE/SINK weightings separate, whereas ANY is a simple merge
	displayMode: 'SOURCE',

	// domain is the min/max boundaries of values that will be used to fit data to the range scale, defaults to auto
	// fit data (min, max-10%), often needs tweaking (depends on shape of your data)
	// if this terminology is confusing you, see:
	// https://javascript.tutorialhorizon.com/2015/01/17/d3-fundamentals-understanding-domain-range-and-scales-in-d3js/
	globalScaleDomain: [0, 100],

	// If provided, any data (weights) outside of the clipRange will be ignored
	clipRange: [25, 75],

	// How the connection weights should be scaled
	// One of: ['GLOBAL', 'LOCAL', 'NONE']
	weightMode: 'GLOBAL',

	// the color scale to use to represent connection strengths
	// note that when used with displayMode=BOTH, SOURCE/SINK connections will be
	// displayed on independent scales (to unify scales, use displayMode=ANY).
	colorScale: ["green", "yellow", "red"],

	// color for connections when not scaled colors
	// i.e. weightMode='NONE'
	sourceColor: 'red',
	sinkColor: 'green',
	allColor: 'blue',

	// styling options for node circles
	nodeFillColor: 'red',
	nodeRadius: 5,
	nodeOpacity: 0.5,

	// styling for connection lines
	lineInactiveColor: 'grey',
	lineOpacity: 0.8,
	lineWidth: 2,
	lineWidthActive: 2,
	lineDashStyle: ("20, 3") // e.g. draw 20, dash 3. default null.

	// whether to use arrows to show line direction,
	// arrows derive their width and opacity from line
	arrows: true,

	arrowSpacing: 100, // pixel distance to space arrowheads (there will be at least always one)

	// if set to false, lines will only be shown for active connections
    // (not valid for weightMode: GLOBAL)
    displayInactive: true, // default: true

	// callback function for click event on node, receives target node
	onClickNode: function(node){
	  // e.g. add clear selection button
	},

	// callback function for mouseenter event on node, receives target node
	onMouseEnterNode: function(node){
	  // e.g. set a tooltip
	},

	// callback function for mouseleave event on node, receives target node
	onMouseLeaveNode: function(node){
	  // e.g. remove a tooltip
	}

	// callback function for mouseenter event on line, receives dom elem
	// which has some data attributes, e.g. weight, lat, long
	onMouseEnterLine: function(elem){
	  // e.g. display elem.dataset.weight

	},

	// callback function for mouseleave event on line, receives dom elem
	// which has some data attributes, e.g. weight, lat, long
	onMouseLeaveLine: function(elem){
	  // e.g. hide weight
	}

});

// add layer as an overlay
layerControl.addOverlay(networkLayer, 'Network Example');

public methods

|method|params|description| |---|---|---| |update||trigger a redraw of all elements using current target| |setData|data: {Object}|update the layer with new data| |setOptions|options: {Object}|update the layer with new options| |setTarget|id: {String}|Set the active target node by id| |getTargetId||Get ID of the active target node| |setDisplayMode|mode: {String}|one of: SOURCE, SINK, ANY, BOTH| |getPointById|id: {String}|Get a node by id| |isActive||Check if layer is active on the map| |getLatLngBounds||Returns leaflet LatLngBounds of the layer| |getConnectionsDomain|clipped: {Boolean}, Optional: data: {Object}|Get the domain (min/max) of values in the data array (defaults to current)|

data format

var data = [
  {
    "properties": {
      "lat": "",
      "lon": "",
      "id": "uid1"
    },
    "connections": {
      "uid1": 233,    // connection score to self, ignored
      "uid2": 0,      // null connection, could be omited
      "uid2": 37      // defines a connection score of 37 with point uid2
    }
  },
  {...}
]

shout outs