Reputation: 31
I have more than 5 normalized tables with one common dimension (primary key).
I don't want to combine them into single dataset and plot graphs.
I have created individual crossfilter objects to load data.
When any graph of the belonging to respected crossfilter object filtered,
I retrieve the filter using (primary key) in following way
rowchart.on("filtered",function(){
var filter=dimension.group().all().filter(function(d){return d.value>0}).map(function(d){return d.key});
}
Then this filter is passed on common dimension of all other crossfilter's object.
This implementation works fine for any two objects.
But when any other chart belonging to other crossfilter object filtered, it resets all the dimensions of all objects.
Is there any better way to implement this use case?
Upvotes: 1
Views: 2050
Reputation: 20120
One way to do this, if you're able to look up rows by the primary key, is to tell crossfilter that your data is just a set of keys, and then define your dimension and group functions to actually do the table lookup.
E.g. for the simple example where you have arrays A
and B
of data, of the same length, and the primary key is the index, do
var ndx = crossfilter(d3.range(0, A.length));
var dateDim = ndx.dimension(function(i) { return A[i].date; });
var nameDim = ndx.dimension(function(i) { return B[i].name; });
Similarly, for the group reductions, refer to the data in the same way, since the reduce functions take a "row" from the main crossfilter. Say you're reducing on sum of salaries in B
:
var salaryGroup = nameDim.reduceSum(function(i) { return B[i].salary; });
I do this in a situation where my data is column-major instead of row-major (R dataframes), and it works great.
Upvotes: 3