crossfilter / reductio

Reductio: Crossfilter grouping
Other
250 stars 42 forks source link

Cap group and retaining grouping values #58

Closed janhartmann closed 5 years ago

janhartmann commented 5 years ago

I am trying to .cap(10) a crossfilter dimension group to having the 10 highest values and then a group for whatever is rest. However, I am struggling to find out how to what the group Others is actually containing.

Take this code:

const group = reductio().count(true)(dimension.group());
const result = group
  .post()
  .sortBy("value.count", (a, b) =>
    b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN
  )
 .cap(10)();

This groups as I am expecting, but I need to know what the Others is actually grouping. Is there anyway I can get that in? I was hoping for a result like:

[
  {
    key: "Group1",
    value:  {
      count: 123
      keys: ["Group1"]
    },
     /* ... more groups like this */
    {
      key: "Others",
      value:  {
        count: 3453
        keys: ["Group10", "Group11", "Group12"]
    }
]

If using .dataList(true) on reductio, the dataList array prop on Others is empty. I would love to use crossfilter alone and not rely on reductio, if possible.

janhartmann commented 5 years ago

I ended up creating a fake group and just slicing the group :-)