@datarailsshared/dr_renderer 1.3.41 → 1.3.42

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.3.41",
3
+ "version": "1.3.42",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1,3 +1,6 @@
1
+ const { DR_SCENARIO } = require('./smart_queries_helper');
2
+
3
+
1
4
  let initDRPivotTable = function($, window, document) {
2
5
  var hasProp = {}.hasOwnProperty;
3
6
  var slice = [].slice;
@@ -1269,6 +1272,9 @@ let initDRPivotTable = function($, window, document) {
1269
1272
  "rowspan": rowHeader.descendants + 1,
1270
1273
  "colspan": colspan
1271
1274
  });
1275
+ if (opts.chartOptions.isSmartQueriesEnabled) {
1276
+ th.textContent = th.textContent.replace(DR_SCENARIO.Forecast, 'Forecast Smart Query');
1277
+ }
1272
1278
  if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1273
1279
  th.textContent = th.textContent.replace('[null]', '');
1274
1280
  }
@@ -1516,6 +1522,13 @@ let initDRPivotTable = function($, window, document) {
1516
1522
  }
1517
1523
  };
1518
1524
  val = aggregator.value();
1525
+
1526
+ if (opts.chartOptions.isSmartQueriesEnabled && flatRowKey.split(' , ').includes(DR_SCENARIO.Forecast)) {
1527
+ const actualsRow = tree[flatRowKey.replace(DR_SCENARIO.Forecast, DR_SCENARIO.SQ_Actuals)] || {};
1528
+ if (actualsRow && actualsRow[flatColKey]) {
1529
+ val += actualsRow[flatColKey]?.value() || 0;
1530
+ }
1531
+ }
1519
1532
  isColSubtotal = colHeader.children.length !== 0;
1520
1533
  style = "pvtVal";
1521
1534
  if (isColSubtotal) {
@@ -1558,6 +1571,9 @@ let initDRPivotTable = function($, window, document) {
1558
1571
  }
1559
1572
 
1560
1573
  val = totalAggregator.value();
1574
+ if (opts.chartOptions.isSmartQueriesEnabled && flatRowKey.split(' , ').includes(DR_SCENARIO.Forecast)) {
1575
+ val += rowTotals[flatRowKey.replace(DR_SCENARIO.Forecast, DR_SCENARIO.SQ_Actuals)]?.value() || 0;
1576
+ }
1561
1577
  style = "pvtTotal rowTotal";
1562
1578
  if (isRowSubtotal) {
1563
1579
  style += " pvtRowSubtotal";
@@ -2338,6 +2354,9 @@ let initDRPivotTable = function($, window, document) {
2338
2354
  }
2339
2355
 
2340
2356
  main = function(rowAttrs, rowKeys, colAttrs, colKeys, pivotData) {
2357
+ if (opts.chartOptions.isSmartQueriesEnabled) {
2358
+ rowKeys = rowKeys.filter(rowKey => !rowKey.includes(DR_SCENARIO.SQ_Actuals));
2359
+ }
2341
2360
  var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
2342
2361
  rowHeaders = [];
2343
2362
  colHeaders = [];
@@ -1,10 +1,16 @@
1
1
  const lodash = require('lodash');
2
2
 
3
+ const DR_SCENARIO = {
4
+ SQ_Actuals: 'SQ_Actuals',
5
+ Forecast: 'Forecast',
6
+ };
7
+
3
8
  function createSingleDataSeriesForForecast(chart_series, chartOptions, pivotData) {
4
9
  const { actuals, forecast, smart_query } = chartOptions.chart;
5
10
  const input = pivotData.input;
6
11
 
7
- const hasSQActuals = input.some(item => item.Scenario && item.Scenario.indexOf('SQ_Actuals') !== -1);
12
+ const hasSQActuals = input.some(item => item.Scenario && item.Scenario.indexOf(DR_SCENARIO.SQ_Actuals) !== -1);
13
+ chartOptions.isSmartQueriesEnabled = hasSQActuals;
8
14
  if (!smart_query || !hasSQActuals) return null;
9
15
 
10
16
  const midMonthOffset = 0.5
@@ -15,7 +21,7 @@ function createSingleDataSeriesForForecast(chart_series, chartOptions, pivotData
15
21
 
16
22
  function buildChartSeriesFromPivotInputOnly(input, actuals, forecast, midMonthOffset) {
17
23
  const filtered = input.filter(item =>
18
- (item.Scenario === 'SQ_Actuals' || item.Scenario === 'Forecast') &&
24
+ (item.Scenario === DR_SCENARIO.SQ_Actuals || item.Scenario === DR_SCENARIO.Forecast) &&
19
25
  item.Amount !== 0
20
26
  );
21
27
 
@@ -26,7 +32,7 @@ function buildChartSeriesFromPivotInputOnly(input, actuals, forecast, midMonthOf
26
32
  type: item.Scenario,
27
33
  })).sort((a, b) => new Date(a.name) - new Date(b.name));
28
34
 
29
- const sqCount = input.filter(item => item.Scenario === 'SQ_Actuals').length;
35
+ const sqCount = input.filter(item => item.Scenario === DR_SCENARIO.SQ_Actuals).length;
30
36
 
31
37
  return {
32
38
  name: "Forecast Smart Query",
@@ -40,8 +46,8 @@ function buildChartSeriesFromPivotInputOnly(input, actuals, forecast, midMonthOf
40
46
  }
41
47
 
42
48
  function buildChartSeriesFromSeries(chart_series, actuals, forecast, midMonthOffset) {
43
- const seriesA = lodash.find(chart_series, s => s.name && lodash.includes(s.name, 'SQ_Actuals'));
44
- const seriesB = lodash.find(chart_series, s => s.name && lodash.includes(s.name, 'Forecast'));
49
+ const seriesA = lodash.find(chart_series, s => s.name && lodash.includes(s.name, DR_SCENARIO.SQ_Actuals));
50
+ const seriesB = lodash.find(chart_series, s => s.name && lodash.includes(s.name, DR_SCENARIO.Forecast));
45
51
 
46
52
  if (!seriesA || !seriesB) return null;
47
53
 
@@ -69,7 +75,7 @@ function buildChartSeriesFromSeries(chart_series, actuals, forecast, midMonthOff
69
75
  y: yA + yB,
70
76
  name: pointA && pointA.name ? pointA.name : null,
71
77
  initialName: (pointA && pointA.name) ? pointA.name : 'Point ' + (i + 1),
72
- type: yA ? "SQ_Actuals" : "Forecast",
78
+ type: yA ? DR_SCENARIO.SQ_Actuals : DR_SCENARIO.Forecast,
73
79
  });
74
80
  }
75
81
 
@@ -86,4 +92,5 @@ function buildChartSeriesFromSeries(chart_series, actuals, forecast, midMonthOff
86
92
 
87
93
  module.exports = {
88
94
  createSingleDataSeriesForForecast,
95
+ DR_SCENARIO
89
96
  };