Reputation: 5568
After creating a new dimension (by date, javascript's date objects).
var byDate = cf.dimension(function (d) { return d.date; });
I filter the dimension to drop all data with date that is before some arbitrary date that I've chosen.
var filteredDim = byDate.filterFunction(function (d) { return d >= startDate; });
This line prints an array of all the objects that passed the filtering. (works properly)
console.log(filteredDim.top(Infinity));
This line prints an array of key-value objects. I expect the keys to be only those that passed the filter, which means dates that occur after the arbitrary chosen date supplied to the filter function. Actually, the array contains keys for all the dates (the unfiltered as well) and their value is the original value as if there was not filtering at all.
console.log(filteredDim.group(d3.time.day).top(Infinity));
I was wondering how can I group a dimension which was filtered and group ONLY the filtered values?
Thanks
UPDATE: Turns out that this behavior is normal by design. Can someone suggest a workaround please?
Upvotes: 4
Views: 5816
Reputation: 71
I know this post is super old, but my solution might help someone.
As Ethan said:
groups respect all filters except those of the dimension on which they are defined.
As a workaround, you can simply create a temporary crossfilter from the dimension you want to group.
With the example above it would be something like:
tempCrossfilter = crossFilter(filteredDim.top(Infinity))
tempDimension = tempCrossfilter.dimension(function (d) { return d.date; });
filteredGroup = tempDimension.group(d3.time.day).top(Infinity)
Upvotes: 0
Reputation: 6010
Crossfilter groups respect all filters except those of the dimension on which they are defined. Define your group on a different dimension and it will be filtered as you expect.
https://github.com/crossfilter/crossfilter/wiki/API-Reference#dimension_group
Upvotes: 3