Define what a tooltip is
Build tooltips to improve the readability of visualizations
Use D3 transitions to animate our graphs
Explain the D3 transition events
Use AJAX in D3 to import and format data from external sources
Use d3.queue to chain multiple requests together
Code: http://bit.ly/2izJPMA
Live Site: http://bit.ly/2w8ETTG
tooltip!
tooltip!
data!
data!
Scatterplot
mousemove
TOOLTIP!
mouseout
Code: http://bit.ly/2wpBs9l
Live Site: http://bit.ly/2wjCV2A
d3.transition()
Creates a new transition
Example transition methods
transition.duration([value])
new duration for the transition
value can be a constant or a callback to be invoked on each element
transition.ease([value])
new easing function for the transition
D3 comes with many easings built in
transition.delay([value])
new delay for the transition
value can be a constant or a callback to be invoked on each element
transition.on(typenames[, listener])
Types of transition events:
Code: http://bit.ly/2vVu185
d3.json(url[, callback])
JSON file location
Code to run when response is received
d3.json(url[, callback])
d3.json('url_goes_here', function(data) {
// data refers to JSON data
});
d3.json('url_goes_here', function(error, data) {
// error refers to any error,
// or null if there is no error.
// data refers to JSON data
});
npm install -g http-server
http-server
d3.csv(url[, callback])
CSV file location
Code to run when response is received
d3.csv(url[, formatter, callback])
CSV file location
Code to run when response is received
format your data by iterating through rows
d3.csv(url[, formatter, callback])
d3.csv('url', function(row, i, headers) {
// row - current CSV row as an object
// i - row index
// headers - array of CSV headers,
// which are also keys in the row object
}, function(error, data) {
// write your code here
});
d3.csv(url[, formatter, callback])
d3.csv('url', function(row, i, headers) {
if (/* condition */) return;
}, function(error, data) {
// rows where condition was true
// are removed from the data array!
});
d3.queue()
queue.defer(fn[, arguments])
Asynchronous function
Arguments for fn
queue.await()
queue.awaitAll()
d3.queue()
.defer(fn1)
.defer(fn2)
.await(function(error, res1, res2) {
// res1 - response from fn1
// res2 - response from fn2
});
d3.queue()
.defer(fn1)
.defer(fn2)
.awaitAll(function(error, res) {
// res[0] - response from fn1
// res[1] - response from fn2
});