Created
July 2, 2015 16:35
-
-
Save stormpython/dc295b828cb12ad5da69 to your computer and use it in GitHub Desktop.
Recursive splitting of divs with D3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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