@ayd-ab/react-pivottable 0.12.0
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.
- package/LICENSE +21 -0
- package/PivotTable.js +66 -0
- package/PivotTable.js.map +1 -0
- package/PivotTableUI.js +722 -0
- package/PivotTableUI.js.map +1 -0
- package/PlotlyRenderers.js +265 -0
- package/PlotlyRenderers.js.map +1 -0
- package/README.md +3 -0
- package/TableRenderers.js +435 -0
- package/TableRenderers.js.map +1 -0
- package/Utilities.js +1035 -0
- package/Utilities.js.map +1 -0
- package/package.json +81 -0
- package/pivottable.css +323 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
+
|
|
9
|
+
var _react = require('react');
|
|
10
|
+
|
|
11
|
+
var _react2 = _interopRequireDefault(_react);
|
|
12
|
+
|
|
13
|
+
var _propTypes = require('prop-types');
|
|
14
|
+
|
|
15
|
+
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
16
|
+
|
|
17
|
+
var _Utilities = require('./Utilities');
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
|
|
21
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
22
|
+
|
|
23
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
24
|
+
|
|
25
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
26
|
+
|
|
27
|
+
// helper function for setting row/col-span in pivotTableRenderer
|
|
28
|
+
var spanSize = function spanSize(arr, i, j) {
|
|
29
|
+
var x = void 0;
|
|
30
|
+
if (i !== 0) {
|
|
31
|
+
var asc = void 0,
|
|
32
|
+
end = void 0;
|
|
33
|
+
var noDraw = true;
|
|
34
|
+
for (x = 0, end = j, asc = end >= 0; asc ? x <= end : x >= end; asc ? x++ : x--) {
|
|
35
|
+
if (arr[i - 1][x] !== arr[i][x]) {
|
|
36
|
+
noDraw = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (noDraw) {
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var len = 0;
|
|
44
|
+
while (i + len < arr.length) {
|
|
45
|
+
var asc1 = void 0,
|
|
46
|
+
end1 = void 0;
|
|
47
|
+
var stop = false;
|
|
48
|
+
for (x = 0, end1 = j, asc1 = end1 >= 0; asc1 ? x <= end1 : x >= end1; asc1 ? x++ : x--) {
|
|
49
|
+
if (arr[i][x] !== arr[i + len][x]) {
|
|
50
|
+
stop = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (stop) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
len++;
|
|
57
|
+
}
|
|
58
|
+
return len;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function redColorScaleGenerator(values) {
|
|
62
|
+
var min = Math.min.apply(Math, values);
|
|
63
|
+
var max = Math.max.apply(Math, values);
|
|
64
|
+
return function (x) {
|
|
65
|
+
// eslint-disable-next-line no-magic-numbers
|
|
66
|
+
var nonRed = 255 - Math.round(255 * (x - min) / (max - min));
|
|
67
|
+
return { backgroundColor: 'rgb(255,' + nonRed + ',' + nonRed + ')' };
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function makeRenderer() {
|
|
72
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
73
|
+
|
|
74
|
+
var TableRenderer = function (_React$PureComponent) {
|
|
75
|
+
_inherits(TableRenderer, _React$PureComponent);
|
|
76
|
+
|
|
77
|
+
function TableRenderer() {
|
|
78
|
+
_classCallCheck(this, TableRenderer);
|
|
79
|
+
|
|
80
|
+
return _possibleConstructorReturn(this, (TableRenderer.__proto__ || Object.getPrototypeOf(TableRenderer)).apply(this, arguments));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_createClass(TableRenderer, [{
|
|
84
|
+
key: 'render',
|
|
85
|
+
value: function render() {
|
|
86
|
+
var _this2 = this;
|
|
87
|
+
|
|
88
|
+
var pivotData = new _Utilities.PivotData(this.props);
|
|
89
|
+
var colAttrs = pivotData.props.cols;
|
|
90
|
+
var rowAttrs = pivotData.props.rows;
|
|
91
|
+
var rowKeys = pivotData.getRowKeys();
|
|
92
|
+
var colKeys = pivotData.getColKeys();
|
|
93
|
+
var grandTotalAggregator = pivotData.getAggregator([], []);
|
|
94
|
+
|
|
95
|
+
var valueCellColors = function valueCellColors() {};
|
|
96
|
+
var rowTotalColors = function rowTotalColors() {};
|
|
97
|
+
var colTotalColors = function colTotalColors() {};
|
|
98
|
+
if (opts.heatmapMode) {
|
|
99
|
+
var colorScaleGenerator = this.props.tableColorScaleGenerator;
|
|
100
|
+
var rowTotalValues = colKeys.map(function (x) {
|
|
101
|
+
return pivotData.getAggregator([], x).value();
|
|
102
|
+
});
|
|
103
|
+
rowTotalColors = colorScaleGenerator(rowTotalValues);
|
|
104
|
+
var colTotalValues = rowKeys.map(function (x) {
|
|
105
|
+
return pivotData.getAggregator(x, []).value();
|
|
106
|
+
});
|
|
107
|
+
colTotalColors = colorScaleGenerator(colTotalValues);
|
|
108
|
+
|
|
109
|
+
if (opts.heatmapMode === 'full') {
|
|
110
|
+
var allValues = [];
|
|
111
|
+
rowKeys.map(function (r) {
|
|
112
|
+
return colKeys.map(function (c) {
|
|
113
|
+
return allValues.push(pivotData.getAggregator(r, c).value());
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
var colorScale = colorScaleGenerator(allValues);
|
|
117
|
+
valueCellColors = function valueCellColors(r, c, v) {
|
|
118
|
+
return colorScale(v);
|
|
119
|
+
};
|
|
120
|
+
} else if (opts.heatmapMode === 'row') {
|
|
121
|
+
var rowColorScales = {};
|
|
122
|
+
rowKeys.map(function (r) {
|
|
123
|
+
var rowValues = colKeys.map(function (x) {
|
|
124
|
+
return pivotData.getAggregator(r, x).value();
|
|
125
|
+
});
|
|
126
|
+
rowColorScales[r] = colorScaleGenerator(rowValues);
|
|
127
|
+
});
|
|
128
|
+
valueCellColors = function valueCellColors(r, c, v) {
|
|
129
|
+
return rowColorScales[r](v);
|
|
130
|
+
};
|
|
131
|
+
} else if (opts.heatmapMode === 'col') {
|
|
132
|
+
var colColorScales = {};
|
|
133
|
+
colKeys.map(function (c) {
|
|
134
|
+
var colValues = rowKeys.map(function (x) {
|
|
135
|
+
return pivotData.getAggregator(x, c).value();
|
|
136
|
+
});
|
|
137
|
+
colColorScales[c] = colorScaleGenerator(colValues);
|
|
138
|
+
});
|
|
139
|
+
valueCellColors = function valueCellColors(r, c, v) {
|
|
140
|
+
return colColorScales[c](v);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
var getClickHandler = this.props.tableOptions && this.props.tableOptions.clickCallback ? function (value, rowValues, colValues) {
|
|
146
|
+
var filters = {};
|
|
147
|
+
var _iteratorNormalCompletion = true;
|
|
148
|
+
var _didIteratorError = false;
|
|
149
|
+
var _iteratorError = undefined;
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
for (var _iterator = Object.keys(colAttrs || {})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
153
|
+
var i = _step.value;
|
|
154
|
+
|
|
155
|
+
var attr = colAttrs[i];
|
|
156
|
+
if (colValues[i] !== null) {
|
|
157
|
+
filters[attr] = colValues[i];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch (err) {
|
|
161
|
+
_didIteratorError = true;
|
|
162
|
+
_iteratorError = err;
|
|
163
|
+
} finally {
|
|
164
|
+
try {
|
|
165
|
+
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
166
|
+
_iterator.return();
|
|
167
|
+
}
|
|
168
|
+
} finally {
|
|
169
|
+
if (_didIteratorError) {
|
|
170
|
+
throw _iteratorError;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
var _iteratorNormalCompletion2 = true;
|
|
176
|
+
var _didIteratorError2 = false;
|
|
177
|
+
var _iteratorError2 = undefined;
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
for (var _iterator2 = Object.keys(rowAttrs || {})[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
181
|
+
var _i = _step2.value;
|
|
182
|
+
|
|
183
|
+
var attr = rowAttrs[_i];
|
|
184
|
+
if (rowValues[_i] !== null) {
|
|
185
|
+
filters[attr] = rowValues[_i];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} catch (err) {
|
|
189
|
+
_didIteratorError2 = true;
|
|
190
|
+
_iteratorError2 = err;
|
|
191
|
+
} finally {
|
|
192
|
+
try {
|
|
193
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
194
|
+
_iterator2.return();
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
if (_didIteratorError2) {
|
|
198
|
+
throw _iteratorError2;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return function (e) {
|
|
204
|
+
return _this2.props.tableOptions.clickCallback(e, value, filters, pivotData);
|
|
205
|
+
};
|
|
206
|
+
} : null;
|
|
207
|
+
|
|
208
|
+
return _react2.default.createElement(
|
|
209
|
+
'table',
|
|
210
|
+
{ className: 'pvtTable' },
|
|
211
|
+
_react2.default.createElement(
|
|
212
|
+
'thead',
|
|
213
|
+
null,
|
|
214
|
+
colAttrs.map(function (c, j) {
|
|
215
|
+
return _react2.default.createElement(
|
|
216
|
+
'tr',
|
|
217
|
+
{ key: 'colAttr' + j },
|
|
218
|
+
j === 0 && rowAttrs.length !== 0 && _react2.default.createElement('th', { colSpan: rowAttrs.length, rowSpan: colAttrs.length }),
|
|
219
|
+
_react2.default.createElement(
|
|
220
|
+
'th',
|
|
221
|
+
{ className: 'pvtAxisLabel' },
|
|
222
|
+
c
|
|
223
|
+
),
|
|
224
|
+
colKeys.map(function (colKey, i) {
|
|
225
|
+
var x = spanSize(colKeys, i, j);
|
|
226
|
+
if (x === -1) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return _react2.default.createElement(
|
|
230
|
+
'th',
|
|
231
|
+
{
|
|
232
|
+
className: 'pvtColLabel',
|
|
233
|
+
key: 'colKey' + i,
|
|
234
|
+
colSpan: x,
|
|
235
|
+
rowSpan: j === colAttrs.length - 1 && rowAttrs.length !== 0 ? 2 : 1
|
|
236
|
+
},
|
|
237
|
+
colKey[j]
|
|
238
|
+
);
|
|
239
|
+
}),
|
|
240
|
+
j === 0 && _react2.default.createElement(
|
|
241
|
+
'th',
|
|
242
|
+
{
|
|
243
|
+
className: 'pvtTotalLabel',
|
|
244
|
+
rowSpan: colAttrs.length + (rowAttrs.length === 0 ? 0 : 1)
|
|
245
|
+
},
|
|
246
|
+
'Totals'
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
}),
|
|
250
|
+
rowAttrs.length !== 0 && _react2.default.createElement(
|
|
251
|
+
'tr',
|
|
252
|
+
null,
|
|
253
|
+
rowAttrs.map(function (r, i) {
|
|
254
|
+
return _react2.default.createElement(
|
|
255
|
+
'th',
|
|
256
|
+
{ className: 'pvtAxisLabel', key: 'rowAttr' + i },
|
|
257
|
+
r
|
|
258
|
+
);
|
|
259
|
+
}),
|
|
260
|
+
_react2.default.createElement(
|
|
261
|
+
'th',
|
|
262
|
+
{ className: 'pvtTotalLabel' },
|
|
263
|
+
colAttrs.length === 0 ? 'Totals' : null
|
|
264
|
+
)
|
|
265
|
+
)
|
|
266
|
+
),
|
|
267
|
+
_react2.default.createElement(
|
|
268
|
+
'tbody',
|
|
269
|
+
null,
|
|
270
|
+
rowKeys.map(function (rowKey, i) {
|
|
271
|
+
var totalAggregator = pivotData.getAggregator(rowKey, []);
|
|
272
|
+
return _react2.default.createElement(
|
|
273
|
+
'tr',
|
|
274
|
+
{ key: 'rowKeyRow' + i },
|
|
275
|
+
rowKey.map(function (txt, j) {
|
|
276
|
+
var x = spanSize(rowKeys, i, j);
|
|
277
|
+
if (x === -1) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return _react2.default.createElement(
|
|
281
|
+
'th',
|
|
282
|
+
{
|
|
283
|
+
key: 'rowKeyLabel' + i + '-' + j,
|
|
284
|
+
className: 'pvtRowLabel',
|
|
285
|
+
rowSpan: x,
|
|
286
|
+
colSpan: j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1
|
|
287
|
+
},
|
|
288
|
+
txt
|
|
289
|
+
);
|
|
290
|
+
}),
|
|
291
|
+
colKeys.map(function (colKey, j) {
|
|
292
|
+
var aggregator = pivotData.getAggregator(rowKey, colKey);
|
|
293
|
+
return _react2.default.createElement(
|
|
294
|
+
'td',
|
|
295
|
+
{
|
|
296
|
+
className: 'pvtVal',
|
|
297
|
+
key: 'pvtVal' + i + '-' + j,
|
|
298
|
+
onClick: getClickHandler && getClickHandler(aggregator.value(), rowKey, colKey),
|
|
299
|
+
style: valueCellColors(rowKey, colKey, aggregator.value())
|
|
300
|
+
},
|
|
301
|
+
aggregator.format(aggregator.value())
|
|
302
|
+
);
|
|
303
|
+
}),
|
|
304
|
+
_react2.default.createElement(
|
|
305
|
+
'td',
|
|
306
|
+
{
|
|
307
|
+
className: 'pvtTotal',
|
|
308
|
+
onClick: getClickHandler && getClickHandler(totalAggregator.value(), rowKey, [null]),
|
|
309
|
+
style: colTotalColors(totalAggregator.value())
|
|
310
|
+
},
|
|
311
|
+
totalAggregator.format(totalAggregator.value())
|
|
312
|
+
)
|
|
313
|
+
);
|
|
314
|
+
}),
|
|
315
|
+
_react2.default.createElement(
|
|
316
|
+
'tr',
|
|
317
|
+
null,
|
|
318
|
+
_react2.default.createElement(
|
|
319
|
+
'th',
|
|
320
|
+
{
|
|
321
|
+
className: 'pvtTotalLabel',
|
|
322
|
+
colSpan: rowAttrs.length + (colAttrs.length === 0 ? 0 : 1)
|
|
323
|
+
},
|
|
324
|
+
'Totals'
|
|
325
|
+
),
|
|
326
|
+
colKeys.map(function (colKey, i) {
|
|
327
|
+
var totalAggregator = pivotData.getAggregator([], colKey);
|
|
328
|
+
return _react2.default.createElement(
|
|
329
|
+
'td',
|
|
330
|
+
{
|
|
331
|
+
className: 'pvtTotal',
|
|
332
|
+
key: 'total' + i,
|
|
333
|
+
onClick: getClickHandler && getClickHandler(totalAggregator.value(), [null], colKey),
|
|
334
|
+
style: rowTotalColors(totalAggregator.value())
|
|
335
|
+
},
|
|
336
|
+
totalAggregator.format(totalAggregator.value())
|
|
337
|
+
);
|
|
338
|
+
}),
|
|
339
|
+
_react2.default.createElement(
|
|
340
|
+
'td',
|
|
341
|
+
{
|
|
342
|
+
onClick: getClickHandler && getClickHandler(grandTotalAggregator.value(), [null], [null]),
|
|
343
|
+
className: 'pvtGrandTotal'
|
|
344
|
+
},
|
|
345
|
+
grandTotalAggregator.format(grandTotalAggregator.value())
|
|
346
|
+
)
|
|
347
|
+
)
|
|
348
|
+
)
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
}]);
|
|
352
|
+
|
|
353
|
+
return TableRenderer;
|
|
354
|
+
}(_react2.default.PureComponent);
|
|
355
|
+
|
|
356
|
+
TableRenderer.defaultProps = _Utilities.PivotData.defaultProps;
|
|
357
|
+
TableRenderer.propTypes = _Utilities.PivotData.propTypes;
|
|
358
|
+
TableRenderer.defaultProps.tableColorScaleGenerator = redColorScaleGenerator;
|
|
359
|
+
TableRenderer.defaultProps.tableOptions = {};
|
|
360
|
+
TableRenderer.propTypes.tableColorScaleGenerator = _propTypes2.default.func;
|
|
361
|
+
TableRenderer.propTypes.tableOptions = _propTypes2.default.object;
|
|
362
|
+
return TableRenderer;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
var TSVExportRenderer = function (_React$PureComponent2) {
|
|
366
|
+
_inherits(TSVExportRenderer, _React$PureComponent2);
|
|
367
|
+
|
|
368
|
+
function TSVExportRenderer() {
|
|
369
|
+
_classCallCheck(this, TSVExportRenderer);
|
|
370
|
+
|
|
371
|
+
return _possibleConstructorReturn(this, (TSVExportRenderer.__proto__ || Object.getPrototypeOf(TSVExportRenderer)).apply(this, arguments));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
_createClass(TSVExportRenderer, [{
|
|
375
|
+
key: 'render',
|
|
376
|
+
value: function render() {
|
|
377
|
+
var pivotData = new _Utilities.PivotData(this.props);
|
|
378
|
+
var rowKeys = pivotData.getRowKeys();
|
|
379
|
+
var colKeys = pivotData.getColKeys();
|
|
380
|
+
if (rowKeys.length === 0) {
|
|
381
|
+
rowKeys.push([]);
|
|
382
|
+
}
|
|
383
|
+
if (colKeys.length === 0) {
|
|
384
|
+
colKeys.push([]);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
var headerRow = pivotData.props.rows.map(function (r) {
|
|
388
|
+
return r;
|
|
389
|
+
});
|
|
390
|
+
if (colKeys.length === 1 && colKeys[0].length === 0) {
|
|
391
|
+
headerRow.push(this.props.aggregatorName);
|
|
392
|
+
} else {
|
|
393
|
+
colKeys.map(function (c) {
|
|
394
|
+
return headerRow.push(c.join('-'));
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
var result = rowKeys.map(function (r) {
|
|
399
|
+
var row = r.map(function (x) {
|
|
400
|
+
return x;
|
|
401
|
+
});
|
|
402
|
+
colKeys.map(function (c) {
|
|
403
|
+
var v = pivotData.getAggregator(r, c).value();
|
|
404
|
+
row.push(v ? v : '');
|
|
405
|
+
});
|
|
406
|
+
return row;
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
result.unshift(headerRow);
|
|
410
|
+
|
|
411
|
+
return _react2.default.createElement('textarea', {
|
|
412
|
+
value: result.map(function (r) {
|
|
413
|
+
return r.join('\t');
|
|
414
|
+
}).join('\n'),
|
|
415
|
+
style: { width: window.innerWidth / 2, height: window.innerHeight / 2 },
|
|
416
|
+
readOnly: true
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}]);
|
|
420
|
+
|
|
421
|
+
return TSVExportRenderer;
|
|
422
|
+
}(_react2.default.PureComponent);
|
|
423
|
+
|
|
424
|
+
TSVExportRenderer.defaultProps = _Utilities.PivotData.defaultProps;
|
|
425
|
+
TSVExportRenderer.propTypes = _Utilities.PivotData.propTypes;
|
|
426
|
+
|
|
427
|
+
exports.default = {
|
|
428
|
+
Table: makeRenderer(),
|
|
429
|
+
'Table Heatmap': makeRenderer({ heatmapMode: 'full' }),
|
|
430
|
+
'Table Col Heatmap': makeRenderer({ heatmapMode: 'col' }),
|
|
431
|
+
'Table Row Heatmap': makeRenderer({ heatmapMode: 'row' }),
|
|
432
|
+
'Exportable TSV': TSVExportRenderer
|
|
433
|
+
};
|
|
434
|
+
module.exports = exports['default'];
|
|
435
|
+
//# sourceMappingURL=TableRenderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["src/TableRenderers.jsx"],"names":["spanSize","arr","i","j","x","asc","end","noDraw","len","length","asc1","end1","stop","redColorScaleGenerator","values","min","Math","apply","max","nonRed","round","backgroundColor","makeRenderer","opts","TableRenderer","pivotData","PivotData","props","colAttrs","cols","rowAttrs","rows","rowKeys","getRowKeys","colKeys","getColKeys","grandTotalAggregator","getAggregator","valueCellColors","rowTotalColors","colTotalColors","heatmapMode","colorScaleGenerator","tableColorScaleGenerator","rowTotalValues","map","value","colTotalValues","allValues","push","r","c","colorScale","v","rowColorScales","rowValues","colColorScales","colValues","getClickHandler","tableOptions","clickCallback","filters","Object","keys","attr","e","colKey","rowKey","totalAggregator","txt","aggregator","format","React","PureComponent","defaultProps","propTypes","PropTypes","func","object","TSVExportRenderer","headerRow","aggregatorName","join","result","row","unshift","width","window","innerWidth","height","innerHeight","Table"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;AACA;;;;;;;;;;AAEA;AACA,IAAMA,WAAW,SAAXA,QAAW,CAASC,GAAT,EAAcC,CAAd,EAAiBC,CAAjB,EAAoB;AACnC,MAAIC,UAAJ;AACA,MAAIF,MAAM,CAAV,EAAa;AACX,QAAIG,YAAJ;AAAA,QAASC,YAAT;AACA,QAAIC,SAAS,IAAb;AACA,SACEH,IAAI,CAAJ,EAAOE,MAAMH,CAAb,EAAgBE,MAAMC,OAAO,CAD/B,EAEED,MAAMD,KAAKE,GAAX,GAAiBF,KAAKE,GAFxB,EAGED,MAAMD,GAAN,GAAYA,GAHd,EAIE;AACA,UAAIH,IAAIC,IAAI,CAAR,EAAWE,CAAX,MAAkBH,IAAIC,CAAJ,EAAOE,CAAP,CAAtB,EAAiC;AAC/BG,iBAAS,KAAT;AACD;AACF;AACD,QAAIA,MAAJ,EAAY;AACV,aAAO,CAAC,CAAR;AACD;AACF;AACD,MAAIC,MAAM,CAAV;AACA,SAAON,IAAIM,GAAJ,GAAUP,IAAIQ,M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SAAlB,GAA8BjD,qBAAUiD,SAAxC;;kBAEe;AACbgB,SAAOrE,cADM;AAEb,mBAAiBA,aAAa,EAACmB,aAAa,MAAd,EAAb,CAFJ;AAGb,uBAAqBnB,aAAa,EAACmB,aAAa,KAAd,EAAb,CAHR;AAIb,uBAAqBnB,aAAa,EAACmB,aAAa,KAAd,EAAb,CAJR;AAKb,oBAAkBsC;AALL,C","file":"TableRenderers.js","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport {PivotData} from './Utilities';\n\n// helper function for setting row/col-span in pivotTableRenderer\nconst spanSize = function(arr, i, j) {\n let x;\n if (i !== 0) {\n let asc, end;\n let noDraw = true;\n for (\n x = 0, end = j, asc = end >= 0;\n asc ? x <= end : x >= end;\n asc ? x++ : x--\n ) {\n if (arr[i - 1][x] !== arr[i][x]) {\n noDraw = false;\n }\n }\n if (noDraw) {\n return -1;\n }\n }\n let len = 0;\n while (i + len < arr.length) {\n let asc1, end1;\n let stop = false;\n for (\n x = 0, end1 = j, asc1 = end1 >= 0;\n asc1 ? x <= end1 : x >= end1;\n asc1 ? x++ : x--\n ) {\n if (arr[i][x] !== arr[i + len][x]) {\n stop = true;\n }\n }\n if (stop) {\n break;\n }\n len++;\n }\n return len;\n};\n\nfunction redColorScaleGenerator(values) {\n const min = Math.min.apply(Math, values);\n const max = Math.max.apply(Math, values);\n return x => {\n // eslint-disable-next-line no-magic-numbers\n const nonRed = 255 - Math.round((255 * (x - min)) / (max - min));\n return {backgroundColor: `rgb(255,${nonRed},${nonRed})`};\n };\n}\n\nfunction makeRenderer(opts = {}) {\n class TableRenderer extends React.PureComponent {\n render() {\n const pivotData = new PivotData(this.props);\n const colAttrs = pivotData.props.cols;\n const rowAttrs = pivotData.props.rows;\n const rowKeys = pivotData.getRowKeys();\n const colKeys = pivotData.getColKeys();\n const grandTotalAggregator = pivotData.getAggregator([], []);\n\n let valueCellColors = () => {};\n let rowTotalColors = () => {};\n let colTotalColors = () => {};\n if (opts.heatmapMode) {\n const colorScaleGenerator = this.props.tableColorScaleGenerator;\n const rowTotalValues = colKeys.map(x =>\n pivotData.getAggregator([], x).value()\n );\n rowTotalColors = colorScaleGenerator(rowTotalValues);\n const colTotalValues = rowKeys.map(x =>\n pivotData.getAggregator(x, []).value()\n );\n colTotalColors = colorScaleGenerator(colTotalValues);\n\n if (opts.heatmapMode === 'full') {\n const allValues = [];\n rowKeys.map(r =>\n colKeys.map(c =>\n allValues.push(pivotData.getAggregator(r, c).value())\n )\n );\n const colorScale = colorScaleGenerator(allValues);\n valueCellColors = (r, c, v) => colorScale(v);\n } else if (opts.heatmapMode === 'row') {\n const rowColorScales = {};\n rowKeys.map(r => {\n const rowValues = colKeys.map(x =>\n pivotData.getAggregator(r, x).value()\n );\n rowColorScales[r] = colorScaleGenerator(rowValues);\n });\n valueCellColors = (r, c, v) => rowColorScales[r](v);\n } else if (opts.heatmapMode === 'col') {\n const colColorScales = {};\n colKeys.map(c => {\n const colValues = rowKeys.map(x =>\n pivotData.getAggregator(x, c).value()\n );\n colColorScales[c] = colorScaleGenerator(colValues);\n });\n valueCellColors = (r, c, v) => colColorScales[c](v);\n }\n }\n\n const getClickHandler =\n this.props.tableOptions && this.props.tableOptions.clickCallback\n ? (value, rowValues, colValues) => {\n const filters = {};\n for (const i of Object.keys(colAttrs || {})) {\n const attr = colAttrs[i];\n if (colValues[i] !== null) {\n filters[attr] = colValues[i];\n }\n }\n for (const i of Object.keys(rowAttrs || {})) {\n const attr = rowAttrs[i];\n if (rowValues[i] !== null) {\n filters[attr] = rowValues[i];\n }\n }\n return e =>\n this.props.tableOptions.clickCallback(\n e,\n value,\n filters,\n pivotData\n );\n }\n : null;\n\n return (\n <table className=\"pvtTable\">\n <thead>\n {colAttrs.map(function(c, j) {\n return (\n <tr key={`colAttr${j}`}>\n {j === 0 && rowAttrs.length !== 0 && (\n <th colSpan={rowAttrs.length} rowSpan={colAttrs.length} />\n )}\n <th className=\"pvtAxisLabel\">{c}</th>\n {colKeys.map(function(colKey, i) {\n const x = spanSize(colKeys, i, j);\n if (x === -1) {\n return null;\n }\n return (\n <th\n className=\"pvtColLabel\"\n key={`colKey${i}`}\n colSpan={x}\n rowSpan={\n j === colAttrs.length - 1 && rowAttrs.length !== 0\n ? 2\n : 1\n }\n >\n {colKey[j]}\n </th>\n );\n })}\n\n {j === 0 && (\n <th\n className=\"pvtTotalLabel\"\n rowSpan={\n colAttrs.length + (rowAttrs.length === 0 ? 0 : 1)\n }\n >\n Totals\n </th>\n )}\n </tr>\n );\n })}\n\n {rowAttrs.length !== 0 && (\n <tr>\n {rowAttrs.map(function(r, i) {\n return (\n <th className=\"pvtAxisLabel\" key={`rowAttr${i}`}>\n {r}\n </th>\n );\n })}\n <th className=\"pvtTotalLabel\">\n {colAttrs.length === 0 ? 'Totals' : null}\n </th>\n </tr>\n )}\n </thead>\n\n <tbody>\n {rowKeys.map(function(rowKey, i) {\n const totalAggregator = pivotData.getAggregator(rowKey, []);\n return (\n <tr key={`rowKeyRow${i}`}>\n {rowKey.map(function(txt, j) {\n const x = spanSize(rowKeys, i, j);\n if (x === -1) {\n return null;\n }\n return (\n <th\n key={`rowKeyLabel${i}-${j}`}\n className=\"pvtRowLabel\"\n rowSpan={x}\n colSpan={\n j === rowAttrs.length - 1 && colAttrs.length !== 0\n ? 2\n : 1\n }\n >\n {txt}\n </th>\n );\n })}\n {colKeys.map(function(colKey, j) {\n const aggregator = pivotData.getAggregator(rowKey, colKey);\n return (\n <td\n className=\"pvtVal\"\n key={`pvtVal${i}-${j}`}\n onClick={\n getClickHandler &&\n getClickHandler(aggregator.value(), rowKey, colKey)\n }\n style={valueCellColors(\n rowKey,\n colKey,\n aggregator.value()\n )}\n >\n {aggregator.format(aggregator.value())}\n </td>\n );\n })}\n <td\n className=\"pvtTotal\"\n onClick={\n getClickHandler &&\n getClickHandler(totalAggregator.value(), rowKey, [null])\n }\n style={colTotalColors(totalAggregator.value())}\n >\n {totalAggregator.format(totalAggregator.value())}\n </td>\n </tr>\n );\n })}\n\n <tr>\n <th\n className=\"pvtTotalLabel\"\n colSpan={rowAttrs.length + (colAttrs.length === 0 ? 0 : 1)}\n >\n Totals\n </th>\n\n {colKeys.map(function(colKey, i) {\n const totalAggregator = pivotData.getAggregator([], colKey);\n return (\n <td\n className=\"pvtTotal\"\n key={`total${i}`}\n onClick={\n getClickHandler &&\n getClickHandler(totalAggregator.value(), [null], colKey)\n }\n style={rowTotalColors(totalAggregator.value())}\n >\n {totalAggregator.format(totalAggregator.value())}\n </td>\n );\n })}\n\n <td\n onClick={\n getClickHandler &&\n getClickHandler(grandTotalAggregator.value(), [null], [null])\n }\n className=\"pvtGrandTotal\"\n >\n {grandTotalAggregator.format(grandTotalAggregator.value())}\n </td>\n </tr>\n </tbody>\n </table>\n );\n }\n }\n\n TableRenderer.defaultProps = PivotData.defaultProps;\n TableRenderer.propTypes = PivotData.propTypes;\n TableRenderer.defaultProps.tableColorScaleGenerator = redColorScaleGenerator;\n TableRenderer.defaultProps.tableOptions = {};\n TableRenderer.propTypes.tableColorScaleGenerator = PropTypes.func;\n TableRenderer.propTypes.tableOptions = PropTypes.object;\n return TableRenderer;\n}\n\nclass TSVExportRenderer extends React.PureComponent {\n render() {\n const pivotData = new PivotData(this.props);\n const rowKeys = pivotData.getRowKeys();\n const colKeys = pivotData.getColKeys();\n if (rowKeys.length === 0) {\n rowKeys.push([]);\n }\n if (colKeys.length === 0) {\n colKeys.push([]);\n }\n\n const headerRow = pivotData.props.rows.map(r => r);\n if (colKeys.length === 1 && colKeys[0].length === 0) {\n headerRow.push(this.props.aggregatorName);\n } else {\n colKeys.map(c => headerRow.push(c.join('-')));\n }\n\n const result = rowKeys.map(r => {\n const row = r.map(x => x);\n colKeys.map(c => {\n const v = pivotData.getAggregator(r, c).value();\n row.push(v ? v : '');\n });\n return row;\n });\n\n result.unshift(headerRow);\n\n return (\n <textarea\n value={result.map(r => r.join('\\t')).join('\\n')}\n style={{width: window.innerWidth / 2, height: window.innerHeight / 2}}\n readOnly={true}\n />\n );\n }\n}\n\nTSVExportRenderer.defaultProps = PivotData.defaultProps;\nTSVExportRenderer.propTypes = PivotData.propTypes;\n\nexport default {\n Table: makeRenderer(),\n 'Table Heatmap': makeRenderer({heatmapMode: 'full'}),\n 'Table Col Heatmap': makeRenderer({heatmapMode: 'col'}),\n 'Table Row Heatmap': makeRenderer({heatmapMode: 'row'}),\n 'Exportable TSV': TSVExportRenderer,\n};\n"]}
|