dc.js - ScatterPlot ElasticY
Why does elasticY not work with ScatterPlot
by JaelB
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.7/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter2/1.4.0/crossfilter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dc/2.1.9/dc.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dc/2.1.9/dc.css">
<p>Brush on one chart to see the points filtered on the other.</p>
<div id="scatLeft"></div>
<div id="scatRight"></div>
JavaScript
var chart1 = dc.scatterPlot("#scatLeft");
var chart2 = dc.scatterPlot("#scatRight");
var data = "x,y,z\n" +
"1,1,3\n" +
"5,2,11\n" +
"13,13,13\n"+
"5,3,20\n"+
"12,12,10\n"+
"3,6,8\n"+
"15,2,9\n"+
"8,6,14\n"+
"1,4,9\n"+
"8,8,12\n";
var data = d3.csv.parse(data);
data.forEach(function (x) {
x.x = +x.x;
x.y = +x.y;
x.z = +x.z;
});
var ndx = crossfilter(data),
dim1 = ndx.dimension(function (d) {
return [+d.x, +d.y];
}),
dim2 = ndx.dimension(function (d) {
return [+d.y, +d.z];
}),
group1 = dim1.group(),
group2 = dim2.group();
function remove_empty_bins(source_group) {
return {
all: function () {
return source_group.all().filter(function(d) {
//return Math.abs(d.value) > 0.00001; // if using floating-point numbers
return d.value !== 0; // if integers only
});
}
};
}
chart1.width(300)
.height(300)
.x(d3.scale.linear().domain([0, 20]))
.yAxisLabel("y")
.xAxisLabel("x")
.clipPadding(10)
.dimension(dim1)
.excludedOpacity(1)
.excludedColor('black')
.group(remove_empty_bins(group1))
.yAxisPadding('5%')
.elasticY(true);
chart2.width(300)
.height(300)
.x(d3.scale.linear().domain([0, 20]))
.yAxisLabel("z")
.xAxisLabel("y")
.clipPadding(10)
.dimension(dim2)
.group(remove_empty_bins(group2))
.yAxisPadding('5%')
.elasticY(true);
...