Reputation: 1716
I have an object like:
[ { "Project": 1; "key":["a", "b", "c", "d"]},
{ "Project": 2; "key":["b", "c", "d"]},
{ "Project": 3; "key":["e", "c", "a"]},
{ "Project": 4; "key":["b", "a", "e", "f"]}
]
so far as I have implemented, reduceCount only counts the occurrence of single element value. I want to change it into something
key value
a 3
b 3
c 3
d 2
e 2
f 1
I want to count it on the times it appear in an individual project like "a" has appeared in 3 projects. Actually this data I want to use in my wordcloud.
I can do this outside crossfilters but not sure how can I achieve this through crossfilters dimensions.
Any assistance is appreciable.
SOLUTION as referred by Ethan Jewett
Upvotes: 1
Views: 144
Reputation: 6010
If you want to do this in the current version of Crossfilter, you need to use groupAll. The answer to this question provides an example: Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?
Alternatively, you could the Reductio library, which provides a way to generating reduce functions for complex groups very easily, and in this case wraps the groupAll in such a way that it is compatible with dc.js. The relevant section of the documentation is here: https://github.com/crossfilter/reductio#aggregations-groupall-aggregations-reductio-b-groupall-b-i-groupingfunction-i-
If you are feeling especially adventurous, you can try using the master branch of the Crossfilter fork at https://github.com/crossfilter/crossfilter. We have recently added a new parameter to the dimension
call that will cause it to treat your data exactly as you describe. Documentation is here: https://github.com/crossfilter/crossfilter/wiki/API-Reference#dimension
Upvotes: 2