@datarailsshared/dr_renderer 1.3.35 → 1.3.38
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
@@ -2,6 +2,7 @@ const helpers = require('./dr-renderer-helpers');
|
|
2
2
|
const { DrGaugeChart, GAUGE_OPTIONS_DEFAULT } = require('./charts/dr_gauge_chart');
|
3
3
|
const { DrDonutChart } = require('./charts/dr_donut_chart');
|
4
4
|
const seriesPointStylesHelper= require('./seriesPointStyles-helper');
|
5
|
+
const smartQueriesHelper = require('./smart_queries_helper');
|
5
6
|
const {DrGaugeCategoriesSummaryChart} = require("./charts/dr_gauge_categories_summary_chart");
|
6
7
|
|
7
8
|
const mobileBrowserRegex = new RegExp([
|
@@ -401,6 +402,21 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
401
402
|
return {};
|
402
403
|
};
|
403
404
|
|
405
|
+
const isChartTypeSupportedForSmartQuery = (type) => {
|
406
|
+
if (!type) return null;
|
407
|
+
return [
|
408
|
+
'line',
|
409
|
+
'spline',
|
410
|
+
'area',
|
411
|
+
'areaspline',
|
412
|
+
highchartsRenderer.CHART_TYPES.LINE_CHART,
|
413
|
+
highchartsRenderer.CHART_TYPES.LINE_CHART_SMOOTH,
|
414
|
+
highchartsRenderer.CHART_TYPES.AREA_CHART,
|
415
|
+
highchartsRenderer.CHART_TYPES.AREA_CHART_SMOOTH,
|
416
|
+
].includes(type);
|
417
|
+
};
|
418
|
+
|
419
|
+
|
404
420
|
const chartHasVerticalDataLabelsOption = (type) => {
|
405
421
|
return ![
|
406
422
|
highchartsRenderer.CHART_TYPES.LINE_CHART,
|
@@ -1404,6 +1420,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1404
1420
|
chart_series = chart_series.concat(trendSerieses);
|
1405
1421
|
|
1406
1422
|
highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts, opts.total && opts.totalSeriesSettings && opts.totalSeriesSettings.secondaryAxis);
|
1423
|
+
|
1424
|
+
const chartType = chartOptions && chartOptions.chart && chartOptions.chart.type ? chartOptions.chart.type : null;
|
1425
|
+
const smartQuerySeries = isChartTypeSupportedForSmartQuery(chartType)
|
1426
|
+
? smartQueriesHelper.createSingleDataSeriesForForecast(chart_series, opts.chartOptions)
|
1427
|
+
: null;
|
1428
|
+
|
1429
|
+
if (smartQuerySeries) {
|
1430
|
+
chart_series.push(smartQuerySeries);
|
1431
|
+
lodash.remove(chart_series, s =>
|
1432
|
+
(s.name && lodash.includes(s.name, 'SQ_Actuals')) || s.name === 'Forecast'
|
1433
|
+
);
|
1434
|
+
}
|
1407
1435
|
|
1408
1436
|
return chart_series;
|
1409
1437
|
};
|
@@ -6610,7 +6638,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
6610
6638
|
value_name: 'showAllLegends',
|
6611
6639
|
element_label: 'Show legends over 10',
|
6612
6640
|
default_value: false
|
6613
|
-
}
|
6641
|
+
},
|
6642
|
+
{
|
6643
|
+
element_type: 'devider',
|
6644
|
+
element_label: 'Chart Patterns',
|
6645
|
+
showFn: isChartTypeSupportedForSmartQuery
|
6646
|
+
},
|
6647
|
+
{
|
6648
|
+
element_type: 'toggle',
|
6649
|
+
element_label: 'Smart Queries',
|
6650
|
+
value_name: 'smart_query',
|
6651
|
+
default_value: true,
|
6652
|
+
showFn: isChartTypeSupportedForSmartQuery
|
6653
|
+
},
|
6654
|
+
{
|
6655
|
+
element_type: 'select',
|
6656
|
+
value_name: 'actuals',
|
6657
|
+
element_label: 'Actuals',
|
6658
|
+
element_options: [
|
6659
|
+
{label: 'Solid', value: 'solid'},
|
6660
|
+
{label: 'Dash', value: 'dash'},
|
6661
|
+
],
|
6662
|
+
default_value: 'Solid',
|
6663
|
+
showFn: isChartTypeSupportedForSmartQuery
|
6664
|
+
},
|
6665
|
+
{
|
6666
|
+
element_type: 'select',
|
6667
|
+
value_name: 'forecast',
|
6668
|
+
element_label: 'Forecast',
|
6669
|
+
element_options: [
|
6670
|
+
{label: 'Solid', value: 'solid'},
|
6671
|
+
{label: 'Dash', value: 'dash'},
|
6672
|
+
],
|
6673
|
+
default_value: 'Dash',
|
6674
|
+
showFn: isChartTypeSupportedForSmartQuery
|
6675
|
+
}
|
6676
|
+
]
|
6614
6677
|
},
|
6615
6678
|
'total_value_label_donut': {
|
6616
6679
|
category_class: 'google-visualization-charteditor-mini-more',
|
@@ -9802,6 +9865,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9802
9865
|
e.point = lodash.cloneDeep(e.point);
|
9803
9866
|
e.point.name = e.point.initialName;
|
9804
9867
|
e.point.series.name = lodash.get(e.point.series, 'userOptions.initialName', e.point.series.name);
|
9868
|
+
const seriesData = lodash.get(e.point.series, 'userOptions.data');
|
9869
|
+
const initialNameForSmartQueries = seriesData
|
9870
|
+
? lodash.find(seriesData, obj => obj.name === e.point.name)
|
9871
|
+
: null;
|
9872
|
+
|
9873
|
+
if (initialNameForSmartQueries && initialNameForSmartQueries.type) {
|
9874
|
+
e.point.series.name = initialNameForSmartQueries.type;
|
9875
|
+
}
|
9805
9876
|
lodash.set(e, 'point.category.userOptions', e.point.initialName.toString().split(highchartsRenderer.delimer));
|
9806
9877
|
}
|
9807
9878
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
const lodash = require('lodash');
|
2
|
+
|
3
|
+
function createSingleDataSeriesForForecast(chart_series, chartOptions) {
|
4
|
+
const { actuals, forecast, smart_query } = chartOptions.chart;
|
5
|
+
|
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
|
+
});
|
12
|
+
|
13
|
+
if (!seriesA || !seriesB || !smart_query) return null;
|
14
|
+
|
15
|
+
const indexOfForecastFirstZero = lodash.findIndex(seriesB.data, function(value) {
|
16
|
+
return value.y === 0;
|
17
|
+
});
|
18
|
+
const indexOfActualsFirstZero = lodash.findIndex(seriesA.data, function(value) {
|
19
|
+
return value.y === 0;
|
20
|
+
});
|
21
|
+
const cutoffIndex = Math.max(indexOfForecastFirstZero, indexOfActualsFirstZero);
|
22
|
+
|
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
|
+
|
33
|
+
const minLength = Math.min(seriesA.data.length, seriesB.data.length);
|
34
|
+
|
35
|
+
for (let i = 0; i < minLength; i++) {
|
36
|
+
const pointA = seriesA.data[i];
|
37
|
+
const pointB = seriesB.data[i];
|
38
|
+
|
39
|
+
const yA = (pointA && pointA.y !== null && typeof pointA.y !== undefined) ? pointA.y : pointA;
|
40
|
+
const yB = (pointB && pointB.y !== null && typeof pointB.y !== undefined) ? pointB.y : pointB;
|
41
|
+
|
42
|
+
derivedSeries.data.push({
|
43
|
+
x: i,
|
44
|
+
y: yA || yB,
|
45
|
+
name: pointA && pointA.name ? pointA.name : null,
|
46
|
+
initialName: (pointA && pointA.name) ? pointA.name : 'Point ' + (i + 1),
|
47
|
+
type: yA ? "SQ_Actuals" : "Forecast",
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
return derivedSeries;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
module.exports = {
|
56
|
+
createSingleDataSeriesForForecast,
|
57
|
+
};
|
@@ -7082,7 +7082,11 @@ describe('highcharts_renderer', () => {
|
|
7082
7082
|
"#70000a"
|
7083
7083
|
];
|
7084
7084
|
opts = {};
|
7085
|
-
chartOptions = {
|
7085
|
+
chartOptions = {
|
7086
|
+
chart: {
|
7087
|
+
type: '',
|
7088
|
+
}
|
7089
|
+
};
|
7086
7090
|
pivotDataMock = {
|
7087
7091
|
getAggregator: (rows, cols) => {
|
7088
7092
|
let aggregator = highchartsRenderer.rhPivotAggregatorSum([''], format, true, {}, {});
|