d3-wrap

0.4.1 • Public • Published

d3-wrap

In the D3 way of functions as objects, composition of functions needs to also inherit the properties of the functions being composed. This is what this small utility aims to acheive, think of it as the combination of two Underscore's functionalities: wrap and extend.

This allows the extention of common D3 modules such as axis, for example:

var height = ...;
 
var xAxis = d3.axisBottom();
 
xAxis = d3.wrap(xAxis, function(selection, xAxis) {
        return xAxis(
            selection.append("g")
                .attr("class", "x axis")
                .attr("transform", "translate(0 " + height + ")"));
    });
 
var svg = d3.select("body").append("svg");
 
svg.call(xAxis.domain([...]));

If the selection is under transition, the transition will be correctly preserved through the call.

For other ways of composing functions with D3 see d3-compose.

Package Sidebar

Install

npm i d3-wrap

Weekly Downloads

1

Version

0.4.1

License

BSD-3-Clause

Unpacked Size

7.88 kB

Total Files

8

Last publish

Collaborators

  • au-phiware