@datarailsshared/dr_renderer 1.2.49 → 1.2.50
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/package.json +1 -1
- package/src/dr_pivottable.js +66 -12
- package/src/highcharts_renderer.js +38 -8
- package/src/pivottable.js +6 -2
package/package.json
CHANGED
package/src/dr_pivottable.js
CHANGED
|
@@ -133,21 +133,75 @@ let initDRPivotTable = function($, window, document) {
|
|
|
133
133
|
return key;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
let newProcessKey = function (record, totals, keys, attrs, getAggregator) {
|
|
137
|
+
var addKey, attr, flatKey, k, key, len, ref;
|
|
138
|
+
key = [];
|
|
139
|
+
addKey = false;
|
|
140
|
+
for (k = 0, len = attrs.length; k < len; k++) {
|
|
141
|
+
attr = attrs[k];
|
|
142
|
+
if (record.hasOwnProperty(attr)) {
|
|
143
|
+
key.push((ref = record[attr]));
|
|
144
|
+
flatKey = key.join(delim);
|
|
145
|
+
}
|
|
146
|
+
if (totals[flatKey] && totals[flatKey].isChangeable) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!flatKey) return [];
|
|
150
|
+
if (!totals[flatKey]) {
|
|
151
|
+
totals[flatKey] = getAggregator(key.slice());
|
|
152
|
+
addKey = true;
|
|
153
|
+
} else {
|
|
154
|
+
totals[flatKey] = getAggregator(key.slice());
|
|
155
|
+
totals[flatKey].push(record);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (addKey) {
|
|
159
|
+
keys.push(key);
|
|
160
|
+
}
|
|
161
|
+
return key;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
DRPivotData.prototype.processRecord = function(record, useTotalsCalculation) {
|
|
137
165
|
var colKey, fColKey, fRowKey, flatColKey, flatRowKey, i, j, k, m, n, ref, results, rowKey;
|
|
138
166
|
rowKey = [];
|
|
139
167
|
colKey = [];
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
if (useTotalsCalculation) {
|
|
169
|
+
rowKey = newProcessKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
|
|
170
|
+
return function(key) {
|
|
171
|
+
return _this.aggregator(_this, key, []);
|
|
172
|
+
};
|
|
173
|
+
})(this));
|
|
174
|
+
colKey = newProcessKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
|
|
175
|
+
return function(key) {
|
|
176
|
+
return _this.aggregator(_this, [], key);
|
|
177
|
+
};
|
|
178
|
+
})(this));
|
|
179
|
+
|
|
180
|
+
if (!colKey.length && !rowKey.length) {
|
|
181
|
+
this.allTotal.push(record);
|
|
182
|
+
}
|
|
183
|
+
if (!colKey.length && rowKey.length === 1) {
|
|
184
|
+
this.rowTotals[rowKey[0]].push(record);
|
|
185
|
+
this.rowTotals[rowKey[0]].isChangeable = true;
|
|
186
|
+
}
|
|
187
|
+
if (!rowKey.length && colKey.length === 1) {
|
|
188
|
+
this.colTotals[colKey[0]].push(record);
|
|
189
|
+
this.colTotals[colKey[0]].isChangeable = true;
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
this.allTotal.push(record);
|
|
193
|
+
rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
|
|
194
|
+
return function(key) {
|
|
195
|
+
return _this.aggregator(_this, key, []);
|
|
196
|
+
};
|
|
197
|
+
})(this));
|
|
198
|
+
colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
|
|
199
|
+
return function(key) {
|
|
200
|
+
return _this.aggregator(_this, [], key);
|
|
201
|
+
};
|
|
202
|
+
})(this));
|
|
203
|
+
}
|
|
204
|
+
|
|
151
205
|
m = rowKey.length - 1;
|
|
152
206
|
n = colKey.length - 1;
|
|
153
207
|
if (m < 0 || n < 0) {
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
let getHighchartsRenderer = function ($, document, Highcharts, default_colors, highchartsRenderer,
|
|
2
2
|
DataFormatter, lodash, moment_lib) {
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let useNewUx = false;
|
|
5
|
+
let useTotalsCalculation = false;
|
|
6
|
+
if (document.ReportHippo && document.ReportHippo && document.ReportHippo.user) {
|
|
7
|
+
useTotalsCalculation = _.includes(document.ReportHippo.user.features, 'enable_server_totals_calculation');
|
|
8
|
+
useNewUx = document.ReportHippo.user.organization && document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
|
|
9
|
+
}
|
|
6
10
|
const textColor = "#151a41";
|
|
7
11
|
const chartLabelColor = "#cfd7dd";
|
|
8
12
|
|
|
@@ -2848,6 +2852,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
2848
2852
|
has_errors: false,
|
|
2849
2853
|
widget_values_format: widget_values_format,
|
|
2850
2854
|
calculated_formats: calculated_info.formats,
|
|
2855
|
+
isChangeable: false,
|
|
2851
2856
|
push: function (record) {
|
|
2852
2857
|
if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
|
|
2853
2858
|
this.data_types = this.data_types.concat(record['data_types']);
|
|
@@ -2868,7 +2873,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
2868
2873
|
if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
|
|
2869
2874
|
this.ignoreValue = true;
|
|
2870
2875
|
}
|
|
2871
|
-
|
|
2876
|
+
|
|
2877
|
+
if (useTotalsCalculation && !isNaN(parseFloat(record[attr]))) {
|
|
2878
|
+
return this.sum = parseFloat(record[attr]);
|
|
2879
|
+
} else if (!isNaN(parseFloat(record[attr]))) {
|
|
2872
2880
|
return this.sum += parseFloat(record[attr]);
|
|
2873
2881
|
}
|
|
2874
2882
|
},
|
|
@@ -2999,6 +3007,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
2999
3007
|
has_errors: false,
|
|
3000
3008
|
widget_values_format: widget_values_format,
|
|
3001
3009
|
calculated_formats: calculated_info.formats,
|
|
3010
|
+
isChangeable: false,
|
|
3002
3011
|
push: function (record) {
|
|
3003
3012
|
if (record.hasOwnProperty('data_types') && record['data_types']) {
|
|
3004
3013
|
if (record['data_types'].length > 0) {
|
|
@@ -3031,7 +3040,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3031
3040
|
this.ignoreValue = true;
|
|
3032
3041
|
}
|
|
3033
3042
|
|
|
3034
|
-
|
|
3043
|
+
if (useTotalsCalculation) {
|
|
3044
|
+
return this.sum = val;
|
|
3045
|
+
} else {
|
|
3046
|
+
return this.sum += val;
|
|
3047
|
+
}
|
|
3035
3048
|
} else {
|
|
3036
3049
|
return this.sum = NaN;
|
|
3037
3050
|
}
|
|
@@ -3094,6 +3107,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3094
3107
|
has_errors: false,
|
|
3095
3108
|
widget_values_format: widget_values_format,
|
|
3096
3109
|
calculated_formats: calculated_info.formats,
|
|
3110
|
+
isChangeable: false,
|
|
3097
3111
|
push: function (record) {
|
|
3098
3112
|
if (record.hasOwnProperty('data_types') && record['data_types']) {
|
|
3099
3113
|
if (record['data_types'].length > 0) {
|
|
@@ -3126,7 +3140,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3126
3140
|
if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
|
|
3127
3141
|
this.ignoreValue = true;
|
|
3128
3142
|
}
|
|
3129
|
-
|
|
3143
|
+
if (useTotalsCalculation) {
|
|
3144
|
+
return this.val = x;
|
|
3145
|
+
} else {
|
|
3146
|
+
return this.val = Math.min(x, (ref = this.val) != null ? ref : x);
|
|
3147
|
+
}
|
|
3130
3148
|
}
|
|
3131
3149
|
},
|
|
3132
3150
|
value: function () {
|
|
@@ -3187,6 +3205,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3187
3205
|
has_errors: false,
|
|
3188
3206
|
widget_values_format: widget_values_format,
|
|
3189
3207
|
calculated_formats: calculated_info.formats,
|
|
3208
|
+
isChangeable: false,
|
|
3190
3209
|
push: function (record) {
|
|
3191
3210
|
if (record.hasOwnProperty('data_types') && record['data_types']) {
|
|
3192
3211
|
if (record['data_types'].length > 0) {
|
|
@@ -3219,8 +3238,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3219
3238
|
if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
|
|
3220
3239
|
this.ignoreValue = true;
|
|
3221
3240
|
}
|
|
3222
|
-
|
|
3223
|
-
|
|
3241
|
+
|
|
3242
|
+
if (useTotalsCalculation) {
|
|
3243
|
+
return this.val = x;
|
|
3244
|
+
} else {
|
|
3245
|
+
return this.val = Math.min(x, (ref = this.val) != null ? ref : x);
|
|
3246
|
+
} }
|
|
3224
3247
|
},
|
|
3225
3248
|
value: function () {
|
|
3226
3249
|
if (this.ignoreValue) {
|
|
@@ -3281,6 +3304,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3281
3304
|
has_errors: false,
|
|
3282
3305
|
widget_values_format: widget_values_format,
|
|
3283
3306
|
calculated_formats: calculated_info.formats,
|
|
3307
|
+
isChangeable: false,
|
|
3284
3308
|
push: function (record) {
|
|
3285
3309
|
if (record.hasOwnProperty('data_types') && record['data_types']) {
|
|
3286
3310
|
if (record['data_types'].length > 0) {
|
|
@@ -3314,7 +3338,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
3314
3338
|
this.ignoreValue = true;
|
|
3315
3339
|
}
|
|
3316
3340
|
|
|
3317
|
-
|
|
3341
|
+
|
|
3342
|
+
if (useTotalsCalculation) {
|
|
3343
|
+
this.sum = parseFloat(x);
|
|
3344
|
+
} else {
|
|
3345
|
+
this.sum += parseFloat(x);
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3318
3348
|
return this.len++;
|
|
3319
3349
|
}
|
|
3320
3350
|
},
|
package/src/pivottable.js
CHANGED
|
@@ -20,6 +20,10 @@ let initPivotTable = function($, window, document) {
|
|
|
20
20
|
}
|
|
21
21
|
return x1 + x2;
|
|
22
22
|
};
|
|
23
|
+
let useTotalsCalculation = false;
|
|
24
|
+
if (document.ReportHippo && document.ReportHippo && document.ReportHippo.user) {
|
|
25
|
+
useTotalsCalculation = _.includes(document.ReportHippo.user.features, 'enable_server_totals_calculation');
|
|
26
|
+
}
|
|
23
27
|
numberFormat = function(opts) {
|
|
24
28
|
var defaults;
|
|
25
29
|
defaults = {
|
|
@@ -689,7 +693,7 @@ let initPivotTable = function($, window, document) {
|
|
|
689
693
|
PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
|
|
690
694
|
return function(record) {
|
|
691
695
|
if (_this.filter(record)) {
|
|
692
|
-
return _this.processRecord(record);
|
|
696
|
+
return _this.processRecord(record, useTotalsCalculation);
|
|
693
697
|
}
|
|
694
698
|
};
|
|
695
699
|
})(this));
|
|
@@ -1863,4 +1867,4 @@ let initPivotTable = function($, window, document) {
|
|
|
1863
1867
|
};
|
|
1864
1868
|
};
|
|
1865
1869
|
|
|
1866
|
-
module.exports = initPivotTable;
|
|
1870
|
+
module.exports = initPivotTable;
|