0

I have the following custom reduce functions

  function reduceAdd(p, v) {
  p.vol_t += v.oqt;
  p.prc_t += v.it;
  ++p.count;
  // p.average = d3.round((p.total / p.count), 2);
  return p;
}

function reduceRemove(p, v) {
  p.vol_t -= v.oqt;
  p.prc_t -= v.it;
  --p.count;
  // p.average = d3.round((p.total / p.count), 2);
  return p;
}

function reduceInitial() {
  return {
    vol_t:  0.0,
    prc_t:  0.0,
    count:  0,
  };
}

My data models is as follows:

    [{cat:'a', oqt:23.0, it: 45.0},
    {cat:'b', oqt:25.0, it: 5.0}, 
    {cat:'b', oqt:22.0, it: 25.0},
    {cat:'c', oqt:17.0, it: 35.0}]

I am trying to plot a bubble chart with dc.js with vol_t as X (keyAccessor), prc_t as Y axis (valueAccessor) and count as radiusAcessor. How do I find the max and min values across all groups. My groups are based on category 'cat' dimension.

Thanks!

bashhike
  • 129
  • 1
  • 10

2 Answers2

3

You can define an arbitrary ordering for a group based on its value: https://github.com/crossfilter/crossfilter/wiki/API-Reference#group_order

However, if you are using a dc.js bubble chart, I don't think it is necessary to define any particular ordering. You just need to define the proper accessors.

Ethan Jewett
  • 6,002
  • 16
  • 25
  • I need it for the domain and ranges for my axes. I was thinking I want to calculate the maximum, minimum with the ordering by top(1)[0]. So for X axis I will have to order by volume and for Y axis I have to order by price. – bashhike Apr 08 '16 at 03:51
  • If you are looking to set the domain once, then you don't want to use Crossfilter for this. Just transform your data to a list of numbers (using Array.map) and use Math.min and Math.max. Or use d3.extent if you prefer. If you are using elasticX/elasticY, then I think dc.js handles this for you. – Ethan Jewett Apr 08 '16 at 13:06
1

Solved it by using d3.extent and passing the category group and accessor function returning volume and price.

bashhike
  • 129
  • 1
  • 10