Giter Club home page Giter Club logo

spatialsankey's Introduction

Sankey diagrams on a map

D3 Plugin for visualizing flows through a network on a leaflet map.

Here is a small example application of the plugin.

The spatialsankey plugin is inspired by the d3-plugin sankey and the the example integration of D3 elements into a leaflet map follows the D3 + Leaflet tutorial.

To use it, prepare a set of points as geojson and an array of link values as either csv or json. The links are defined as an array of objects with a source, target and flow value. The source and targets are the point IDs from the geojson points. Example data snippets are shown below.

After loading the data, the links can be displayed on a leaflet map with just a few lines of code:

// Instantiate spatial sankey
var spatialsankey = d3.spatialsankey()
                      .lmap(map)
                      .nodes(nodes.features)
                      .links(links);

// Draw nodes
var node = spatialsankey.node();
var circs = nodelayer.selectAll("circle")
                     .data(spatialsankey.nodes())
                     .enter()
                     .append("circle")
                     .attr("cx", node.cx)
                     .attr("cy", node.cy)
                     .attr("r", node.r)
                     .style("fill", node.fill);
                     
// Draw links
link = spatialsankey.link();
var beziers = linklayer.selectAll("path")
                       .data(nodelinks);
                       .enter()
                       .append("path")
                       .attr("d", link)
                       .attr('id', function(d){return d.id})
                       .style("stroke-width", linke.width())
                       .style("fill", 'none');

nodes.geojson

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "id": "AD",
      "geometry": {
        "type": "Point",
        "coordinates": [ 1.6002, 42.5462 ]
      }
    },
    {
      "type": "Feature",
      "id": "AE",
      "geometry": {
        "type": "Point",
        "coordinates": [ 53.9791, 23.4330 ]
      }
    },
    {
      "type": "Feature",
      "id": "AF",
      "geometry": {
        "type": "Point",
        "coordinates": [ 65.5818, 33.6508 ]
      }
    }
]}

links.csv

target,source,flow
AD,AE,23230
AD,AF,371
AF,AE,1310

spatialsankey's People

Contributors

tomay avatar yellowcap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

spatialsankey's Issues

Arrowhead option

Add direction to the links, allowing arrowheads or other symbology that indicates flow direction

Add legend to graph

  • Add unit to parameter space
  • Create legend for the width, colors and radii

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.