@datarailsshared/dr_renderer 1.2.8 → 1.2.9

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/src/pivottable.js CHANGED
@@ -1,3 +1,5 @@
1
+ const helpers = require('./dr-renderer-helpers');
2
+
1
3
  // from pivottable@2.23.0
2
4
  let initPivotTable = function($, window, document) {
3
5
  var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
@@ -7,7 +9,7 @@ let initPivotTable = function($, window, document) {
7
9
  /*
8
10
  Utilities
9
11
  */
10
- var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad;
12
+ var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad, errorHandling;
11
13
  addSeparators = function(nStr, thousandsSep, decimalSep) {
12
14
  var rgx, x, x1, x2;
13
15
  nStr += '';
@@ -20,6 +22,7 @@ let initPivotTable = function($, window, document) {
20
22
  }
21
23
  return x1 + x2;
22
24
  };
25
+
23
26
  numberFormat = function(opts) {
24
27
  var defaults;
25
28
  defaults = {
@@ -573,6 +576,7 @@ let initPivotTable = function($, window, document) {
573
576
  l_mapping = {};
574
577
  for (i in order) {
575
578
  x = order[i];
579
+ if (order[i] === null) x = '[null]';
576
580
  mapping[x] = i;
577
581
  if (typeof x === "string") {
578
582
  l_mapping[x.toLowerCase()] = i;
@@ -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) {
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 ${placeholder.class}"></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
@@ -623,6 +668,7 @@ let initPivotTable = function($, window, document) {
623
668
  this.getAggregator = bind(this.getAggregator, this);
624
669
  this.getRowKeys = bind(this.getRowKeys, this);
625
670
  this.getColKeys = bind(this.getColKeys, this);
671
+ this.getRowKeysByCols = bind(this.getRowKeysByCols, this);
626
672
  this.sortKeys = bind(this.sortKeys, this);
627
673
  this.arrSort = bind(this.arrSort, this);
628
674
  this.input = input;
@@ -639,12 +685,30 @@ let initPivotTable = function($, window, document) {
639
685
  return true;
640
686
  });
641
687
  this.tree = {};
642
- this.rowKeys = [];
643
- this.colKeys = [];
688
+
689
+ this.isKeysSortingDoneOnBackendSide = opts.keysObject && typeof opts.keysObject === 'object' && helpers.backendSortingKeysAreNotEmpty(opts.keysObject);
690
+ if (this.isKeysSortingDoneOnBackendSide) {
691
+ this.rowKeys = opts.keysObject.row_keys;
692
+ this.colKeys = opts.keysObject.col_keys;
693
+ this.rowKeysByCols = opts.keysObject.row_keys_by_cols;
694
+ } else {
695
+ this.rowKeys = [];
696
+ this.colKeys = [];
697
+ }
698
+
644
699
  this.rowTotals = {};
645
700
  this.colTotals = {};
646
701
  this.allTotal = this.aggregator(this, [], []);
647
702
  this.sorted = false;
703
+ this.dateValuesDictionary = opts.dateValuesDictionary;
704
+ this.sortByValueAttrs = opts.sortByValueAttrs || [];
705
+ this.colFormats = opts.colFormats || [];
706
+ this.rowFormats = opts.rowFormats || [];
707
+ this.isFormattingAxisLabels = opts.rendererOptions && opts.rendererOptions.isFormattingAxisLabels;
708
+ this.getFormattedColKeys = (keys) => opts.getFormattedColKeys(this, keys);
709
+ this.getFormattedRowKeys = (keys) => opts.getFormattedRowKeys(this, keys);
710
+ this.isDrillDownDisabled = opts.isDrillDownDisabled;
711
+
648
712
  PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
649
713
  return function(record) {
650
714
  if (_this.filter(record)) {
@@ -804,15 +868,23 @@ let initPivotTable = function($, window, document) {
804
868
  };
805
869
 
806
870
  PivotData.prototype.getColKeys = function() {
807
- this.sortKeys();
871
+ if (!this.isKeysSortingDoneOnBackendSide) {
872
+ this.sortKeys();
873
+ }
808
874
  return this.colKeys;
809
875
  };
810
876
 
811
877
  PivotData.prototype.getRowKeys = function() {
812
- this.sortKeys();
878
+ if (!this.isKeysSortingDoneOnBackendSide) {
879
+ this.sortKeys();
880
+ }
813
881
  return this.rowKeys;
814
882
  };
815
883
 
884
+ PivotData.prototype.getRowKeysByCols = function() {
885
+ return this.rowKeysByCols;
886
+ };
887
+
816
888
  PivotData.prototype.processRecord = function(record) {
817
889
  var colKey, flatColKey, flatRowKey, l, len1, len2, n, ref, ref1, ref2, ref3, rowKey, x;
818
890
  colKey = [];
@@ -881,6 +953,7 @@ let initPivotTable = function($, window, document) {
881
953
  return PivotData;
882
954
 
883
955
  })();
956
+
884
957
  $.pivotUtilities = {
885
958
  aggregatorTemplates: aggregatorTemplates,
886
959
  aggregators: aggregators,
@@ -890,8 +963,12 @@ let initPivotTable = function($, window, document) {
890
963
  naturalSort: naturalSort,
891
964
  numberFormat: numberFormat,
892
965
  sortAs: sortAs,
893
- PivotData: PivotData
966
+ PivotData: PivotData,
967
+ errorHandling: errorHandling,
894
968
  };
969
+ if (window.$) {
970
+ window.$.pivotUtilities = $.pivotUtilities
971
+ }
895
972
 
896
973
  /*
897
974
  Default Renderer for hierarchical table layout
@@ -1821,4 +1898,4 @@ let initPivotTable = function($, window, document) {
1821
1898
  };
1822
1899
  };
1823
1900
 
1824
- module.exports = initPivotTable;
1901
+ module.exports = initPivotTable;
@@ -0,0 +1,365 @@
1
+ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
2
+
3
+ this.document = {};
4
+ this.scope = {};
5
+ this.options = {};
6
+ this.isScenarioMode = null;
7
+ this.settings = {};
8
+
9
+ publishedItemsRenderer.formulaCellClicked = function (event, scope, options, window) {
10
+ event.stopPropagation();
11
+ event.preventDefault();
12
+ try {
13
+ const td = event.currentTarget;
14
+ const a = td.querySelector('a');
15
+ const locationId = a.getAttribute('location_id');
16
+ scope.callFromPublishItem(event, options.widgetId, options.dashboardId, locationId, window.published_item_sheetname);
17
+ } catch (e) {
18
+ }
19
+ return false;
20
+ }
21
+
22
+ publishedItemsRenderer.resizeTable = function (options, iframeWindow) {
23
+ const publish_item_image = iframeWindow.document.getElementById('publish_item_image');
24
+ const table = iframeWindow.document.getElementsByTagName("table")[0];
25
+ const body = iframeWindow.document.getElementsByTagName("body")[0];
26
+
27
+ if (table && options.responsive) {
28
+ publishedItemsRenderer.zoomTable(iframeWindow, table, body);
29
+ }
30
+
31
+ publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
32
+ }
33
+
34
+ publishedItemsRenderer.zoomTable = function (iframeWindow, table, body) {
35
+ const bodyZoom = parseFloat(body.style.zoom) || 1;
36
+ const SCROLL_OFFSET = 16;
37
+
38
+ const tableWidth = table.getBoundingClientRect().width * bodyZoom;
39
+ const tableHeight = table.getBoundingClientRect().height * bodyZoom;
40
+ const root = iframeWindow.document.documentElement;
41
+
42
+ let requiredZoom = (root.clientWidth - SCROLL_OFFSET) / tableWidth;
43
+ if (this.settings.resizeTableUsingBothDimensions) {
44
+ requiredZoom = Math.min(requiredZoom, (root.clientHeight - SCROLL_OFFSET) / tableHeight);
45
+ }
46
+
47
+ table.style.zoom = requiredZoom;
48
+ };
49
+
50
+ publishedItemsRenderer.resizePublishedImage = function (publish_item_image, iframeWindow, body) {
51
+ if (!publish_item_image) return;
52
+
53
+ let body_zoom = body.style.zoom;
54
+ body_zoom = parseFloat(body_zoom) || 1;
55
+
56
+ if (publish_item_image.style.height === '100%') {
57
+ publish_item_image.style.height = 'auto';
58
+ publish_item_image.style.width = '100%';
59
+ publish_item_image.style.marginTop = "";
60
+ setTimeout(function () {
61
+ publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
62
+ }, 10);
63
+ }
64
+
65
+ const imgPositionInfo = publish_item_image.getBoundingClientRect();
66
+ const height = (imgPositionInfo.height + imgPositionInfo.y * 2) * body_zoom;
67
+ if (height > iframeWindow.innerHeight) {
68
+ publish_item_image.style.height = '100%';
69
+ publish_item_image.style.width = 'auto';
70
+ } else if (height < iframeWindow.innerHeight) {
71
+ const temp = (iframeWindow.innerHeight - height) / 2;
72
+ publish_item_image.style.marginTop = (temp / body_zoom + imgPositionInfo.y) + "px";
73
+ }
74
+ }
75
+
76
+ publishedItemsRenderer.resetTableZoom = function (document) {
77
+ const table = document.getElementsByTagName("table")[0];
78
+ if (table) {
79
+ table.style.zoom = 1;
80
+ }
81
+ }
82
+
83
+ publishedItemsRenderer.changedAutoResize = function (options, iframeWindow, document) {
84
+ Object.assign(iframeWindow.__options__, options);
85
+ const table = document.getElementsByTagName("table")[0];
86
+ if (table) {
87
+ table.style.margin = options.responsive ? '0 auto' : '';
88
+ }
89
+
90
+ if (!options.responsive) {
91
+ publishedItemsRenderer.resetTableZoom(document);
92
+ } else {
93
+ publishedItemsRenderer.resizeTable(options, iframeWindow);
94
+ }
95
+ }
96
+
97
+ publishedItemsRenderer.changedInputValue = function (firstTime, scope, options) {
98
+ const input_values = [];
99
+ if (options.inputValuesData) {
100
+ for (let key in options.inputValuesData) {
101
+ input_values.push(options.inputValuesData[key]);
102
+ }
103
+ }
104
+
105
+ try {
106
+ scope.changedInputValues(input_values, options.widgetId, options.dashboardId, firstTime);
107
+ } catch (e) {
108
+ console.error(e);
109
+ }
110
+ }
111
+
112
+ publishedItemsRenderer.changedInputElement = function (event, scope, options) {
113
+ const inputElement = event.currentTarget;
114
+ const name = inputElement.getAttribute('name');
115
+ const metaData = options.inputValuesData ? options.inputValuesData[name] : null;
116
+ let newValue = inputElement.value;
117
+ if (metaData) {
118
+ if (metaData.type === 'editInput') {
119
+ newValue = parseFloat(newValue);
120
+ } else if (metaData.type === 'editInputPercent') {
121
+ newValue = parseFloat(newValue) + '%';
122
+ }
123
+
124
+ if (metaData.value !== newValue) {
125
+ metaData.value = newValue;
126
+ publishedItemsRenderer.changedInputValue(false, scope, options);
127
+ }
128
+ }
129
+ }
130
+
131
+ publishedItemsRenderer.createInputElement = function (tdElement, inputMetaData, formatValue, scope, options, document) {
132
+ const _this = this;
133
+ tdElement.innerHTML = '';
134
+ if (inputMetaData) {
135
+ switch (inputMetaData.type) {
136
+ case "editInput":
137
+ case "editInputPercent":
138
+ let inEl = document.createElement("INPUT");
139
+ let labelEl = document.createElement("LABEL");
140
+
141
+ if (inputMetaData.value === 'DR_INPUT') {
142
+ labelEl.innerText = null;
143
+ } else {
144
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inputMetaData.value).value : inputMetaData.value;
145
+ }
146
+ if (_this.isScenarioMode) {
147
+ labelEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;");
148
+ } else {
149
+ labelEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
150
+ }
151
+ const onLabelClick = function (event, isScenarioMode) {
152
+ event.stopPropagation();
153
+ if (isScenarioMode) {
154
+ inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
155
+ } else {
156
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
157
+ }
158
+ labelEl.style.display = 'none';
159
+ setTimeout(function () {
160
+ inEl.focus();
161
+ }, 1)
162
+ }
163
+ labelEl.addEventListener("click", (event) => onLabelClick(event, _this.isScenarioMode));
164
+
165
+ inEl.setAttribute("type", "number");
166
+ inEl.setAttribute("name", inputMetaData.name);
167
+ if (_this.isScenarioMode) {
168
+ inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
169
+ } else {
170
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
171
+ }
172
+ inEl.value = inputMetaData.type === 'editInputPercent' ? parseFloat(inputMetaData.value.replace('%', '')) : inputMetaData.value;
173
+ inEl.addEventListener("focusout", function (event) {
174
+ event.preventDefault();
175
+ publishedItemsRenderer.changedInputElement(event, scope, options);
176
+ inEl.style.display = 'none';
177
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
178
+ labelEl.style.display = 'block';
179
+ });
180
+ inEl.addEventListener("keyup", function (event) {
181
+ // Number 13 is the "Enter" key on the keyboard
182
+ if (event.keyCode === 13) {
183
+ // Cancel the default action, if needed
184
+ event.preventDefault();
185
+ publishedItemsRenderer.changedInputElement(event, scope, options);
186
+ inEl.style.display = 'none';
187
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
188
+ labelEl.style.display = 'block';
189
+ }
190
+ });
191
+ tdElement.appendChild(inEl);
192
+ tdElement.appendChild(labelEl);
193
+ break;
194
+ case "dateInput":
195
+ let dateEl = document.createElement("DIV");
196
+ const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
197
+ const formattedDate = formatValue('d', format, inputMetaData.value).value
198
+ if (_this.isScenarioMode) {
199
+ dateEl.innerHTML = '<label class="value dateInput" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;">' + formattedDate + '</label>';
200
+ } else {
201
+ dateEl.innerHTML = '<label class="value dateInput" style="cursor: pointer;">' + formattedDate + '</label>';
202
+ }
203
+ tdElement.appendChild(dateEl);
204
+ tdElement.classList.toggle("input-filter-list-td");
205
+ tdElement.setAttribute("name", inputMetaData.name);
206
+ tdElement.addEventListener("click", function (event) {
207
+ try {
208
+ scope.openDatePickerFromPublishedItem(event, options.widgetId, options.dashboardId, inputMetaData, format);
209
+ } catch (e) {
210
+ console.error(e);
211
+ }
212
+ })
213
+ break;
214
+ case "excelList":
215
+ let selectEl = document.createElement("SELECT");
216
+ selectEl.setAttribute("name", inputMetaData.name);
217
+ selectEl.setAttribute("class", "dr_input");
218
+ for (let i = 0; i < inputMetaData.values.length; i++) {
219
+ let option = document.createElement("option");
220
+ option.setAttribute("value", inputMetaData.values[i]);
221
+ option.innerText = inputMetaData.values[i];
222
+ if (inputMetaData.values[i] === inputMetaData.value) {
223
+ option.setAttribute("selected", "");
224
+ }
225
+ selectEl.appendChild(option);
226
+ }
227
+ selectEl.addEventListener("change", function (event) {
228
+ publishedItemsRenderer.changedInputElement(event, scope, options)
229
+ });
230
+ tdElement.appendChild(selectEl);
231
+ break;
232
+ case "filterList":
233
+ let listHolderEl = document.createElement("DIV");
234
+ listHolderEl.setAttribute("class", "filter_list_holder");
235
+ if (_this.isScenarioMode) {
236
+ listHolderEl.innerHTML = '<label class="value filterList" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
237
+ } else {
238
+ listHolderEl.innerHTML = '<label class="value filterList" style="cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
239
+ }
240
+ tdElement.appendChild(listHolderEl);
241
+ tdElement.classList.toggle("input-filter-list-td");
242
+ tdElement.setAttribute("name", inputMetaData.name);
243
+ tdElement.addEventListener("click", function (event) {
244
+ let inputElement = event.currentTarget;
245
+ let name = inputElement.getAttribute('name');
246
+ let metaData = options.inputValuesData ? options.inputValuesData[name] : null;
247
+ if (metaData) {
248
+ try {
249
+ scope.openFilterListFromPublishedItem(event, options.widgetId, options.dashboardId, metaData);
250
+ } catch (e) {
251
+ console.error(e);
252
+ }
253
+ }
254
+ });
255
+ break;
256
+ }
257
+ }
258
+ }
259
+
260
+ publishedItemsRenderer.changedInputFilterValue = function (metaData, newValue, document) {
261
+ let tdLabelElement = document.querySelector('td[name="' + metaData.name + '"]>div>label[class="value"]');
262
+ if (tdLabelElement) {
263
+ tdLabelElement.innerText = newValue;
264
+ }
265
+ console.log(tdLabelElement, newValue);
266
+ }
267
+
268
+ publishedItemsRenderer.changeStylesForLabel = function (elementsArray, styles, isScenarioMode) {
269
+ if (elementsArray.length) {
270
+ elementsArray.forEach(element => {
271
+ element.setAttribute("style", isScenarioMode ? styles : "cursor:pointer;");
272
+ })
273
+ }
274
+ }
275
+
276
+ publishedItemsRenderer.prepareInputCells = function (document, scope, options, isScenarioMode) {
277
+ const inputCells = document.querySelectorAll('td>a[href="DR_INPUT"], td>div>a[href="DR_INPUT"]');
278
+ const inputs = document.querySelectorAll('td>input');
279
+ const dateInputs = document.querySelectorAll('.dateInput');
280
+ const filterList = document.querySelectorAll('.filterList');
281
+ const styleForLabel = "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;";
282
+ if (!options.inputValuesData) {
283
+ options.inputValuesData = {};
284
+ }
285
+ publishedItemsRenderer.changeStylesForLabel(filterList, styleForLabel, isScenarioMode);
286
+ publishedItemsRenderer.changeStylesForLabel(dateInputs, styleForLabel, isScenarioMode);
287
+ if (inputs.length) {
288
+ inputs.forEach(element => {
289
+ const labelElement = element.nextSibling;
290
+ labelElement.setAttribute("style", isScenarioMode ?
291
+ "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;" :
292
+ "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
293
+ });
294
+ }
295
+ if (inputCells.length) {
296
+ for (let i = 0; i < inputCells.length; i++) {
297
+ let tdElement = inputCells[i].parentElement;
298
+ let inputId = inputCells[i].getAttribute('name') || 'no_attribute';
299
+ publishedItemsRenderer.createInputElement(tdElement, options.inputValuesData[inputId], scope.highchartsRenderer.formatValue, scope, options, document, isScenarioMode);
300
+ }
301
+ }
302
+ }
303
+
304
+ publishedItemsRenderer.addEventListeners = function (document, iframeWindow, scope, options) {
305
+ let resizeTimeout;
306
+ const handleDimensionChange = () => {
307
+ if (resizeTimeout) {
308
+ cancelAnimationFrame(resizeTimeout);
309
+ }
310
+
311
+ resizeTimeout = requestAnimationFrame(() => {
312
+ publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
313
+ });
314
+ }
315
+
316
+ document.addEventListener("DOMContentLoaded", handleDimensionChange);
317
+ iframeWindow.addEventListener("resize", handleDimensionChange);
318
+
319
+ // Add click event to cell with formula
320
+ let all_a_hrefs = document.querySelectorAll('td a[location_id]');
321
+ for (let i = 0; i < all_a_hrefs.length; i++) {
322
+ let td_elem = all_a_hrefs[i].closest('td');
323
+ td_elem.classList.add("apply_hover");
324
+ td_elem.addEventListener('click', function (event) {
325
+ publishedItemsRenderer.formulaCellClicked(event, scope, options, iframeWindow)
326
+ });
327
+ }
328
+ }
329
+
330
+ publishedItemsRenderer.scenarioModeChange = function (flag, document) {
331
+ this.isScenarioMode = flag;
332
+ publishedItemsRenderer.prepareInputCells(document, this.scope, this.options, this.isScenarioMode);
333
+ }
334
+
335
+ publishedItemsRenderer.getInputValues = function () {
336
+ return this.options.inputValuesData;
337
+ }
338
+
339
+ publishedItemsRenderer.initPublishedItem = function (document, iframeWindow, scope, options) {
340
+ this.document = document;
341
+ this.scope = scope;
342
+ this.options = options;
343
+ iframeWindow.__options__ = options;
344
+ publishedItemsRenderer.prepareInputCells(document, scope, options, this.isScenarioMode);
345
+ publishedItemsRenderer.applyInitDocumentStyles(document, iframeWindow);
346
+ publishedItemsRenderer.addEventListeners(document, iframeWindow, scope, options);
347
+
348
+ setTimeout(function () {
349
+ publishedItemsRenderer.changedInputValue(true, scope, options);
350
+ }, 500);
351
+ }
352
+
353
+ publishedItemsRenderer.applyInitDocumentStyles = function (document, iframeWindow) {
354
+ const table = document.getElementsByTagName('table')[0];
355
+ if (table) {
356
+ table.style.overflow = 'hidden';
357
+ table.style.margin = iframeWindow.__options__.responsive ? '0 auto' : '';
358
+ }
359
+
360
+ const body = document.body;
361
+ body.style.margin = '0';
362
+ }
363
+ }
364
+
365
+ module.exports = getPublishedItemsRenderer;
@@ -0,0 +1,43 @@
1
+ function getSeriesPointStyles(isSelected) {
2
+ return {
3
+ opacity: isSelected ? 1 : 0.1,
4
+ marker: {
5
+ enabled: true,
6
+ radius: isSelected ? 8 : 3,
7
+ },
8
+ dataLabels: {
9
+ style: {
10
+ fontWeight: isSelected ? "bold" : "normal",
11
+ },
12
+ },
13
+ };
14
+ }
15
+
16
+ function setSeriesPointStylesOnClick(e) {
17
+ const selectedPoint = e.point;
18
+ e.point.series.chart.series.forEach((series) =>
19
+ series.points.forEach((point) => {
20
+ point.update(getSeriesPointStyles(point === selectedPoint), false);
21
+ })
22
+ );
23
+ e.point.series.chart.redraw();
24
+ }
25
+
26
+ function setInitialPointStyles(opts, series) {
27
+ series.forEach((series) => {
28
+ if (Array.isArray(series.data)) {
29
+ series.data.forEach((item) => {
30
+ const isSelected =
31
+ item && opts.selectedPoint &&
32
+ item.initialName === opts.selectedPoint.initialName &&
33
+ item.y.toFixed(2) === opts.selectedPoint.y.toFixed(2);
34
+ item = Object.assign(item, getSeriesPointStyles(isSelected));
35
+ });
36
+ }
37
+ });
38
+ }
39
+
40
+ module.exports = {
41
+ setSeriesPointStylesOnClick,
42
+ setInitialPointStyles,
43
+ };