ng-prime-tools 1.0.96 → 1.0.97

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.
@@ -4223,14 +4223,24 @@ const createDefaultChartOptions = (chartType, theme, config) => {
4223
4223
  label: (context) => config.tooltipLabel(context, isCircularChart),
4224
4224
  },
4225
4225
  },
4226
+ /*
4227
+ * Do not use `display: isCircularChart`.
4228
+ * For non-circular charts, this plugin version can still enter
4229
+ * its drawing lifecycle and throw `undefined.length`.
4230
+ */
4226
4231
  datalabels: {
4227
- display: isCircularChart,
4232
+ display: () => isCircularChart,
4228
4233
  color: theme.textColor,
4229
4234
  anchor: isCircularChart ? 'center' : 'end',
4230
4235
  align: isCircularChart ? 'center' : 'top',
4231
4236
  clamp: true,
4232
4237
  clip: false,
4233
- formatter: (value, context) => config.dataLabel(value, context, isCircularChart),
4238
+ formatter: (value, context) => {
4239
+ if (!isCircularChart) {
4240
+ return '';
4241
+ }
4242
+ return config.dataLabel(value, context, true);
4243
+ },
4234
4244
  font: {
4235
4245
  family: config.fontFamily,
4236
4246
  size: PT_CHART_FONT_SIZES.dataLabel,
@@ -4322,7 +4332,11 @@ class PTChartComponent {
4322
4332
  this.colorSchemeChangeListener = () => {
4323
4333
  this.refreshTheme();
4324
4334
  };
4325
- Chart.register(...registerables, ChartDataLabels);
4335
+ /*
4336
+ * Do not register ChartDataLabels globally.
4337
+ * It must only be enabled for pie, doughnut and polar-area charts.
4338
+ */
4339
+ Chart.register(...registerables);
4326
4340
  }
4327
4341
  ngAfterViewInit() {
4328
4342
  this.viewInitialized = true;
@@ -4355,10 +4369,9 @@ class PTChartComponent {
4355
4369
  if (!this.viewInitialized || !this.chartConfig) {
4356
4370
  return;
4357
4371
  }
4358
- const canvas = this.canvasRef.nativeElement;
4359
4372
  this.destroyChart();
4360
4373
  const configuration = this.buildChartConfiguration();
4361
- this.chart = new Chart(canvas, configuration);
4374
+ this.chart = new Chart(this.canvasRef.nativeElement, configuration);
4362
4375
  this.currentChartType = this.chartConfig.type;
4363
4376
  this.scheduleChartResize();
4364
4377
  }
@@ -4392,6 +4405,12 @@ class PTChartComponent {
4392
4405
  type: chartType,
4393
4406
  data: this.cloneChartData(this.chartConfig.data),
4394
4407
  options: this.mergeChartOptions(defaultOptions, consumerOptions, chartType),
4408
+ /*
4409
+ * ChartDataLabels is attached only for circular charts.
4410
+ * It is not registered globally, so it cannot break line,
4411
+ * bar, scatter, bubble or comparison charts.
4412
+ */
4413
+ plugins: isCircularChartType(chartType) ? [ChartDataLabels] : [],
4395
4414
  };
4396
4415
  }
4397
4416
  buildDefaultOptions(chartType, theme) {
@@ -4465,12 +4484,21 @@ class PTChartComponent {
4465
4484
  ...consumerPlugins?.tooltip?.callbacks,
4466
4485
  },
4467
4486
  },
4487
+ },
4488
+ };
4489
+ /*
4490
+ * Add datalabel options only to circular charts.
4491
+ * For Cartesian charts, the plugin is not installed at all.
4492
+ */
4493
+ if (isCircularChartType(chartType)) {
4494
+ mergedOptions.plugins = {
4495
+ ...mergedOptions.plugins,
4468
4496
  datalabels: {
4469
4497
  ...defaultPlugins?.datalabels,
4470
4498
  ...consumerPlugins?.datalabels,
4471
4499
  },
4472
- },
4473
- };
4500
+ };
4501
+ }
4474
4502
  if (isCartesianChartType(chartType)) {
4475
4503
  mergedOptions.scales = this.mergeScales(defaultOptions.scales, consumerOptions.scales);
4476
4504
  }
@@ -7765,7 +7793,11 @@ class PTChartComparisonComponent {
7765
7793
  this.xAxisTitle = PT_CHART_COMPARISON_DEFAULT_X_AXIS_TITLE;
7766
7794
  this.yAxisTitle = PT_CHART_COMPARISON_DEFAULT_Y_AXIS_TITLE;
7767
7795
  this.viewInitialized = false;
7768
- Chart.register(...registerables, ChartDataLabels);
7796
+ /*
7797
+ * Do not register ChartDataLabels here.
7798
+ * PTChartComparison is a line/comparison chart and does not use it.
7799
+ */
7800
+ Chart.register(...registerables);
7769
7801
  }
7770
7802
  ngAfterViewInit() {
7771
7803
  this.viewInitialized = true;
@@ -7807,19 +7839,19 @@ class PTChartComparisonComponent {
7807
7839
  if (!this.chartConfig || !this.canvasRef) {
7808
7840
  return;
7809
7841
  }
7810
- const canvas = this.canvasRef.nativeElement;
7811
7842
  this.destroyChart();
7812
7843
  const configuration = {
7813
7844
  type: this.chartConfig.type || 'line',
7814
7845
  data: this.getFormattedChartData(),
7815
7846
  options: this.getChartOptions(),
7816
7847
  };
7817
- this.chart = new Chart(canvas, configuration);
7848
+ this.chart = new Chart(this.canvasRef.nativeElement, configuration);
7818
7849
  this.scheduleResize();
7819
7850
  }
7820
7851
  getFormattedChartData() {
7852
+ const sourceDatasets = this.chartConfig.data.datasets ?? [];
7821
7853
  return {
7822
- labels: this.chartConfig.data.labels,
7854
+ labels: [...(this.chartConfig.data.labels ?? [])],
7823
7855
  datasets: [
7824
7856
  {
7825
7857
  label: this.chartConfig.medianTitle?.trim() ||
@@ -7828,7 +7860,10 @@ class PTChartComparisonComponent {
7828
7860
  data: this.calculateMedian(),
7829
7861
  ...PT_CHART_COMPARISON_MEDIAN_DATASET,
7830
7862
  },
7831
- ...this.chartConfig.data.datasets,
7863
+ ...sourceDatasets.map((dataset) => ({
7864
+ ...dataset,
7865
+ data: [...(dataset.data ?? [])],
7866
+ })),
7832
7867
  ],
7833
7868
  };
7834
7869
  }
@@ -7837,7 +7872,7 @@ class PTChartComparisonComponent {
7837
7872
  const labels = this.chartConfig.data.labels ?? [];
7838
7873
  return labels.map((_, index) => {
7839
7874
  const valuesAtTime = datasets
7840
- .map((dataset) => dataset.data[index])
7875
+ .map((dataset) => dataset.data?.[index])
7841
7876
  .filter((value) => typeof value === 'number' && Number.isFinite(value))
7842
7877
  .sort((left, right) => left - right);
7843
7878
  if (!valuesAtTime.length) {
@@ -7862,6 +7897,11 @@ class PTChartComparisonComponent {
7862
7897
  ...externalOptions,
7863
7898
  responsive: true,
7864
7899
  maintainAspectRatio: false,
7900
+ interaction: {
7901
+ mode: 'index',
7902
+ intersect: false,
7903
+ ...(externalOptions.interaction ?? {}),
7904
+ },
7865
7905
  plugins: {
7866
7906
  ...externalPlugins,
7867
7907
  legend: {
@@ -7870,13 +7910,10 @@ class PTChartComparisonComponent {
7870
7910
  ...(externalPlugins.legend ?? {}),
7871
7911
  },
7872
7912
  tooltip: {
7913
+ enabled: true,
7873
7914
  ...PT_CHART_COMPARISON_DEFAULT_TOOLTIP,
7874
7915
  ...(externalPlugins.tooltip ?? {}),
7875
7916
  },
7876
- datalabels: {
7877
- display: false,
7878
- ...(externalPlugins.datalabels ?? {}),
7879
- },
7880
7917
  },
7881
7918
  scales: {
7882
7919
  x: {