Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="https://rawgit.com/monfera/plotly.js/sankey-micro-alignment/dist/plotly.min.js"></script>
</head>
<body>
<div id="graphDiv"></div>
</body>
</html>
              
            
!

CSS

              
                body {
  margin:0; 
}
              
            
!

JS

              
                // Sankey core layout code Copyright Mike Bostock, 2015 (MIT)
// with a modification covered with a PR
//
// Add-on features:
//    - use of force for drag&drop without manual overlap fiddling
//       - multiple force ticks per frame for faster response
//       - starting/stopping force per graph layer (column)
//       - use of force for handling apparently non-circular shapes
//    - vertical layout (sorry, transition to be disabled later)
//    - option for multi-edge handling https://github.com/d3/d3-sankey/pull/19
//    - plotly tooltips and raising various plotly events
//    - plotly-style color contrast: text becomes white on darker backgrounds
//    - highlight all connecting links and nodes when hovering a node
// 
// Current limitations:
//    - positions aren't saved (layout lost on update)
//    - positions aren't specifiable yet (no attributes for this yet)
//    - cheesy horizontal/vertical switch
//    - screenshot fails for a couple of reasons
//
// PR: https://github.com/plotly/plotly.js/pull/1591

var d3 = Plotly.d3;

var mock = {
  data: [{"node": {"color": ["#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46", "#262C46"], "line": {"color": "black", "width": 0.5}, "thickness": 30, "pad": 10, "label": ["People from Iran", "People from Afghanistan", "People from Pakistan", "People from Iraq", "People from Bangladesh", "People from Myanmar", "People from Somalia", "People from Lebanon", "People from Myanmar (Stateless)", "People from Sri Lanka", "Stateless People", "People from Nepal", "Other People", "People from India", "Manus", "Nauru", "Total Asylum Seekers", "Still on Manus or Nauru", "Unknown", "Iran", "Iraq", "Cambodia", "Afghanistan", "Lebanon", "Sri Lanka", "Somalia"]}, "valueformat": ".0f", "domain": {"y": [0, 1], "x": [0, 1]}, "orientation": "h", "link": {"source": [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16], "target": [14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 14, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 16, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], "value": [548, 167, 135, 37, 105, 74, 106, 21, 74, 42, 53, 17, 48, 9, 46, 13, 27, 123, 41, 104, 19, 12, 18, 13, 13, 14, 1246, 633, 1215, 607, 34, 10, 4, 2, 4, 2, 1]}, "type": "sankey"}],
  layout: {"height": 772, "font": {"size": 10}, "marging": {"right": 0, "left": 0}, "title": "Refugee movement through Manus and Nauru, via <a href='http:\/\/www.bryanbrussee.com\/sankey.html'>Bryan Brussee<\/a>"}
};

Plotly.plot('graphDiv', mock.data, mock.layout); 
 
graphDiv.on('plotly_hover', function(e) {
    console.log('hover', e);
});

graphDiv.on('plotly_unhover', function(e) {
    console.log('unhover', e);
});
              
            
!
999px

Console