Sankey Updating
Some issues updating a Sankey layout
by IPWright83
HTML
<script src="https://dl.dropboxusercontent.com/u/41796243/JSFiddle/Sankey/sankey.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<button id="update">Update</button>
<div id="chart"/>
CSS
#chart { height: 900px; width: 1920px; background-color:#000; }
svg {
font-family: "Archivo Narrow", "Helvetica Neue", Helvetica, Arial, sans-serif;
color : #fff;
font-size: 12px;
JavaScript
/////////////////////////////////// START SANKEY
mood = { d3 : { } };
mood.d3.sankey = function () {
// Protect against missing new keyword
if(!(this instanceof mood.d3.sankey)) {
return new mood.d3.sankey();
}
var control = {}; // The sankey control that will be returned
// The following properties are public and modified through the getter/setter functions
var margin = { top: 0, left: 0, bottom: 0, right: 0 };
var width = 1000;
var height = 1000;
var nodeHeight = 24;
var nodeWidth = 24;
var data;
var svg; // The main target element that the visualization is injected into
var vis; // The main grouping element that contains the visualization
var sankey; // The sankey layout
/**
* Changes the margin of the control (pre initialization only)
* @param {object} The margin that the control should use
* @returns {number} The margin that the control is using or the control
*/
control.margin = function (_) {
if (!arguments.length) return margin;
margin = _;
return control;
};
/**
* Changes the width of the control (pre initialization only)
* @param {number} The width that the control should take
* @returns {number} The width that the control should take or the control
*/
control.width = function (_) {
if (!arguments.length) return width;
width = _;
return control;
};
/**
* Changes the height of the control (pre initialization only)
* @param {number} The height that the control should take
* @returns {number} The height that the control should take or the control
*/
control.height = function (_) {
if (!arguments.length) return height;
height = _;
return control;
};
/**
* Changes the height of the nodes on the diagram
* @param {number} The height that the nodes should take
* @returns {number} The height that the nodes should...