D3.js Selection Conditional Rendering
Using the d3js join model, is it possible to do conditional rendering based on the data content? I want to do something like this: var nodes = svg.selectAll('.node').data(nodes);
Solution 1:
You could use a filter:
var nodes = svg.selectAll('.node').data(nodes);
nodes.enter()
.insert('svg:g')
.attr('class', 'node');
nodes.filter(function(d,i){
return d.hasDuration;
}).append('svg:rect');
nodes.filter(function(d,i){
return !d.hasDuration;
}).append('svg:circle');
Example here.
Post a Comment for "D3.js Selection Conditional Rendering"