Small utils to make developing with d3 easier, inspired by d3-jetpack and d3-starterkit
npm install d3-utils
var d3 = require('d3')
var lifecycle = require('d3-utils/lifecycle')
var ƒ = require('d3-utils/get')
var o = require('d3-utils/compose')
var scale = {x: d3.scale.linear().range([0, 1000])}
d3.selectAll('li')
.data(someDataArray) // [{label: 'Hello world', x: 0.5}, ...]
.call(lifecycle(
enter => enter.append('li').text(ƒ('label')),
update => update.style('top', o(ƒ('x'), scale.x)),
exit => exit.remove()
))
Makes handeling the lifecycle of a D3 selection a bit easier.
Type: Function
Default noop
Calls this function with selection.enter()
Type: Function
Default noop
Calls this function with selection
Type: Function
Default noop
Calls this function with selection.exit()
Returns a function that accesses prop
and returns it, optionally returning
default
if null
Type: String
Retrieve value with key prop
from whatever object is called on the returining
function
Type: Any
Default null
Default value to return
Takes any number of functions and composes them from left to right, returning the compose function, eg:
f(g(h(x))) === utils.compose(h, g, f)(x)