1

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

Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?

Community
  • 1
  • 1
user3050590
  • 1,656
  • 4
  • 21
  • 40

1 Answers1

2

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

Community
  • 1
  • 1
Ethan Jewett
  • 6,002
  • 16
  • 25
  • Thanks for your suggestion. I was just wondering what if I have to get the relevant Projects with each count. Like as from example: 'a' has COUNT '3' and PROJECTS "1,3,4". I have tried creating a dimension on more than one variable but it is still not providing the PROJECT name. – user3050590 Mar 13 '16 at 17:15
  • You'd keep a list of projects on your group keys (e.g. 'a') as well as the count. The tricky part here is that you need to keep track of exactly how many of each project is currently in the group and increment/decrement that count when records are added or removed. – Ethan Jewett Mar 13 '16 at 18:56