react-pivottable-plus 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/{PivotTable.js → dist/PivotTable.js} +0 -1
  2. package/dist/PivotTable.js.map +1 -0
  3. package/dist/PivotTableUI.js.map +1 -0
  4. package/{PlotlyRenderers.js → dist/PlotlyRenderers.js} +0 -1
  5. package/dist/PlotlyRenderers.js.map +1 -0
  6. package/dist/SubtotalRenderers.js +1372 -0
  7. package/dist/SubtotalRenderers.js.map +1 -0
  8. package/{TableRenderers.js → dist/TableRenderers.js} +0 -1
  9. package/dist/TableRenderers.js.map +1 -0
  10. package/dist/Utilities.js.map +1 -0
  11. package/dist/__tests__/PivotTableUI-test.js +177 -0
  12. package/dist/__tests__/PivotTableUI-test.js.map +1 -0
  13. package/dist/__tests__/Utilities-test.js +366 -0
  14. package/dist/__tests__/Utilities-test.js.map +1 -0
  15. package/dist/hooks/usePivot.js.map +1 -0
  16. package/dist/renderers/RadixUI.js.map +1 -0
  17. package/dist/renderers/ShadcnDashboardUI.js.map +1 -0
  18. package/dist/renderers/TailwindUI.js.map +1 -0
  19. package/package.json +18 -19
  20. package/PivotTable.js.map +0 -1
  21. package/PivotTableUI.js.map +0 -1
  22. package/PlotlyRenderers.js.map +0 -1
  23. package/TableRenderers.js.map +0 -1
  24. package/Utilities.js.map +0 -1
  25. package/hooks/usePivot.js.map +0 -1
  26. package/renderers/RadixUI.js.map +0 -1
  27. package/renderers/ShadcnDashboardUI.js.map +0 -1
  28. package/renderers/TailwindUI.js.map +0 -1
  29. /package/{PivotTableUI.js → dist/PivotTableUI.js} +0 -0
  30. /package/{Utilities.js → dist/Utilities.js} +0 -0
  31. /package/{hooks → dist/hooks}/usePivot.js +0 -0
  32. /package/{renderers → dist/renderers}/RadixUI.js +0 -0
  33. /package/{renderers → dist/renderers}/ShadcnDashboardUI.js +0 -0
  34. /package/{renderers → dist/renderers}/TailwindUI.js +0 -0
@@ -0,0 +1,1372 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _Utilities = require("./Utilities");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
15
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
16
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
17
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
19
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
20
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
21
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
22
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
23
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
24
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
25
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
26
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
27
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
28
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
29
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
30
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
31
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
32
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
33
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
34
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
35
+ function redColorScaleGenerator(values) {
36
+ var min = Math.min.apply(Math, values);
37
+ var max = Math.max.apply(Math, values);
38
+ return function (x) {
39
+ // eslint-disable-next-line no-magic-numbers
40
+ var nonRed = 255 - Math.round(255 * (x - min) / (max - min));
41
+ return {
42
+ backgroundColor: "rgb(255,".concat(nonRed, ",").concat(nonRed, ")")
43
+ };
44
+ };
45
+ }
46
+ function makeRenderer() {
47
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
48
+ var SubtotalRenderer = /*#__PURE__*/function (_React$Component) {
49
+ function SubtotalRenderer(props) {
50
+ var _this;
51
+ _classCallCheck(this, SubtotalRenderer);
52
+ _this = _callSuper(this, SubtotalRenderer, [props]);
53
+ _this.state = {
54
+ collapsedRows: {},
55
+ collapsedCols: {}
56
+ };
57
+ return _this;
58
+ }
59
+ _inherits(SubtotalRenderer, _React$Component);
60
+ return _createClass(SubtotalRenderer, [{
61
+ key: "componentDidMount",
62
+ value: function componentDidMount() {
63
+ if (opts.subtotals && !document.getElementById('react-pivottable-subtotal-styles')) {
64
+ var style = document.createElement('style');
65
+ style.id = 'react-pivottable-subtotal-styles';
66
+ style.innerHTML = "\n .pvtSubtotal {\n font-weight: bold;\n background-color: #f0f0f0;\n }\n .pvtSubtotalRow {\n border-top: 1px solid #ddd;\n }\n .pvtSubtotalVal {\n color: #777;\n font-style: italic;\n }\n ";
67
+ document.head.appendChild(style);
68
+ }
69
+ }
70
+ }, {
71
+ key: "getBasePivotSettings",
72
+ value: function getBasePivotSettings() {
73
+ var _this2 = this;
74
+ var props = this.props;
75
+ var colAttrs = props.cols;
76
+ var rowAttrs = props.rows;
77
+ var tableOptions = Object.assign({
78
+ rowTotals: true,
79
+ colTotals: true
80
+ }, props.tableOptions);
81
+ var rowTotals = tableOptions.rowTotals || colAttrs.length === 0;
82
+ var colTotals = tableOptions.colTotals || rowAttrs.length === 0;
83
+ var subtotalOptions = Object.assign({
84
+ arrowCollapsed: "\u25B6",
85
+ arrowExpanded: "\u25E2"
86
+ }, props.subtotalOptions);
87
+ var colSubtotalDisplay = Object.assign({
88
+ displayOnTop: false,
89
+ enabled: rowTotals,
90
+ hideOnExpand: false
91
+ }, subtotalOptions.colSubtotalDisplay);
92
+ var rowSubtotalDisplay = Object.assign({
93
+ displayOnTop: true,
94
+ enabled: colTotals,
95
+ hideOnExpand: false
96
+ }, subtotalOptions.rowSubtotalDisplay);
97
+ var pivotData = new _Utilities.PivotData(props, !opts.subtotals ? {} : {
98
+ rowEnabled: rowSubtotalDisplay.enabled,
99
+ colEnabled: colSubtotalDisplay.enabled,
100
+ rowPartialOnTop: rowSubtotalDisplay.displayOnTop,
101
+ colPartialOnTop: colSubtotalDisplay.displayOnTop
102
+ });
103
+ var rowKeys = pivotData.getRowKeys();
104
+ var colKeys = pivotData.getColKeys();
105
+ var cellCallbacks = {};
106
+ var rowTotalCallbacks = {};
107
+ var colTotalCallbacks = {};
108
+ var grandTotalCallback = null;
109
+ if (tableOptions.clickCallback) {
110
+ rowKeys.forEach(function (rowKey) {
111
+ var flatRowKey = (0, _Utilities.flatKey)(rowKey);
112
+ cellCallbacks[flatRowKey] = {};
113
+ colKeys.forEach(function (colKey) {
114
+ var flatColKey = (0, _Utilities.flatKey)(colKey);
115
+ if (!(flatRowKey in cellCallbacks)) {
116
+ cellCallbacks[flatRowKey] = {};
117
+ }
118
+ cellCallbacks[flatRowKey][flatColKey] = _this2.clickHandler(pivotData, rowKey, colKey);
119
+ });
120
+ rowTotalCallbacks[flatRowKey] = _this2.clickHandler(pivotData, rowKey, []);
121
+ });
122
+ colKeys.forEach(function (colKey) {
123
+ var flatColKey = (0, _Utilities.flatKey)(colKey);
124
+ colTotalCallbacks[flatColKey] = _this2.clickHandler(pivotData, [], colKey);
125
+ });
126
+ grandTotalCallback = this.clickHandler(pivotData, [], []);
127
+ }
128
+ return Object.assign({
129
+ pivotData: pivotData,
130
+ colAttrs: colAttrs,
131
+ rowAttrs: rowAttrs,
132
+ colKeys: colKeys,
133
+ rowKeys: rowKeys,
134
+ rowTotals: rowTotals,
135
+ colTotals: colTotals,
136
+ arrowCollapsed: subtotalOptions.arrowCollapsed,
137
+ arrowExpanded: subtotalOptions.arrowExpanded,
138
+ colSubtotalDisplay: colSubtotalDisplay,
139
+ rowSubtotalDisplay: rowSubtotalDisplay,
140
+ cellCallbacks: cellCallbacks,
141
+ rowTotalCallbacks: rowTotalCallbacks,
142
+ colTotalCallbacks: colTotalCallbacks,
143
+ grandTotalCallback: grandTotalCallback
144
+ }, SubtotalRenderer.heatmapMappers(pivotData, props.tableColorScaleGenerator, colTotals, rowTotals));
145
+ }
146
+ }, {
147
+ key: "clickHandler",
148
+ value: function clickHandler(pivotData, rowValues, colValues) {
149
+ var _this3 = this;
150
+ var colAttrs = this.props.cols;
151
+ var rowAttrs = this.props.rows;
152
+ var value = pivotData.getAggregator(rowValues, colValues).value();
153
+ var filters = {};
154
+ var colLimit = Math.min(colAttrs.length, colValues.length);
155
+ for (var i = 0; i < colLimit; i++) {
156
+ var attr = colAttrs[i];
157
+ if (colValues[i] !== null) {
158
+ filters[attr] = colValues[i];
159
+ }
160
+ }
161
+ var rowLimit = Math.min(rowAttrs.length, rowValues.length);
162
+ for (var _i = 0; _i < rowLimit; _i++) {
163
+ var _attr = rowAttrs[_i];
164
+ if (rowValues[_i] !== null) {
165
+ filters[_attr] = rowValues[_i];
166
+ }
167
+ }
168
+ return function (e) {
169
+ return _this3.props.tableOptions.clickCallback(e, value, filters, pivotData);
170
+ };
171
+ }
172
+ }, {
173
+ key: "collapseAttr",
174
+ value: function collapseAttr(rowOrCol, attrIdx, allKeys) {
175
+ return function () {
176
+ var flatCollapseKeys = {};
177
+ for (var i = 0; i < allKeys.length; i++) {
178
+ var k = allKeys[i];
179
+ var slicedKey = k.slice(0, attrIdx + 1);
180
+ flatCollapseKeys[(0, _Utilities.flatKey)(slicedKey)] = true;
181
+ }
182
+ this.setState(function (prevState) {
183
+ if (rowOrCol === 'row') {
184
+ return {
185
+ collapsedRows: Object.assign({}, prevState.collapsedRows, flatCollapseKeys)
186
+ };
187
+ } else if (rowOrCol === 'col') {
188
+ return {
189
+ collapsedCols: Object.assign({}, prevState.collapsedCols, flatCollapseKeys)
190
+ };
191
+ }
192
+ return null;
193
+ });
194
+ }.bind(this);
195
+ }
196
+ }, {
197
+ key: "expandAttr",
198
+ value: function expandAttr(rowOrCol, attrIdx, allKeys) {
199
+ return function () {
200
+ var flatCollapseKeys = {};
201
+ for (var i = 0; i < allKeys.length; i++) {
202
+ var k = allKeys[i];
203
+ var slicedKey = k.slice(0, attrIdx + 1);
204
+ flatCollapseKeys[(0, _Utilities.flatKey)(slicedKey)] = false;
205
+ }
206
+ this.setState(function (prevState) {
207
+ if (rowOrCol === 'row') {
208
+ return {
209
+ collapsedRows: Object.assign({}, prevState.collapsedRows, flatCollapseKeys)
210
+ };
211
+ } else if (rowOrCol === 'col') {
212
+ return {
213
+ collapsedCols: Object.assign({}, prevState.collapsedCols, flatCollapseKeys)
214
+ };
215
+ }
216
+ return null;
217
+ });
218
+ }.bind(this);
219
+ }
220
+ }, {
221
+ key: "toggleRowKey",
222
+ value: function toggleRowKey(flatRowKey) {
223
+ return function () {
224
+ this.setState(function (prevState) {
225
+ var newCollapsedRows = Object.assign({}, prevState.collapsedRows);
226
+ newCollapsedRows[flatRowKey] = !prevState.collapsedRows[flatRowKey];
227
+ return {
228
+ collapsedRows: newCollapsedRows
229
+ };
230
+ });
231
+ }.bind(this);
232
+ }
233
+ }, {
234
+ key: "toggleColKey",
235
+ value: function toggleColKey(flatColKey) {
236
+ return function () {
237
+ this.setState(function (prevState) {
238
+ var newCollapsedCols = Object.assign({}, prevState.collapsedCols);
239
+ newCollapsedCols[flatColKey] = !prevState.collapsedCols[flatColKey];
240
+ return {
241
+ collapsedCols: newCollapsedCols
242
+ };
243
+ });
244
+ }.bind(this);
245
+ }
246
+
247
+ // Given an array of attribute values (i.e. each element is another array with
248
+ // the value at every level), compute the spans for every attribute value at
249
+ // each level.
250
+ }, {
251
+ key: "calcAttrSpans",
252
+ value: function calcAttrSpans(attrArr, numAttrs) {
253
+ var spans = [];
254
+ var li = Array(numAttrs).map(function () {
255
+ return 0;
256
+ });
257
+ var lv = Array(numAttrs).map(function () {
258
+ return null;
259
+ });
260
+ for (var i = 0; i < attrArr.length; i++) {
261
+ var cv = attrArr[i];
262
+ var isSubtotal = cv[cv.length - 1] === '__subtotal__';
263
+ var actualCv = isSubtotal ? cv.slice(0, -1) : cv;
264
+ var ent = [];
265
+ var depth = 0;
266
+ var limit = Math.min(lv.length, actualCv.length);
267
+ while (depth < limit && lv[depth] === actualCv[depth]) {
268
+ ent.push(-1);
269
+ spans[li[depth]][depth]++;
270
+ depth++;
271
+ }
272
+ while (depth < actualCv.length) {
273
+ li[depth] = i;
274
+ ent.push(1);
275
+ depth++;
276
+ }
277
+ spans.push(ent);
278
+ lv = actualCv;
279
+ }
280
+ return spans;
281
+ }
282
+ }, {
283
+ key: "renderColHeaderRow",
284
+ value: function renderColHeaderRow(attrName, attrIdx, pivotSettings) {
285
+ var rowAttrs = pivotSettings.rowAttrs,
286
+ colAttrs = pivotSettings.colAttrs,
287
+ visibleColKeys = pivotSettings.visibleColKeys,
288
+ colAttrSpans = pivotSettings.colAttrSpans,
289
+ rowTotals = pivotSettings.rowTotals,
290
+ arrowExpanded = pivotSettings.arrowExpanded,
291
+ arrowCollapsed = pivotSettings.arrowCollapsed,
292
+ colSubtotalDisplay = pivotSettings.colSubtotalDisplay;
293
+ var spaceCell = attrIdx === 0 && rowAttrs.length !== 0 ? /*#__PURE__*/_react["default"].createElement("th", {
294
+ key: "padding",
295
+ colSpan: rowAttrs.length,
296
+ rowSpan: colAttrs.length
297
+ }) : null;
298
+ var needToggle = opts.subtotals && colSubtotalDisplay.enabled && attrIdx !== colAttrs.length - 1;
299
+ var attrNameCell = /*#__PURE__*/_react["default"].createElement("th", {
300
+ key: "label",
301
+ className: "pvtAxisLabel"
302
+ }, attrName);
303
+ var attrValueCells = [];
304
+ var rowIncrSpan = rowAttrs.length !== 0 ? 1 : 0;
305
+ var i = 0;
306
+ while (i < visibleColKeys.length) {
307
+ var colKey = visibleColKeys[i];
308
+ var isSubtotalCol = colKey[colKey.length - 1] === '__subtotal__';
309
+ var actualColKey = isSubtotalCol ? colKey.slice(0, -1) : colKey;
310
+ var colSpan = attrIdx < actualColKey.length ? colAttrSpans[i][attrIdx] : 1;
311
+ if (attrIdx < actualColKey.length) {
312
+ var rowSpan = 1 + (attrIdx === colAttrs.length - 1 ? rowIncrSpan : 0);
313
+ var flatColKey = (0, _Utilities.flatKey)(actualColKey.slice(0, attrIdx + 1));
314
+ var onClick = needToggle ? this.toggleColKey(flatColKey) : null;
315
+ var headerText = actualColKey[attrIdx];
316
+ var headerClass = 'pvtColLabel';
317
+ var isCollapsedParent = this.state.collapsedCols[flatColKey] && actualColKey.length < colAttrs.length;
318
+ if (isSubtotalCol) {
319
+ headerText = "".concat(headerText, " (Subtotal)");
320
+ headerClass += ' pvtSubtotal';
321
+ } else if (isCollapsedParent) {
322
+ headerClass += ' pvtSubtotal';
323
+ }
324
+ attrValueCells.push(/*#__PURE__*/_react["default"].createElement("th", {
325
+ className: headerClass,
326
+ key: 'colKey-' + flatColKey + (isSubtotalCol ? '-subtotal' : ''),
327
+ colSpan: colSpan,
328
+ rowSpan: rowSpan,
329
+ onClick: onClick,
330
+ style: {
331
+ cursor: needToggle ? 'pointer' : 'default'
332
+ }
333
+ }, needToggle ? (this.state.collapsedCols[flatColKey] ? arrowCollapsed : arrowExpanded) + ' ' : null, headerText));
334
+ } else if (attrIdx === actualColKey.length) {
335
+ var _rowSpan = colAttrs.length - actualColKey.length + rowIncrSpan;
336
+ var _flatColKey = (0, _Utilities.flatKey)(actualColKey);
337
+ var _isCollapsedParent = this.state.collapsedCols[_flatColKey] && actualColKey.length < colAttrs.length;
338
+ attrValueCells.push(/*#__PURE__*/_react["default"].createElement("th", {
339
+ className: "pvtColLabel ".concat(isSubtotalCol || _isCollapsedParent ? 'pvtSubtotal' : ''),
340
+ key: 'colKeyBuffer-' + (0, _Utilities.flatKey)(actualColKey) + (isSubtotalCol ? '-subtotal' : ''),
341
+ colSpan: colSpan,
342
+ rowSpan: _rowSpan
343
+ }));
344
+ }
345
+ i = i + colSpan;
346
+ }
347
+ var totalCell = attrIdx === 0 && rowTotals ? /*#__PURE__*/_react["default"].createElement("th", {
348
+ key: "total",
349
+ className: "pvtTotalLabel",
350
+ rowSpan: colAttrs.length + Math.min(rowAttrs.length, 1)
351
+ }, "Totals") : null;
352
+ var cells = [spaceCell, attrNameCell].concat(attrValueCells, [totalCell]);
353
+ return cells;
354
+ }
355
+ }, {
356
+ key: "renderRowHeaderRow",
357
+ value: function renderRowHeaderRow(pivotSettings) {
358
+ var colAttrs = pivotSettings.colAttrs,
359
+ rowAttrs = pivotSettings.rowAttrs;
360
+ var cells = [];
361
+ if (rowAttrs.length !== 0) {
362
+ rowAttrs.map(function (r, i) {
363
+ cells.push(/*#__PURE__*/_react["default"].createElement("th", {
364
+ className: "pvtAxisLabel",
365
+ key: "rowAttr".concat(i)
366
+ }, r));
367
+ });
368
+ cells.push(/*#__PURE__*/_react["default"].createElement("th", {
369
+ className: "pvtTotalLabel",
370
+ key: "total"
371
+ }, colAttrs.length === 0 ? 'Totals' : null));
372
+ }
373
+ return cells;
374
+ }
375
+ }, {
376
+ key: "renderTableRow",
377
+ value: function renderTableRow(rowKey, rowIdx, pivotSettings) {
378
+ var _this4 = this;
379
+ var colKeys = pivotSettings.colKeys,
380
+ rowAttrs = pivotSettings.rowAttrs,
381
+ colAttrs = pivotSettings.colAttrs,
382
+ rowTotals = pivotSettings.rowTotals,
383
+ pivotData = pivotSettings.pivotData,
384
+ rowMapper = pivotSettings.rowMapper,
385
+ colMapper = pivotSettings.colMapper,
386
+ cellCallbacks = pivotSettings.cellCallbacks,
387
+ rowTotalCallbacks = pivotSettings.rowTotalCallbacks;
388
+ var visibleColKeys = this.visibleKeys(colKeys, this.state.collapsedCols);
389
+ var cells = [];
390
+ var isSubtotalRow = rowKey[rowKey.length - 1] === '__subtotal__';
391
+ var actualRowKey = isSubtotalRow ? rowKey.slice(0, -1) : rowKey;
392
+ visibleColKeys.forEach(function (colKey, i) {
393
+ try {
394
+ if (!actualRowKey || !colKey) {
395
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
396
+ className: "pvtVal",
397
+ key: "pvtVal-".concat(i)
398
+ }));
399
+ return;
400
+ }
401
+ var aggregator,
402
+ className,
403
+ valCss = {};
404
+ var isSubtotalCol = colKey[colKey.length - 1] === '__subtotal__';
405
+ var actualColKey = isSubtotalCol ? colKey.slice(0, -1) : colKey;
406
+ var needsSubtotalValue = isSubtotalRow || isSubtotalCol || actualColKey.length < colAttrs.length && _this4.state.collapsedCols[(0, _Utilities.flatKey)(actualColKey)] || actualRowKey.length < rowAttrs.length && _this4.state.collapsedRows[(0, _Utilities.flatKey)(actualRowKey)];
407
+ if (needsSubtotalValue) {
408
+ var _value = _this4.calculateSubtotal(pivotData, actualRowKey, actualColKey, pivotSettings);
409
+ className = 'pvtSubtotal';
410
+ var tempAggregator = _this4.safeGetAggregator(pivotData, [], []);
411
+ aggregator = {
412
+ value: function value() {
413
+ return _value;
414
+ },
415
+ format: tempAggregator ? tempAggregator.format : function (x) {
416
+ return x;
417
+ }
418
+ };
419
+ if (opts.heatmapMode && colMapper.bgColorFromSubtotalValue) {
420
+ var cellColor;
421
+ if (opts.heatmapMode === 'full') {
422
+ cellColor = colMapper.bgColorFromSubtotalValue(_value);
423
+ } else if (opts.heatmapMode === 'row') {
424
+ cellColor = colMapper.bgColorFromSubtotalValue(_value, actualRowKey);
425
+ } else if (opts.heatmapMode === 'col') {
426
+ cellColor = colMapper.bgColorFromSubtotalValue(_value, actualRowKey, actualColKey);
427
+ }
428
+ if (cellColor) {
429
+ valCss = cellColor;
430
+ }
431
+ }
432
+ } else {
433
+ aggregator = _this4.safeGetAggregator(pivotData, actualRowKey, actualColKey);
434
+ className = 'pvtVal';
435
+ if (opts.heatmapMode && colMapper.bgColorFromRowColKey) {
436
+ var _cellColor = colMapper.bgColorFromRowColKey(actualRowKey, actualColKey);
437
+ if (_cellColor) {
438
+ valCss = _cellColor;
439
+ }
440
+ }
441
+ }
442
+ if (!aggregator || aggregator.value() === null) {
443
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
444
+ className: className,
445
+ key: "pvtVal-".concat(i),
446
+ style: valCss
447
+ }));
448
+ return;
449
+ }
450
+ var val = aggregator.value();
451
+ var formattedVal;
452
+ if (val === null) {
453
+ formattedVal = '';
454
+ } else if (className === 'pvtSubtotal' && val === 0) {
455
+ formattedVal = '';
456
+ } else {
457
+ formattedVal = aggregator.format(val);
458
+ }
459
+ var cellKey = (0, _Utilities.flatKey)(actualRowKey);
460
+ var colCellKey = (0, _Utilities.flatKey)(actualColKey);
461
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
462
+ className: className,
463
+ key: "pvtVal-".concat(i),
464
+ style: valCss,
465
+ onClick: cellCallbacks[cellKey] && colCellKey in cellCallbacks[cellKey] ? cellCallbacks[cellKey][colCellKey] : null
466
+ }, formattedVal));
467
+ } catch (error) {
468
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
469
+ className: "pvtVal",
470
+ key: "pvtVal-".concat(i)
471
+ }));
472
+ }
473
+ });
474
+ if (rowTotals) {
475
+ try {
476
+ var className = isSubtotalRow ? 'pvtTotal pvtSubtotal' : 'pvtTotal';
477
+ var valCss = {};
478
+ var totalVal = 0;
479
+ var formattedTotal = '';
480
+ if (isSubtotalRow) {
481
+ totalVal = this.calculateSubtotal(pivotData, actualRowKey, [], pivotSettings);
482
+ if (opts.heatmapMode && colMapper.bgColorFromSubtotalValue) {
483
+ var cellColor;
484
+ if (opts.heatmapMode === 'full') {
485
+ cellColor = colMapper.bgColorFromSubtotalValue(totalVal);
486
+ } else if (opts.heatmapMode === 'row') {
487
+ cellColor = colMapper.bgColorFromSubtotalValue(totalVal, actualRowKey);
488
+ } else if (opts.heatmapMode === 'col') {
489
+ cellColor = colMapper.bgColorFromSubtotalValue(totalVal, actualRowKey, []);
490
+ }
491
+ if (cellColor) {
492
+ valCss = cellColor;
493
+ }
494
+ }
495
+ } else if (actualRowKey.length < rowAttrs.length && this.state.collapsedRows[(0, _Utilities.flatKey)(actualRowKey)]) {
496
+ totalVal = this.calculateSubtotal(pivotData, actualRowKey, [], pivotSettings);
497
+ if (opts.heatmapMode && colMapper.bgColorFromSubtotalValue) {
498
+ var _cellColor2;
499
+ if (opts.heatmapMode === 'full') {
500
+ _cellColor2 = colMapper.bgColorFromSubtotalValue(totalVal);
501
+ } else if (opts.heatmapMode === 'row') {
502
+ _cellColor2 = colMapper.bgColorFromSubtotalValue(totalVal, actualRowKey);
503
+ } else if (opts.heatmapMode === 'col') {
504
+ _cellColor2 = colMapper.bgColorFromSubtotalValue(totalVal, actualRowKey, []);
505
+ }
506
+ if (_cellColor2) {
507
+ valCss = _cellColor2;
508
+ }
509
+ }
510
+ } else {
511
+ pivotData.getColKeys().forEach(function (colKey) {
512
+ var agg = _this4.safeGetAggregator(pivotData, actualRowKey, colKey);
513
+ if (agg) {
514
+ var val = agg.value();
515
+ if (val !== null && !isNaN(val)) {
516
+ totalVal += val;
517
+ }
518
+ }
519
+ });
520
+ if (opts.heatmapMode && totalVal !== 0) {
521
+ if (opts.heatmapMode === 'row' && colMapper.bgColorFromSubtotalValue) {
522
+ var _cellColor3 = colMapper.bgColorFromSubtotalValue(totalVal, actualRowKey);
523
+ if (_cellColor3) {
524
+ valCss = _cellColor3;
525
+ }
526
+ } else if (rowMapper.totalColor) {
527
+ var _cellColor4 = rowMapper.totalColor(actualRowKey[0]);
528
+ if (_cellColor4) {
529
+ valCss = _cellColor4;
530
+ }
531
+ }
532
+ }
533
+ }
534
+ if (totalVal !== 0 || isSubtotalRow) {
535
+ var tempAggregator = this.safeGetAggregator(pivotData, [], []);
536
+ var formatFunc = tempAggregator && tempAggregator.format ? tempAggregator.format : function (x) {
537
+ return x;
538
+ };
539
+ if (className.includes('pvtSubtotal') && totalVal === 0) {
540
+ formattedTotal = '';
541
+ } else {
542
+ formattedTotal = totalVal === null || totalVal === 0 ? '' : formatFunc(totalVal);
543
+ }
544
+ }
545
+ var cellKey = (0, _Utilities.flatKey)(actualRowKey);
546
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
547
+ className: className,
548
+ key: "total",
549
+ style: valCss,
550
+ onClick: rowTotalCallbacks[cellKey]
551
+ }, formattedTotal));
552
+ } catch (error) {
553
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
554
+ className: "pvtTotal",
555
+ key: "total"
556
+ }));
557
+ }
558
+ }
559
+ return cells;
560
+ }
561
+ }, {
562
+ key: "renderTotalsRow",
563
+ value: function renderTotalsRow(pivotSettings) {
564
+ var _this5 = this;
565
+ var colKeys = pivotSettings.colKeys,
566
+ colAttrs = pivotSettings.colAttrs,
567
+ rowAttrs = pivotSettings.rowAttrs,
568
+ colTotals = pivotSettings.colTotals,
569
+ pivotData = pivotSettings.pivotData,
570
+ colMapper = pivotSettings.colMapper,
571
+ grandTotalCallback = pivotSettings.grandTotalCallback,
572
+ colTotalCallbacks = pivotSettings.colTotalCallbacks;
573
+ var visibleColKeys = this.visibleKeys(colKeys, this.state.collapsedCols);
574
+ var cells = [];
575
+ cells.push(/*#__PURE__*/_react["default"].createElement("th", {
576
+ key: "labelTotal",
577
+ className: "pvtTotalLabel",
578
+ colSpan: rowAttrs.length + (colAttrs.length === 0 ? 0 : 1)
579
+ }, "Totals"));
580
+ visibleColKeys.forEach(function (colKey, i) {
581
+ try {
582
+ var isSubtotalCol = colKey[colKey.length - 1] === '__subtotal__';
583
+ var actualColKey = isSubtotalCol ? colKey.slice(0, -1) : colKey;
584
+ if (!actualColKey) {
585
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
586
+ className: "pvtTotal",
587
+ key: "total-".concat(i)
588
+ }));
589
+ return;
590
+ }
591
+ var colTotal = 0;
592
+ var flatColKey = (0, _Utilities.flatKey)(actualColKey);
593
+ var isCollapsedParent = _this5.state.collapsedCols[flatColKey] && actualColKey.length < colAttrs.length;
594
+ if (isSubtotalCol || isCollapsedParent) {
595
+ colTotal = _this5.calculateSubtotal(pivotData, [], actualColKey, pivotSettings);
596
+ } else {
597
+ pivotData.getRowKeys().forEach(function (rowKey) {
598
+ var agg = _this5.safeGetAggregator(pivotData, rowKey, actualColKey);
599
+ if (agg) {
600
+ var val = agg.value();
601
+ if (val !== null && !isNaN(val)) {
602
+ colTotal += val;
603
+ }
604
+ }
605
+ });
606
+ }
607
+ var valCss = {};
608
+ if (isSubtotalCol || isCollapsedParent) {
609
+ if (opts.heatmapMode && colMapper.bgColorFromSubtotalValue) {
610
+ var cellColor;
611
+ if (opts.heatmapMode === 'full') {
612
+ cellColor = colMapper.bgColorFromSubtotalValue(colTotal);
613
+ } else if (opts.heatmapMode === 'row') {
614
+ cellColor = colMapper.bgColorFromSubtotalValue(colTotal, []);
615
+ } else if (opts.heatmapMode === 'col') {
616
+ cellColor = colMapper.bgColorFromSubtotalValue(colTotal, [], actualColKey);
617
+ }
618
+ if (cellColor) {
619
+ valCss = cellColor;
620
+ }
621
+ }
622
+ } else {
623
+ if (opts.heatmapMode && colTotal !== 0) {
624
+ if (opts.heatmapMode === 'col' && colMapper.bgColorFromSubtotalValue) {
625
+ var _cellColor5 = colMapper.bgColorFromSubtotalValue(colTotal, [], actualColKey);
626
+ if (_cellColor5) {
627
+ valCss = _cellColor5;
628
+ }
629
+ } else if (colMapper.totalColor) {
630
+ var _cellColor6 = colMapper.totalColor(actualColKey[0]);
631
+ if (_cellColor6) {
632
+ valCss = _cellColor6;
633
+ }
634
+ }
635
+ }
636
+ }
637
+ var tempAggregator = _this5.safeGetAggregator(pivotData, [], []);
638
+ var format = tempAggregator && tempAggregator.format ? tempAggregator.format : function (x) {
639
+ return x;
640
+ };
641
+ var displayValue;
642
+ if (colTotal === null || colTotal === 0) {
643
+ displayValue = '';
644
+ } else {
645
+ displayValue = format ? format(colTotal) : colTotal;
646
+ }
647
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
648
+ className: "pvtTotal ".concat(isSubtotalCol || isCollapsedParent ? 'pvtSubtotal' : ''),
649
+ key: "total-".concat(i),
650
+ style: valCss,
651
+ onClick: colTotalCallbacks[(0, _Utilities.flatKey)(actualColKey)]
652
+ }, displayValue));
653
+ } catch (error) {
654
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
655
+ className: "pvtTotal",
656
+ key: "total-".concat(i)
657
+ }));
658
+ }
659
+ });
660
+ if (colTotals) {
661
+ try {
662
+ var grandTotal = 0;
663
+ var validValuesFound = false;
664
+ try {
665
+ var grandTotalAggregator = pivotData.getAggregator([], []);
666
+ if (grandTotalAggregator) {
667
+ var val = grandTotalAggregator.value();
668
+ if (val !== null && !isNaN(val)) {
669
+ grandTotal = val;
670
+ validValuesFound = true;
671
+ }
672
+ }
673
+ } catch (e) {
674
+ // Error getting grand total directly, will calculate manually
675
+ }
676
+ if (!validValuesFound) {
677
+ pivotData.getRowKeys().forEach(function (rowKey) {
678
+ pivotData.getColKeys().forEach(function (colKey) {
679
+ try {
680
+ var agg = _this5.safeGetAggregator(pivotData, rowKey, colKey);
681
+ if (agg) {
682
+ var _val = agg.value();
683
+ if (_val !== null && !isNaN(_val)) {
684
+ grandTotal += _val;
685
+ validValuesFound = true;
686
+ }
687
+ }
688
+ } catch (e) {
689
+ // Ignore errors for missing combinations
690
+ }
691
+ });
692
+ });
693
+ }
694
+ var tempAggregator = this.safeGetAggregator(pivotData, [], []);
695
+ var format = tempAggregator && tempAggregator.format ? tempAggregator.format : function (x) {
696
+ return x;
697
+ };
698
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
699
+ className: "pvtGrandTotal",
700
+ key: "grandTotal",
701
+ style: opts.heatmapMode && colMapper.grandTotalColor ? colMapper.grandTotalColor : {},
702
+ onClick: grandTotalCallback
703
+ }, validValuesFound && grandTotal !== 0 ? format ? format(grandTotal) : grandTotal : ''));
704
+ } catch (error) {
705
+ cells.push(/*#__PURE__*/_react["default"].createElement("td", {
706
+ className: "pvtGrandTotal",
707
+ key: "grandTotal"
708
+ }));
709
+ }
710
+ }
711
+ return cells;
712
+ }
713
+ }, {
714
+ key: "visibleKeys",
715
+ value: function visibleKeys(keys, collapsed) {
716
+ if (!opts.subtotals) {
717
+ return keys;
718
+ }
719
+ var sortedKeys = keys.slice().sort(function (a, b) {
720
+ var minLength = Math.min(a.length, b.length);
721
+ for (var i = 0; i < minLength; i++) {
722
+ var aStr = String(a[i]);
723
+ var bStr = String(b[i]);
724
+ var cmp = aStr.localeCompare(bStr);
725
+ if (cmp !== 0) {
726
+ return cmp;
727
+ }
728
+ }
729
+ return a.length - b.length;
730
+ });
731
+ var result = [];
732
+ var processedKeys = new Set();
733
+ var _iterator = _createForOfIteratorHelper(sortedKeys),
734
+ _step;
735
+ try {
736
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
737
+ var _key3 = _step.value;
738
+ var parentCollapsed = false;
739
+ var deepestCollapsedParent = null;
740
+ for (var _i4 = 0; _i4 < _key3.length; _i4++) {
741
+ var _parentKey3 = _key3.slice(0, _i4 + 1);
742
+ var flatParentKey = (0, _Utilities.flatKey)(_parentKey3);
743
+ if (collapsed[flatParentKey]) {
744
+ parentCollapsed = true;
745
+ deepestCollapsedParent = _parentKey3;
746
+ break;
747
+ }
748
+ }
749
+ if (parentCollapsed) {
750
+ var _flatParentKey = (0, _Utilities.flatKey)(deepestCollapsedParent);
751
+ if (!processedKeys.has(_flatParentKey)) {
752
+ result.push(deepestCollapsedParent);
753
+ processedKeys.add(_flatParentKey);
754
+ }
755
+ } else {
756
+ var flatKey_ = (0, _Utilities.flatKey)(_key3);
757
+ if (!processedKeys.has(flatKey_)) {
758
+ result.push(_key3);
759
+ processedKeys.add(flatKey_);
760
+ }
761
+ }
762
+ }
763
+ } catch (err) {
764
+ _iterator.e(err);
765
+ } finally {
766
+ _iterator.f();
767
+ }
768
+ var finalResult = [];
769
+ var addedSubtotals = new Set();
770
+ var parentGroups = new Map();
771
+ for (var _i2 = 0, _result = result; _i2 < _result.length; _i2++) {
772
+ var key = _result[_i2];
773
+ for (var level = 1; level < key.length; level++) {
774
+ var parentKey = key.slice(0, level);
775
+ var parentKeyStr = (0, _Utilities.flatKey)(parentKey);
776
+ if (!parentGroups.has(parentKeyStr)) {
777
+ parentGroups.set(parentKeyStr, {
778
+ key: parentKey,
779
+ level: level,
780
+ lastChildIndex: -1
781
+ });
782
+ }
783
+ }
784
+ }
785
+ for (var i = 0; i < result.length; i++) {
786
+ var _key = result[i];
787
+ for (var _level = 1; _level < _key.length; _level++) {
788
+ var _parentKey = _key.slice(0, _level);
789
+ var _parentKeyStr = (0, _Utilities.flatKey)(_parentKey);
790
+ var parentGroup = parentGroups.get(_parentKeyStr);
791
+ if (parentGroup) {
792
+ parentGroup.lastChildIndex = Math.max(parentGroup.lastChildIndex, i);
793
+ }
794
+ }
795
+ }
796
+ for (var _i3 = 0; _i3 < result.length; _i3++) {
797
+ var _key2 = result[_i3];
798
+ finalResult.push(_key2);
799
+ var subtotalsToAdd = [];
800
+ for (var _level2 = _key2.length - 1; _level2 >= 1; _level2--) {
801
+ var _parentKey2 = _key2.slice(0, _level2);
802
+ var _parentKeyStr2 = (0, _Utilities.flatKey)(_parentKey2);
803
+ var _parentGroup = parentGroups.get(_parentKeyStr2);
804
+ if (collapsed[_parentKeyStr2]) {
805
+ continue;
806
+ }
807
+ if (_parentGroup && _parentGroup.lastChildIndex === _i3) {
808
+ var subtotalKey = [].concat(_toConsumableArray(_parentKey2), ['__subtotal__']);
809
+ var subtotalKeyStr = (0, _Utilities.flatKey)(subtotalKey);
810
+ if (!addedSubtotals.has(subtotalKeyStr)) {
811
+ subtotalsToAdd.push(subtotalKey);
812
+ addedSubtotals.add(subtotalKeyStr);
813
+ }
814
+ }
815
+ }
816
+ finalResult.push.apply(finalResult, subtotalsToAdd);
817
+ }
818
+ return finalResult;
819
+ }
820
+ }, {
821
+ key: "getSubtotal",
822
+ value: function getSubtotal(rowKey, colKey, pivotSettings) {
823
+ var pivotData = pivotSettings.pivotData;
824
+ return pivotData.getAggregator(rowKey, colKey).value();
825
+ }
826
+ }, {
827
+ key: "hasSubtotals",
828
+ value: function hasSubtotals(rowOrCol, key, pivotSettings) {
829
+ var rowAttrs = pivotSettings.rowAttrs,
830
+ colAttrs = pivotSettings.colAttrs;
831
+ var attrs = rowOrCol === 'row' ? rowAttrs : colAttrs;
832
+ return key.length < attrs.length;
833
+ }
834
+ }, {
835
+ key: "safeGetAggregator",
836
+ value: function safeGetAggregator(pivotData, rowKey, colKey) {
837
+ try {
838
+ return pivotData.getAggregator(rowKey, colKey);
839
+ } catch (error) {
840
+ return null;
841
+ }
842
+ }
843
+ }, {
844
+ key: "calculateSubtotal",
845
+ value: function calculateSubtotal(pivotData, rowKey, colKey, pivotSettings) {
846
+ var _this6 = this;
847
+ var rowAttrs = pivotSettings.rowAttrs,
848
+ colAttrs = pivotSettings.colAttrs;
849
+ if (rowKey.length === rowAttrs.length && colKey.length === colAttrs.length) {
850
+ var agg = this.safeGetAggregator(pivotData, rowKey, colKey);
851
+ return agg ? agg.value() : 0;
852
+ }
853
+ var total = 0;
854
+ var hasValidValues = false;
855
+ var childRowKeys = [];
856
+ if (rowKey.length < rowAttrs.length) {
857
+ pivotData.getRowKeys().forEach(function (fullRowKey) {
858
+ var isChild = true;
859
+ for (var i = 0; i < rowKey.length; i++) {
860
+ if (fullRowKey[i] !== rowKey[i]) {
861
+ isChild = false;
862
+ break;
863
+ }
864
+ }
865
+ if (isChild) {
866
+ childRowKeys.push(fullRowKey);
867
+ }
868
+ });
869
+ } else {
870
+ childRowKeys.push(rowKey);
871
+ }
872
+ var childColKeys = [];
873
+ if (colKey.length < colAttrs.length) {
874
+ pivotData.getColKeys().forEach(function (fullColKey) {
875
+ var isChild = true;
876
+ for (var i = 0; i < colKey.length; i++) {
877
+ if (fullColKey[i] !== colKey[i]) {
878
+ isChild = false;
879
+ break;
880
+ }
881
+ }
882
+ if (isChild) {
883
+ childColKeys.push(fullColKey);
884
+ }
885
+ });
886
+ } else {
887
+ childColKeys.push(colKey);
888
+ }
889
+ if (childRowKeys.length === 0 || childColKeys.length === 0) {
890
+ var _agg = this.safeGetAggregator(pivotData, rowKey, colKey);
891
+ return _agg ? _agg.value() || 0 : 0;
892
+ }
893
+ childRowKeys.forEach(function (childRowKey) {
894
+ childColKeys.forEach(function (childColKey) {
895
+ var agg = _this6.safeGetAggregator(pivotData, childRowKey, childColKey);
896
+ if (agg) {
897
+ var val = agg.value();
898
+ if (val !== null && !isNaN(val)) {
899
+ total += val;
900
+ hasValidValues = true;
901
+ }
902
+ }
903
+ });
904
+ });
905
+ return hasValidValues ? total : 0;
906
+ }
907
+ }, {
908
+ key: "render",
909
+ value: function render() {
910
+ var _this7 = this;
911
+ var pivotSettings = this.getBasePivotSettings();
912
+ var colAttrs = pivotSettings.colAttrs,
913
+ rowAttrs = pivotSettings.rowAttrs,
914
+ rowKeys = pivotSettings.rowKeys,
915
+ colKeys = pivotSettings.colKeys,
916
+ rowTotals = pivotSettings.rowTotals;
917
+ var renderedLabels = {};
918
+ var visibleRowKeys = opts.subtotals ? this.visibleKeys(rowKeys, this.state.collapsedRows) : rowKeys;
919
+ var visibleColKeys = opts.subtotals ? this.visibleKeys(colKeys, this.state.collapsedCols) : colKeys;
920
+ var finalPivotSettings = Object.assign({
921
+ visibleRowKeys: visibleRowKeys,
922
+ maxRowVisible: Math.max.apply(Math, _toConsumableArray(visibleRowKeys.map(function (k) {
923
+ return k.length;
924
+ }))),
925
+ visibleColKeys: visibleColKeys,
926
+ maxColVisible: Math.max.apply(Math, _toConsumableArray(visibleColKeys.map(function (k) {
927
+ return k.length;
928
+ }))),
929
+ rowAttrSpans: this.calcAttrSpans(visibleRowKeys, rowAttrs.length),
930
+ colAttrSpans: this.calcAttrSpans(visibleColKeys, colAttrs.length)
931
+ }, pivotSettings);
932
+ var rowspans = {};
933
+ visibleRowKeys.forEach(function (rowKey, rowIdx) {
934
+ var isSubtotalRow = rowKey[rowKey.length - 1] === '__subtotal__';
935
+ var actualRowKey = isSubtotalRow ? rowKey.slice(0, -1) : rowKey;
936
+ for (var level = 0; level < actualRowKey.length; level++) {
937
+ var cellKey = "".concat(rowIdx, "-").concat(level);
938
+ var span = 1;
939
+ var j = rowIdx + 1;
940
+ while (j < visibleRowKeys.length) {
941
+ var nextKey = visibleRowKeys[j];
942
+ var isNextSubtotal = nextKey[nextKey.length - 1] === '__subtotal__';
943
+ var actualNextKey = isNextSubtotal ? nextKey.slice(0, -1) : nextKey;
944
+ if (level >= actualNextKey.length) {
945
+ break;
946
+ }
947
+ var matches = true;
948
+ for (var l = 0; l <= level; l++) {
949
+ if (l >= actualNextKey.length || actualNextKey[l] !== actualRowKey[l]) {
950
+ matches = false;
951
+ break;
952
+ }
953
+ }
954
+ if (!matches) {
955
+ break;
956
+ }
957
+ span++;
958
+ j++;
959
+ }
960
+ rowspans[cellKey] = span;
961
+ }
962
+ });
963
+ var renderedRows = visibleRowKeys.map(function (rowKey, i) {
964
+ var rowCells = [];
965
+ var isSubtotalRow = rowKey[rowKey.length - 1] === '__subtotal__';
966
+ var actualRowKey = isSubtotalRow ? rowKey.slice(0, -1) : rowKey;
967
+ if (isSubtotalRow) {
968
+ rowCells.push(/*#__PURE__*/_react["default"].createElement("th", {
969
+ key: "subtotalLabel",
970
+ className: "pvtRowLabel pvtSubtotal",
971
+ colSpan: rowAttrs.length - actualRowKey.length + 1
972
+ }));
973
+ } else {
974
+ for (var level = 0; level < actualRowKey.length; level++) {
975
+ var labelKey = "".concat(actualRowKey.slice(0, level + 1).join('|'));
976
+ if (!renderedLabels[labelKey]) {
977
+ renderedLabels[labelKey] = true;
978
+ var cellKey = "".concat(i, "-").concat(level);
979
+ var rowspan = rowspans[cellKey] || 1;
980
+ var flatRowKey = (0, _Utilities.flatKey)(actualRowKey.slice(0, level + 1));
981
+ var isCollapsed = _this7.state.collapsedRows[flatRowKey];
982
+ var className = 'pvtRowLabel';
983
+ var icon = null;
984
+ if (level + 1 < rowAttrs.length) {
985
+ if (isCollapsed) {
986
+ className += ' collapsed';
987
+ icon = pivotSettings.arrowCollapsed;
988
+ } else {
989
+ className += ' expanded';
990
+ icon = pivotSettings.arrowExpanded;
991
+ }
992
+ rowCells.push(/*#__PURE__*/_react["default"].createElement("th", {
993
+ key: "rowLabel-".concat(level),
994
+ className: className,
995
+ rowSpan: rowspan,
996
+ onClick: _this7.toggleRowKey(flatRowKey),
997
+ style: {
998
+ cursor: 'pointer'
999
+ }
1000
+ }, icon && /*#__PURE__*/_react["default"].createElement("span", {
1001
+ className: "pvtAttr",
1002
+ style: {
1003
+ marginRight: '6px'
1004
+ }
1005
+ }, icon), /*#__PURE__*/_react["default"].createElement("span", null, actualRowKey[level])));
1006
+ continue;
1007
+ }
1008
+ var isLeafLevel = level === actualRowKey.length - 1 && actualRowKey.length === rowAttrs.length;
1009
+ var leafColspan = isLeafLevel ? 2 : 1;
1010
+ rowCells.push(/*#__PURE__*/_react["default"].createElement("th", {
1011
+ key: "rowLabel-".concat(level),
1012
+ className: className,
1013
+ rowSpan: rowspan,
1014
+ colSpan: leafColspan,
1015
+ onClick: _this7.toggleRowKey(flatRowKey)
1016
+ }, icon && /*#__PURE__*/_react["default"].createElement("span", {
1017
+ className: "pvtAttr"
1018
+ }, icon), /*#__PURE__*/_react["default"].createElement("span", null, actualRowKey[level])));
1019
+ }
1020
+ }
1021
+ if (actualRowKey.length < rowAttrs.length) {
1022
+ rowCells.push(/*#__PURE__*/_react["default"].createElement("th", {
1023
+ key: "padding",
1024
+ className: "pvtRowLabel",
1025
+ colSpan: rowAttrs.length - actualRowKey.length + 1
1026
+ }));
1027
+ }
1028
+ }
1029
+ var dataCells = _this7.renderTableRow(rowKey, i, finalPivotSettings);
1030
+ return /*#__PURE__*/_react["default"].createElement("tr", {
1031
+ key: "row-".concat(i),
1032
+ className: isSubtotalRow && opts.subtotals ? 'pvtSubtotalRow' : ''
1033
+ }, rowCells, dataCells);
1034
+ });
1035
+ var colAttrsHeaders = colAttrs.map(function (attrName, i) {
1036
+ return /*#__PURE__*/_react["default"].createElement("tr", {
1037
+ key: "colAttr-".concat(i)
1038
+ }, _this7.renderColHeaderRow(attrName, i, finalPivotSettings));
1039
+ });
1040
+ var rowAttrsHeader = null;
1041
+ if (rowAttrs.length > 0) {
1042
+ rowAttrsHeader = /*#__PURE__*/_react["default"].createElement("tr", {
1043
+ key: "rowAttr-0"
1044
+ }, this.renderRowHeaderRow(finalPivotSettings));
1045
+ }
1046
+ var totalHeader = null;
1047
+ if (rowTotals) {
1048
+ totalHeader = /*#__PURE__*/_react["default"].createElement("tr", {
1049
+ key: "total"
1050
+ }, this.renderTotalsRow(finalPivotSettings));
1051
+ }
1052
+ return /*#__PURE__*/_react["default"].createElement("table", {
1053
+ className: "pvtTable"
1054
+ }, /*#__PURE__*/_react["default"].createElement("thead", null, colAttrsHeaders, rowAttrsHeader), /*#__PURE__*/_react["default"].createElement("tbody", null, renderedRows, totalHeader));
1055
+ }
1056
+ }], [{
1057
+ key: "heatmapMappers",
1058
+ value: function heatmapMappers(pivotData, colorScaleGenerator, colTotals, rowTotals) {
1059
+ var colMapper = {};
1060
+ var rowMapper = {};
1061
+ if (colorScaleGenerator && opts.heatmapMode) {
1062
+ var valueCellColors = {};
1063
+ var rowTotalColors = {};
1064
+ var colTotalColors = {};
1065
+ var grandTotalColor = null;
1066
+ var allValues = [];
1067
+ var rowValues = {};
1068
+ var colValues = {};
1069
+ pivotData.forEachCell(function (val, rowKey, colKey) {
1070
+ if (val !== null && !isNaN(val)) {
1071
+ allValues.push(val);
1072
+ var flatRow = (0, _Utilities.flatKey)(rowKey);
1073
+ if (!rowValues[flatRow]) {
1074
+ rowValues[flatRow] = [];
1075
+ }
1076
+ rowValues[flatRow].push(val);
1077
+ var flatCol = (0, _Utilities.flatKey)(colKey);
1078
+ if (!colValues[flatCol]) {
1079
+ colValues[flatCol] = [];
1080
+ }
1081
+ colValues[flatCol].push(val);
1082
+ }
1083
+ });
1084
+ if (opts.heatmapMode === 'row' && colTotals) {
1085
+ pivotData.getRowKeys().forEach(function (rowKey) {
1086
+ var rowTotal = 0;
1087
+ var hasValidValues = false;
1088
+ pivotData.getColKeys().forEach(function (colKey) {
1089
+ var agg = pivotData.getAggregator(rowKey, colKey);
1090
+ if (agg) {
1091
+ var val = agg.value();
1092
+ if (val !== null && !isNaN(val)) {
1093
+ rowTotal += val;
1094
+ hasValidValues = true;
1095
+ }
1096
+ }
1097
+ });
1098
+ if (hasValidValues && rowTotal !== 0) {
1099
+ var flatRow = (0, _Utilities.flatKey)(rowKey);
1100
+ if (!rowValues[flatRow]) {
1101
+ rowValues[flatRow] = [];
1102
+ }
1103
+ rowValues[flatRow].push(rowTotal);
1104
+ }
1105
+ });
1106
+ }
1107
+ if (opts.heatmapMode === 'col' && rowTotals) {
1108
+ pivotData.getColKeys().forEach(function (colKey) {
1109
+ var colTotal = 0;
1110
+ var hasValidValues = false;
1111
+ pivotData.getRowKeys().forEach(function (rowKey) {
1112
+ var agg = pivotData.getAggregator(rowKey, colKey);
1113
+ if (agg) {
1114
+ var val = agg.value();
1115
+ if (val !== null && !isNaN(val)) {
1116
+ colTotal += val;
1117
+ hasValidValues = true;
1118
+ }
1119
+ }
1120
+ });
1121
+ if (hasValidValues && colTotal !== 0) {
1122
+ var flatCol = (0, _Utilities.flatKey)(colKey);
1123
+ if (!colValues[flatCol]) {
1124
+ colValues[flatCol] = [];
1125
+ }
1126
+ colValues[flatCol].push(colTotal);
1127
+ }
1128
+ });
1129
+ }
1130
+ if (colTotals) {
1131
+ var rowTotalValues = [];
1132
+ pivotData.forEachTotal(function (_ref) {
1133
+ var _ref2 = _slicedToArray(_ref, 2),
1134
+ valKey = _ref2[0],
1135
+ _x = _ref2[1];
1136
+ var val = pivotData.getAggregator([valKey], []).value();
1137
+ if (val !== null && !isNaN(val)) {
1138
+ rowTotalValues.push(val);
1139
+ if (opts.heatmapMode === 'full') {
1140
+ allValues.push(val);
1141
+ }
1142
+ }
1143
+ });
1144
+ var rowTotalColorScale = opts.heatmapMode === 'full' ? colorScaleGenerator(allValues) : colorScaleGenerator(rowTotalValues);
1145
+ pivotData.forEachTotal(function (_ref3) {
1146
+ var _ref4 = _slicedToArray(_ref3, 2),
1147
+ valKey = _ref4[0],
1148
+ _x = _ref4[1];
1149
+ var val = pivotData.getAggregator([valKey], []).value();
1150
+ if (val !== null && !isNaN(val)) {
1151
+ rowTotalColors[(0, _Utilities.flatKey)([valKey])] = rowTotalColorScale(val);
1152
+ }
1153
+ });
1154
+ }
1155
+ if (rowTotals) {
1156
+ var colTotalValues = [];
1157
+ pivotData.forEachTotal(function (_ref5) {
1158
+ var _ref6 = _slicedToArray(_ref5, 2),
1159
+ _x = _ref6[0],
1160
+ valKey = _ref6[1];
1161
+ var val = pivotData.getAggregator([], [valKey]).value();
1162
+ if (val !== null && !isNaN(val)) {
1163
+ colTotalValues.push(val);
1164
+ if (opts.heatmapMode === 'full') {
1165
+ allValues.push(val);
1166
+ }
1167
+ }
1168
+ });
1169
+ var colTotalColorScale = opts.heatmapMode === 'full' ? colorScaleGenerator(allValues) : colorScaleGenerator(colTotalValues);
1170
+ pivotData.forEachTotal(function (_ref7) {
1171
+ var _ref8 = _slicedToArray(_ref7, 2),
1172
+ _x = _ref8[0],
1173
+ valKey = _ref8[1];
1174
+ var val = pivotData.getAggregator([], [valKey]).value();
1175
+ if (val !== null && !isNaN(val)) {
1176
+ colTotalColors[(0, _Utilities.flatKey)([valKey])] = colTotalColorScale(val);
1177
+ }
1178
+ });
1179
+ }
1180
+ if (colTotals && rowTotals) {
1181
+ var grandTotalVal = pivotData.getAggregator([], []).value();
1182
+ if (grandTotalVal !== null && !isNaN(grandTotalVal)) {
1183
+ if (opts.heatmapMode === 'full') {
1184
+ allValues.push(grandTotalVal);
1185
+ var grandTotalColorScale = colorScaleGenerator(allValues);
1186
+ grandTotalColor = grandTotalColorScale(grandTotalVal);
1187
+ }
1188
+ }
1189
+ }
1190
+ if (rowTotals) {
1191
+ colMapper.totalColor = function (key) {
1192
+ return colTotalColors[(0, _Utilities.flatKey)([key])];
1193
+ };
1194
+ }
1195
+ if (colTotals) {
1196
+ rowMapper.totalColor = function (key) {
1197
+ return rowTotalColors[(0, _Utilities.flatKey)([key])];
1198
+ };
1199
+ }
1200
+ if (grandTotalColor) {
1201
+ colMapper.grandTotalColor = grandTotalColor;
1202
+ }
1203
+ if (opts.heatmapMode === 'full') {
1204
+ // Full heatmap: Compare values across the entire table
1205
+ // Note: allValues already contains all cell values from earlier collection
1206
+ var colorScale = colorScaleGenerator(allValues);
1207
+ pivotData.forEachCell(function (val, rowKey, colKey) {
1208
+ if (val !== null && !isNaN(val)) {
1209
+ valueCellColors["".concat((0, _Utilities.flatKey)(rowKey), "_").concat((0, _Utilities.flatKey)(colKey))] = colorScale(val);
1210
+ }
1211
+ });
1212
+ colMapper.bgColorFromRowColKey = function (rowKey, colKey) {
1213
+ return valueCellColors["".concat((0, _Utilities.flatKey)(rowKey), "_").concat((0, _Utilities.flatKey)(colKey))];
1214
+ };
1215
+ colMapper.bgColorFromSubtotalValue = function (value) {
1216
+ if (value !== null && !isNaN(value)) {
1217
+ return colorScale(value);
1218
+ }
1219
+ return null;
1220
+ };
1221
+ } else if (opts.heatmapMode === 'row') {
1222
+ // Row heatmap: Compare values within each row
1223
+ // Note: rowValues already populated from earlier collection
1224
+ var rowColorScales = {};
1225
+ Object.entries(rowValues).forEach(function (_ref9) {
1226
+ var _ref0 = _slicedToArray(_ref9, 2),
1227
+ flatRow = _ref0[0],
1228
+ values = _ref0[1];
1229
+ if (values.length > 0) {
1230
+ rowColorScales[flatRow] = colorScaleGenerator(values);
1231
+ }
1232
+ });
1233
+ pivotData.forEachCell(function (val, rowKey, colKey) {
1234
+ var flatRow = (0, _Utilities.flatKey)(rowKey);
1235
+ if (val !== null && !isNaN(val) && rowColorScales[flatRow]) {
1236
+ valueCellColors["".concat(flatRow, "_").concat((0, _Utilities.flatKey)(colKey))] = rowColorScales[flatRow](val);
1237
+ }
1238
+ });
1239
+ colMapper.bgColorFromRowColKey = function (rowKey, colKey) {
1240
+ return valueCellColors["".concat((0, _Utilities.flatKey)(rowKey), "_").concat((0, _Utilities.flatKey)(colKey))];
1241
+ };
1242
+ colMapper.bgColorFromSubtotalValue = function (value, rowKey) {
1243
+ if (value !== null && !isNaN(value)) {
1244
+ var flatRow = (0, _Utilities.flatKey)(rowKey);
1245
+ if (rowColorScales[flatRow]) {
1246
+ return rowColorScales[flatRow](value);
1247
+ }
1248
+ }
1249
+ return null;
1250
+ };
1251
+ } else if (opts.heatmapMode === 'col') {
1252
+ // Column heatmap: Compare values within each column
1253
+ // Note: colValues already populated from earlier collection
1254
+ var colColorScales = {};
1255
+ Object.entries(colValues).forEach(function (_ref1) {
1256
+ var _ref10 = _slicedToArray(_ref1, 2),
1257
+ flatCol = _ref10[0],
1258
+ values = _ref10[1];
1259
+ if (values.length > 0) {
1260
+ colColorScales[flatCol] = colorScaleGenerator(values);
1261
+ }
1262
+ });
1263
+ pivotData.forEachCell(function (val, rowKey, colKey) {
1264
+ var flatCol = (0, _Utilities.flatKey)(colKey);
1265
+ if (val !== null && !isNaN(val) && colColorScales[flatCol]) {
1266
+ valueCellColors["".concat((0, _Utilities.flatKey)(rowKey), "_").concat(flatCol)] = colColorScales[flatCol](val);
1267
+ }
1268
+ });
1269
+ colMapper.bgColorFromRowColKey = function (rowKey, colKey) {
1270
+ return valueCellColors["".concat((0, _Utilities.flatKey)(rowKey), "_").concat((0, _Utilities.flatKey)(colKey))];
1271
+ };
1272
+ colMapper.bgColorFromSubtotalValue = function (value, rowKey, colKey) {
1273
+ if (value !== null && !isNaN(value)) {
1274
+ var flatCol = (0, _Utilities.flatKey)(colKey);
1275
+ if (colColorScales[flatCol]) {
1276
+ return colColorScales[flatCol](value);
1277
+ }
1278
+ }
1279
+ return null;
1280
+ };
1281
+ }
1282
+ }
1283
+ return {
1284
+ colMapper: colMapper,
1285
+ rowMapper: rowMapper
1286
+ };
1287
+ }
1288
+ }]);
1289
+ }(_react["default"].Component);
1290
+ SubtotalRenderer.defaultProps = Object.assign({}, _Utilities.PivotData.defaultProps, {
1291
+ tableColorScaleGenerator: redColorScaleGenerator,
1292
+ tableOptions: {}
1293
+ });
1294
+ SubtotalRenderer.propTypes = Object.assign({}, _Utilities.PivotData.propTypes, {
1295
+ tableColorScaleGenerator: _propTypes["default"].func,
1296
+ tableOptions: _propTypes["default"].object
1297
+ });
1298
+ return SubtotalRenderer;
1299
+ }
1300
+ var TSVExportRenderer = /*#__PURE__*/function (_React$PureComponent) {
1301
+ function TSVExportRenderer() {
1302
+ _classCallCheck(this, TSVExportRenderer);
1303
+ return _callSuper(this, TSVExportRenderer, arguments);
1304
+ }
1305
+ _inherits(TSVExportRenderer, _React$PureComponent);
1306
+ return _createClass(TSVExportRenderer, [{
1307
+ key: "render",
1308
+ value: function render() {
1309
+ var pivotData = new _Utilities.PivotData(this.props);
1310
+ var rowKeys = pivotData.getRowKeys();
1311
+ var colKeys = pivotData.getColKeys();
1312
+ if (rowKeys.length === 0) {
1313
+ rowKeys.push([]);
1314
+ }
1315
+ if (colKeys.length === 0) {
1316
+ colKeys.push([]);
1317
+ }
1318
+ var headerRow = pivotData.props.rows.map(function (r) {
1319
+ return r;
1320
+ });
1321
+ if (colKeys.length === 1 && colKeys[0].length === 0) {
1322
+ headerRow.push(this.props.aggregatorName);
1323
+ } else {
1324
+ colKeys.map(function (c) {
1325
+ return headerRow.push(c.join('-'));
1326
+ });
1327
+ }
1328
+ var result = rowKeys.map(function (r) {
1329
+ var row = r.map(function (x) {
1330
+ return x;
1331
+ });
1332
+ colKeys.map(function (c) {
1333
+ var aggregator = pivotData.getAggregator(r, c);
1334
+ row.push(aggregator.value());
1335
+ });
1336
+ return row;
1337
+ });
1338
+ result.unshift(headerRow);
1339
+ return /*#__PURE__*/_react["default"].createElement("textarea", {
1340
+ value: result.map(function (r) {
1341
+ return r.join('\t');
1342
+ }).join('\n'),
1343
+ style: {
1344
+ width: window.innerWidth / 2,
1345
+ height: window.innerHeight / 2
1346
+ },
1347
+ readOnly: true
1348
+ });
1349
+ }
1350
+ }]);
1351
+ }(_react["default"].PureComponent);
1352
+ TSVExportRenderer.defaultProps = _Utilities.PivotData.defaultProps;
1353
+ TSVExportRenderer.propTypes = _Utilities.PivotData.propTypes;
1354
+ var _default = exports["default"] = {
1355
+ 'Table With Subtotal': makeRenderer({
1356
+ subtotals: true
1357
+ }),
1358
+ 'Heatmap With Subtotal': makeRenderer({
1359
+ heatmapMode: 'full',
1360
+ subtotals: true
1361
+ }),
1362
+ 'Col Heatmap With Subtotal': makeRenderer({
1363
+ heatmapMode: 'col',
1364
+ subtotals: true
1365
+ }),
1366
+ 'Row Heatmap With Subtotal': makeRenderer({
1367
+ heatmapMode: 'row',
1368
+ subtotals: true
1369
+ }),
1370
+ 'Exportable TSV': TSVExportRenderer
1371
+ };
1372
+ //# sourceMappingURL=SubtotalRenderers.js.map