开发者社区> 镜像站> NPM> d3-utils
d3-utils
Small utils to make developing with d3 easier, inspired by d3-jetpack and d3-starterkit
Last updated 4 years ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install d3-utils 
SYNC missed versions from official npm registry.

d3-utils

Build Status

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

Install

npm install d3-utils

Usage

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()
  ))

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:

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

License

ISC

Current Tags

  • 2.0.1                                ...           latest (4 years ago)

2 Versions

  • 2.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (0)
None
Dependents (2)