@datarailsshared/dr_renderer 1.2.10 → 1.2.11
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/.circleci/config.yml +2 -2
- package/README.md +5 -0
- package/package.json +3 -2
- package/src/charts/dr_gauge_chart.js +566 -0
- package/src/dataformatter.d.ts +13 -0
- package/src/dataformatter.js +44 -2
- package/src/dr-renderer-helpers.js +58 -0
- package/src/dr_chart_tooltip.js +277 -0
- package/src/dr_pivottable.js +89 -157
- package/src/graph-table-renderer.js +147 -0
- package/src/highcharts_renderer.js +2425 -1734
- package/src/novix_renderer.js +13 -11
- package/src/pivottable.js +35 -9
- package/src/published_items_renderer.js +29 -51
- package/src/seriesPointStyles-helper.js +43 -0
- package/tests/dr-renderer-helpers.test.js +150 -0
- package/tests/dr_chart_tooltip.test.js +739 -0
- package/tests/dr_gauge_chart.test.js +1931 -0
- package/tests/highcharts_renderer.test.js +9355 -14
- package/tests/mock/add-in-dynamic-ranges.json +127 -0
- package/tests/mock/add-in-functions.json +410 -0
- package/tests/mock/add-in-tables.json +347 -0
- package/tests/mock/tables.json +2258 -0
- package/tests/mock/widgets.json +403 -0
- package/tests/seriesPointStyles-helper.test.js +114 -0
- package/tsconfig.json +15 -0
- package/types/graph-table-renderer.d.ts +79 -0
- package/types/index.d.ts +1 -0
package/src/dr_pivottable.js
CHANGED
|
@@ -12,6 +12,10 @@ let initDRPivotTable = function($, window, document) {
|
|
|
12
12
|
document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
|
|
13
13
|
// const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
|
|
14
14
|
|
|
15
|
+
const isFlatKeyInPivotKeys = function(keys, flatKey) {
|
|
16
|
+
return keys.some(key => key.join(delim) === flatKey);
|
|
17
|
+
};
|
|
18
|
+
|
|
15
19
|
DRPivotData = (function(superClass) {
|
|
16
20
|
extend(DRPivotData, superClass);
|
|
17
21
|
|
|
@@ -91,6 +95,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
91
95
|
|
|
92
96
|
DRPivotData.prototype.arrSort = function(attrs) {
|
|
93
97
|
var a, sortersArr;
|
|
98
|
+
const sortByValueAttrs = this.sortByValueAttrs;
|
|
94
99
|
sortersArr = (function() {
|
|
95
100
|
var l, len1, results;
|
|
96
101
|
results = [];
|
|
@@ -100,11 +105,21 @@ let initDRPivotTable = function($, window, document) {
|
|
|
100
105
|
}
|
|
101
106
|
return results;
|
|
102
107
|
}).call(this);
|
|
108
|
+
|
|
103
109
|
return function(a, b) {
|
|
104
110
|
var comparison, i, sorter;
|
|
105
111
|
for (i in sortersArr) {
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
const index = parseInt(i);
|
|
113
|
+
sorter = sortersArr[index];
|
|
114
|
+
if (sortByValueAttrs.indexOf(attrs[index]) !== -1) {
|
|
115
|
+
|
|
116
|
+
// For case current Field attrs[index] is sorted by value we are concatenating values passed to sorter function
|
|
117
|
+
// Concatenation is done from first field in a block (first axis or first series) until current field index.
|
|
118
|
+
// Cause for this case sorting will be as list of these concatenated strings (which is prepared in getSortingByValueOrderList)
|
|
119
|
+
comparison = sorter(a.slice(0, index + 1).join(','), b.slice(0, index + 1).join(','));
|
|
120
|
+
} else {
|
|
121
|
+
comparison = sorter(a[index], b[index]);
|
|
122
|
+
}
|
|
108
123
|
if (comparison !== 0) {
|
|
109
124
|
return comparison;
|
|
110
125
|
}
|
|
@@ -143,120 +158,72 @@ let initDRPivotTable = function($, window, document) {
|
|
|
143
158
|
return key;
|
|
144
159
|
};
|
|
145
160
|
|
|
146
|
-
DRPivotData.prototype.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
let getRowAggregator = (function(_this) {
|
|
153
|
-
return function(key) {
|
|
154
|
-
return _this.aggregator(_this, key, []);
|
|
155
|
-
};
|
|
156
|
-
})(this);
|
|
157
|
-
let getColAggregator = (function(_this) {
|
|
158
|
-
return function(key) {
|
|
159
|
-
return _this.aggregator(_this, [], key);
|
|
160
|
-
};
|
|
161
|
-
})(this);
|
|
162
|
-
|
|
163
|
-
let rowKey = [];
|
|
164
|
-
for (k = 0; k < this.rowAttrs.length; k++) {
|
|
165
|
-
let attr = this.rowAttrs[k];
|
|
166
|
-
if (record.hasOwnProperty(attr)) {
|
|
167
|
-
rowKey.push((ref = record[attr]) != null ? ref : "null");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
let colKey = [];
|
|
172
|
-
for (k = 0; k < this.colAttrs.length; k++) {
|
|
173
|
-
let attr = this.colAttrs[k];
|
|
174
|
-
if (record.hasOwnProperty(attr)) {
|
|
175
|
-
colKey.push((ref = record[attr]) != null ? ref : "null");
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
let flatRowKey = rowKey.join(delim);
|
|
180
|
-
let flatColKey = colKey.join(delim);
|
|
181
|
-
|
|
182
|
-
if (this.keysLength === rowKey.length + colKey.length) {
|
|
183
|
-
if (!this.rowKeys.some(rKey => rKey.join(delim) === flatRowKey)) {
|
|
184
|
-
this.rowKeys.push(rowKey);
|
|
185
|
-
}
|
|
186
|
-
if (!this.colKeys.some(cKey => cKey.join(delim) === flatColKey)) {
|
|
187
|
-
this.colKeys.push(colKey);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (!colKey.length && !rowKey.length) {
|
|
192
|
-
this.allTotal.push(record);
|
|
193
|
-
} else if (!colKey.length && rowKey.length) {
|
|
194
|
-
if (!this.rowTotals[flatRowKey]) {
|
|
195
|
-
this.rowTotals[flatRowKey] = getRowAggregator(rowKey.slice());
|
|
196
|
-
this.rowTotals[flatRowKey].push(record);
|
|
197
|
-
}
|
|
198
|
-
} else if (!rowKey.length && colKey.length) {
|
|
199
|
-
if (!this.colTotals[flatColKey]) {
|
|
200
|
-
this.colTotals[flatColKey] = getColAggregator(colKey.slice());
|
|
201
|
-
this.colTotals[flatColKey].push(record);
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
if (!this.tree[flatRowKey]) {
|
|
205
|
-
this.tree[flatRowKey] = {};
|
|
206
|
-
}
|
|
207
|
-
this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
|
|
208
|
-
this.tree[flatRowKey][flatColKey].push(record);
|
|
161
|
+
DRPivotData.prototype.getAttrsKeys = function(record, attrs) {
|
|
162
|
+
const keys = [];
|
|
163
|
+
for (let k = 0; k < attrs.length; k++) {
|
|
164
|
+
const attr = attrs[k];
|
|
165
|
+
if (record.hasOwnProperty(attr)) {
|
|
166
|
+
keys.push(record[attr] != null ? record[attr] : 'null');
|
|
209
167
|
}
|
|
210
|
-
return;
|
|
211
168
|
}
|
|
169
|
+
return keys;
|
|
170
|
+
}
|
|
212
171
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (!
|
|
220
|
-
this.
|
|
172
|
+
DRPivotData.prototype.getFlatKey = function(record, attrs) {
|
|
173
|
+
const keys = this.getAttrsKeys(record, attrs);
|
|
174
|
+
return keys.join(delim);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
DRPivotData.prototype.processRecord = function(record) {
|
|
178
|
+
if (!this.notFirst) {
|
|
179
|
+
this.keysLength = _.filter(_.keys(record), key => !_.includes(['data_types', 'formats', 'values_formats'], key)).length - 1;
|
|
180
|
+
this.notFirst = true;
|
|
221
181
|
}
|
|
222
|
-
|
|
182
|
+
let getRowAggregator = (function(_this) {
|
|
223
183
|
return function(key) {
|
|
224
184
|
return _this.aggregator(_this, key, []);
|
|
225
185
|
};
|
|
226
|
-
})(this)
|
|
227
|
-
|
|
186
|
+
})(this);
|
|
187
|
+
let getColAggregator = (function(_this) {
|
|
228
188
|
return function(key) {
|
|
229
189
|
return _this.aggregator(_this, [], key);
|
|
230
190
|
};
|
|
231
|
-
})(this)
|
|
191
|
+
})(this);
|
|
232
192
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
193
|
+
const rowKey = this.getAttrsKeys(record, this.rowAttrs);
|
|
194
|
+
const colKey = this.getAttrsKeys(record, this.colAttrs);
|
|
195
|
+
|
|
196
|
+
let flatRowKey = rowKey.join(delim);
|
|
197
|
+
let flatColKey = colKey.join(delim);
|
|
198
|
+
|
|
199
|
+
if (this.keysLength === rowKey.length + colKey.length) {
|
|
200
|
+
if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.rowKeys, flatRowKey)) {
|
|
201
|
+
this.rowKeys.push(rowKey);
|
|
202
|
+
}
|
|
203
|
+
if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.colKeys, flatColKey)) {
|
|
204
|
+
this.colKeys.push(colKey);
|
|
205
|
+
}
|
|
237
206
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
207
|
+
|
|
208
|
+
if (!colKey.length && !rowKey.length) {
|
|
209
|
+
this.allTotal.push(record);
|
|
210
|
+
} else if (!colKey.length && rowKey.length) {
|
|
211
|
+
if (!this.rowTotals[flatRowKey]) {
|
|
212
|
+
this.rowTotals[flatRowKey] = getRowAggregator(rowKey.slice());
|
|
213
|
+
this.rowTotals[flatRowKey].push(record);
|
|
214
|
+
}
|
|
215
|
+
} else if (!rowKey.length && colKey.length) {
|
|
216
|
+
if (!this.colTotals[flatColKey]) {
|
|
217
|
+
this.colTotals[flatColKey] = getColAggregator(colKey.slice());
|
|
218
|
+
this.colTotals[flatColKey].push(record);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
242
221
|
if (!this.tree[flatRowKey]) {
|
|
243
222
|
this.tree[flatRowKey] = {};
|
|
244
223
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
results1 = [];
|
|
248
|
-
for (j = l = 0, ref1 = n; 0 <= ref1 ? l <= ref1 : l >= ref1; j = 0 <= ref1 ? ++l : --l) {
|
|
249
|
-
fColKey = colKey.slice(0, j + 1);
|
|
250
|
-
flatColKey = fColKey.join(delim);
|
|
251
|
-
if (!this.tree[flatRowKey][flatColKey]) {
|
|
252
|
-
this.tree[flatRowKey][flatColKey] = this.aggregator(this, fRowKey, fColKey);
|
|
253
|
-
}
|
|
254
|
-
results1.push(this.tree[flatRowKey][flatColKey].push(record));
|
|
255
|
-
}
|
|
256
|
-
return results1;
|
|
257
|
-
}).call(this));
|
|
224
|
+
this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
|
|
225
|
+
this.tree[flatRowKey][flatColKey].push(record);
|
|
258
226
|
}
|
|
259
|
-
return results;
|
|
260
227
|
};
|
|
261
228
|
|
|
262
229
|
DRPivotData.prototype.getAggregator = function(rowKey, colKey) {
|
|
@@ -429,13 +396,10 @@ let initDRPivotTable = function($, window, document) {
|
|
|
429
396
|
switch (opts.chartOptions.negative_numbers.value) {
|
|
430
397
|
case 'red_minus':
|
|
431
398
|
return '<span style="color: red; fill: red;">' + aggregator.format(val, format_argument) + '</span>';
|
|
432
|
-
break;
|
|
433
399
|
case 'absolute':
|
|
434
400
|
return '(' + aggregator.format(Math.abs(val), format_argument) + ')';
|
|
435
|
-
break;
|
|
436
401
|
case 'red_absolute':
|
|
437
402
|
return '<span style="color: red; fill: red;">(' + aggregator.format(Math.abs(val), format_argument) + ')</span>';
|
|
438
|
-
break;
|
|
439
403
|
default:
|
|
440
404
|
return aggregator.format(val, format_argument);
|
|
441
405
|
}
|
|
@@ -471,8 +435,11 @@ let initDRPivotTable = function($, window, document) {
|
|
|
471
435
|
return resultsArr;
|
|
472
436
|
} else {
|
|
473
437
|
let tooMuch = false;
|
|
474
|
-
|
|
475
|
-
|
|
438
|
+
const show_more_than_thousand_rows = _.get(opts, 'chartOptions.table_options.show_more_than_thousand_rows', false);
|
|
439
|
+
if (pvtData &&
|
|
440
|
+
(pvtData.rowKeys.length > 1000 || pvtData.colKeys.length > 500) &&
|
|
441
|
+
(!opts.show_more_function_cols || !opts.show_more_function_cols) &&
|
|
442
|
+
!show_more_than_thousand_rows) {
|
|
476
443
|
pvtData.rowKeys = [];
|
|
477
444
|
pvtData.colKeys = [];
|
|
478
445
|
tooMuch = true;
|
|
@@ -484,11 +451,11 @@ let initDRPivotTable = function($, window, document) {
|
|
|
484
451
|
}
|
|
485
452
|
|
|
486
453
|
SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false, error_params) {
|
|
487
|
-
var addClass, allTotal, arrowCollapsed, arrowExpanded, buildColHeaderHeader, buildColHeaderHeaders, buildColHeaderHeadersClickEvents, buildColHeaders, buildColTotals, buildColTotalsHeader, buildGrandTotal, buildRowHeaderHeaders, buildRowHeaderHeadersClickEvents, buildRowHeaders, buildRowTotalsHeader, buildValues, classColCollapsed, classColExpanded, classColHide, classColShow, classCollapsed, classExpanded, classRowCollapsed, classRowExpanded, classRowHide, classRowShow, clickStatusCollapsed, clickStatusExpanded, colAttrs, colDisableAfter, colKeys, colTotals, collapseCol, collapseColsAt, collapseHideDescendantRow, collapseRow, collapseRowsAt, collapseShowColSubtotal, collapseShowRowSubtotal, applyInlineStyles, createElement, defaults, expandChildCol, expandChildRow, expandCol, expandColsAt, expandHideColSubtotal, expandHideRowSubtotal, expandRow, expandRowsAt, expandShowColSubtotal, expandShowRowSubtotal, getTableEventHandlers, hasClass, hideDescendantCol, isColDisable, isColDisableExpandCollapse, isColHideOnExpand, isRowDisable, isRowDisableExpandCollapse, isRowHideOnExpand, main, getSubtotalInBrackets, processKeys, encodeHtmlEntities, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, removeClass, replaceClass, rowAttrs, rowDisableAfter, rowKeys, rowTotals, setAttributes, showChildCol, showChildRow, toggleCol, toggleColHeaderHeader, toggleRow, toggleRowHeaderHeader, tree,
|
|
454
|
+
var addClass, allTotal, arrowCollapsed, arrowExpanded, buildColHeaderHeader, buildColHeaderHeaders, buildColHeaderHeadersClickEvents, buildColHeaders, buildColTotals, buildColTotalsHeader, buildGrandTotal, buildRowHeaderHeaders, buildRowHeaderHeadersClickEvents, buildRowHeaders, buildRowTotalsHeader, buildValues, classColCollapsed, classColExpanded, classColHide, classColShow, classCollapsed, classExpanded, classRowCollapsed, classRowExpanded, classRowHide, classRowShow, clickStatusCollapsed, clickStatusExpanded, colAttrs, colDisableAfter, colKeys, colTotals, collapseCol, collapseColsAt, collapseHideDescendantRow, collapseRow, collapseRowsAt, collapseShowColSubtotal, collapseShowRowSubtotal, applyInlineStyles, createElement, defaults, expandChildCol, expandChildRow, expandCol, expandColsAt, expandHideColSubtotal, expandHideRowSubtotal, expandRow, expandRowsAt, expandShowColSubtotal, expandShowRowSubtotal, getTableEventHandlers, hasClass, hideDescendantCol, isColDisable, isColDisableExpandCollapse, isColHideOnExpand, isRowDisable, isRowDisableExpandCollapse, isRowHideOnExpand, main, getSubtotalInBrackets, processKeys, encodeHtmlEntities, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, removeClass, replaceClass, rowAttrs, rowDisableAfter, rowKeys, rowTotals, setAttributes, showChildCol, showChildRow, toggleCol, toggleColHeaderHeader, toggleRow, toggleRowHeaderHeader, tree, subscribeToClick;
|
|
488
455
|
var createTotalValsBolder, createGrandTotalBolder, getHeaderColorProperties, colorizeRowLabelHeaders, colorizeTableIfNeed, valueNoDashes, getColorsWithOffsetForTable, offsetColors, handleFreezePanesScroll, selectFreezableElements, removeRowHeaderNullValue;
|
|
489
456
|
var getAdditionalAggregation, buildAdditionalHeaderCols, buildAdditionalHeaderRows, buildAdditionalColValues, buildAdditionalRowValues, buildAdditionalRowTotals, buildAdditionalColTotals;
|
|
490
457
|
var additionalFieldsCol, additionalFieldsRow, additionalFieldsList;
|
|
491
|
-
var
|
|
458
|
+
var getExistingAggregator;
|
|
492
459
|
|
|
493
460
|
var horizontalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' horizontal-freeze-pane' : '';
|
|
494
461
|
var verticalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' vertical-freeze-pane' : '';
|
|
@@ -539,7 +506,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
539
506
|
if(opts.chartOptions.table_options.start_collapsed_columns) {
|
|
540
507
|
opts.collapseColsAt = 0;
|
|
541
508
|
}
|
|
542
|
-
edit_assumptions = opts.chartOptions.edit_assumptions;
|
|
543
509
|
isRowDisable = (ref = opts.rowSubtotalDisplay) != null ? ref.disableSubtotal : void 0;
|
|
544
510
|
isRowHideOnExpand = (ref1 = opts.rowSubtotalDisplay) != null ? ref1.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_rows;
|
|
545
511
|
isRowDisableExpandCollapse = (ref2 = opts.rowSubtotalDisplay) != null ? ref2.disableExpandCollapse : void 0;
|
|
@@ -876,7 +842,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
876
842
|
return string_val;
|
|
877
843
|
};
|
|
878
844
|
|
|
879
|
-
processKeys = function(keysArr, className, dimention, attrs) {
|
|
845
|
+
processKeys = function(keysArr, className, dimention, attrs, formattedKeys) {
|
|
880
846
|
for (let i = 0; i < keysArr.length; i++) {
|
|
881
847
|
const additionalField = _.find(additionalFieldsList, {key: keysArr[i][0]})
|
|
882
848
|
|
|
@@ -897,7 +863,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
897
863
|
lastCol = 0;
|
|
898
864
|
}
|
|
899
865
|
rMark = [];
|
|
900
|
-
th = createElement("th", className, valueNoDashes(encodeHtmlEntities(
|
|
866
|
+
th = createElement("th", className, valueNoDashes(encodeHtmlEntities(formattedKeys[0][0]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, 0)));
|
|
901
867
|
key = [];
|
|
902
868
|
key.push(keysArr[0][0]);
|
|
903
869
|
nodePos = 0;
|
|
@@ -917,7 +883,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
917
883
|
rMark[0] = node;
|
|
918
884
|
c = 1;
|
|
919
885
|
while (c <= lastCol) {
|
|
920
|
-
th = createElement("th", className, valueNoDashes(encodeHtmlEntities(
|
|
886
|
+
th = createElement("th", className, valueNoDashes(encodeHtmlEntities(formattedKeys[0][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, c)));
|
|
921
887
|
key = key.slice();
|
|
922
888
|
key.push(keysArr[0][c]);
|
|
923
889
|
++nodePos;
|
|
@@ -983,7 +949,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
983
949
|
}
|
|
984
950
|
|
|
985
951
|
|
|
986
|
-
th = createElement("th", className, valueNoDashes(encodeHtmlEntities(
|
|
952
|
+
th = createElement("th", className, valueNoDashes(encodeHtmlEntities(formattedKeys[r][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, r, c)));
|
|
987
953
|
++nodePos;
|
|
988
954
|
node = {
|
|
989
955
|
node: nodePos,
|
|
@@ -1570,7 +1536,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
1570
1536
|
if ((isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) || (isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter))) {
|
|
1571
1537
|
td.style.display = "none";
|
|
1572
1538
|
}
|
|
1573
|
-
|
|
1539
|
+
subscribeToClick(td, rowHeader, rowAttrs, colHeader, colAttrs, val);
|
|
1574
1540
|
|
|
1575
1541
|
tr.appendChild(td);
|
|
1576
1542
|
}
|
|
@@ -1608,7 +1574,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
1608
1574
|
td.style.display = "none";
|
|
1609
1575
|
}
|
|
1610
1576
|
|
|
1611
|
-
|
|
1577
|
+
subscribeToClick(td, rowHeader, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
|
|
1612
1578
|
|
|
1613
1579
|
if(opts.chartOptions.table_options.show_row_total)
|
|
1614
1580
|
tr.appendChild(td);
|
|
@@ -1618,43 +1584,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
1618
1584
|
return results;
|
|
1619
1585
|
};
|
|
1620
1586
|
|
|
1621
|
-
|
|
1622
|
-
if(edit_assumptions){
|
|
1623
|
-
var filters = [];
|
|
1624
|
-
var i=0;
|
|
1625
|
-
var temp;
|
|
1626
|
-
for(i=0; i<rowHeader.key.length; i++){
|
|
1627
|
-
temp = {
|
|
1628
|
-
name: rowAttrs[i],
|
|
1629
|
-
values: [rowHeader.key[i]],
|
|
1630
|
-
is_excluded:false
|
|
1631
|
-
}
|
|
1632
|
-
filters.push(temp);
|
|
1633
|
-
}
|
|
1634
|
-
for(i=0; i<colHeader.key.length; i++){
|
|
1635
|
-
temp = {
|
|
1636
|
-
name: colAttrs[i],
|
|
1637
|
-
values: [colHeader.key[i]],
|
|
1638
|
-
is_excluded:false
|
|
1639
|
-
}
|
|
1640
|
-
filters.push(temp);
|
|
1641
|
-
}
|
|
1642
|
-
var obj_to_send = {
|
|
1643
|
-
"flatColKey": colHeader.flatKey,
|
|
1644
|
-
"flatRowKey": rowHeader.flatKey,
|
|
1645
|
-
"val": val,
|
|
1646
|
-
"filters": filters
|
|
1647
|
-
};
|
|
1648
|
-
|
|
1649
|
-
// td.addEventListener('dblclick', function(){
|
|
1650
|
-
// edit_assumptions.fn(obj_to_send, this);
|
|
1651
|
-
// });
|
|
1652
|
-
|
|
1653
|
-
td.addEventListener('click', function(){
|
|
1654
|
-
edit_assumptions.fn(obj_to_send, this);
|
|
1655
|
-
});
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1587
|
+
subscribeToClick = function(td, rowHeader, rowAttrs, colHeader, colAttrs, val){
|
|
1658
1588
|
if(opts.value_drill_down_fn){
|
|
1659
1589
|
td.classList.add('clickable');
|
|
1660
1590
|
td.addEventListener('click', function(rowKey, colKey, rowAttrs, colAttrs){
|
|
@@ -1715,7 +1645,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
1715
1645
|
td.style.display = "none";
|
|
1716
1646
|
}
|
|
1717
1647
|
|
|
1718
|
-
|
|
1648
|
+
subscribeToClick(td, {key:[], flatKey:''}, rowAttrs, h, colAttrs, val);
|
|
1719
1649
|
|
|
1720
1650
|
results.push(tr.appendChild(td));
|
|
1721
1651
|
}
|
|
@@ -1741,7 +1671,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
1741
1671
|
"data-value": val
|
|
1742
1672
|
}, getTableEventHandlers(val, [], []));
|
|
1743
1673
|
createTotalValsBolder(td);
|
|
1744
|
-
|
|
1674
|
+
subscribeToClick(td, {key:[], flatKey:''}, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
|
|
1745
1675
|
|
|
1746
1676
|
tr.appendChild(td);
|
|
1747
1677
|
return result.appendChild(tr);
|
|
@@ -2407,7 +2337,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
2407
2337
|
return Array.from(wrapper.querySelectorAll(selectString));
|
|
2408
2338
|
}
|
|
2409
2339
|
|
|
2410
|
-
main = function(rowAttrs, rowKeys, colAttrs, colKeys) {
|
|
2340
|
+
main = function(rowAttrs, rowKeys, colAttrs, colKeys, pivotData) {
|
|
2411
2341
|
var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
|
|
2412
2342
|
rowHeaders = [];
|
|
2413
2343
|
colHeaders = [];
|
|
@@ -2416,10 +2346,12 @@ let initDRPivotTable = function($, window, document) {
|
|
|
2416
2346
|
colHeaderHeaders = [];
|
|
2417
2347
|
colHeaderCols = [];
|
|
2418
2348
|
if (rowAttrs.length > 0 && rowKeys.length > 0) {
|
|
2419
|
-
|
|
2349
|
+
const formattedKeys = pivotData.getFormattedRowKeys(rowKeys);
|
|
2350
|
+
rowHeaders = processKeys(rowKeys, "pvtRowLabel", 'rows', rowAttrs, formattedKeys);
|
|
2420
2351
|
}
|
|
2421
2352
|
if (colAttrs.length > 0 && colKeys.length > 0) {
|
|
2422
|
-
|
|
2353
|
+
const formattedKeys = pivotData.getFormattedColKeys(colKeys);
|
|
2354
|
+
colHeaders = processKeys(colKeys, "pvtColLabel", 'cols', colAttrs, formattedKeys);
|
|
2423
2355
|
}
|
|
2424
2356
|
var tableClasses = ['pvtTable'];
|
|
2425
2357
|
if (opts.chartOptions.table_options.use_new_table_design) {
|
|
@@ -2564,7 +2496,7 @@ let initDRPivotTable = function($, window, document) {
|
|
|
2564
2496
|
|
|
2565
2497
|
return wrapper;
|
|
2566
2498
|
};
|
|
2567
|
-
return main(rowAttrs, rowKeys, colAttrs, colKeys);
|
|
2499
|
+
return main(rowAttrs, rowKeys, colAttrs, colKeys, pivotData);
|
|
2568
2500
|
};
|
|
2569
2501
|
// $.pivotUtilities.subtotal_renderers = SubtotalRenderer;
|
|
2570
2502
|
$.pivotUtilities.subtotal_renderers = NovixRenderer;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} HighChartsRenderer
|
|
3
|
+
* @property {(rows: Rows, options: GTROptions | null, isTable: boolean, widget: any, pivotModel?: PivotModel) => string} rhPivotViewV2
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} PivotUtilities
|
|
8
|
+
* @property {(rows: Rows, options: GTROptions) => PivotModel} getPivotDataModel
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} JQuery
|
|
13
|
+
* @property {PivotUtilities} pivotUtilities
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} PivotModel
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {Object} RendererOptions
|
|
22
|
+
* @property {any} hcInstance
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {Object} GTROptions
|
|
27
|
+
* @property {RendererOptions} rendererOptions
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {Record<string, Record<string, number | string> | number | string>[]} Rows - BE data response
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export class GraphTableRenderer {
|
|
35
|
+
/**
|
|
36
|
+
* @type {PivotModel | undefined}
|
|
37
|
+
*/
|
|
38
|
+
#pivotModel;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @type {GTROptions | null}
|
|
42
|
+
*/
|
|
43
|
+
#options = null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @type {Record<string, Record<string, number | string> | number | string>[]}
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
#rows = [];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Utility properties
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* @type {HighChartsRenderer}
|
|
56
|
+
*/
|
|
57
|
+
#hcr;
|
|
58
|
+
/**
|
|
59
|
+
* @type {JQuery}
|
|
60
|
+
*/
|
|
61
|
+
#$;
|
|
62
|
+
/**
|
|
63
|
+
* @type {PivotUtilities}
|
|
64
|
+
*/
|
|
65
|
+
#pivotUtilities;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @type {any | null}
|
|
69
|
+
*/
|
|
70
|
+
#hcInstance = null;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param {HighChartsRenderer} hcr
|
|
75
|
+
* @param {JQuery} $
|
|
76
|
+
*/
|
|
77
|
+
constructor(hcr, $) {
|
|
78
|
+
this.#hcr = hcr;
|
|
79
|
+
this.#$ = $;
|
|
80
|
+
this.#pivotUtilities = this.#$.pivotUtilities;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates Pivot Data Model that works we BE data response to aggregate data to render with Chart and Table
|
|
85
|
+
* @param {Rows} rows BE data response
|
|
86
|
+
* @param {GTROptions} options
|
|
87
|
+
* @returns {this}
|
|
88
|
+
*/
|
|
89
|
+
createPivotModel(rows, options) {
|
|
90
|
+
this.#options = options;
|
|
91
|
+
this.#rows = rows;
|
|
92
|
+
this.#pivotModel = this.#pivotUtilities.getPivotDataModel(rows, options);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @returns {void}
|
|
98
|
+
*/
|
|
99
|
+
disposePivotModel() {
|
|
100
|
+
this.#pivotModel = undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @see createPivotModel
|
|
105
|
+
* @returns {PivotModel | undefined}
|
|
106
|
+
*/
|
|
107
|
+
getPivotModel() {
|
|
108
|
+
return this.#pivotModel;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @description returns Chart instance of HighCharts library
|
|
113
|
+
* @returns {any | null}
|
|
114
|
+
*/
|
|
115
|
+
hcInstance() {
|
|
116
|
+
return this.#hcInstance;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#setHcInstance() {
|
|
120
|
+
if (!this.#options) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.#hcInstance = this.#options.rendererOptions.hcInstance;
|
|
124
|
+
if (!this.#hcInstance) {
|
|
125
|
+
console.warn('[dr_renderer] HighCharts instance not found in options after the chart is rendered.');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* hcInstance object is not needed in options after the chart is rendered - it's an internal object of HighCharts library
|
|
129
|
+
* Deleting to not supply it to widget object, so it cannot be used anywhere else
|
|
130
|
+
*/
|
|
131
|
+
delete this.#options.rendererOptions.hcInstance;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
renderTable(widget = null) {
|
|
135
|
+
return this.#hcr.rhPivotViewV2(this.#rows, this.#options, true, widget, this.#pivotModel);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
renderChart(widget = null) {
|
|
139
|
+
const chart = this.#hcr.rhPivotViewV2(this.#rows, this.#options, false, widget, this.#pivotModel);
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
this.#setHcInstance();
|
|
142
|
+
});
|
|
143
|
+
return chart;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default GraphTableRenderer;
|