Skip to content

Instantly share code, notes, and snippets.

@stormpython
Created February 13, 2015 18:34
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/77d2cde268e77b32c273 to your computer and use it in GitHub Desktop.
Save stormpython/77d2cde268e77b32c273 to your computer and use it in GitHub Desktop.
Grid Layout
// D3 code
var $el = $('.visualize-chart')[0];
var data = {
type: 'chart',
series: [{}, {}, {}]
};
var selection = d3.select($el).datum(data).call(split);
function split (selection) {
selection.each(function (data) {
var div = d3.select(this).data([data]);
var charts = div.selectAll('div')
.data(function (d) {
if (d.cols) return d.cols;
if (d.rows) return d.rows;
if (d.horizontal) return d.horizontal;
if (d.vertical) return d.vertical;
return d;
})
.enter().append('div')
.attr('class', function (d) {
if (d.type === 'split') ? {
return d.horizontal ? 'horizontal' : 'vertical';
}
return d.type;
});
if (data.type !== 'chart' || data.type !== 'cols' || data.type !== 'rows' ) {
charts.call(split);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment