d3.select('body')
.transition()
.style('background-color', 'red')
Start
End
White
Red
Initial DOM state
Specified attribute
d3.select('body')
.style('background-color', 'green')
.transition()
.style('background-color', 'red')
Start
End
Green
Red
Set Initial State
Specified attribute
Start
End
Green
Red
Set Initial State
Specified attribute
Start
End
~Tween~
0
1
Intervals
d3.select("body").transition()
.styleTween("background-color", function() {
return d3.interpolateRgb("green", "red");
});
d3.select("body").transition()
.styleTween("background-color", function() {
return function(t) {
return "hsl(" + t * 300 + ",100%,50%)"
}
});
Start
End
Schedule
Run
selection()
.transition()
selection() .transition() .style()
selection()
.delay()
selection()
.styleTween()
selection()
.styleTween('color', function() {
return function(t){
//t
}
})
selection() .duration()
selection()
.easeLinear()
bit.ly/d3AnimateBars
If visualization is constructing “visual representations of abstract data to amplify cognition ”, then perhaps the most important concept in D3 is the scale, which maps a dimension of abstract data to a visual variable.
-- Mike Bostock, Creator of D3
396
166513
10
300
Input Domain
Output Range
396
166513
0
1
56171
~0.338
(166513 - 396)
56171
________________
(Max - Min)
Datapoint
________________
x
available space
(height/width)
300
x
var scale = d3.scaleLinear()
.domain([396, 166513])
.range([10, 300])
scale(396) // 10
scale(56171) // 107.36962502332692
scale(166513) // 300
bit.ly/d3ScalesStarter
bit.ly/d3ScalesFin
d3.axisTop(scale)
d3.axisBottom(scale)
d3.axisLeft(scale)
d3.axisRight(scale)
svg.append('g')
.call(xAxis)
svg.axisLeft(scale)
.tickFormat(d3.format(".1%"))
svg.axisLeft(scale)
.tickFormat(d3.timeFormat("%H:%M"))
svg.axisLeft(scale)
.ticks(5)
bit.ly/d3ScalesAxes