plotly / react-pivottable

React-based drag'n'drop pivot table with Plotly.js charts
https://react-pivottable.js.org/
MIT License
1k stars 259 forks source link

unable to define a custom aggregator with custom formatter #59

Closed gparida1989 closed 6 years ago

gparida1989 commented 6 years ago

Hello All,

I am defining aggregator like this .

SumResidual: () => aggregatorTemplates.Sum(CustomFormatter)([aggregateFieldName]),

and aggregatorName=SumResidual

also I am defining vals to aggregateFieldName

1) CustomFormatter is my own formatter function 2) aggregatorFieldName is of string array and is the value of field on which aggregation needs to be performed

But the below line in Utilities.js this.aggregator = this.props.aggregatorsthis.props.aggregatorName;

calls sum()() with _ref3 as my formatter function where I am expecting it should receive the aggreagtor field name

below is the sum function from utilities. sum: function sum() { var formatter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : usFmt;

return function (_ref3) {
  var _ref4 = _slicedToArray(_ref3, 1),
      attr = _ref4[0];

  return function () {
    return {
      sum: 0,
      push: function push(record) {
        if (!isNaN(parseFloat(record[attr]))) {
          this.sum += parseFloat(record[attr]);
        }
      },
      value: function value() {
        return this.sum;
      },

      format: formatter,
      numInputs: typeof attr !== 'undefined' ? 0 : 1
    };
  };
};

},

Am I doing it correctly ?

Any help is appreciated :)

Regards

gparida1989 commented 6 years ago

I want to override the default formatter here

gparida1989 commented 6 years ago

Hello I got it resolved by using react-pivottable/Utilities.js.

Thanks