d3
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 https://d3js.org/
Great examples of whats possible at https://github.com/d3/d3/wiki/Gallery
DOM
select([Selector String])
selectAll([Selector String])
selectAll("h2 span")
=> span within h2
Must use d3 commands with return
Modifiers of Selector
.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
Example
Binding Data
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 }
Inside D3 Fts
Data
Importing
ajax based method for csv, tsv, json, etc
Wont work locally, need server
Creating HTML from Data
Select things that dont exist ,enter them ,and create your selection
.enter()
create sub-selection
.exit()
sub-selection
HTML
JS
Scales
Linear
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 Scales
Ordinal needs order
.scaleBand, .domain, .range, .padding OR .paddingInner and .paddingOuter
Guides
.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
Events
Transitions
Create startup animations and movement or hover effects
Check out CSS transitions for more information
.transition()
.duration()
.ease()
.delay()
Other Ideas
Tooltip, by changing absolute position of element on hover and adding transition of opacity
Last updated