block by NPashaP 2684287c2526c837b04ce873901c918d

biPartite - update

Full Screen

viz.bP().update

This method sets a new data and transitions the biPartite.

For other options and examples, check out VizJS

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.mainBars{
  shape-rendering: auto;
  fill-opacity: 0;
  stroke-width: 0.5px;
  stroke: rgb(0, 0, 0);
  stroke-opacity: 0;
}
.subBars{
	shape-rendering:crispEdges;
}
.edges{
	stroke:none;
	fill-opacity:0.3;
}
</style>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="//vizjs.org/viz.v1.1.1.min.js"></script>
<script>
var data=[
['A','X', 1]
,['A','Y', 3]
,['B','X', 5]
,['B','Y', 8]
,['C','X', 2]
,['C','Y', 9]
];
var width=960, height=700;
var color = {A:"#3366CC", B:"#DC3912",  C:"#FF9900"};

//create bp object
var bp=viz.bP().data(data).pad(2).fill(d=>color[d.primary]);
			
// create svg and g elements and draw bp on it
d3.select("body").append("svg").attr("width", width).attr("height", height)
  .append("g").attr("transform","translate(250,50)").call(bp);

// refresh data every second
setInterval(update,1000);

function update(){
  // reate some random values
  data.forEach(function(d){ d[2] =Math.random()*10 ;});
  //set the new data and redraw
  bp.update(data);
}

// adjust the bl.ocks frame dimension.
d3.select(self.frameElement).style("height", height+"px").style("width", width+"px");      
</script>
</body>
</html>