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

@mwatson/world-network

v1.0.1-1

Published

Render a D3 map of Earth with a graph (nodes and edges, defined by lon/lat coordinates) superimposed in its surface.

Downloads

3

Readme

world-network

Render a D3 map of Earth with a superimposed (non-directed) graph on its surface that consists of edges between nodes whose locations are defined by lon/lat coordinates.

Install

npm install --save world-network

Usage

Imports

Along with React, the WorldNetwork component needs to be imported alongside D3.

import React from 'react'
import { WorldNetwork } from '@mwatson/world-network'
import '@mwatson/world-network/dist/index.css'

The stylesheet that ships with this module can be pulled from @mwatson/world-network/dist/index.css, and it will provide basic styling. This module uses CSS modules, so the resulting class names look something like this: _styles__country__192bf. The styles can be overridden by selecting DOM elements by partial class names, like path[class*="_styles__country"], which would select all country paths in the resulting SVG.

Using the WorldNetwork Component

Use the WorldNetwork component within your React component by passing it the following props: projection, scale, nodes, and edges, which will be detailed below.

<WorldNetwork
  projection="geoOrthographic" 
  scale={ 300 }
  nodes={ nodes }
  edges={ edges }
/>

Props

Projection

The projection props takes a string equal to one of the following of D3's built-in projections:

  • geoAlbers
  • geoAzimuthalEqualArea
  • geoAzimuthalEquidistant
  • geoConicConformal
  • geoConicEqualArea
  • geoConicEquidistant
  • geoEqualEarth
  • geoEquirectangular
  • geoGnomonic
  • geoMercator
  • geoNaturalEarth1
  • geoOrthographic
  • geoProjection
  • geoTransverseMercator

Scale

Because the result from different projections can vary the size and shape of the rendered map, the scale prop is exposed to adjust for this.

Nodes

The nodes props receives an Array of Objects of the following shape:

{
  "id": "london",
  "name": "London",
  "location": [-0.1275, 51.50722]
}

where id is a unique identifier for the node, name is the name to display to the client, and location is an Array of coordinates (Numbers): [longitude, latitude].

Edges

The edges prop receives an Array of two-dimensional Arrays, each of which identifies two nodes to be connected by a path in the resulting graph. This edge Array would instruct the WorldNetwork component to draw three (non-directed) edges between New York City and London, Mexico City, and Zanzibar.

[
  ["london", "new-york-city"],
  ["mexico-city", "new-york-city"],
  ["zanzibar", "new-york-city"]
]

License

MIT © mbwatson