@datarailsshared/dr_renderer 1.2.75 → 1.2.79

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.75",
3
+ "version": "1.2.79",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -497,11 +497,11 @@ var DataFormatterImpl = function () {
497
497
  var minutes = n.getMinutes();
498
498
  var seconds = n.getSeconds();
499
499
 
500
- var adjustMinutesValue = function(minutes) {
501
- if (minutes < 10) {
502
- return '0' + minutes;
500
+ var padStartTime = function(time) {
501
+ if (time < 10) {
502
+ return '0' + time;
503
503
  }
504
- return minutes;
504
+ return time;
505
505
  }
506
506
 
507
507
  // Build res
@@ -513,11 +513,11 @@ var DataFormatterImpl = function () {
513
513
  }
514
514
 
515
515
  if (fmin) {
516
- return fmin + _this3.applyNumberPattern(adjustMinutesValue(minutes), '00');
516
+ return fmin + _this3.applyNumberPattern(padStartTime(minutes), '00');
517
517
  }
518
518
 
519
519
  if (fmin2) {
520
- return _this3.applyNumberPattern(adjustMinutesValue(minutes), '00') + fmin2;
520
+ return _this3.applyNumberPattern(padStartTime(minutes), '00') + fmin2;
521
521
  }
522
522
 
523
523
  if (mmin) {
@@ -534,7 +534,7 @@ var DataFormatterImpl = function () {
534
534
  return res.replace(/(ss)|(s)|(hh)|(h)|(dddd)|(ddd)|(dd)|(d)|(mmmmm)|(mmmm)|(mmm)|(mm)|(m)|(yyyy)|(yy)|(\[\])/gi, function (a, ss, s, hh, h, dddd, ddd, dd, d, mmmmm, mmmm, mmm, mm, m, yyyy, yy, ampm) {
535
535
 
536
536
  if (ss) {
537
- return _this3.applyNumberPattern(seconds, '00');
537
+ return _this3.applyNumberPattern(padStartTime(seconds), '00');
538
538
  }
539
539
 
540
540
  if (s) {
@@ -542,7 +542,7 @@ var DataFormatterImpl = function () {
542
542
  }
543
543
 
544
544
  if (hh) {
545
- return _this3.applyNumberPattern(foundAMPM ? hours % 12 : hours, '00');
545
+ return _this3.applyNumberPattern(padStartTime(foundAMPM ? hours % 12 : hours), '00');
546
546
  }
547
547
 
548
548
  if (h) {
@@ -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 {
@@ -440,7 +440,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
440
440
  rows = [];
441
441
  }
442
442
 
443
- if (pivotData.rowAttrs.length == 0) {
443
+ if (pivotData.rowAttrs.length == 0
444
+ || this.series.options.className === 'totalSeries'
445
+ || this.series.options.className === 'trendSeries') {
444
446
  rows = [];
445
447
  }
446
448
  var cols = this.key;
@@ -466,7 +468,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
466
468
  }
467
469
 
468
470
  if (opts && opts.chartOptions && opts.chartOptions.label && opts.chartOptions.label.percentage) {
469
- return (Math.round((this.y / this.total) * 10000) / 100) + '%';
471
+ return (Math.round((this.y / this.total) * 100)) + '%';
470
472
  } else if (opts && opts.chartOptions && opts.chartOptions.label && opts.chartOptions.label.show_percentage) {
471
473
  let aggrPercentages = pivotData.getAggregator(rows, [])
472
474
  let total = aggrPercentages.value()
@@ -533,7 +535,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
533
535
  if (is_drill_down_pie && highchartsRenderer.selfStartsWith(series_name,"Series ")) {
534
536
  rows = [];
535
537
  }
536
- if (pivotData.rowAttrs.length == 0) {
538
+ if (pivotData.rowAttrs.length == 0
539
+ || this.series.options.className === 'totalSeries'
540
+ || this.series.options.className === 'trendSeries') {
537
541
  rows = [];
538
542
  }
539
543
  var cols = this.key;
@@ -586,7 +590,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
586
590
  }
587
591
 
588
592
  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) + '%';
593
+ to_return += '<br/>' + (Math.round((this.y / this.total) * 100)) + '%';
590
594
  }
591
595
  return to_return;
592
596
 
@@ -980,6 +984,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
980
984
  const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
981
985
 
982
986
  const trendSeries = lodash.clone(chart_series[chart_series.length - 1]);
987
+ trendSeries.className = 'trendSeries';
983
988
  trendSeries.name = 'Trend Line (' + trendSeries.name + ')';
984
989
  trendSeries.dashStyle = 'shortdot';
985
990
  trendSeries.type = 'line';
@@ -1026,6 +1031,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1026
1031
  if (opts.totalSeriesSettings) {
1027
1032
  newSeries.yAxis = opts.totalSeriesSettings.secondaryAxis ? 1 : undefined;
1028
1033
  }
1034
+ newSeries.className = 'totalSeries';
1029
1035
  newSeries.name = 'Total';
1030
1036
  newSeries.data = [];
1031
1037
  col_n_keys.forEach(columnKey => {
@@ -1145,6 +1151,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1145
1151
  const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
1146
1152
 
1147
1153
  const trendSeries = lodash.clone(chart_series[chart_series.length - 1]);
1154
+ trendSeries.className = 'trendSeries';
1148
1155
  trendSeries.name = 'Trend Line (' + trendSeries.name + ')';
1149
1156
  trendSeries.dashStyle = 'shortdot';
1150
1157
  trendSeries.type = 'line';
@@ -1206,6 +1213,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1206
1213
  }
1207
1214
  }
1208
1215
 
1216
+ totalSeries.className = 'totalSeries';
1209
1217
  totalSeries.name = 'Total';
1210
1218
  totalSeries.data = [];
1211
1219
  col_n_keys.forEach(columnKey => {
@@ -2017,7 +2025,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2017
2025
  };
2018
2026
 
2019
2027
  highchartsRenderer.setTitleAndSubTitle = function (chartOptions, opts, additionOptions) {
2020
- chartOptions.title = opts.chartOptions.hideChartHeader ? null : {
2028
+ chartOptions.title = opts.chartOptions.hideChartHeader ? { text: null } : {
2021
2029
  align: 'center',
2022
2030
  text: opts && opts.chart_title ? opts.chart_title : "",
2023
2031
  style: {
@@ -4307,6 +4315,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4307
4315
  format = format.replace('dd', 'DD');
4308
4316
  format = format.replace('yyyy', 'YYYY');
4309
4317
  format = format.replace('yy', 'YY');
4318
+ format = lodash.replace(format, /h/g, 'H');
4310
4319
  return moment_lib(tryParse).utcOffset(0).format(format) + "";
4311
4320
  } else {
4312
4321
  return 'Wrong date format';
@@ -4482,7 +4491,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4482
4491
  },
4483
4492
  seriesOptions: []
4484
4493
  }
4485
- if (options.chartOptions.delta_column && options.chartOptions.delta_column.field === 'series') {
4494
+ if (options.chartOptions && options.chartOptions.delta_column && options.chartOptions.delta_column.field === 'series') {
4486
4495
  let deltaColumnSeries = {
4487
4496
  series: options.chartOptions.delta_column.name,
4488
4497
  secondaryAxis: !options.chartOptions.delta_column.same_yaxis,
@@ -7374,6 +7383,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7374
7383
  minHeight: 16,
7375
7384
  maxHeight: 45,
7376
7385
  x: -3,
7386
+ y: -26,
7377
7387
  layout: "horizontal"
7378
7388
  } : {
7379
7389
  enabled: rowAttrsLength > 0,
@@ -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 () {