@datarailsshared/dr_renderer 1.3.40 → 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
@@ -1420,14 +1420,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1420
1420
|
|
1421
1421
|
const chartType = chartOptions && chartOptions.chart && chartOptions.chart.type ? chartOptions.chart.type : null;
|
1422
1422
|
const smartQuerySeries = isChartTypeSupportedForSmartQuery(chartType)
|
1423
|
-
? smartQueriesHelper.createSingleDataSeriesForForecast(chart_series, opts.chartOptions)
|
1423
|
+
? smartQueriesHelper.createSingleDataSeriesForForecast(chart_series, opts.chartOptions, pivotData)
|
1424
1424
|
: null;
|
1425
1425
|
|
1426
1426
|
if (smartQuerySeries) {
|
1427
|
-
chart_series.
|
1428
|
-
|
1427
|
+
if (chart_series.length > 1) {
|
1428
|
+
lodash.remove(chart_series, s =>
|
1429
1429
|
(s.name && lodash.includes(s.name, 'SQ_Actuals')) || s.name === 'Forecast'
|
1430
|
-
|
1430
|
+
);
|
1431
|
+
} else {
|
1432
|
+
chart_series = []
|
1433
|
+
}
|
1434
|
+
chart_series.push(smartQuerySeries);
|
1431
1435
|
}
|
1432
1436
|
|
1433
1437
|
return chart_series;
|
@@ -9913,9 +9917,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9913
9917
|
const initialNameForSmartQueries = seriesData
|
9914
9918
|
? lodash.find(seriesData, obj => obj.name === e.point.name)
|
9915
9919
|
: null;
|
9916
|
-
|
9917
9920
|
if (initialNameForSmartQueries && initialNameForSmartQueries.type) {
|
9918
|
-
e.point.series.name = initialNameForSmartQueries.type;
|
9921
|
+
e.point.series.name = initialNameForSmartQueries.type === "SQ_Actuals" ? 'Actuals' : 'Forecast';
|
9919
9922
|
}
|
9920
9923
|
lodash.set(e, 'point.category.userOptions', e.point.initialName.toString().split(highchartsRenderer.delimer));
|
9921
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
|
7
|
-
|
8
|
-
|
9
|
-
const
|
10
|
-
|
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
|
-
|
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
|
-
|
67
|
+
data.push({
|
43
68
|
x: i,
|
44
|
-
y: yA
|
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
|
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
|
};
|