@datarailsshared/dr_renderer 1.2.43-beta → 1.2.45-beta

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.43-beta",
3
+ "version": "1.2.45-beta",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1003,6 +1003,10 @@ var DataFormatterImpl = function () {
1003
1003
 
1004
1004
  // Call function
1005
1005
  result = this.memoized[pattern].call(this, n, type);
1006
+
1007
+ if (result.value === result.pattern) {
1008
+ result.value = n;
1009
+ }
1006
1010
  }
1007
1011
  catch (e) {
1008
1012
 
@@ -133,21 +133,75 @@ let initDRPivotTable = function($, window, document) {
133
133
  return key;
134
134
  };
135
135
 
136
- DRPivotData.prototype.processRecord = function(record) {
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
- this.allTotal.push(record);
141
- rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
142
- return function(key) {
143
- return _this.aggregator(_this, key, []);
144
- };
145
- })(this));
146
- colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
147
- return function(key) {
148
- return _this.aggregator(_this, [], key);
149
- };
150
- })(this));
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) {
@@ -384,12 +438,14 @@ let initDRPivotTable = function($, window, document) {
384
438
  pvtData.rowKeys = [];
385
439
  pvtData.colKeys = [];
386
440
  tooMuch = true;
441
+ opts.error_has_occurred = true;
442
+ opts.error_params = $.pivotUtilities.errorHandling.placeholders.tooMuchData;
387
443
  }
388
- return SubtotalRenderer(pvtData, opts, charttype, tooMuch);
444
+ return SubtotalRenderer(pvtData, opts, charttype, tooMuch, opts.error_params);
389
445
  }
390
446
  }
391
447
 
392
- SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false) {
448
+ SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false, error_params) {
393
449
  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, 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, assumptionSubscribe;
394
450
  var createTotalValsBolder, createGrandTotalBolder, getHeaderColorProperties, colorizeRowLabelHeaders, colorizeTableIfNeed, valueNoDashes, getColorsWithOffsetForTable, offsetColors, handleFreezePanesScroll, selectFreezableElements, removeRowHeaderNullValue;
395
451
  var edit_assumptions;
@@ -2001,6 +2057,8 @@ let initDRPivotTable = function($, window, document) {
2001
2057
 
2002
2058
  handleFreezePanesScroll = function(freezableElements) {
2003
2059
  return function(event) {
2060
+ if (event.target.dataset.canFreezePanes) return;
2061
+
2004
2062
  const wrapper = event.target;
2005
2063
 
2006
2064
  const translateY = `translate(0px, ${wrapper.scrollTop}px)`;
@@ -2130,7 +2188,9 @@ let initDRPivotTable = function($, window, document) {
2130
2188
  }
2131
2189
 
2132
2190
  if (tooMuch) {
2133
- resultsArr.push($('<div class="noData"><i class="fa fa-info"></i> There are too many rows to display in the table.<br>Please filter or change the table type in options.</div>'));
2191
+ const defaultPlaceholder = $('<div class="noData"><i class="fa fa-info"></i> There are too many rows to display in the table.<br>Please filter or change the table type in options.</div>');
2192
+
2193
+ resultsArr.push($.pivotUtilities.errorHandling.getErrorPlaceholder(error_params, useNewUx) || defaultPlaceholder);
2134
2194
  } else {
2135
2195
  var tableContainer = document.createElement("div");
2136
2196
  tableContainer.className = "pivot-div";
@@ -1,8 +1,12 @@
1
1
  let getHighchartsRenderer = function ($, document, Highcharts, default_colors, highchartsRenderer,
2
2
  DataFormatter, lodash, moment_lib) {
3
3
 
4
- const useNewUx = document.ReportHippo && document.ReportHippo && document.ReportHippo.user &&
5
- document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
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
 
@@ -721,9 +725,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
721
725
  }
722
726
 
723
727
  if (to_match) {
724
- resultsArr.push($('<div class="noData"><i class="' + (useNewUx ? 'noData-image' : 'fa fa-info') + '"></i> Too much data to show</div>'));
728
+ resultsArr.push(highchartsRenderer.getWidgetPlaceholder(highchartsRenderer.widgetPlaceholders.tooMuchData));
725
729
  } else {
726
- resultsArr.push($('<div class="noData"><i class="' + (useNewUx ? 'noData-image' : 'fa fa-info') + '"></i> no data</div>'));
730
+ resultsArr.push(highchartsRenderer.getWidgetPlaceholder(highchartsRenderer.widgetPlaceholders.nodata));
727
731
  }
728
732
 
729
733
  temp_result.html(resultsArr);
@@ -731,6 +735,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
731
735
  return temp_result;
732
736
  };
733
737
 
738
+ highchartsRenderer.getWidgetPlaceholder = function(placeholder) {
739
+ const defaultPlaceholder = $('<div class="noData"><i class="' + (useNewUx ? 'noData-image' : 'fa fa-info') + '"></i> no data</div>');
740
+ return $.pivotUtilities.errorHandling.getErrorPlaceholder(placeholder, useNewUx) || defaultPlaceholder;
741
+ }
742
+
734
743
  highchartsRenderer.ptCreateElementAndDraw = function (chartOptions, opts) {
735
744
  if (lodash.get(opts, 'paletteOptions.widgetPalette', null)) {
736
745
  const mc_palette = lodash.find(lodash.get(opts.paletteOptions, 'monochromePalettes', []), { selected: true });
@@ -820,8 +829,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
820
829
 
821
830
  if (!seriesDataLength && !chartOptions.onlyText) {
822
831
  result = highchartsRenderer.getNoDataResult(chartOptions);
832
+ opts.error_has_occurred = true;
833
+ opts.error_params = highchartsRenderer.widgetPlaceholders.nodata;
823
834
  } else if (!chartOptions.onlyText && chartOptions.series && toMatch) {
824
835
  result = highchartsRenderer.getNoDataResult(chartOptions, toMatch);
836
+ opts.error_has_occurred = true;
837
+ opts.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
825
838
  } else {
826
839
  chartOptions = highchartsRenderer.updateChartOptions(chartOptions, opts);
827
840
  chartOptions = highchartsRenderer.updateChartOptions(chartOptions, {credits: {enabled: false}});
@@ -2547,7 +2560,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2547
2560
  style = {};
2548
2561
  }
2549
2562
  }
2563
+
2564
+ if(typeof style !== 'object' || style === null){
2565
+ style = {};
2566
+ }
2567
+
2550
2568
  style.fontWeight = useNewUx ? 'normal' : 'bold';
2569
+
2551
2570
  return style;
2552
2571
  }
2553
2572
 
@@ -2833,6 +2852,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2833
2852
  has_errors: false,
2834
2853
  widget_values_format: widget_values_format,
2835
2854
  calculated_formats: calculated_info.formats,
2855
+ isChangeable: false,
2836
2856
  push: function (record) {
2837
2857
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
2838
2858
  this.data_types = this.data_types.concat(record['data_types']);
@@ -2853,7 +2873,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2853
2873
  if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
2854
2874
  this.ignoreValue = true;
2855
2875
  }
2856
- if (!isNaN(parseFloat(record[attr]))) {
2876
+
2877
+ if (useTotalsCalculation && !isNaN(parseFloat(record[attr]))) {
2878
+ return this.sum = parseFloat(record[attr]);
2879
+ } else if (!isNaN(parseFloat(record[attr]))) {
2857
2880
  return this.sum += parseFloat(record[attr]);
2858
2881
  }
2859
2882
  },
@@ -2984,6 +3007,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2984
3007
  has_errors: false,
2985
3008
  widget_values_format: widget_values_format,
2986
3009
  calculated_formats: calculated_info.formats,
3010
+ isChangeable: false,
2987
3011
  push: function (record) {
2988
3012
  if (record.hasOwnProperty('data_types') && record['data_types']) {
2989
3013
  if (record['data_types'].length > 0) {
@@ -3016,7 +3040,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3016
3040
  this.ignoreValue = true;
3017
3041
  }
3018
3042
 
3019
- return this.sum += val;
3043
+ if (useTotalsCalculation) {
3044
+ return this.sum = val;
3045
+ } else {
3046
+ return this.sum += val;
3047
+ }
3020
3048
  } else {
3021
3049
  return this.sum = NaN;
3022
3050
  }
@@ -3079,6 +3107,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3079
3107
  has_errors: false,
3080
3108
  widget_values_format: widget_values_format,
3081
3109
  calculated_formats: calculated_info.formats,
3110
+ isChangeable: false,
3082
3111
  push: function (record) {
3083
3112
  if (record.hasOwnProperty('data_types') && record['data_types']) {
3084
3113
  if (record['data_types'].length > 0) {
@@ -3111,7 +3140,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3111
3140
  if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
3112
3141
  this.ignoreValue = true;
3113
3142
  }
3114
- return this.val = Math.min(x, (ref = this.val) != null ? ref : x);
3143
+ if (useTotalsCalculation) {
3144
+ return this.val = x;
3145
+ } else {
3146
+ return this.val = Math.min(x, (ref = this.val) != null ? ref : x);
3147
+ }
3115
3148
  }
3116
3149
  },
3117
3150
  value: function () {
@@ -3172,6 +3205,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3172
3205
  has_errors: false,
3173
3206
  widget_values_format: widget_values_format,
3174
3207
  calculated_formats: calculated_info.formats,
3208
+ isChangeable: false,
3175
3209
  push: function (record) {
3176
3210
  if (record.hasOwnProperty('data_types') && record['data_types']) {
3177
3211
  if (record['data_types'].length > 0) {
@@ -3204,8 +3238,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3204
3238
  if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
3205
3239
  this.ignoreValue = true;
3206
3240
  }
3207
- return this.val = Math.max(x, (ref = this.val) != null ? ref : x);
3208
- }
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
+ } }
3209
3247
  },
3210
3248
  value: function () {
3211
3249
  if (this.ignoreValue) {
@@ -3266,6 +3304,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3266
3304
  has_errors: false,
3267
3305
  widget_values_format: widget_values_format,
3268
3306
  calculated_formats: calculated_info.formats,
3307
+ isChangeable: false,
3269
3308
  push: function (record) {
3270
3309
  if (record.hasOwnProperty('data_types') && record['data_types']) {
3271
3310
  if (record['data_types'].length > 0) {
@@ -3299,7 +3338,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3299
3338
  this.ignoreValue = true;
3300
3339
  }
3301
3340
 
3302
- this.sum += parseFloat(x);
3341
+
3342
+ if (useTotalsCalculation) {
3343
+ this.sum = parseFloat(x);
3344
+ } else {
3345
+ this.sum += parseFloat(x);
3346
+ }
3347
+
3303
3348
  return this.len++;
3304
3349
  }
3305
3350
  },
@@ -3459,6 +3504,30 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3459
3504
  filter = (a) => a > bottomx;
3460
3505
  }
3461
3506
  break;
3507
+ case "filter_smallest":
3508
+ const smallest_sumOfFields = lodash.reduce(totals, (acc, curr) => acc += curr.sum, 0);
3509
+ const smallest = Math.floor((smallest_sumOfFields * vals[0])/100);
3510
+
3511
+ if (is_absolute)
3512
+ filter = (a) => Math.abs(a) > smallest;
3513
+ else
3514
+ filter = (a) => a > smallest;
3515
+ break;
3516
+ case "filter_largest":
3517
+ const largest_sumOfFields = lodash.reduce(totals, (acc, curr) => acc += curr.sum, 0);
3518
+ const largest = Math.floor((largest_sumOfFields * vals[0])/100);
3519
+
3520
+ if (is_absolute)
3521
+ filter = (a) => Math.abs(a) < largest;
3522
+ else
3523
+ filter = (a) => a < largest;
3524
+ break;
3525
+ case "filter_out_zero":
3526
+ if (is_absolute)
3527
+ filter = (a) => Math.abs(a) == 0;
3528
+ else
3529
+ filter = (a) => a == 0;
3530
+ break;
3462
3531
  default:
3463
3532
 
3464
3533
  }
@@ -3709,6 +3778,30 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3709
3778
  return to_return;
3710
3779
  };
3711
3780
 
3781
+ highchartsRenderer.checkFreezePanesAvaliable = function (pivotView) {
3782
+ if (!pivotView || !pivotView.querySelector) {
3783
+ return;
3784
+ }
3785
+
3786
+ const tableContainer = pivotView.querySelector('.pivot-div');
3787
+ const tableHead = pivotView.querySelector('table.pvtTable thead');
3788
+ const tableHeadChildren = tableHead ? tableHead.children[0] : null;
3789
+ const trChildren = tableHeadChildren ? tableHeadChildren.children : [];
3790
+ let thWidth = 0;
3791
+
3792
+ for (let th of trChildren) {
3793
+ if (th.classList.contains('axis-freeze-pane') || th.classList.contains('horizontal-freeze-pane')) {
3794
+ thWidth += th.offsetWidth;
3795
+ }
3796
+ }
3797
+
3798
+ if (thWidth >= tableContainer.offsetWidth) {
3799
+ tableContainer.dataset.canFreezePanes = 'false';
3800
+ } else if (thWidth < tableContainer.offsetWidth && tableContainer.dataset.canFreezePanes) {
3801
+ delete tableContainer.dataset.canFreezePanes;
3802
+ }
3803
+ };
3804
+
3712
3805
  highchartsRenderer.rhPivotView = function (rowData, options, isTable = false) {
3713
3806
  if (!rowData || !rowData) {
3714
3807
  if (options.onlyOptions) {
@@ -3722,6 +3815,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3722
3815
  return {};
3723
3816
  }
3724
3817
 
3818
+ options.error_has_occurred = true;
3819
+ options.error_params = highchartsRenderer.widgetPlaceholders.nodata;
3725
3820
  return highchartsRenderer.getNoDataResult(options.rendererOptions);
3726
3821
  }
3727
3822
 
@@ -3730,6 +3825,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3730
3825
  return {};
3731
3826
  }
3732
3827
 
3828
+ options.error_has_occurred = true;
3829
+ options.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
3733
3830
  return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
3734
3831
  }
3735
3832
 
@@ -4168,7 +4265,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4168
4265
  options.chartOptions.legends_position = { value: 'none' };
4169
4266
  delete options.chartOptions.chart.hideLegends;
4170
4267
  }
4171
- if (['pie-chart', 'pie-chart-drilldown'].includes(type)) {
4268
+ if (lodash.includes(['pie-chart', 'pie-chart-drilldown'], type)) {
4172
4269
  if (options.chartOptions && options.chartOptions.label) {
4173
4270
  if (options.chartOptions.label.only_value) {
4174
4271
  options.chartOptions.label.show_percentage_in_labels = false;
@@ -4293,6 +4390,60 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4293
4390
  exTableOptions.pivot.calculatedValues = highchartsRenderer.objectCopyJsonMethod(exTableOptions.calculated_values || []);
4294
4391
  };
4295
4392
 
4393
+ highchartsRenderer.addTemplateDataToDynamicRangeOptions = function (selectedTemplate, dynamicRangeOptions) {
4394
+ highchartsRenderer.setWidgetFieldsToTemplate(selectedTemplate);
4395
+
4396
+ var fields = highchartsRenderer.objectCopyJsonMethod(selectedTemplate.widget_fields);
4397
+ var fieldOb;
4398
+ var filterFields = [];
4399
+ var selectedFields = [];
4400
+
4401
+ lodash.forEach(dynamicRangeOptions.filters, function (filterObj) {
4402
+ fieldOb = lodash.find(fields, {id: filterObj.field});
4403
+ if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype === 'list') {
4404
+ filterObj.values = filterObj.values.val
4405
+ } else if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype !== 'list') {
4406
+ fieldOb.values = filterObj.values;
4407
+ } else if (fieldOb && filterObj.values && filterObj.values.type === 'advanced') {
4408
+ fieldOb.values = filterObj.values;
4409
+ }
4410
+ if (fieldOb && filterObj.values && filterObj.values instanceof Array) {
4411
+ if (filterObj.is_excluded == true) {
4412
+ fieldOb.excludes = filterObj.values;
4413
+ } else {
4414
+ fieldOb.includes = filterObj.values;
4415
+ }
4416
+ }
4417
+ if (filterObj.allow_nulls && fieldOb) {
4418
+ fieldOb.allow_nulls = filterObj.allow_nulls;
4419
+ }
4420
+ });
4421
+
4422
+ // fill selected fields
4423
+ lodash.forEach(dynamicRangeOptions.fields, function (valObj) {
4424
+ fieldOb = lodash.find(fields, {id: valObj.field_id});
4425
+ if (fieldOb) {
4426
+ selectedFields.push(fieldOb);
4427
+ lodash.remove(fields, {id: fieldOb.id});
4428
+ }
4429
+ });
4430
+
4431
+ // fill filter fields
4432
+ lodash.forEach(dynamicRangeOptions.filters, function (valObj) {
4433
+ fieldOb = lodash.find(fields, {id: valObj.field});
4434
+ if (fieldOb) {
4435
+ filterFields.push(fieldOb);
4436
+ lodash.remove(fields, {id: fieldOb.id});
4437
+ }
4438
+ });
4439
+
4440
+ dynamicRangeOptions.pivot = {};
4441
+ dynamicRangeOptions.pivot.fieldsArray = fields;
4442
+ dynamicRangeOptions.pivot.selectedFieldsArray = selectedFields;
4443
+ dynamicRangeOptions.pivot.filtersArray = filterFields;
4444
+ dynamicRangeOptions.pivot.calculatedValues = highchartsRenderer.objectCopyJsonMethod(dynamicRangeOptions.calculated_values || []);
4445
+ }
4446
+
4296
4447
  highchartsRenderer.addTemplateDataToFunctionOptions = function (selectedTemplate, functionOptions) {
4297
4448
  highchartsRenderer.setWidgetFieldsToTemplate(selectedTemplate);
4298
4449
 
@@ -4648,6 +4799,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4648
4799
  return valToReturn;
4649
4800
  };
4650
4801
 
4802
+ highchartsRenderer.widgetPlaceholders = Object.assign({}, $.pivotUtilities.errorHandling.placeholders);
4803
+
4651
4804
  highchartsRenderer.suboptions = {
4652
4805
  'default_show': {
4653
4806
  category_class: 'google-visualization-charteditor-mini-more',
@@ -6579,7 +6732,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6579
6732
  const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
6580
6733
  if (isCustomSorting) {
6581
6734
  lodash.forEach(datesFields, function (field) {
6582
- const fieldToSort = widget.options.sortingFields.find(element => element.id === field.id);
6735
+ const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
6583
6736
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
6584
6737
  });
6585
6738
  }
@@ -6626,7 +6779,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6626
6779
 
6627
6780
  if (isCustomSorting) {
6628
6781
  lodash.forEach(rowsAndCols, function (field) {
6629
- const fieldToSort = widget.options.sortingFields.find(element => element.id === field.id);
6782
+ const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
6630
6783
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
6631
6784
  });
6632
6785
  }
package/src/pivottable.js CHANGED
@@ -7,7 +7,7 @@ let initPivotTable = function($, window, document) {
7
7
  /*
8
8
  Utilities
9
9
  */
10
- var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad;
10
+ var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad, errorHandling;
11
11
  addSeparators = function(nStr, thousandsSep, decimalSep) {
12
12
  var rgx, x, x1, x2;
13
13
  nStr += '';
@@ -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 = {
@@ -610,6 +614,47 @@ let initPivotTable = function($, window, document) {
610
614
  }
611
615
  return naturalSort;
612
616
  };
617
+ errorHandling = {
618
+ placeholders: {
619
+ nodata: {
620
+ title: 'No Data Available',
621
+ text: 'This might happen because of a global filter or a change in the underlying data',
622
+ btnText: '',
623
+ class: 'nodata',
624
+ },
625
+ noPermission: {
626
+ title: 'No Permission',
627
+ text: 'You do not have permission to view the data',
628
+ btnText: 'Request Permission',
629
+ class: 'no-permission',
630
+ },
631
+ tooMuchData: {
632
+ title: 'There is too much data. Please edit this widget',
633
+ text: '',
634
+ btnText: 'Edit Widget',
635
+ class: 'too-much-data',
636
+ },
637
+ noPublishItem: {
638
+ title: 'We can’t find the published item in the source file',
639
+ text: '',
640
+ btnText: 'Go to filebox',
641
+ class: 'no-publish-item',
642
+ },
643
+ },
644
+ getErrorPlaceholder: function(placeholder, useNewUx = true) {
645
+ if (placeholder && typeof placeholder === 'object') {
646
+ return $(`
647
+ <div class="noData">
648
+ <div class="noData-title">${placeholder.title}</div>
649
+ <i class="noData-image ${useNewUx ? placeholder.class : 'fa fa-info'}"></i>
650
+ <div class="noData-text">${placeholder.text}</div>
651
+ <div class="noData-error-action"></div>
652
+ </div>
653
+ `);
654
+ }
655
+ return null;
656
+ },
657
+ };
613
658
 
614
659
  /*
615
660
  Data Model class
@@ -648,7 +693,7 @@ let initPivotTable = function($, window, document) {
648
693
  PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
649
694
  return function(record) {
650
695
  if (_this.filter(record)) {
651
- return _this.processRecord(record);
696
+ return _this.processRecord(record, useTotalsCalculation);
652
697
  }
653
698
  };
654
699
  })(this));
@@ -890,7 +935,8 @@ let initPivotTable = function($, window, document) {
890
935
  naturalSort: naturalSort,
891
936
  numberFormat: numberFormat,
892
937
  sortAs: sortAs,
893
- PivotData: PivotData
938
+ PivotData: PivotData,
939
+ errorHandling: errorHandling,
894
940
  };
895
941
 
896
942
  /*
@@ -1821,4 +1867,4 @@ let initPivotTable = function($, window, document) {
1821
1867
  };
1822
1868
  };
1823
1869
 
1824
- module.exports = initPivotTable;
1870
+ module.exports = initPivotTable;
@@ -15,9 +15,9 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
15
15
 
16
16
  publishedItemsRenderer.resizeTable = function (options, window) {
17
17
  options.alreadySetTimeout = null;
18
- const publish_item_image = document.getElementById('publish_item_image');
19
- const table = document.getElementsByTagName("table")[0];
20
- const body = document.getElementsByTagName("body")[0];
18
+ const publish_item_image = window.document.getElementById('publish_item_image');
19
+ const table = window.document.getElementsByTagName("table")[0];
20
+ const body = window.document.getElementsByTagName("body")[0];
21
21
  let body_zoom = body.style.zoom;
22
22
  body_zoom = parseFloat(body_zoom);
23
23
 
@@ -124,8 +124,11 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
124
124
  const metaData = options.inputValuesData ? options.inputValuesData[name] : null;
125
125
  let newValue = inputElement.value;
126
126
  if (metaData) {
127
- if (metaData.type === 'editInput')
127
+ if (metaData.type === 'editInput') {
128
128
  newValue = parseFloat(newValue);
129
+ } else if (metaData.type === 'editInputPercent') {
130
+ newValue = parseFloat(newValue) + '%';
131
+ }
129
132
 
130
133
  if (metaData.value !== newValue) {
131
134
  metaData.value = newValue;
@@ -158,19 +161,14 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
158
161
  }, 1)
159
162
  });
160
163
 
161
- if (inputMetaData.type === 'editInputPercent')
162
- inEl.setAttribute("type", "text");
163
- else if (inputMetaData.type === 'editInput')
164
- inEl.setAttribute("type", "number");
165
-
164
+ inEl.setAttribute("type", "number");
166
165
  inEl.setAttribute("name", inputMetaData.name);
167
166
  inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
168
- inEl.value = inputMetaData.value;
167
+ inEl.value = inputMetaData.type === 'editInputPercent' ? parseFloat(inputMetaData.value.replace('%', '')) : inputMetaData.value;
169
168
  inEl.addEventListener("focusout", function (event) {
170
169
  event.preventDefault();
171
170
  publishedItemsRenderer.changedInputElement(event, scope, options);
172
171
  inEl.style.display = 'none';
173
- labelEl.innerText = inEl.value;
174
172
  labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
175
173
  labelEl.style.display = 'block';
176
174
  });
@@ -190,7 +188,7 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
190
188
  break;
191
189
  case "dateInput":
192
190
  let dateEl = document.createElement("DIV");
193
- const format = inputMetaData.format.toUpperCase() || 'MM/DD/YYYY';
191
+ const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
194
192
  const formattedDate = formatValue('d', format, inputMetaData.value).value
195
193
  dateEl.innerHTML = '<label class="value" style="cursor: pointer;">' + formattedDate + '</label>';
196
194
  tdElement.appendChild(dateEl);