crossfilter.js is great for identifying data points that match particular contiguous segments of data dimensions. This is usually the exact behavior that you want, but I have a peculiar use case where it would be convenient to know the set of data points that do not match any of the selected filters. Is there a way to obtain the complement of the selected dimensions in crossfilter.js?
As a concrete example, when you load the crossfilter.js page, I'd like to know the list of all flights that are not in February (the pre-specified date range).
At the time of writing, there's no straightforward way to complement the current set of filters for a given Crossfilter instance. Such an operation would recompute all groups so that they match the complemented filters.
If you simply want a list of records that do not match the current set of filters, it's not exactly straightforward but you might consider iterating over an array of all records (in a particular order), and comparing with an array of matching records (in the same order).
For example:
var db = crossfilter(data),
date = db.dimension(function(d) { return d.date; }),
recordsByDate = date.top(Infinity),
n = db.size();
// Add some filters here on various dimensions…
date.filterRange([0, 31536e6]);
// Retrieve matching records in date order.
var matchesByDate = date.top(Infinity),
m = matchesByDate.length;
// Iterate over all records in date order, and compare with matching records.
for (var i = 0, j = 0; i < n && j < m; ++i) {
if (recordsByDate[i] === matchesByDate[j]) {
// Ignore matches.
++j;
continue;
}
// Otherwise, non-matching record: process immediately or add to an array.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With