@datarailsshared/dr_renderer 1.3.39 → 1.3.41

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.39",
3
+ "version": "1.3.41",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -406,6 +406,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
406
406
  if (!type) return null;
407
407
  return [
408
408
  'line',
409
+ 'line-chart-forecast',
409
410
  'spline',
410
411
  'area',
411
412
  'areaspline',
@@ -1419,14 +1420,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1419
1420
 
1420
1421
  const chartType = chartOptions && chartOptions.chart && chartOptions.chart.type ? chartOptions.chart.type : null;
1421
1422
  const smartQuerySeries = isChartTypeSupportedForSmartQuery(chartType)
1422
- ? smartQueriesHelper.createSingleDataSeriesForForecast(chart_series, opts.chartOptions)
1423
+ ? smartQueriesHelper.createSingleDataSeriesForForecast(chart_series, opts.chartOptions, pivotData)
1423
1424
  : null;
1424
1425
 
1425
1426
  if (smartQuerySeries) {
1426
- chart_series.push(smartQuerySeries);
1427
- lodash.remove(chart_series, s =>
1427
+ if (chart_series.length > 1) {
1428
+ lodash.remove(chart_series, s =>
1428
1429
  (s.name && lodash.includes(s.name, 'SQ_Actuals')) || s.name === 'Forecast'
1429
- );
1430
+ );
1431
+ } else {
1432
+ chart_series = []
1433
+ }
1434
+ chart_series.push(smartQuerySeries);
1430
1435
  }
1431
1436
 
1432
1437
  return chart_series;
@@ -6657,7 +6662,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6657
6662
  },
6658
6663
  {
6659
6664
  element_type: 'toggle',
6660
- element_label: 'Smart Queries',
6665
+ element_label: 'Forecast Chart',
6661
6666
  value_name: 'smart_query',
6662
6667
  default_value: true,
6663
6668
  showFn: isChartTypeSupportedForSmartQuery
@@ -7660,6 +7665,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7660
7665
  axisTooltipTitle: 'Drag one or more fields here to create your x-axis.',
7661
7666
  legendTooltipTitle: 'Adding a field in this section will display lines for each item in that field.',
7662
7667
  },
7668
+ 'line-chart-forecast': {
7669
+ name: 'Combined Line',
7670
+ label: 'Combined Line',
7671
+ title: 'Show forecast over time.',
7672
+ description: 'For example, see how your Monthly Revenue evolves over a given period.',
7673
+ axisName: 'X - Axis',
7674
+ legendName: 'Data series',
7675
+ startedMessage: '“To get started, drag the Reporting Month field to the x-axis, include the Scenario Cycle field in the data series, and add one field to the value section.”',
7676
+ axisTooltipTitle: 'Drag one or more fields here to create your x-axis.',
7677
+ legendTooltipTitle: 'Adding a field in this section will display lines for each item in that field.',
7678
+ },
7663
7679
  'scatter-chart': {
7664
7680
  name: 'Scatter chart',
7665
7681
  label: 'Scatter Chart',
@@ -7853,6 +7869,27 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7853
7869
  highchartsRenderer.suboptions["legends"],
7854
7870
  ]
7855
7871
  },
7872
+ {
7873
+ type: 'line-chart-forecast',
7874
+ name: highchartsRenderer.chartsTypesInfo['line-chart-forecast'].name,
7875
+ class: 'google-visualization-charteditor-thumbs-linechart-forecast',
7876
+ render: highchartsRenderer.ptRenderSpLine,
7877
+ suboptions: [
7878
+ highchartsRenderer.suboptions["axisY"],
7879
+ highchartsRenderer.suboptions["axisX"],
7880
+ highchartsRenderer.suboptions["tooltips"],
7881
+ highchartsRenderer.suboptions["label"],
7882
+ highchartsRenderer.suboptions["subtitle"],
7883
+ highchartsRenderer.suboptions["widget_library"],
7884
+ highchartsRenderer.suboptions["table_options_transpose"],
7885
+ highchartsRenderer.suboptions["table_design_options"],
7886
+ highchartsRenderer.suboptions["chart_grid"],
7887
+ highchartsRenderer.suboptions["negative_number_format"],
7888
+ highchartsRenderer.suboptions["delta_column"],
7889
+ highchartsRenderer.suboptions["advanced"],
7890
+ highchartsRenderer.suboptions["legends"],
7891
+ ]
7892
+ },
7856
7893
  {
7857
7894
  type: 'scatter-chart',
7858
7895
  name: highchartsRenderer.chartsTypesInfo['scatter-chart'].name,
@@ -9880,9 +9917,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9880
9917
  const initialNameForSmartQueries = seriesData
9881
9918
  ? lodash.find(seriesData, obj => obj.name === e.point.name)
9882
9919
  : null;
9883
-
9884
9920
  if (initialNameForSmartQueries && initialNameForSmartQueries.type) {
9885
- e.point.series.name = initialNameForSmartQueries.type;
9921
+ e.point.series.name = initialNameForSmartQueries.type === "SQ_Actuals" ? 'Actuals' : 'Forecast';
9886
9922
  }
9887
9923
  lodash.set(e, 'point.category.userOptions', e.point.initialName.toString().split(highchartsRenderer.delimer));
9888
9924
  }
@@ -1,16 +1,49 @@
1
1
  const lodash = require('lodash');
2
2
 
3
- function createSingleDataSeriesForForecast(chart_series, chartOptions) {
3
+ function createSingleDataSeriesForForecast(chart_series, chartOptions, pivotData) {
4
4
  const { actuals, forecast, smart_query } = chartOptions.chart;
5
+ const input = pivotData.input;
5
6
 
6
- const seriesA = lodash.find(chart_series, function(s) {
7
- return s.name && lodash.includes(s.name, 'SQ_Actuals');
8
- });
9
- const seriesB = lodash.find(chart_series, function(s) {
10
- return s.name && lodash.includes(s.name, 'Forecast');
11
- });
7
+ const hasSQActuals = input.some(item => item.Scenario && item.Scenario.indexOf('SQ_Actuals') !== -1);
8
+ if (!smart_query || !hasSQActuals) return null;
9
+
10
+ const midMonthOffset = 0.5
11
+ return chart_series.length === 1
12
+ ? buildChartSeriesFromPivotInputOnly(input, actuals, forecast, midMonthOffset)
13
+ : buildChartSeriesFromSeries(chart_series, actuals, forecast, midMonthOffset);
14
+ }
15
+
16
+ function buildChartSeriesFromPivotInputOnly(input, actuals, forecast, midMonthOffset) {
17
+ const filtered = input.filter(item =>
18
+ (item.Scenario === 'SQ_Actuals' || item.Scenario === 'Forecast') &&
19
+ item.Amount !== 0
20
+ );
21
+
22
+ const data = filtered.map(item => ({
23
+ y: item.Amount,
24
+ name: item.Reporting_Month,
25
+ initialName: item.Reporting_Month,
26
+ type: item.Scenario,
27
+ })).sort((a, b) => new Date(a.name) - new Date(b.name));
28
+
29
+ const sqCount = input.filter(item => item.Scenario === 'SQ_Actuals').length;
30
+
31
+ return {
32
+ name: "Forecast Smart Query",
33
+ data,
34
+ zoneAxis: "x",
35
+ zones: [
36
+ { value: sqCount - midMonthOffset, dashStyle: actuals },
37
+ { dashStyle: forecast },
38
+ ],
39
+ };
40
+ }
12
41
 
13
- if (!seriesA || !seriesB || !smart_query) return null;
42
+ 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'));
45
+
46
+ if (!seriesA || !seriesB) return null;
14
47
 
15
48
  const indexOfForecastFirstZero = lodash.findIndex(seriesB.data, function(value) {
16
49
  return value.y === 0;
@@ -20,17 +53,9 @@ function createSingleDataSeriesForForecast(chart_series, chartOptions) {
20
53
  });
21
54
  const cutoffIndex = Math.max(indexOfForecastFirstZero, indexOfActualsFirstZero);
22
55
 
23
- const derivedSeries = {
24
- name: "Forecast Smart Query",
25
- data: [],
26
- zoneAxis: "x",
27
- zones: [
28
- { value: cutoffIndex - 1, dashStyle: actuals },
29
- { dashStyle: forecast },
30
- ],
31
- };
32
56
 
33
57
  const minLength = Math.min(seriesA.data.length, seriesB.data.length);
58
+ const data = [];
34
59
 
35
60
  for (let i = 0; i < minLength; i++) {
36
61
  const pointA = seriesA.data[i];
@@ -39,19 +64,26 @@ function createSingleDataSeriesForForecast(chart_series, chartOptions) {
39
64
  const yA = (pointA && pointA.y !== null && typeof pointA.y !== undefined) ? pointA.y : pointA;
40
65
  const yB = (pointB && pointB.y !== null && typeof pointB.y !== undefined) ? pointB.y : pointB;
41
66
 
42
- derivedSeries.data.push({
67
+ data.push({
43
68
  x: i,
44
- y: yA || yB,
69
+ y: yA + yB,
45
70
  name: pointA && pointA.name ? pointA.name : null,
46
71
  initialName: (pointA && pointA.name) ? pointA.name : 'Point ' + (i + 1),
47
72
  type: yA ? "SQ_Actuals" : "Forecast",
48
73
  });
49
74
  }
50
75
 
51
- return derivedSeries;
76
+ return {
77
+ name: "Forecast Smart Query",
78
+ data,
79
+ zoneAxis: "x",
80
+ zones: [
81
+ { value: cutoffIndex - midMonthOffset, dashStyle: actuals },
82
+ { dashStyle: forecast },
83
+ ],
84
+ };
52
85
  }
53
86
 
54
-
55
87
  module.exports = {
56
88
  createSingleDataSeriesForForecast,
57
89
  };