11. What You Need
✦ Data Item: #69ce85
✦ Visualization:
<div style="
rgb(108,background-color:
199, 224);
height: 20px;
width: 25px;"
class="color"></div>
15. Using Scales
✦
✦
So far our scale was “coded-in” the
visualization
D3 helps us decouple the scale
16. Using Scales
✦ The scale function creates a
scale
✦ Domain is the input
✦ Range is the output
✦ Basically, it translates
FROM domain TO range
✦ https://github.com/
mbostock/d3/wiki/Scales
var xScale = d3.scale.linear()
.domain([0,data.length])
.range([50,500]);
.attr('cx', function(d, i) {
xScale( i );return
})
23. D3 Charts Example
✦ Create a shape with:
var arc = d3.svg.arc().outerRadius(150).innerRadius(0);
✦
0 0,1
Now we get:
arc(p_data[0]) ==
"M-88.16778784387098,-121.3525491562421A150,150
-2.7553642961003488e-14,-150L0,0Z"