d3
Last updated
Last updated
Super easy DOM and data manipulation that combos with SVG and CSS to make easy, scriptable graphics
Easy DOM manipulation, data binding, transitions, and animations
Install from
Great examples of whats possible at
select([Selector String])
selectAll([Selector String])
selectAll("h2 span")
=> span within h2
Must use d3 commands with return
.text("hot")
.html('<strong class="temp">hot</strong>'
.append('span')
=> add to end of element
.insert('span', ':first-child')
=> append with granularity
.remove()
.style('background', 'red')
.classed('label', true)
=>turn label on
.attr(?)
//defined in html
.property(?)
//property of DOM node
Assign data to selector, with callback access and index
1).data(...)
generously assigns first data to first selection
extra data and extra html will be ignored
array or dict
2) use callback ft function(d, i) { return d }
ajax based method for csv, tsv, json, etc
Wont work locally, need server
Select things that dont exist ,enter them ,and create your selection
.enter()
create sub-selection
.exit()
sub-selection
HTML
JS
Can scale values to size of graphics
.scaleLinear, .domain, .range
yScale is a ft that maps values from domain to range(normalizes height)
Colors scales
linear extrapolation between two colors
can do multiple color stops by putting multiple values in domain&range
Ordinal needs order
.scaleBand, .domain, .range, .padding OR .paddingInner and .paddingOuter
.axisTop, .axisRight, .axisBottom, .axisLeft
tick methods, and group elements
this is pretty complex because of padding and margins, see example
ticks can be much more complex and date scales are possible
Create startup animations and movement or hover effects
Check out CSS transitions for more information
.transition()
.duration()
.ease()
.delay()
Tooltip, by changing absolute position of element on hover and adding transition of opacity