@c8y/ngx-components 1023.81.3 → 1023.82.1

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.
@@ -105,12 +105,14 @@ class YAxisService {
105
105
  constructor(appStateService) {
106
106
  this.appStateService = appStateService;
107
107
  this.Y_AXIS_OFFSET = 48;
108
+ this.Y_AXIS_OFFSET_WITH_DP_VALUES = 22;
109
+ this.Y_AXIS_OFFSET_WITHOUT_DP_VALUES = 15;
108
110
  this.intlNumberFormatCompliantLocale = this.appStateService.state.lang.replace('_', '-');
109
111
  }
110
112
  getYAxis(datapointsWithValues, YAxisOptions) {
111
113
  const YAxisPlacement = this.getYAxisPlacement(datapointsWithValues, YAxisOptions);
112
- const hasValues = datapointsWithValues.some(dp => dp.values && Object.keys(dp.values).length > 0);
113
- const nameGap = hasValues ? 22 : 15;
114
+ const hasValues = dp => dp.values && Object.keys(dp.values).length > 0;
115
+ const anyDpHasValues = datapointsWithValues.some(dp => hasValues(dp));
114
116
  if (YAxisOptions.forceMergeDatapoints) {
115
117
  return {
116
118
  name: Array.from(datapointsWithValues)
@@ -120,7 +122,9 @@ class YAxisService {
120
122
  nameTruncate: {
121
123
  maxWidth: 350
122
124
  },
123
- nameGap,
125
+ nameGap: anyDpHasValues
126
+ ? this.Y_AXIS_OFFSET_WITH_DP_VALUES
127
+ : this.Y_AXIS_OFFSET_WITHOUT_DP_VALUES,
124
128
  nameTextStyle: {
125
129
  // add rich text to support multiple colors for different dp units
126
130
  rich: this.buildRichTextStyle(datapointsWithValues)
@@ -187,7 +191,9 @@ class YAxisService {
187
191
  nameTruncate: {
188
192
  maxWidth: 350
189
193
  },
190
- nameGap,
194
+ nameGap: hasValues(dp)
195
+ ? this.Y_AXIS_OFFSET_WITH_DP_VALUES
196
+ : this.Y_AXIS_OFFSET_WITHOUT_DP_VALUES,
191
197
  nameTextStyle: {
192
198
  rich: this.buildRichTextStyle(uniqueUnitDps)
193
199
  },
@@ -576,8 +582,8 @@ class EchartsOptionsService {
576
582
  show: false
577
583
  },
578
584
  xAxis: {
579
- min: Object.keys(aggregatedDatapoint.values || {}).length > 0
580
- ? Math.min(Object.keys(aggregatedDatapoint.values)
585
+ min: Object.keys(aggregatedDatapoint?.values || {}).length > 0
586
+ ? Math.min(Object.keys(aggregatedDatapoint?.values || {})
581
587
  .map(date => new Date(date).valueOf())
582
588
  .sort((a, b) => a - b)[0], new Date(timeRange.dateFrom).valueOf())
583
589
  : new Date(timeRange.dateFrom).valueOf() - intervalInMs,
@@ -673,6 +679,9 @@ class EchartsOptionsService {
673
679
  return intervalInMs;
674
680
  }
675
681
  getAggregatedSeries(aggregatedDatapoint, displayOptions) {
682
+ if (!aggregatedDatapoint) {
683
+ return { type: 'line', data: [], id: 'aggregated-empty' };
684
+ }
676
685
  const series = [];
677
686
  const renderType = aggregatedDatapoint?.renderType || 'min';
678
687
  const idx = 0;
@@ -2641,17 +2650,19 @@ class ChartsComponent {
2641
2650
  });
2642
2651
  const extendedDateFrom = new Date(new Date(timeRange.dateFrom).valueOf() - extendedIntervalMs).toISOString();
2643
2652
  this.widgetTimeContextDateRangeService.updateInitialTimeRange(timeRange);
2644
- const aggregatedDatapoints = await lastValueFrom(this.fetchAggregatedSeriesForSelectedDatapoint$({
2645
- dateFrom: extendedDateFrom,
2646
- dateTo: timeRange.dateTo
2647
- }, this.config.aggregatedDatapoint));
2653
+ const aggregatedDatapoint = this.config.showSlider
2654
+ ? await lastValueFrom(this.fetchAggregatedSeriesForSelectedDatapoint$({
2655
+ dateFrom: extendedDateFrom,
2656
+ dateTo: timeRange.dateTo
2657
+ }, this.config.aggregatedDatapoint))
2658
+ : undefined;
2648
2659
  return this.echartsOptionsService.getChartOptions(datapointsWithValues, timeRange, {
2649
2660
  YAxis: this.config.yAxisSplitLines || false,
2650
2661
  XAxis: this.config.xAxisSplitLines || false
2651
2662
  }, this.events, this.alarms, {
2652
2663
  sliderPositionMode,
2653
2664
  ...this.displayOptions
2654
- }, undefined, aggregatedDatapoints);
2665
+ }, undefined, aggregatedDatapoint);
2655
2666
  }
2656
2667
  else {
2657
2668
  const cachedTimeRange = this.widgetTimeContextDateRangeService.initialTimeRange();
@@ -2661,10 +2672,12 @@ class ChartsComponent {
2661
2672
  dateTo: cachedTimeRange.dateTo
2662
2673
  });
2663
2674
  const initialExtendedDateFrom = new Date(initialDateFromValue - calculateInitialIntervalInMs).toISOString();
2664
- const aggregatedDatapoints = await lastValueFrom(this.fetchAggregatedSeriesForSelectedDatapoint$({
2665
- dateFrom: initialExtendedDateFrom,
2666
- dateTo: new Date(this.widgetTimeContextDateRangeService.initialTimeRange().dateTo).toISOString()
2667
- }, this.config.aggregatedDatapoint));
2675
+ const aggregatedDatapoint = this.config.showSlider
2676
+ ? await lastValueFrom(this.fetchAggregatedSeriesForSelectedDatapoint$({
2677
+ dateFrom: initialExtendedDateFrom,
2678
+ dateTo: new Date(this.widgetTimeContextDateRangeService.initialTimeRange().dateTo).toISOString()
2679
+ }, this.config.aggregatedDatapoint))
2680
+ : undefined;
2668
2681
  // we need to update the initial time range by adding the refresh interval to the dateFrom and dateTo
2669
2682
  const initialTimeRange = this.widgetTimeContextDateRangeService.initialTimeRange();
2670
2683
  // needed due to a race condition where the time range is updated before the chart options are fetched...
@@ -2683,7 +2696,7 @@ class ChartsComponent {
2683
2696
  }, this.events, this.alarms, {
2684
2697
  sliderPositionMode,
2685
2698
  ...this.displayOptions
2686
- }, timeRange, aggregatedDatapoints, true);
2699
+ }, timeRange, aggregatedDatapoint, true);
2687
2700
  }
2688
2701
  }
2689
2702
  fetchSeriesForDatapoints$() {