项目作者: emilbayes

项目描述 :
Small utils to make developing with d3 easier, inspired by d3-jetpack and d3-starterkit
高级语言: JavaScript
项目地址: git://github.com/emilbayes/d3-utils.git
创建时间: 2016-08-05T09:02:01Z
项目社区:https://github.com/emilbayes/d3-utils

开源协议:ISC License

下载


d3-utils

Build Status

Small utils to make developing with d3 easier, inspired by d3-jetpack and d3-starterkit

Install

  1. npm install d3-utils

Usage

  1. var d3 = require('d3')
  2. var lifecycle = require('d3-utils/lifecycle')
  3. var ƒ = require('d3-utils/get')
  4. var o = require('d3-utils/compose')
  5. var scale = {x: d3.scale.linear().range([0, 1000])}
  6. d3.selectAll('li')
  7. .data(someDataArray) // [{label: 'Hello world', x: 0.5}, ...]
  8. .call(lifecycle(
  9. enter => enter.append('li').text(ƒ('label')),
  10. update => update.style('top', o(ƒ('x'), scale.x)),
  11. exit => exit.remove()
  12. ))

API

utils.lifecycle([enter], [update], [exit])

Makes handeling the lifecycle of a D3 selection a bit easier.

enter

Type: Function

Default noop

Calls this function with selection.enter()

update

Type: Function

Default noop

Calls this function with selection

exit

Type: Function

Default noop

Calls this function with selection.exit()

utils.get(prop, [default])

Returns a function that accesses prop and returns it, optionally returning
default if null

prop

Type: String

Retrieve value with key prop from whatever object is called on the returining
function

default

Type: Any

Default null

Default value to return

utils.compose([fn...])

Takes any number of functions and composes them from left to right, returning
the compose function, eg:

  1. f(g(h(x))) === utils.compose(h, g, f)(x)

License

ISC