Try D3 Now - D3 Visualization Tutorial
christopheviau.com
christopheviau.com
Here's some examples: http://www.twosides.co/issues/185-should-euthanasia-or-physi... http://www.twosides.co/jono (the venn diagram/bar graph wouldn't be transparent if you had an account)
sampleSVG.append("svg:circle")
.style("stroke", "gray")
.style("fill", "white")
.attr("r", 40)
.attr("cx", 50)
.attr("cy", 50)
.attr("width", 100)
.attr("height", 100);
I'd prefer to express it like this sampleSVG.append("svg:circle")
.style({
"stroke": "gray",
"fill": "white"})
.attr({
"r": 40,
"cx": 50,
"cy": 50,
"width": 100,
"height": 100});
That way, I can just pass object literals as arguments to functions such as attr.https://github.com/mbostock/d3/commits/map https://github.com/mbostock/d3/pull/179
We're working on this syntax for: style, classed, property, on, attr, attrTween, style, styleTween. It's a more concise syntax, especially when the attrs are functions. An example from the tutorial:
d3.select(this).selectAll("rect")
.data(function(d){return d;})
.enter().append("svg:rect")
.attr("fill", "aliceblue")
.attr("stroke", "steelblue")
.attr("stroke-width", "1px")
.attr("width", function(d, i){return (histoW/dataset[0].length)+"px"})
.attr("height", function(d, i){return (d/dataMax[rectIdx]*histoH)+"px"})
.attr("x", function(d, i){return i*(histoW/dataset[0].length)+"px"})
Becomes: d3.select(this).selectAll("rect")
.data(function(d){return d;})
.enter().append("svg:rect")
.attr(function(d,i ) {
return {
"fill": "aliceblue",
"stroke": "steelblue",
"stroke-width": "1px",
"width": (histoW/dataset[0].length)+"px",
"height": (d/dataMax[rectIdx]*histoH)+"px",
"x": i*(histoW/dataset[0].length)+"px"
};
});
Three anonymous functions become a single function which returns an object.This tutorial comes in handy - thanks!
This is more verbose, but is actually really powerful, because there's no translation between what your code is doing and what the browser is using to display your graphics. You can do anything SVG can do in your visualizations, and it is much easier to debug.
To draw a circle in D3? svg:circle.
Raphaël can be switched to WebGL, for instance, and you won't even need to rewrite any code using that library, while you're stuck with the verbose low level calls to a particular implementation of SVG.
Raphaël is a simple, unified interface to SVG and VML. You ask for a circle, and it will make one, whether in SVG or VML.
But if you have an array of data and want to visualize it, you have to write the code that creates the circle (and its position, size, color, etc) for each point. And if that data changes, you have to write the code which adds circles, removes circles, or animates the update of existing circles with the new corresponding data.
D3 is a general library to help you write that code, but it assumes you are working with DOM objects. It will create/remove/update HTML, SVG, or VML elements -- whatever you want. D3 is not a renderer abstraction library like Raphaël; it is a data to DOM mapper.
You could make something like D3 for Raphaël, but it makes sense to just assume you have SVG support now. You get to use its groups, CSS, and standard DOM events, without reinventing those wheels.