@datarailsshared/dr_renderer 1.3.35 → 1.3.37

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.35",
3
+ "version": "1.3.37",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -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,20 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
401
402
  return {};
402
403
  };
403
404
 
405
+ const isChartTypeSupportedForSmartQuery = (type) => {
406
+ return [
407
+ 'line',
408
+ 'spline',
409
+ 'area',
410
+ 'areaspline',
411
+ highchartsRenderer.CHART_TYPES.LINE_CHART,
412
+ highchartsRenderer.CHART_TYPES.LINE_CHART_SMOOTH,
413
+ highchartsRenderer.CHART_TYPES.AREA_CHART,
414
+ highchartsRenderer.CHART_TYPES.AREA_CHART_SMOOTH,
415
+ ].includes(type);
416
+ };
417
+
418
+
404
419
  const chartHasVerticalDataLabelsOption = (type) => {
405
420
  return ![
406
421
  highchartsRenderer.CHART_TYPES.LINE_CHART,
@@ -1404,6 +1419,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1404
1419
  chart_series = chart_series.concat(trendSerieses);
1405
1420
 
1406
1421
  highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts, opts.total && opts.totalSeriesSettings && opts.totalSeriesSettings.secondaryAxis);
1422
+
1423
+ const smartQuerySeries = isChartTypeSupportedForSmartQuery(chartOptions.chart.type)
1424
+ ? smartQueriesHelper.createSingleDataSeriesForForecast(chart_series, opts.chartOptions)
1425
+ : null;
1426
+
1427
+ if (smartQuerySeries) {
1428
+ chart_series.push(smartQuerySeries);
1429
+ lodash.remove(chart_series, s =>
1430
+ (s.name && lodash.includes(s.name, 'SQ_Actuals')) || s.name === 'Forecast'
1431
+ );
1432
+ }
1407
1433
 
1408
1434
  return chart_series;
1409
1435
  };
@@ -6610,7 +6636,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6610
6636
  value_name: 'showAllLegends',
6611
6637
  element_label: 'Show legends over 10',
6612
6638
  default_value: false
6613
- }]
6639
+ },
6640
+ {
6641
+ element_type: 'devider',
6642
+ element_label: 'Chart Patterns',
6643
+ showFn: isChartTypeSupportedForSmartQuery
6644
+ },
6645
+ {
6646
+ element_type: 'toggle',
6647
+ element_label: 'Smart Queries',
6648
+ value_name: 'smart_query',
6649
+ default_value: true,
6650
+ showFn: isChartTypeSupportedForSmartQuery
6651
+ },
6652
+ {
6653
+ element_type: 'select',
6654
+ value_name: 'actuals',
6655
+ element_label: 'Actuals',
6656
+ element_options: [
6657
+ {label: 'Solid', value: 'solid'},
6658
+ {label: 'Dash', value: 'dash'},
6659
+ ],
6660
+ default_value: 'Solid',
6661
+ showFn: isChartTypeSupportedForSmartQuery
6662
+ },
6663
+ {
6664
+ element_type: 'select',
6665
+ value_name: 'forecast',
6666
+ element_label: 'Forecast',
6667
+ element_options: [
6668
+ {label: 'Solid', value: 'solid'},
6669
+ {label: 'Dash', value: 'dash'},
6670
+ ],
6671
+ default_value: 'Dash',
6672
+ showFn: isChartTypeSupportedForSmartQuery
6673
+ }
6674
+ ]
6614
6675
  },
6615
6676
  'total_value_label_donut': {
6616
6677
  category_class: 'google-visualization-charteditor-mini-more',
@@ -9802,6 +9863,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9802
9863
  e.point = lodash.cloneDeep(e.point);
9803
9864
  e.point.name = e.point.initialName;
9804
9865
  e.point.series.name = lodash.get(e.point.series, 'userOptions.initialName', e.point.series.name);
9866
+ const seriesData = lodash.get(e.point.series, 'userOptions.data');
9867
+ const initialNameForSmartQueries = seriesData
9868
+ ? lodash.find(seriesData, obj => obj.name === e.point.name)
9869
+ : null;
9870
+
9871
+ if (initialNameForSmartQueries && initialNameForSmartQueries.type) {
9872
+ e.point.series.name = initialNameForSmartQueries.type;
9873
+ }
9805
9874
  lodash.set(e, 'point.category.userOptions', e.point.initialName.toString().split(highchartsRenderer.delimer));
9806
9875
  }
9807
9876
 
@@ -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, {}, {});