Giter Club home page Giter Club logo

d3-plugin-captain-sankey's Introduction

Sankey Diagrams

Demo

Captain Sankey Diagram Example

Basic usage

Expected data (format): arrays of nodes and links.

// Array of node objects (e.g. with a 'name' field here):
var nodes = [
    {name: "a"},
    {name: "b"},
    // ...
];
// Array of links between the nodes:
// objects with 'source', 'target' node indices and a 'value' for the link weight:
var links = [
    {source: 0, target: 1, value: 10.2},
    {source: 0, target: 2, value: 5.4}
    // ...
];

Configure the Sankey object and get a path data generator.

var sankey = d3.sankey()
    .size([width, height])
    .nodeWidth(15)
    .nodePadding(10)
    .nodes(nodes)
    .links(links)
    .layout(32);

var path = sankey.link();

Draw links and nodes, the bare essence:

// Draw links (as svg paths)
root.selectAll('.link')
    .data(links)
    .enter().append('path')
    .attr('class', 'link')
    .attr('d', path)
    .style("stroke-width", function (d) { return Math.max(1, d.dy); })
    // ...

// Draw nodes
root.selectAll('.node')
    .data(nodes)
    .enter().append('rect')
    .attr({
        'class': 'node',
        x: function (d) { return d.x },
        y: function (d) { return d.y },
        height: function (d) { return d.dy; },
        width: sankey.nodeWidth()
    })
    // ...

d3-plugin-captain-sankey's People

Contributors

soxofaan avatar mbostock avatar jasondavies avatar nmalkin avatar smashtie avatar hongtaobai avatar

Stargazers

 avatar

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.