Skip to content

Instantly share code, notes, and snippets.

@stormpython
Created July 2, 2015 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stormpython/dc295b828cb12ad5da69 to your computer and use it in GitHub Desktop.
Save stormpython/dc295b828cb12ad5da69 to your computer and use it in GitHub Desktop.
Recursive splitting of divs with D3
define(function (require) {
var d3 = require("d3");
return function split() {
var splitBy = function (d) { return d; };
var element = "div";
var elementClass = function () { return "horizontal"; };
var predicate = false;
function layout(selection) {
selection.each(function (data) {
var elem = d3.select(this).data([data]);
var elems = elem.selectAll("splits")
.data(splitBy)
.enter().append(element)
.attr("class", elementClass);
if (predicate) {
elems.call(split);
}
});
}
layout.splitBy = function (_) {
if (!arguments.length) { return splitBy; }
splitBy = _;
return layout;
};
layout.element = function (_) {
if (!arguments.length) { return element; }
element = _;
return layout;
};
layout.elementClass = function (_) {
if (!arguments.length) { return elementClass; }
elementClass = _;
return layout;
};
layout.predicate = function (_) {
if (!arguments.length) { return predicate; }
predicate = _;
return layout;
};
return layout;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment