Skip to content

A small utility function that supports wrapping a function to d3.call

License

Notifications You must be signed in to change notification settings

au-phiware/d3-wrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A small utility function that supports wrapping a function to d3.call

Resources

License

Stars

Watchers

Forks

Packages

No packages published