Flow Visualization - Straight

D3 SVG flow visualization of transmitted/received data

by bizamajig

HTML

<script src="http://d3js.org/d3.v2.min.js"></script>

CSS

/*
The MIT License (MIT)

Copyright (c) 2014 Stephen Boak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

svg {
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAdCAMAAACKeiw+AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////9fb3h/JDwQAAABtJREFUeNpiYMQLGBgZ8IJR6VHpUWnKpAECDACcGgA72QxfPgAAAABJRU5ErkJggg==);
  border: solid 1px #ddd;
}
svg .circle {
  fill: steelblue;
  stroke: white;
  stroke-width: 2;
}
svg circle:hover{
  cursor: pointer;
}
svg circle:active{
  stroke: yellow;
}
svg .link_line {
  stroke: rgba(255,255,255,.5);
  stroke-width: 1.5;
}

JavaScript

/*
The MIT License (MIT)

Copyright (c) 2014 Stephen Boak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

(function () {

  var width = 598,
    height = 300;

  var radius = 30; /* radius of circles */
  var numCircles = 6; /* number of circles - you must update link source/target values to match changes in the number of circles */
  var d3LineLinear = d3.svg.line().interpolate("linear");
  var d3color = d3.interpolateRgb("#BAE4B3", "#006D2C"); /* color range for flow lines */ 

  //A LIST OF LINKS BETWEEN CIRCLES
  var links = [
    {source: 0, target: 5, strength: Math.round(Math.random()*10)},
    {source: 0, target: 2, strength: Math.round(Math.random()*10)},
    {source: 1, target: 3, strength: Math.round(Math.random()*10)},
    {source: 2, target: 4, strength: Math.round(Math.random()*10)},
    {source: 3, target: 5, strength: Math.round(Math.random()*10)},
    {source: 5, target: 0, strength: Math.round(Math.random()*10)},
    {source: 2, target: 0, strength: Math.round(Math.random()*10)},
   ...