@datarailsshared/dr_renderer 1.2.77 → 1.2.78

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.77",
3
+ "version": "1.2.78",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -197,7 +197,7 @@ let initDRPivotTable = function($, window, document) {
197
197
  }
198
198
  } else if (!rowKey.length && colKey.length) {
199
199
  if (!this.colTotals[flatColKey]) {
200
- this.colTotals[flatColKey] = getColAggregator(rowKey.slice());
200
+ this.colTotals[flatColKey] = getColAggregator(colKey.slice());
201
201
  this.colTotals[flatColKey].push(record);
202
202
  }
203
203
  } else {
@@ -466,7 +466,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
466
466
  }
467
467
 
468
468
  if (opts && opts.chartOptions && opts.chartOptions.label && opts.chartOptions.label.percentage) {
469
- return (Math.round((this.y / this.total) * 10000) / 100) + '%';
469
+ return (Math.round((this.y / this.total) * 100)) + '%';
470
470
  } else if (opts && opts.chartOptions && opts.chartOptions.label && opts.chartOptions.label.show_percentage) {
471
471
  let aggrPercentages = pivotData.getAggregator(rows, [])
472
472
  let total = aggrPercentages.value()
@@ -586,7 +586,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
586
586
  }
587
587
 
588
588
  if (lodash.has(opts, "chartOptions.label.percentage") && opts.chartOptions.label.percentage && this.total) {
589
- to_return += '<br/>' + (Math.round((this.y / this.total) * 10000) / 100) + '%';
589
+ to_return += '<br/>' + (Math.round((this.y / this.total) * 100)) + '%';
590
590
  }
591
591
  return to_return;
592
592
 
@@ -4483,7 +4483,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4483
4483
  },
4484
4484
  seriesOptions: []
4485
4485
  }
4486
- if (options.chartOptions.delta_column && options.chartOptions.delta_column.field === 'series') {
4486
+ if (options.chartOptions && options.chartOptions.delta_column && options.chartOptions.delta_column.field === 'series') {
4487
4487
  let deltaColumnSeries = {
4488
4488
  series: options.chartOptions.delta_column.name,
4489
4489
  secondaryAxis: !options.chartOptions.delta_column.same_yaxis,
@@ -1,5 +1,10 @@
1
1
  let getPublishedItemsRenderer = function (publishedItemsRenderer) {
2
2
 
3
+ this.document = {};
4
+ this.scope = {};
5
+ this.options = {};
6
+ this.isScenarioMode = null;
7
+
3
8
  publishedItemsRenderer.formulaCellClicked = function (event, scope, options, window) {
4
9
  event.stopPropagation();
5
10
  event.preventDefault();
@@ -135,6 +140,7 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
135
140
  }
136
141
 
137
142
  publishedItemsRenderer.createInputElement = function (tdElement, inputMetaData, formatValue, scope, options, document) {
143
+ const _this = this;
138
144
  tdElement.innerHTML = '';
139
145
  if (inputMetaData) {
140
146
  switch (inputMetaData.type) {
@@ -148,19 +154,32 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
148
154
  } else {
149
155
  labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inputMetaData.value).value : inputMetaData.value;
150
156
  }
151
- labelEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
152
- labelEl.addEventListener("click", function (event) {
157
+ if (_this.isScenarioMode) {
158
+ labelEl.setAttribute("style", "background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;");
159
+ } else {
160
+ labelEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
161
+ }
162
+ const onLabelClick = function (event, isScenarioMode) {
153
163
  event.stopPropagation();
164
+ if (isScenarioMode) {
165
+ inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
166
+ } else {
167
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
168
+ }
154
169
  labelEl.style.display = 'none';
155
- inEl.style.display = 'block';
156
170
  setTimeout(function () {
157
171
  inEl.focus();
158
172
  }, 1)
159
- });
173
+ }
174
+ labelEl.addEventListener("click", (event) => onLabelClick(event, _this.isScenarioMode));
160
175
 
161
176
  inEl.setAttribute("type", "number");
162
177
  inEl.setAttribute("name", inputMetaData.name);
163
- inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
178
+ if (_this.isScenarioMode) {
179
+ inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
180
+ } else {
181
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
182
+ }
164
183
  inEl.value = inputMetaData.type === 'editInputPercent' ? parseFloat(inputMetaData.value.replace('%', '')) : inputMetaData.value;
165
184
  inEl.addEventListener("focusout", function (event) {
166
185
  event.preventDefault();
@@ -187,7 +206,11 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
187
206
  let dateEl = document.createElement("DIV");
188
207
  const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
189
208
  const formattedDate = formatValue('d', format, inputMetaData.value).value
190
- dateEl.innerHTML = '<label class="value" style="cursor: pointer;">' + formattedDate + '</label>';
209
+ if (_this.isScenarioMode) {
210
+ dateEl.innerHTML = '<label class="value dateInput" style="background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;">' + formattedDate + '</label>';
211
+ } else {
212
+ dateEl.innerHTML = '<label class="value dateInput" style="cursor: pointer;">' + formattedDate + '</label>';
213
+ }
191
214
  tdElement.appendChild(dateEl);
192
215
  tdElement.classList.toggle("input-filter-list-td");
193
216
  tdElement.setAttribute("name", inputMetaData.name);
@@ -220,7 +243,11 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
220
243
  case "filterList":
221
244
  let listHolderEl = document.createElement("DIV");
222
245
  listHolderEl.setAttribute("class", "filter_list_holder");
223
- listHolderEl.innerHTML = '<label class="value">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
246
+ if (_this.isScenarioMode) {
247
+ listHolderEl.innerHTML = '<label class="value filterList" style="background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
248
+ } else {
249
+ listHolderEl.innerHTML = '<label class="value filterList" style="cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
250
+ }
224
251
  tdElement.appendChild(listHolderEl);
225
252
  tdElement.classList.toggle("input-filter-list-td");
226
253
  tdElement.setAttribute("name", inputMetaData.name);
@@ -249,16 +276,38 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
249
276
  console.log(tdLabelElement, newValue);
250
277
  }
251
278
 
252
- publishedItemsRenderer.prepareInputCells = function (document, scope, options) {
253
- let inputCells = document.querySelectorAll('td>a[href="DR_INPUT"], td>div>a[href="DR_INPUT"]');
279
+ publishedItemsRenderer.changeStylesForLabel = function (elementsArray, styles, isScenarioMode) {
280
+ if (elementsArray.length) {
281
+ elementsArray.forEach(element => {
282
+ element.setAttribute("style", isScenarioMode ? styles : "cursor:pointer;");
283
+ })
284
+ }
285
+ }
286
+
287
+ publishedItemsRenderer.prepareInputCells = function (document, scope, options, isScenarioMode) {
288
+ const inputCells = document.querySelectorAll('td>a[href="DR_INPUT"], td>div>a[href="DR_INPUT"]');
289
+ const inputs = document.querySelectorAll('td>input');
290
+ const dateInputs = document.querySelectorAll('.dateInput');
291
+ const filterList = document.querySelectorAll('.filterList');
292
+ const styleForLabel = "background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;";
254
293
  if (!options.inputValuesData) {
255
294
  options.inputValuesData = {};
256
295
  }
257
- if (inputCells.length > 0) {
296
+ publishedItemsRenderer.changeStylesForLabel(filterList, styleForLabel, isScenarioMode);
297
+ publishedItemsRenderer.changeStylesForLabel(dateInputs, styleForLabel, isScenarioMode);
298
+ if (inputs.length) {
299
+ inputs.forEach(element => {
300
+ const labelElement = element.nextSibling;
301
+ labelElement.setAttribute("style", isScenarioMode ?
302
+ "background: #FFEDBF;padding: 2px 8px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;" :
303
+ "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
304
+ });
305
+ }
306
+ if (inputCells.length) {
258
307
  for (let i = 0; i < inputCells.length; i++) {
259
308
  let tdElement = inputCells[i].parentElement;
260
309
  let inputId = inputCells[i].getAttribute('name') || 'no_attribute';
261
- publishedItemsRenderer.createInputElement(tdElement, options.inputValuesData[inputId], scope.highchartsRenderer.formatValue, scope, options, document);
310
+ publishedItemsRenderer.createInputElement(tdElement, options.inputValuesData[inputId], scope.highchartsRenderer.formatValue, scope, options, document, isScenarioMode);
262
311
  }
263
312
  }
264
313
  }
@@ -290,8 +339,20 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
290
339
  }
291
340
  }
292
341
 
342
+ publishedItemsRenderer.scenarioModeChange = function (flag, document) {
343
+ this.isScenarioMode = flag;
344
+ publishedItemsRenderer.prepareInputCells(document, this.scope, this.options, this.isScenarioMode);
345
+ }
346
+
347
+ publishedItemsRenderer.getInputValues = function () {
348
+ return this.options.inputValuesData;
349
+ }
350
+
293
351
  publishedItemsRenderer.initPublishedItem = function (document, window, scope, options) {
294
- publishedItemsRenderer.prepareInputCells(document, scope, options);
352
+ this.document = document;
353
+ this.scope = scope;
354
+ this.options = options;
355
+ publishedItemsRenderer.prepareInputCells(document, scope, options, this.isScenarioMode);
295
356
  publishedItemsRenderer.addEventListeners(document, window, scope, options);
296
357
 
297
358
  setTimeout(function () {