Your excellent new documentation led me to try using enter() and exit(), but I seem to be doing something wrong.
I have the most recent version of d3 (git log says feb 2011).
To try to make a simple example, I edited your stack.html example as follows, starting at about line 85 in the original. I didn't see an easy way to add an id to the array of arrays, so I used a summation. I figured that summing the data y
values should produce a unique id.
var vis = d3.select("body")
.append("svg:svg")
.attr("width", w)
.attr("height", h + p);
var layers = vis.selectAll("g.layer")
.data(data, function(d,g,i){
var sumd = 0;
d.map(function(val){ sumd += val.y ; });
return sumd;
});
layers.enter().append("svg:g")
.attr("fill", function(d, i) { return color(i / (n - 1)); })
.attr("class", "layer");
However, while the sums work, the layers object is an array of nulls, and the enter().append
line does nothing, and the subsequent bars lines do nothing either.
I started to dig at the source code, and I can't see what might be going on...but mostly because I don't understand all of the logic flows yet. It does seem like the join function might get called twice, but I was only seeing it called once, so I'm not sure.
My use case is to have stacked bar charts, and to be able to insert and remove series in the stack, as well as to extend or shrink the time scale (x-axis), so being able to use enter and exit would rock. Any help or insight would be appreciated.
Regards,
James
Usually, when the select
operator is run, each newly-selected node inherits its data from the corresponding node in the original selection. However, this was recently changed so that if the new selection already hd data, it would not inherit data from the original:
if (subnode && !subnode.__data__) subnode.__data__ = node.__data__;
However, I'm not sure this is what we want.
First, what if the data is an array of numbers or booleans (or null, rather than undefined)? This could be very confusing in terms of some of the newly-selected nodes inheriting data and some of them not.
Second, the above implementation prevents the new selection from inheriting the data, even if the original selection has data defined. Perhaps we should check if the data was set explicitly on the original selection, so that it can override what's stored in the DOM's __data__
?
Hi,
Started trying this with Circos and got nowhere. This looks easier as I am not a coder. Trying to understand how to get more rows, and or/columns in the matrix.
Tried this and the browser gives me a blank page with no errors in Firebug.
.matrix([
[ 12500, 10300, 10500, 7800 ], //black
[ 16500, 11200, 7300, 9200 ], //green
[ 20600, 10900, 9600, 3200 ], //red
[ 13600, 4200, 1900, 14500 ], //purple
[ 3400, 6100, 1200, 4300 ] //yellow ******* this is new line added
]);
var w = 910,
h = 800,
r0 = Math.min(w, h) * .41,
r1 = r0 * 1.1;
var fill = d3.scale.ordinal()
.domain(d3.range(5)) //color ranges ****** changed from orig (4) to this (5)
.range(["#000000", "#22dd33", "#ff1133", "#3311ff", "#ffd538" ]); ****** added in additional color
But this doesn't work. Guessing I'm missing something else in the code that allows for the addition of more data sets but can't find what that might be.
Anyone know how to handle this? I need to be able to handle many more data sets than the demo has.
Tks,
Jeff