@eclipse-scout/chart 22.0.41 → 23.1.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.
Files changed (130) hide show
  1. package/LICENSE +277 -0
  2. package/README.md +4 -8
  3. package/dist/d.ts/chart/AbstractChartRenderer.d.ts +48 -0
  4. package/dist/d.ts/chart/AbstractChartRenderer.d.ts.map +1 -0
  5. package/dist/d.ts/chart/AbstractSvgChartRenderer.d.ts +65 -0
  6. package/dist/d.ts/chart/AbstractSvgChartRenderer.d.ts.map +1 -0
  7. package/dist/d.ts/chart/Chart.d.ts +162 -0
  8. package/dist/d.ts/chart/Chart.d.ts.map +1 -0
  9. package/dist/d.ts/chart/ChartAdapter.d.ts +8 -0
  10. package/dist/d.ts/chart/ChartAdapter.d.ts.map +1 -0
  11. package/dist/d.ts/chart/ChartEventMap.d.ts +16 -0
  12. package/dist/d.ts/chart/ChartEventMap.d.ts.map +1 -0
  13. package/dist/d.ts/chart/ChartJsRenderer.d.ts +299 -0
  14. package/dist/d.ts/chart/ChartJsRenderer.d.ts.map +1 -0
  15. package/dist/d.ts/chart/ChartLayout.d.ts +8 -0
  16. package/dist/d.ts/chart/ChartLayout.d.ts.map +1 -0
  17. package/dist/d.ts/chart/ChartModel.d.ts +11 -0
  18. package/dist/d.ts/chart/ChartModel.d.ts.map +1 -0
  19. package/dist/d.ts/chart/FulfillmentChartRenderer.d.ts +22 -0
  20. package/dist/d.ts/chart/FulfillmentChartRenderer.d.ts.map +1 -0
  21. package/dist/d.ts/chart/SalesfunnelChartRenderer.d.ts +61 -0
  22. package/dist/d.ts/chart/SalesfunnelChartRenderer.d.ts.map +1 -0
  23. package/dist/d.ts/chart/SpeedoChartRenderer.d.ts +90 -0
  24. package/dist/d.ts/chart/SpeedoChartRenderer.d.ts.map +1 -0
  25. package/dist/d.ts/chart/VennAsync3Calculator.d.ts +32 -0
  26. package/dist/d.ts/chart/VennAsync3Calculator.d.ts.map +1 -0
  27. package/dist/d.ts/chart/VennChartRenderer.d.ts +36 -0
  28. package/dist/d.ts/chart/VennChartRenderer.d.ts.map +1 -0
  29. package/dist/d.ts/chart/VennCircle.d.ts +20 -0
  30. package/dist/d.ts/chart/VennCircle.d.ts.map +1 -0
  31. package/dist/d.ts/chart/VennCircleHelper.d.ts +13 -0
  32. package/dist/d.ts/chart/VennCircleHelper.d.ts.map +1 -0
  33. package/dist/d.ts/form/fields/chartfield/ChartField.d.ts +11 -0
  34. package/dist/d.ts/form/fields/chartfield/ChartField.d.ts.map +1 -0
  35. package/dist/d.ts/form/fields/chartfield/ChartFieldAdapter.d.ts +4 -0
  36. package/dist/d.ts/form/fields/chartfield/ChartFieldAdapter.d.ts.map +1 -0
  37. package/dist/d.ts/form/fields/chartfield/ChartFieldModel.d.ts +6 -0
  38. package/dist/d.ts/form/fields/chartfield/ChartFieldModel.d.ts.map +1 -0
  39. package/dist/d.ts/index.d.ts +31 -0
  40. package/dist/d.ts/index.d.ts.map +1 -0
  41. package/dist/d.ts/table/controls/ChartTableControl.d.ts +136 -0
  42. package/dist/d.ts/table/controls/ChartTableControl.d.ts.map +1 -0
  43. package/dist/d.ts/table/controls/ChartTableControlAdapter.d.ts +5 -0
  44. package/dist/d.ts/table/controls/ChartTableControlAdapter.d.ts.map +1 -0
  45. package/dist/d.ts/table/controls/ChartTableControlEventMap.d.ts +9 -0
  46. package/dist/d.ts/table/controls/ChartTableControlEventMap.d.ts.map +1 -0
  47. package/dist/d.ts/table/controls/ChartTableControlLayout.d.ts +8 -0
  48. package/dist/d.ts/table/controls/ChartTableControlLayout.d.ts.map +1 -0
  49. package/dist/d.ts/table/controls/ChartTableControlModel.d.ts +9 -0
  50. package/dist/d.ts/table/controls/ChartTableControlModel.d.ts.map +1 -0
  51. package/dist/d.ts/table/controls/ChartTableUserFilter.d.ts +28 -0
  52. package/dist/d.ts/table/controls/ChartTableUserFilter.d.ts.map +1 -0
  53. package/dist/d.ts/table/controls/ChartTableUserFilterModel.d.ts +11 -0
  54. package/dist/d.ts/table/controls/ChartTableUserFilterModel.d.ts.map +1 -0
  55. package/dist/d.ts/tile/ChartFieldTile.d.ts +14 -0
  56. package/dist/d.ts/tile/ChartFieldTile.d.ts.map +1 -0
  57. package/dist/d.ts/tile/ChartFieldTileAdapter.d.ts +4 -0
  58. package/dist/d.ts/tile/ChartFieldTileAdapter.d.ts.map +1 -0
  59. package/dist/d.ts/tile/ChartFieldTileModel.d.ts +6 -0
  60. package/dist/d.ts/tile/ChartFieldTileModel.d.ts.map +1 -0
  61. package/dist/eclipse-scout-chart-fae6f958a044232e659c.min.js +3 -0
  62. package/dist/eclipse-scout-chart-fae6f958a044232e659c.min.js.map +1 -0
  63. package/dist/eclipse-scout-chart-theme-56ba6667e592ef147869.min.css +1 -0
  64. package/dist/eclipse-scout-chart-theme-dark-593955eea95984c5aa62.min.css +1 -0
  65. package/dist/eclipse-scout-chart-theme-dark.css +53 -59
  66. package/dist/eclipse-scout-chart-theme-dark.css.map +1 -1
  67. package/dist/eclipse-scout-chart-theme.css +41 -45
  68. package/dist/eclipse-scout-chart-theme.css.map +1 -1
  69. package/dist/eclipse-scout-chart.esm-2119cfea86a9d6f34a35.min.js +3 -0
  70. package/dist/eclipse-scout-chart.esm-2119cfea86a9d6f34a35.min.js.map +1 -0
  71. package/dist/eclipse-scout-chart.esm.js +6898 -0
  72. package/dist/eclipse-scout-chart.esm.js.map +1 -0
  73. package/dist/eclipse-scout-chart.js +737 -15226
  74. package/dist/eclipse-scout-chart.js.map +1 -1
  75. package/dist/file-list +8 -5
  76. package/dist/texts.json +17 -17
  77. package/package.json +22 -16
  78. package/src/chart/{AbstractChartRenderer.js → AbstractChartRenderer.ts} +36 -31
  79. package/src/chart/{AbstractSvgChartRenderer.js → AbstractSvgChartRenderer.ts} +82 -48
  80. package/src/chart/Chart.less +8 -8
  81. package/src/chart/{Chart.js → Chart.ts} +157 -68
  82. package/src/chart/ChartAdapter.ts +26 -0
  83. package/src/chart/ChartEventMap.ts +26 -0
  84. package/src/chart/{ChartJsRenderer.js → ChartJsRenderer.ts} +362 -357
  85. package/src/chart/{ChartLayout.js → ChartLayout.ts} +13 -13
  86. package/src/chart/ChartModel.ts +20 -0
  87. package/src/chart/{FulfillmentChartRenderer.js → FulfillmentChartRenderer.ts} +25 -23
  88. package/src/chart/{SalesfunnelChartRenderer.js → SalesfunnelChartRenderer.ts} +102 -66
  89. package/src/chart/{SpeedoChartRenderer.js → SpeedoChartRenderer.ts} +56 -43
  90. package/src/chart/{VennAsync3Calculator.js → VennAsync3Calculator.ts} +41 -18
  91. package/src/chart/{VennChartRenderer.js → VennChartRenderer.ts} +63 -40
  92. package/src/chart/VennCircle.ts +47 -0
  93. package/src/chart/{VennCircleHelper.js → VennCircleHelper.ts} +19 -14
  94. package/src/eclipse-scout-chart-theme-dark.less +7 -8
  95. package/src/eclipse-scout-chart-theme.less +7 -8
  96. package/src/form/fields/chartfield/ChartField.ts +44 -0
  97. package/src/form/fields/chartfield/ChartFieldAdapter.ts +13 -0
  98. package/src/form/fields/chartfield/ChartFieldModel.ts +15 -0
  99. package/src/index-dark.less +6 -7
  100. package/src/index.less +6 -7
  101. package/src/index.ts +45 -0
  102. package/src/style/colors-dark.less +7 -8
  103. package/src/style/colors.less +6 -7
  104. package/src/table/controls/ChartTableControl.less +6 -7
  105. package/src/table/controls/{ChartTableControl.js → ChartTableControl.ts} +164 -125
  106. package/src/table/controls/ChartTableControlAdapter.ts +18 -0
  107. package/src/table/controls/ChartTableControlEventMap.ts +18 -0
  108. package/src/table/controls/ChartTableControlLayout.ts +30 -0
  109. package/src/table/controls/ChartTableControlModel.ts +18 -0
  110. package/src/table/controls/ChartTableUserFilter.ts +84 -0
  111. package/src/table/controls/ChartTableUserFilterModel.ts +18 -0
  112. package/src/tile/ChartFieldTile.less +6 -7
  113. package/src/tile/ChartFieldTile.ts +51 -0
  114. package/src/tile/ChartFieldTileAdapter.ts +13 -0
  115. package/src/tile/ChartFieldTileModel.ts +15 -0
  116. package/dist/eclipse-scout-chart-8eb9461c14872058f638.min.js +0 -3
  117. package/dist/eclipse-scout-chart-8eb9461c14872058f638.min.js.LICENSE.txt +0 -6
  118. package/dist/eclipse-scout-chart-8eb9461c14872058f638.min.js.map +0 -1
  119. package/dist/eclipse-scout-chart-theme-79622289bda68b525e3e.min.css +0 -1
  120. package/dist/eclipse-scout-chart-theme-dark-1de09c03e3dc40a9529a.min.css +0 -1
  121. package/src/chart/ChartAdapter.js +0 -30
  122. package/src/chart/VennCircle.js +0 -41
  123. package/src/form/fields/chartfield/ChartField.js +0 -39
  124. package/src/form/fields/chartfield/ChartFieldAdapter.js +0 -19
  125. package/src/index.js +0 -36
  126. package/src/table/controls/ChartTableControlAdapter.js +0 -20
  127. package/src/table/controls/ChartTableControlLayout.js +0 -29
  128. package/src/table/controls/ChartTableUserFilter.js +0 -72
  129. package/src/tile/ChartFieldTile.js +0 -46
  130. package/src/tile/ChartFieldTileAdapter.js +0 -18
@@ -1,68 +1,25 @@
1
1
  /*
2
- * Copyright (c) 2010-2022 BSI Business Systems Integration AG.
3
- * All rights reserved. This program and the accompanying materials
4
- * are made available under the terms of the Eclipse Public License v1.0
5
- * which accompanies this distribution, and is available at
6
- * https://www.eclipse.org/legal/epl-v10.html
2
+ * Copyright (c) 2010, 2023 BSI Business Systems Integration AG
7
3
  *
8
- * Contributors:
9
- * BSI Business Systems Integration AG - initial API and implementation
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
10
9
  */
11
10
  import {AbstractChartRenderer, Chart} from '../index';
12
- import ChartJs from 'chart.js/auto';
13
- import {arrays, colorSchemes, Event, graphics, numbers, objects, scout, strings, styles, tooltips} from '@eclipse-scout/core';
14
- import ChartDataLabels from 'chartjs-plugin-datalabels';
11
+ import {
12
+ ActiveElement, ArcElement, BarElement, BubbleDataPoint, CartesianScaleOptions, Chart as ChartJs, ChartArea, ChartConfiguration, ChartDataset, ChartEvent, ChartType as ChartJsType, Color, DefaultDataPoint, FontSpec, LegendElement,
13
+ LegendItem, LegendOptions, LinearScaleOptions, PointElement, PointHoverOptions, PointOptions, PointProps, RadialLinearScaleOptions, Scale, ScatterDataPoint, TooltipCallbacks, TooltipItem, TooltipLabelStyle, TooltipModel, TooltipOptions
14
+ } from 'chart.js';
15
+ import 'chart.js/auto'; // Import from auto to register charts
16
+ import {arrays, colorSchemes, graphics, numbers, objects, scout, strings, styles, Tooltip, tooltips} from '@eclipse-scout/core';
17
+ import ChartDataLabels, {Context} from 'chartjs-plugin-datalabels';
15
18
  import $ from 'jquery';
19
+ import {ChartAxis, ChartConfig, ChartData, ChartType, ClickObject, NumberFormatter} from './Chart';
16
20
 
17
21
  ChartJs.register(ChartDataLabels);
18
22
 
19
- /**
20
- * @typedef CoreChartOptions
21
- * @property {number} [font.size]
22
- */
23
-
24
- /**
25
- * @typedef TickOptions
26
- * @property {number} maxRotation
27
- */
28
-
29
- /**
30
- * @typedef Scale
31
- * @property {number} labelRotation
32
- * @property {number} height
33
- * @property {object} _labelSizes
34
- * @property {object} _labelSizes.widest
35
- */
36
-
37
- /**
38
- * @typedef TooltipModel
39
- * @property {array} _tooltipItems
40
- */
41
-
42
- /**
43
- * @typedef ArcElement
44
- * @property {number} innerRadius
45
- * @property {number} outerRadius
46
- * @property {number} startAngle
47
- * @property {number} endAngle
48
- */
49
-
50
- /**
51
- * @typedef PointElement
52
- * @property {number} angle
53
- */
54
-
55
- /**
56
- * @typedef BarElement
57
- * @property {number} height
58
- * @property {number} width
59
- */
60
-
61
- /**
62
- * @typedef TooltipOptions
63
- * @property {string} titleFont.family
64
- */
65
-
66
23
  $.extend(true, ChartJs.defaults, {
67
24
  maintainAspectRatio: false,
68
25
  elements: {
@@ -87,7 +44,7 @@ $.extend(true, ChartJs.defaults, {
87
44
  legend: {
88
45
  labels: {
89
46
  usePointStyle: true,
90
- boxWidth: 7
47
+ boxHeight: 7
91
48
  }
92
49
  }
93
50
  }
@@ -112,44 +69,56 @@ $.extend(true, ChartJs.overrides, {
112
69
  let chartJsGlobalsInitialized = false;
113
70
  const PHI = (1 + Math.sqrt(5)) / 2; // golden ratio
114
71
 
115
- /**
116
- * @typedef Dataset
117
- * @property {string} [datasetId]
118
- * @property {array} [data]
119
- *
120
- * @property {array|string} [backgroundColor]
121
- * @property {array|string} [backgroundColorBackup]
122
- * @property {array|string} [hoverBackgroundColor]
123
- *
124
- * @property {array|string} [pointBackgroundColor]
125
- * @property {array|string} [pointHoverBackgroundColor]
126
- * @property {array|number} [pointRadius]
127
- *
128
- * @property {array|string} [uncheckedBackgroundColor]
129
- * @property {array|string} [uncheckedHoverBackgroundColor]
130
- * @property {array|string} [uncheckedPointBackgroundColor]
131
- * @property {array|string} [uncheckedPointHoverBackgroundColor]
132
- * @property {array|number} [uncheckedPointRadius]
133
- *
134
- * @property {array|string} [checkedBackgroundColor]
135
- * @property {array|string} [checkedHoverBackgroundColor]
136
- * @property {array|string} [checkedPointBackgroundColor]
137
- * @property {array|string} [checkedPointHoverBackgroundColor]
138
- * @property {array|number} [checkedPointRadius]
139
- *
140
- * @property {array|string} [legendColor]
141
- */
142
-
143
- export default class ChartJsRenderer extends AbstractChartRenderer {
144
-
72
+ export class ChartJsRenderer extends AbstractChartRenderer {
145
73
  static ARROW_LEFT_RIGHT = '\u2194';
146
74
  static ARROW_UP_DOWN = '\u2195';
147
75
 
148
- constructor(chart) {
76
+ chartJs: ChartJsChart;
77
+ onlyIntegers: boolean;
78
+ maxXAxesTicksHeight: number;
79
+ numSupportedColors: number;
80
+ colorSchemeCssClass: string;
81
+ minRadialChartDatalabelSpace: number;
82
+ resetDatasetAfterHover: boolean;
83
+ legendHoverDatasets: number[];
84
+ removing: boolean;
85
+
86
+ $canvas: JQuery<HTMLCanvasElement>;
87
+
88
+ protected _labelFormatter: LabelFormatter;
89
+ protected _xLabelFormatter: LabelFormatter;
90
+ protected _yLabelFormatter: LabelFormatter;
91
+ protected _xAxisFitter: AxisFitter;
92
+ protected _yAxisFitter: AxisFitter;
93
+ protected _radialChartDatalabelsDisplayHandler: DatalabelsDisplayHandler;
94
+ protected _radialChartDatalabelsFormatter: RadialChartDatalabelsFormatter;
95
+ protected _datalabelsFormatter: DatalabelsFormatter;
96
+ protected _datalabelBackgroundColorHandler: DatalabelBackgroundColorHandler;
97
+ protected _legendLabelGenerator: LegendLabelGenerator;
98
+ protected _clickHandler: ChartEventHandler;
99
+ protected _hoverHandler: ChartEventHandler;
100
+ protected _pointerHoverHandler: ChartEventHandler;
101
+ protected _legendClickHandler: LegendEventHandler;
102
+ protected _legendHoverHandler: LegendEventHandler;
103
+ protected _legendPointerHoverHandler: LegendEventHandler;
104
+ protected _legendLeaveHandler: LegendEventHandler;
105
+ protected _legendPointerLeaveHandler: LegendEventHandler;
106
+ protected _resizeHandler: ResizeHandler;
107
+ protected _tooltipTitleGenerator: TooltipTitleGenerator;
108
+ protected _tooltipItemsGenerator: TooltipItemsGenerator;
109
+ protected _tooltipLabelGenerator: TooltipLabelGenerator;
110
+ protected _tooltipLabelValueGenerator: TooltipLabelValueGenerator;
111
+ protected _tooltipLabelColorGenerator: TooltipLabelColorGenerator;
112
+ protected _tooltipRenderer: TooltipRenderer;
113
+ protected _tooltip: Tooltip;
114
+ protected _tooltipTimeoutId: number;
115
+ protected _updatingDatalabels: boolean;
116
+
117
+ constructor(chart: Chart) {
149
118
  super(chart);
150
119
  this.chartJs = null;
151
120
  this.onlyIntegers = true;
152
- this.maxXAxesTicksHeigth = 75;
121
+ this.maxXAxesTicksHeight = 75;
153
122
  this.numSupportedColors = 6;
154
123
  this.colorSchemeCssClass = '';
155
124
  this.minRadialChartDatalabelSpace = 25;
@@ -194,7 +163,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
194
163
  this._tooltipTimeoutId = null;
195
164
  }
196
165
 
197
- _validateChartData() {
166
+ protected override _validateChartData(): boolean {
198
167
  let chartDataValid = true;
199
168
  let chartData = this.chart && this.chart.data;
200
169
 
@@ -259,28 +228,21 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
259
228
  return chartConfigDataValid;
260
229
  }
261
230
 
262
- _render() {
231
+ protected override _render() {
263
232
  if (!this.$canvas) {
264
- this.$canvas = this.chart.$container.appendElement('<canvas>');
233
+ this.$canvas = this.chart.$container.appendElement('<canvas>') as JQuery<HTMLCanvasElement>;
265
234
  }
266
235
  this.firstOpaqueBackgroundColor = styles.getFirstOpaqueBackgroundColor(this.$canvas);
267
236
  if (!chartJsGlobalsInitialized) {
268
237
  ChartJs.defaults.font.family = this.$canvas.css('font-family');
269
238
  chartJsGlobalsInitialized = true;
270
239
  }
271
- /**
272
- * @property {number} options.bubble.sizeOfLargestBubble
273
- * @property {object} options.numberFormatter
274
- * @property {object} options.scaleLabelByTypeMap
275
- * @property {object} options.xLabelMap
276
- * @property {object} options.yLabelMap
277
- */
278
240
  let config = $.extend(true, {}, this.chart.config);
279
241
  this._adjustConfig(config);
280
242
  this._renderChart(config, true);
281
243
  }
282
244
 
283
- _renderChart(config, animated) {
245
+ protected _renderChart(config: ChartConfig, animated: boolean) {
284
246
  if (this.chartJs) {
285
247
  this.chartJs.destroy();
286
248
  }
@@ -291,17 +253,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
291
253
  }, config);
292
254
  config.options.animation.duration = animated ? this.animationDuration : 0;
293
255
 
294
- /**
295
- * @type {Chart}
296
- * @property {object} config
297
- * @property {object} chartArea
298
- */
299
- this.chartJs = new ChartJs(this.$canvas[0].getContext('2d'), config);
256
+ this.chartJs = new ChartJs(this.$canvas[0].getContext('2d'), config as ChartConfiguration) as ChartJsChart;
300
257
  this._adjustSize(this.chartJs.config, this.chartJs.chartArea);
301
258
  this.chartJs.update();
302
259
  }
303
260
 
304
- _updateData() {
261
+ protected override _updateData() {
305
262
  if (!this.chartJs) {
306
263
  return;
307
264
  }
@@ -313,10 +270,10 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
313
270
 
314
271
  // Transfer property from source object to target object:
315
272
  // 1. If the property is not set on the target object, copy it from source.
316
- // 2. If the property is not set on the source object, set it to undefined if setToUndefined = true. Otherwise empty the array if it is an array property or set it to undefined.
273
+ // 2. If the property is not set on the source object, set it to undefined if setToUndefined = true. Otherwise, empty the array if it is an array property or set it to undefined.
317
274
  // 3. If the property is not an array on the source or the target object, copy the property from the source to the target object.
318
275
  // 4. If the property is an array on both objects, do not update the array, but transfer the elements (update elements directly, use pop(), push() or splice() if one array is longer than the other).
319
- let transferProperty = (source, target, property, setToUndefined) => {
276
+ let transferProperty = (source: object, target: object, property: string, setToUndefined?) => {
320
277
  if (!source || !target || !property) {
321
278
  return;
322
279
  }
@@ -365,8 +322,8 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
365
322
  }
366
323
  };
367
324
 
368
- let findDataset = (datasets, datasetId) => arrays.find(datasets, dataset => dataset.datasetId === datasetId);
369
- let findDatasetIndex = (datasets, datasetId) => arrays.findIndex(datasets, dataset => dataset.datasetId === datasetId);
325
+ let findDataset = (datasets: ChartDataset[], datasetId) => arrays.find(datasets, dataset => dataset.datasetId === datasetId);
326
+ let findDatasetIndex = (datasets: ChartDataset[], datasetId) => arrays.findIndex(datasets, dataset => dataset.datasetId === datasetId);
370
327
 
371
328
  if (targetData && sourceData) {
372
329
  // Transfer properties from source to target, instead of overwriting the whole data object.
@@ -472,8 +429,8 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
472
429
  });
473
430
  let scales = this.chartJs.config.options.scales || {},
474
431
  axes = [scales.x || {}, scales.y || {}, scales.yDiffType || {}, scales.r || {}];
475
- axes.forEach(axis => {
476
- (axis.ticks || {}).stepSize = undefined;
432
+ axes.forEach((axis: LinearScaleOptions | RadialLinearScaleOptions) => {
433
+ (axis.ticks || {} as (LinearScaleOptions | RadialLinearScaleOptions)['ticks']).stepSize = undefined;
477
434
  });
478
435
 
479
436
  this.chartJs.update();
@@ -482,11 +439,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
482
439
  this.chartJs.update();
483
440
  }
484
441
 
485
- isDataUpdatable() {
442
+ override isDataUpdatable(): boolean {
486
443
  return true;
487
444
  }
488
445
 
489
- refresh() {
446
+ override refresh() {
490
447
  if (this.chartJs) {
491
448
  this.chartJs.update();
492
449
  } else {
@@ -494,13 +451,13 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
494
451
  }
495
452
  }
496
453
 
497
- _renderCheckedItems() {
454
+ protected override _renderCheckedItems() {
498
455
  if (this.chartJs && this._checkItems(this.chartJs.config)) {
499
456
  this.chartJs.update();
500
457
  }
501
458
  }
502
459
 
503
- _checkItems(config) {
460
+ protected _checkItems(config: ChartConfig): boolean {
504
461
  if (!config || !config.data) {
505
462
  return false;
506
463
  }
@@ -520,10 +477,10 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
520
477
  return 0;
521
478
  };
522
479
  let changed = 0;
523
- config.data.datasets.forEach((dataset, datasetIndex) => {
480
+ config.data.datasets.forEach((dataset: ChartDataset, datasetIndex) => {
524
481
  let checkedIndices = this.chart.checkedItems.filter(item => item.datasetIndex === datasetIndex)
525
482
  .map(item => item.dataIndex),
526
- uncheckedIndices = arrays.init(dataset.data.length).map((elem, idx) => idx);
483
+ uncheckedIndices = arrays.init(dataset.data.length, null).map((elem, idx) => idx);
527
484
  arrays.removeAll(uncheckedIndices, checkedIndices);
528
485
 
529
486
  changed = changed +
@@ -552,7 +509,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
552
509
  }
553
510
  }
554
511
 
555
- _adjustConfig(config) {
512
+ protected _adjustConfig(config: ChartConfig) {
556
513
  if (!config || !config.type) {
557
514
  return;
558
515
  }
@@ -569,7 +526,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
569
526
  this._adjustResizeHandler(config);
570
527
  }
571
528
 
572
- _adjustType(config) {
529
+ protected _adjustType(config: ChartConfig) {
573
530
  if (config.type === Chart.Type.COMBO_BAR_LINE) {
574
531
  config.type = Chart.Type.BAR;
575
532
 
@@ -585,7 +542,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
585
542
  }
586
543
  }
587
544
 
588
- _computeDatasets(chartData, config) {
545
+ protected _computeDatasets(chartData: ChartData, config: ChartConfig) {
589
546
  let labels = [],
590
547
  datasets = [];
591
548
 
@@ -607,22 +564,18 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
607
564
  data: $.extend(true, [], elem.values)
608
565
  }));
609
566
 
610
- /**
611
- * @type {object}
612
- * @property {Dataset[]} datasets
613
- */
614
567
  config.data = {
615
568
  labels: labels,
616
569
  datasets: datasets
617
570
  };
618
571
  }
619
572
 
620
- _isHorizontalBar(config) {
573
+ protected _isHorizontalBar(config: ChartConfig): boolean {
621
574
  return config && (config.type === Chart.Type.BAR_HORIZONTAL
622
575
  || (config.type === Chart.Type.BAR && config.options && config.options.indexAxis === 'y'));
623
576
  }
624
577
 
625
- _computeLabelMap(axis) {
578
+ protected _computeLabelMap(axis: ChartAxis[]): Record<number, string> {
626
579
  let labelMap = {};
627
580
  (axis || []).forEach((elem, idx) => {
628
581
  labelMap[idx] = elem.label;
@@ -630,7 +583,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
630
583
  return labelMap;
631
584
  }
632
585
 
633
- _adjustData(config) {
586
+ protected _adjustData(config: ChartConfig) {
634
587
  if (!config || !config.data || !config.type) {
635
588
  return;
636
589
  }
@@ -641,7 +594,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
641
594
  this._adjustOnlyIntegers(config);
642
595
  }
643
596
 
644
- _adjustBarBorderWidth(config) {
597
+ protected _adjustBarBorderWidth(config: ChartConfig) {
645
598
  if (!config || !config.data || !config.type || !scout.isOneOf(config.type, Chart.Type.BAR)) {
646
599
  return;
647
600
  }
@@ -655,7 +608,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
655
608
  });
656
609
  }
657
610
 
658
- _adjustDatasetBorderWidths(dataset) {
611
+ protected _adjustDatasetBorderWidths(dataset: ChartDataset) {
659
612
  this._adjustDatasetBorderWidth(dataset);
660
613
  this._adjustDatasetBorderWidth(dataset, true);
661
614
  }
@@ -664,10 +617,9 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
664
617
  * Sets the borderWidth to 0 if the backgroundColor and the borderColor are identical and backups the original value.
665
618
  * This method is idempotent as it restores the original state first and then applies its logic.
666
619
  *
667
- * @param {Dataset} dataset
668
- * @param {boolean?} hover whether hoverBorderWidth, hoverBackgroundColor and hoverBorderColor should be considered instead of borderWidth, backgroundColor and borderColor
620
+ * @param hover whether hoverBorderWidth, hoverBackgroundColor and hoverBorderColor should be considered instead of borderWidth, backgroundColor and borderColor
669
621
  */
670
- _adjustDatasetBorderWidth(dataset, hover) {
622
+ protected _adjustDatasetBorderWidth(dataset: ChartDataset, hover?: boolean) {
671
623
  if (!dataset) {
672
624
  return;
673
625
  }
@@ -675,7 +627,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
675
627
  borderWidthBackupIdentifier = hover ? 'hoverBorderWidthBackup' : 'borderWidthBackup',
676
628
  backgroundColorIdentifier = hover ? 'hoverBackgroundColor' : 'backgroundColor',
677
629
  borderColorIdentifier = hover ? 'hoverBorderColor' : 'borderColor';
678
- // restore original state if there is an backup
630
+ // restore original state if there is a backup
679
631
  if (dataset[borderWidthBackupIdentifier]) {
680
632
  dataset[borderWidthIdentifier] = dataset[borderWidthBackupIdentifier];
681
633
  delete dataset[borderWidthBackupIdentifier];
@@ -703,7 +655,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
703
655
  }
704
656
  let borderWidth = dataset[borderWidthIdentifier],
705
657
  length = borderWidth.length,
706
- borderWidthBackup = arrays.init(length);
658
+ borderWidthBackup = arrays.init(length, null);
707
659
  for (let i = 0; i < length; i++) {
708
660
  // it makes no difference if the backgroundColor/borderColor is not an array as a not-array-value is applied to every element by chart.js
709
661
  let backgroundColor = isBackgroundColorArray ? dataset[backgroundColorIdentifier][i] : dataset[backgroundColorIdentifier],
@@ -719,7 +671,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
719
671
  }
720
672
  }
721
673
 
722
- _adjustMaxSegments(config) {
674
+ protected _adjustMaxSegments(config: ChartConfig) {
723
675
  if (!config || !config.data || !config.type || !scout.isOneOf(config.type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA, Chart.Type.RADAR)) {
724
676
  return;
725
677
  }
@@ -730,7 +682,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
730
682
  }
731
683
  config.data.datasets.forEach(elem => {
732
684
  let newData = elem.data.slice(0, maxSegments);
733
- newData[maxSegments - 1] = elem.data.slice(maxSegments - 1, elem.data.length).reduce((x, y) => {
685
+ newData[maxSegments - 1] = elem.data.slice(maxSegments - 1, elem.data.length).reduce((x: number, y: number) => {
734
686
  return x + y;
735
687
  }, 0);
736
688
  elem.data = newData;
@@ -742,7 +694,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
742
694
  config.data.maxSegmentsExceeded = true;
743
695
  }
744
696
 
745
- _isMaxSegmentsExceeded(config, index) {
697
+ protected _isMaxSegmentsExceeded(config: ChartConfig, index: number): boolean {
746
698
  if (!scout.isOneOf(config.type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA, Chart.Type.RADAR)) {
747
699
  return false;
748
700
  }
@@ -760,12 +712,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
760
712
  * This allows the chart to render itself with correct dimensions and with no interfering from bubbles (very large bubbles make the chart grid itself smaller).
761
713
  * Later on in {@link _adjustBubbleSizes}, the bubble sizes will be calculated relative to the chart dimensions and the configured min/max sizes.
762
714
  */
763
- _adjustBubbleRadii(config) {
715
+ protected _adjustBubbleRadii(config: ChartConfig) {
764
716
  if (!config || !config.data || !config.type || config.type !== Chart.Type.BUBBLE) {
765
717
  return;
766
718
  }
767
719
 
768
- config.data.datasets.forEach(dataset => dataset.data.forEach(data => {
720
+ config.data.datasets.forEach(dataset => dataset.data.forEach((data: BubbleDataPoint) => {
769
721
  if (!isNaN(data.r)) {
770
722
  data.z = Math.pow(data.r, 2);
771
723
  }
@@ -773,7 +725,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
773
725
  }));
774
726
  }
775
727
 
776
- _adjustOnlyIntegers(config) {
728
+ protected _adjustOnlyIntegers(config: ChartConfig) {
777
729
  this.onlyIntegers = true;
778
730
 
779
731
  if (!config || !config.data || !config.type) {
@@ -781,13 +733,13 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
781
733
  }
782
734
 
783
735
  if (scout.isOneOf(config.type, Chart.Type.BUBBLE, Chart.Type.SCATTER)) {
784
- this.onlyIntegers = config.data.datasets.every(dataset => dataset.data.every(data => numbers.isInteger(data.x) && numbers.isInteger(data.y)));
736
+ this.onlyIntegers = config.data.datasets.every(dataset => dataset.data.every((data: ScatterDataPoint | BubbleDataPoint) => numbers.isInteger(data.x) && numbers.isInteger(data.y)));
785
737
  } else {
786
738
  this.onlyIntegers = config.data.datasets.every(dataset => dataset.data.every(data => numbers.isInteger(data)));
787
739
  }
788
740
  }
789
741
 
790
- _adjustTooltip(config) {
742
+ protected _adjustTooltip(config: ChartConfig) {
791
743
  if (!config) {
792
744
  return;
793
745
  }
@@ -816,12 +768,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
816
768
  tooltip.external = this._tooltipRenderer;
817
769
  }
818
770
 
819
- _generateTooltipTitle(tooltipItems) {
771
+ protected _generateTooltipTitle(tooltipItems: TooltipItem<any>[]): string | string[] {
820
772
  if (!tooltipItems || !tooltipItems.length) {
821
773
  return '';
822
774
  }
823
775
  let tooltipItem = tooltipItems[0],
824
- chart = tooltipItem.chart,
776
+ chart = tooltipItem.chart as ChartJsChart,
825
777
  config = chart.config,
826
778
  dataset = tooltipItem.dataset,
827
779
  title = [];
@@ -829,33 +781,35 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
829
781
  let xAxis = config.options.scales.x,
830
782
  yAxis = config.options.scales.y,
831
783
  axisLabels = this._getAxisLabels(config);
832
- let xTickLabel = xAxis.ticks.callback(dataset.data[tooltipItem.dataIndex].x);
784
+ // @ts-expect-error
785
+ let xTickLabel = xAxis.ticks.callback(dataset.data[tooltipItem.dataIndex].x, null, null) as string;
833
786
  if (xTickLabel) {
834
787
  title.push(this._createTooltipAttribute(axisLabels.x, strings.encode(xTickLabel), true));
835
788
  }
836
- let yTickLabel = yAxis.ticks.callback(dataset.data[tooltipItem.dataIndex].y);
789
+ // @ts-expect-error
790
+ let yTickLabel = yAxis.ticks.callback(dataset.data[tooltipItem.dataIndex].y, null, null) as string;
837
791
  if (yTickLabel) {
838
792
  title.push(this._createTooltipAttribute(axisLabels.y, strings.encode(yTickLabel), true));
839
793
  }
840
794
  } else if (scout.isOneOf(config.type, Chart.Type.SCATTER)) {
841
795
  // nop, scatter has the title in the items table
842
796
  } else {
843
- let label = chart.data.labels[tooltipItem.dataIndex];
797
+ let label = chart.data.labels[tooltipItem.dataIndex] as string;
844
798
  title.push(this._createTooltipAttribute(config.options.reformatLabels ? this._formatLabel(label) : label, '', true));
845
799
  }
846
800
  return title;
847
801
  }
848
802
 
849
- _getAxisLabels(config) {
803
+ protected _getAxisLabels(config: ChartConfig): { x: string; y: string } {
850
804
  let xAxisLabel = config.options.scales.x.title.text,
851
805
  yAxisLabel = config.options.scales.y.title.text;
852
- xAxisLabel = this._resolveAxisLabel(xAxisLabel, ChartJsRenderer.ARROW_LEFT_RIGHT);
853
- yAxisLabel = this._resolveAxisLabel(yAxisLabel, '&nbsp;' + ChartJsRenderer.ARROW_UP_DOWN + '&nbsp;');
806
+ xAxisLabel = this._resolveAxisLabel(xAxisLabel as string, ChartJsRenderer.ARROW_LEFT_RIGHT);
807
+ yAxisLabel = this._resolveAxisLabel(yAxisLabel as string, '&nbsp;' + ChartJsRenderer.ARROW_UP_DOWN + '&nbsp;');
854
808
 
855
809
  return {x: xAxisLabel, y: yAxisLabel};
856
810
  }
857
811
 
858
- _resolveAxisLabel(axisLabel, defaultLabel = '') {
812
+ protected _resolveAxisLabel(axisLabel: string | (() => string), defaultLabel = ''): string {
859
813
  if (objects.isFunction(axisLabel)) {
860
814
  axisLabel = axisLabel();
861
815
  axisLabel = objects.isString(axisLabel) ? axisLabel : '';
@@ -863,12 +817,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
863
817
  return axisLabel ? strings.encode(axisLabel) : defaultLabel;
864
818
  }
865
819
 
866
- _generateTooltipItems(tooltipItems, tooltipLabel, tooltipLabelValue, tooltipColor) {
820
+ protected _generateTooltipItems(tooltipItems: TooltipItem<any>[], tooltipLabel: TooltipLabelGenerator, tooltipLabelValue: TooltipLabelValueGenerator, tooltipColor: TooltipLabelColorGenerator): string {
867
821
  if (!tooltipItems || !tooltipItems.length) {
868
822
  return '';
869
823
  }
870
824
  let tooltipItem = tooltipItems[0],
871
- chart = tooltipItem.chart,
825
+ chart = tooltipItem.chart as ChartJsChart,
872
826
  config = chart.config,
873
827
  xAxisValues = false,
874
828
  yAxisValues = false,
@@ -877,11 +831,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
877
831
  tooltipItems.forEach(tooltipItem => {
878
832
  let {label, labelValue, labelColor} = this._getItemDetails(tooltipItem, tooltipLabel, tooltipLabelValue, tooltipColor);
879
833
  if (scout.isOneOf(config.type, Chart.Type.SCATTER)) {
880
- xAxisValues |= objects.isString(labelValue.x);
881
- yAxisValues |= objects.isString(labelValue.y);
882
- itemsText += this._createTooltipScatterAttribute(label, labelValue.x, labelValue.y, false, labelColor);
834
+ let {x, y} = labelValue as { x: string; y: string };
835
+ xAxisValues ||= objects.isString(x);
836
+ yAxisValues ||= objects.isString(y);
837
+ itemsText += this._createTooltipScatterAttribute(label, x, y, false, labelColor);
883
838
  } else {
884
- itemsText += this._createTooltipAttribute(label, labelValue, false, labelColor);
839
+ itemsText += this._createTooltipAttribute(label, labelValue as string, false, labelColor);
885
840
  }
886
841
  });
887
842
 
@@ -892,8 +847,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
892
847
  tableHeader += this._createTooltipScatterAttribute('',
893
848
  xAxisValues ? axisLabels.x : '', // do not show axis label if no values are shown
894
849
  yAxisValues ? axisLabels.y : '', // do not show axis label if no values are shown
895
- true,
896
- null);
850
+ true);
897
851
  let tableFooter = '</tbody></table>';
898
852
  itemsText = strings.box(tableHeader, itemsText, tableFooter);
899
853
  }
@@ -901,7 +855,8 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
901
855
  return itemsText;
902
856
  }
903
857
 
904
- _getItemDetails(tooltipItem, tooltipLabel, tooltipLabelValue, tooltipColor) {
858
+ protected _getItemDetails(tooltipItem: TooltipItem<any>, tooltipLabel: TooltipLabelGenerator, tooltipLabelValue: TooltipLabelValueGenerator, tooltipColor: TooltipLabelColorGenerator)
859
+ : { label: string; labelValue: string | { x: string; y: string }; labelColor: string } {
905
860
  let label, labelValue, labelColor;
906
861
  if (objects.isFunction(tooltipLabel)) {
907
862
  label = tooltipLabel(tooltipItem);
@@ -918,12 +873,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
918
873
  return {label, labelValue, labelColor};
919
874
  }
920
875
 
921
- _generateTooltipLabel(tooltipItem) {
876
+ protected _generateTooltipLabel(tooltipItem: TooltipItem<any>): string {
922
877
  return strings.encode(tooltipItem.dataset.label);
923
878
  }
924
879
 
925
- _generateTooltipLabelValue(tooltipItem) {
926
- let config = tooltipItem.chart.config,
880
+ protected _generateTooltipLabelValue(tooltipItem: TooltipItem<any>): string | { x: string; y: string } {
881
+ let config = tooltipItem.chart.config as ChartConfiguration,
927
882
  dataset = tooltipItem.dataset;
928
883
  if (config.type === Chart.Type.BUBBLE) {
929
884
  return strings.encode(this._formatLabel(dataset.data[tooltipItem.dataIndex].z));
@@ -936,8 +891,8 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
936
891
  return strings.encode(this._formatLabel(dataset.data[tooltipItem.dataIndex]));
937
892
  }
938
893
 
939
- _generateTooltipLabelColor(tooltipItem) {
940
- let config = tooltipItem.chart.config,
894
+ protected _generateTooltipLabelColor(tooltipItem: TooltipItem<any>): TooltipLabelStyle {
895
+ let config = tooltipItem.chart.config as ChartConfiguration,
941
896
  dataset = tooltipItem.dataset,
942
897
  legendColor, backgroundColor, borderColor, index;
943
898
  if (scout.isOneOf((dataset.type || config.type), Chart.Type.LINE, Chart.Type.BAR, Chart.Type.BAR_HORIZONTAL, Chart.Type.RADAR, Chart.Type.BUBBLE, Chart.Type.SCATTER)) {
@@ -957,7 +912,6 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
957
912
  let tooltipLabelColor = legendColor || backgroundColor || borderColor;
958
913
  if (!tooltipLabelColor || objects.isFunction(tooltipLabelColor)) {
959
914
  let defaultTypeTooltipLabelColor;
960
- // noinspection DuplicatedCode
961
915
  if (ChartJs.overrides[config.type] && ChartJs.overrides[config.type].plugins && ChartJs.overrides[config.type].plugins.tooltip && ChartJs.overrides[config.type].plugins.tooltip.callbacks) {
962
916
  defaultTypeTooltipLabelColor = ChartJs.overrides[config.type].plugins.tooltip.callbacks.labelColor;
963
917
  }
@@ -966,10 +920,10 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
966
920
  }
967
921
  return {
968
922
  backgroundColor: tooltipLabelColor
969
- };
923
+ } as TooltipLabelStyle;
970
924
  }
971
925
 
972
- _createTooltipAttribute(label, value, isTitle, color) {
926
+ protected _createTooltipAttribute(label: string, value: string, isTitle: boolean, color?: string): string {
973
927
  let cssClass = isTitle ? 'attribute title' : 'attribute';
974
928
  return '<div class="' + cssClass + '">' +
975
929
  (color ? '<div class="color" style="background-color:' + color + '"></div>' : '') +
@@ -978,7 +932,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
978
932
  '</div>';
979
933
  }
980
934
 
981
- _createTooltipScatterAttribute(label, xValue, yValue, isTitle, color) {
935
+ protected _createTooltipScatterAttribute(label: string, xValue: string, yValue: string, isTitle: boolean, color?: string): string {
982
936
  let cssClass = isTitle ? 'attribute title' : 'attribute';
983
937
  return '<tr class="' + cssClass + '">' +
984
938
  '<td class="color-cell">' +
@@ -990,8 +944,8 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
990
944
  '</tr>';
991
945
  }
992
946
 
993
- _renderTooltip(context) {
994
- let isHideTooltip = context.tooltip.opacity === 0 || context.tooltip._tooltipItems.length < 1;
947
+ protected _renderTooltip(context: { chart: ChartJs; tooltip: TooltipModel<any> }) {
948
+ let isHideTooltip = context.tooltip.opacity === 0 || context.tooltip.dataPoints.length < 1;
995
949
  if (isHideTooltip) {
996
950
  if (this._tooltipTimeoutId) {
997
951
  clearTimeout(this._tooltipTimeoutId);
@@ -1012,7 +966,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1012
966
  }
1013
967
  }
1014
968
 
1015
- _renderTooltipLater(context) {
969
+ protected _renderTooltipLater(context: { chart: ChartJs; tooltip: TooltipModel<any> }) {
1016
970
  if (!this.rendered || this.removing) {
1017
971
  return;
1018
972
  }
@@ -1031,9 +985,9 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1031
985
  this._tooltip = null;
1032
986
  }
1033
987
 
1034
- let tooltipOptions = tooltip.options || {},
1035
- tooltipCallbacks = tooltipOptions.callbacks || {},
1036
- tooltipTitle = tooltipCallbacks.title,
988
+ let tooltipOptions = tooltip.options || {} as TooltipOptions,
989
+ tooltipCallbacks = tooltipOptions.callbacks || {} as TooltipCallbacks<any>,
990
+ tooltipTitle = tooltipCallbacks.title as TooltipTitleGenerator,
1037
991
  tooltipItems = tooltipCallbacks.items,
1038
992
  tooltipLabel = tooltipCallbacks.label,
1039
993
  tooltipLabelValue = tooltipCallbacks.labelValue,
@@ -1054,7 +1008,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1054
1008
  origin.height = positionAndOffset.height;
1055
1009
 
1056
1010
  this._tooltip = scout.create({
1057
- objectType: 'Tooltip',
1011
+ objectType: Tooltip,
1058
1012
  parent: this.chart,
1059
1013
  $anchor: this.$canvas,
1060
1014
  text: tooltipText,
@@ -1069,10 +1023,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1069
1023
  this._tooltip.$container
1070
1024
  .css('pointer-events', 'none');
1071
1025
 
1072
- let reposition = false;
1073
- if ((tooltipOptions.titleFont || {}).family) {
1026
+ let reposition = false,
1027
+ fontFamily = ((tooltipOptions.titleFont || {}) as FontSpec).family;
1028
+ if (fontFamily) {
1074
1029
  this._tooltip.$container
1075
- .css('--chart-tooltip-font-family', tooltipOptions.titleFont.family);
1030
+ .css('--chart-tooltip-font-family', fontFamily);
1076
1031
  reposition = true;
1077
1032
  }
1078
1033
 
@@ -1090,14 +1045,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1090
1045
  }
1091
1046
  }
1092
1047
 
1093
- _computeTooltipPositionAndOffset(tooltipItem) {
1094
- let tooltipPosition = 'top',
1095
- tooltipDirection = 'right',
1048
+ protected _computeTooltipPositionAndOffset(tooltipItem: TooltipItem<any>): { tooltipPosition: 'top' | 'bottom'; tooltipDirection: 'left' | 'right'; offsetX: number; offsetY: number; height: number } {
1049
+ let tooltipPosition: 'top' | 'bottom' = 'top',
1050
+ tooltipDirection: 'left' | 'right' = 'right',
1096
1051
  offsetX = 0,
1097
1052
  offsetY = 0,
1098
1053
  height = 0;
1099
1054
 
1100
- let chart = tooltipItem.chart,
1055
+ let chart = tooltipItem.chart as ChartJsChart,
1101
1056
  datasetIndex = tooltipItem.datasetIndex,
1102
1057
  dataIndex = tooltipItem.dataIndex,
1103
1058
  config = chart.config,
@@ -1106,7 +1061,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1106
1061
  value = dataset.data[dataIndex];
1107
1062
 
1108
1063
  if (this._isHorizontalBar(config)) {
1109
- if (value && objects.isArray(value.x) && value.x.length === 2) {
1064
+ if (objects.isPlainObject(value) && objects.isArray(value.x) && value.x.length === 2) {
1110
1065
  let avg = (value.x[0] + value.x[1]) / 2;
1111
1066
  tooltipDirection = avg < 0 ? 'left' : 'right';
1112
1067
  } else {
@@ -1115,22 +1070,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1115
1070
  } else if ((dataset.type || config.type) === Chart.Type.BAR) {
1116
1071
  tooltipPosition = value < 0 ? 'bottom' : 'top';
1117
1072
  } else if (scout.isOneOf(config.type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA)) {
1118
- // noinspection JSValidateTypes
1119
- /**
1120
- * @type ArcElement
1121
- */
1122
- let element = chart.getDatasetMeta(datasetIndex).data[dataIndex];
1073
+ let element = (chart.getDatasetMeta(datasetIndex).data[dataIndex] as unknown as ArcElement).getProps(['startAngle', 'endAngle']);
1123
1074
  let startAngle = element.startAngle,
1124
1075
  endAngle = element.endAngle,
1125
1076
  angle = (startAngle + endAngle) / 2;
1126
1077
  tooltipPosition = (0 <= angle && angle < Math.PI) ? 'bottom' : 'top';
1127
1078
  tooltipDirection = (-Math.PI / 2 <= angle && angle < Math.PI / 2) ? 'right' : 'left';
1128
1079
  } else if (config.type === Chart.Type.RADAR) {
1129
- // noinspection JSValidateTypes
1130
- /**
1131
- * @type PointElement
1132
- */
1133
- let element = chart.getDatasetMeta(datasetIndex).data[dataIndex];
1080
+ let element = (chart.getDatasetMeta(datasetIndex).data[dataIndex] as unknown as RadarPointElement).getProps(['angle']);
1134
1081
  let angle = element.angle;
1135
1082
  tooltipPosition = (0 <= angle && angle < Math.PI) ? 'bottom' : 'top';
1136
1083
  tooltipDirection = (-Math.PI / 2 <= angle && angle < Math.PI / 2) ? 'right' : 'left';
@@ -1142,11 +1089,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1142
1089
  }
1143
1090
 
1144
1091
  if (this._isHorizontalBar(config)) {
1145
- // noinspection JSValidateTypes
1146
- /**
1147
- * @type BarElement
1148
- */
1149
- let element = chart.getDatasetMeta(datasetIndex).data[dataIndex];
1092
+ let element = (chart.getDatasetMeta(datasetIndex).data[dataIndex] as unknown as BarElement).getProps(['height', 'width']);
1150
1093
  height = element.height;
1151
1094
  let width = element.width,
1152
1095
  // golden ratio: (a + b) / a = a / b = PHI
@@ -1157,25 +1100,17 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1157
1100
  offsetY = -height / 2;
1158
1101
  offsetX = tooltipDirection === 'left' ? b : -b;
1159
1102
  } else if (scout.isOneOf(config.type, Chart.Type.LINE, Chart.Type.BUBBLE, Chart.Type.SCATTER, Chart.Type.RADAR) || dataset.type === Chart.Type.LINE) {
1160
- // noinspection JSValidateTypes
1161
- /**
1162
- * @type PointElement
1163
- */
1164
- let element = chart.getDatasetMeta(datasetIndex).data[dataIndex];
1165
- let options = element.options,
1103
+ let element = chart.getDatasetMeta(datasetIndex).data[dataIndex] as unknown as PointElement;
1104
+ let options = element.options as unknown as PointHoverOptions,
1166
1105
  offset = options.hoverRadius + options.hoverBorderWidth;
1167
1106
  if (config.type === Chart.Type.BUBBLE) {
1168
- offset += value.r;
1107
+ offset += (value as BubbleDataPoint).r;
1169
1108
  }
1170
1109
 
1171
1110
  height = 2 * offset;
1172
1111
  offsetY = -offset;
1173
1112
  } else if (scout.isOneOf(config.type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA)) {
1174
- // noinspection JSValidateTypes
1175
- /**
1176
- * @type ArcElement
1177
- */
1178
- let element = chart.getDatasetMeta(datasetIndex).data[dataIndex];
1113
+ let element = (chart.getDatasetMeta(datasetIndex).data[dataIndex] as unknown as ArcElement).getProps(['startAngle', 'endAngle', 'innerRadius', 'outerRadius']);
1179
1114
  let startAngle = element.startAngle,
1180
1115
  endAngle = element.endAngle,
1181
1116
  angle = (startAngle + endAngle) / 2,
@@ -1189,7 +1124,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1189
1124
  return {tooltipPosition, tooltipDirection, offsetX, offsetY, height};
1190
1125
  }
1191
1126
 
1192
- _adjustGrid(config) {
1127
+ protected _adjustGrid(config: ChartConfig) {
1193
1128
  if (!config) {
1194
1129
  return;
1195
1130
  }
@@ -1200,7 +1135,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1200
1135
  this._adjustScalesXY(config);
1201
1136
  }
1202
1137
 
1203
- _adjustScalesR(config) {
1138
+ protected _adjustScalesR(config: ChartConfig) {
1204
1139
  if (!config || !config.type || !config.options) {
1205
1140
  return;
1206
1141
  }
@@ -1234,7 +1169,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1234
1169
  }
1235
1170
  }
1236
1171
 
1237
- _adjustScalesXY(config) {
1172
+ protected _adjustScalesXY(config: ChartConfig) {
1238
1173
  if (!config || !config.type || !config.options) {
1239
1174
  return;
1240
1175
  }
@@ -1273,7 +1208,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1273
1208
  this._adjustYAxis(config);
1274
1209
  }
1275
1210
 
1276
- _adjustXAxis(config) {
1211
+ protected _adjustXAxis(config: ChartConfig) {
1277
1212
  if (!config || !config.type || !config.options || !config.options.scales || !config.options.scales.x) {
1278
1213
  return;
1279
1214
  }
@@ -1312,7 +1247,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1312
1247
  scales.x.afterCalculateLabelRotation = this._xAxisFitter;
1313
1248
  }
1314
1249
 
1315
- _adjustYAxis(config) {
1250
+ protected _adjustYAxis(config: ChartConfig) {
1316
1251
  if (!config || !config.type || !config.options || !config.options.scales || !config.options.scales.y) {
1317
1252
  return;
1318
1253
  }
@@ -1349,11 +1284,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1349
1284
  scales.y.afterFit = this._yAxisFitter;
1350
1285
  }
1351
1286
 
1352
- _adjustPlugins(config) {
1287
+ protected _adjustPlugins(config: ChartConfig) {
1353
1288
  this._adjustPluginsDatalabels(config);
1354
1289
  }
1355
1290
 
1356
- _adjustPluginsDatalabels(config) {
1291
+ protected _adjustPluginsDatalabels(config: ChartConfig) {
1357
1292
  if (!config || !config.type || !config.options || !config.options.plugins || !config.options.plugins.datalabels || !config.options.plugins.datalabels.display) {
1358
1293
  return;
1359
1294
  }
@@ -1399,8 +1334,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1399
1334
 
1400
1335
  // the datalabels plugin stores its data on the chart in $datalabels (see EXPANDO_KEY in chartjs-plugin-datalabels)
1401
1336
  chart['$' + ChartDataLabels.id]._actives = inactiveElements;
1402
- // noinspection JSCheckFunctionSignatures
1403
- ChartDataLabels.afterEvent(chart);
1337
+ ChartDataLabels.afterEvent(chart, null, null);
1404
1338
  this._updatingDatalabels = false;
1405
1339
  },
1406
1340
  updateDatalabelsAndDefaultCallback = (animation, defaultCallback) => {
@@ -1457,44 +1391,45 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1457
1391
  }, plugins.datalabels);
1458
1392
  }
1459
1393
 
1460
- _formatLabel(label) {
1394
+ protected _formatLabel(label: number | string): string {
1461
1395
  return this._formatLabelMap(label, null, this._getNumberFormatter());
1462
1396
  }
1463
1397
 
1464
- _getNumberFormatter() {
1398
+ protected _getNumberFormatter(): NumberFormatter {
1465
1399
  if (this.chartJs && this.chartJs.config && this.chartJs.config.options) {
1466
1400
  return this.chartJs.config.options.numberFormatter;
1467
1401
  }
1468
1402
  }
1469
1403
 
1470
- _formatXLabel(label) {
1404
+ protected _formatXLabel(label: number | string): string {
1471
1405
  return this._formatLabelMap(label, this._getXLabelMap(), this._getNumberFormatter());
1472
1406
  }
1473
1407
 
1474
- _formatYLabel(label) {
1408
+ protected _formatYLabel(label: number | string): string {
1475
1409
  return this._formatLabelMap(label, this._getYLabelMap(), this._getNumberFormatter());
1476
1410
  }
1477
1411
 
1478
- _getXLabelMap() {
1412
+ protected _getXLabelMap(): Record<number | string, string> {
1479
1413
  return this._getLabelMap('xLabelMap');
1480
1414
  }
1481
1415
 
1482
- _getYLabelMap() {
1416
+ protected _getYLabelMap(): Record<number | string, string> {
1483
1417
  return this._getLabelMap('yLabelMap');
1484
1418
  }
1485
1419
 
1486
- _getLabelMap(identifier) {
1420
+ protected _getLabelMap(identifier): Record<number | string, string> {
1487
1421
  if (this.chartJs && this.chartJs.config && this.chartJs.config.options) {
1488
1422
  return this.chartJs.config.options[identifier];
1489
1423
  }
1490
1424
  }
1491
1425
 
1492
- _formatLabelMap(label, labelMap, numberFormatter) {
1426
+ protected _formatLabelMap(label: number | string, labelMap: Record<string, string>, numberFormatter: NumberFormatter): string {
1493
1427
  if (labelMap) {
1494
1428
  return labelMap[label];
1495
1429
  }
1430
+ // @ts-expect-error
1496
1431
  if (isNaN(label)) {
1497
- return label;
1432
+ return '' + label;
1498
1433
  }
1499
1434
  if (numberFormatter) {
1500
1435
  return numberFormatter(label, this._formatNumberLabel.bind(this));
@@ -1502,10 +1437,12 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1502
1437
  return this._formatNumberLabel(label);
1503
1438
  }
1504
1439
 
1505
- _formatNumberLabel(label) {
1440
+ protected _formatNumberLabel(label: number | string): string {
1441
+ // @ts-expect-error
1506
1442
  if (isNaN(label)) {
1507
- return label;
1443
+ return '' + label;
1508
1444
  }
1445
+ // @ts-expect-error
1509
1446
  let abs = Math.abs(label);
1510
1447
  let abbreviation = '';
1511
1448
  if (abs >= 1000000) {
@@ -1526,20 +1463,18 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1526
1463
  }
1527
1464
  }
1528
1465
  }
1466
+ // @ts-expect-error
1529
1467
  return this.session.locale.decimalFormat.format(Math.sign(label) * abs) + abbreviation;
1530
1468
  }
1531
1469
 
1532
- /**
1533
- * @param {Scale} xAxis
1534
- */
1535
- _fitXAxis(xAxis) {
1470
+ protected _fitXAxis(xAxis: Scale<CartesianScaleOptions>) {
1536
1471
  if (!xAxis || xAxis.labelRotation === 0) {
1537
1472
  return;
1538
1473
  }
1539
- let maxHeight = this.maxXAxesTicksHeigth,
1474
+ let maxHeight = this.maxXAxesTicksHeight,
1540
1475
  fontDefaults = ChartJs.defaults.font,
1541
- ticksDefaults = ChartJs.defaults.scale.ticks,
1542
- ticksFontDefaults = ticksDefaults.font || {},
1476
+ ticksDefaults = (ChartJs.defaults.scale as CartesianScaleOptions).ticks,
1477
+ ticksFontDefaults = (ticksDefaults.font || {}) as FontSpec,
1543
1478
  fontSize,
1544
1479
  maxRotation;
1545
1480
  if (this.chartJs) {
@@ -1549,7 +1484,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1549
1484
  }
1550
1485
  if (xAxis.options && xAxis.options.ticks) {
1551
1486
  maxRotation = xAxis.options.ticks.maxRotation;
1552
- let ticksFont = xAxis.options.ticks.font || {};
1487
+ let ticksFont = (xAxis.options.ticks.font || {}) as FontSpec;
1553
1488
  fontSize = ticksFont.size;
1554
1489
  }
1555
1490
  maxRotation = maxRotation || ticksDefaults.maxRotation;
@@ -1566,19 +1501,21 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1566
1501
  // => height = sin(labelRotation) * labelLength + sin(90° - labelRotation) * fontSize
1567
1502
  // <=> labelLength = (height - sin(90° - labelRotation) * fontSize) / sin(labelRotation)
1568
1503
  maxLabelLength = (maxHeight - (fontSize * Math.sin(((90 - labelRotation) / 180) * Math.PI))) / Math.sin((labelRotation / 180) * Math.PI);
1504
+ // @ts-expect-error
1569
1505
  let labelSizes = xAxis._labelSizes || {},
1570
1506
  widest = labelSizes.widest || {};
1571
1507
  if (widest.width > maxLabelLength) {
1572
1508
  let measureText = xAxis.ctx.measureText.bind(xAxis.ctx);
1573
1509
  xAxis.ticks.forEach(tick => {
1574
- tick.label = strings.truncateText(tick.label, maxLabelLength, measureText);
1510
+ tick.label = strings.truncateText(tick.label as string, maxLabelLength, measureText);
1575
1511
  });
1576
1512
  // reset label sizes, chart.js will recalculate them using the new truncated labels
1513
+ // @ts-expect-error
1577
1514
  xAxis._labelSizes = undefined;
1578
1515
  }
1579
1516
  }
1580
1517
 
1581
- _fitYAxis(yAxis) {
1518
+ protected _fitYAxis(yAxis: Scale<CartesianScaleOptions>) {
1582
1519
  if (!yAxis) {
1583
1520
  return;
1584
1521
  }
@@ -1590,23 +1527,20 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1590
1527
  if (yAxis.options && yAxis.options.grid) {
1591
1528
  tickLength = yAxis.options.grid.tickLength || 0;
1592
1529
  }
1530
+ // @ts-expect-error
1593
1531
  let labelSizes = yAxis._labelSizes || {},
1594
1532
  widest = labelSizes.widest || {};
1595
1533
  if (widest.width > yAxis.maxWidth - padding) {
1596
1534
  let horizontalSpace = yAxis.maxWidth - padding - tickLength,
1597
1535
  measureText = yAxis.ctx.measureText.bind(yAxis.ctx);
1598
1536
  yAxis.ticks.forEach(tick => {
1599
- tick.label = strings.truncateText(tick.label, horizontalSpace, measureText);
1537
+ tick.label = strings.truncateText(tick.label as string, horizontalSpace, measureText);
1600
1538
  });
1601
1539
  }
1602
1540
  }
1603
1541
 
1604
- _displayDatalabelsOnRadialChart(context) {
1605
- // noinspection JSValidateTypes
1606
- /**
1607
- * @type ArcElement
1608
- */
1609
- let element = context.chart.getDatasetMeta(context.datasetIndex).data[context.dataIndex];
1542
+ protected _displayDatalabelsOnRadialChart(context: Context): boolean {
1543
+ let element = (context.chart.getDatasetMeta(context.datasetIndex).data[context.dataIndex] as unknown as ArcElement).getProps(['startAngle', 'endAngle', 'innerRadius', 'outerRadius']);
1610
1544
  // Compute the biggest circle that fits inside sector/arc with center in the middle between inner and outer radius.
1611
1545
  // First compute a circle C1 that touches the straight boundaries of the sector/arc. Then compute a circle C2 that touches the inner and the outer radius.
1612
1546
  // The smaller one of these two circles is the biggest possible circle that fits inside sector/arc with center in the middle between inner and outer radius.
@@ -1621,13 +1555,13 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1621
1555
  return Math.min(diameter1, diameter2) > this.minRadialChartDatalabelSpace;
1622
1556
  }
1623
1557
 
1624
- _formatDatalabelsOnRadialChart(value, context) {
1558
+ protected _formatDatalabelsOnRadialChart(value: number, context: Context): string {
1625
1559
  let sum = this._computeSumOfVisibleElements(context),
1626
1560
  dataset = context.dataset,
1627
1561
  roundingError = 0,
1628
1562
  roundedResults = [];
1629
1563
  for (let i = 0; i < context.dataIndex + 1; i++) {
1630
- let result = dataset.data[i] / sum * 100 - roundingError,
1564
+ let result = (dataset.data[i] as number) / sum * 100 - roundingError,
1631
1565
  roundedResult = Math.round(result);
1632
1566
  roundingError = roundedResult - result;
1633
1567
  roundedResults.push(roundedResult + '%');
@@ -1635,32 +1569,33 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1635
1569
  return roundedResults[context.dataIndex];
1636
1570
  }
1637
1571
 
1638
- _computeSumOfVisibleElements(context) {
1572
+ protected _computeSumOfVisibleElements(context: Context): number {
1639
1573
  let dataset = context.dataset,
1640
1574
  chart = context.chart,
1641
1575
  sum = 0;
1642
1576
  for (let i = 0; i < dataset.data.length; i++) {
1643
1577
  if (chart.getDataVisibility(i)) {
1644
- sum += dataset.data[i];
1578
+ sum += dataset.data[i] as number;
1645
1579
  }
1646
1580
  }
1647
1581
  return sum;
1648
1582
  }
1649
1583
 
1650
- _formatDatalabels(value, context) {
1651
- if (context.chart.config.type === Chart.Type.BUBBLE) {
1652
- return this._formatLabel(value.z);
1653
- } else if (context.chart.config.type === Chart.Type.SCATTER) {
1654
- return strings.join(' / ', this._formatLabel(value.x), this._formatLabel(value.y));
1584
+ protected _formatDatalabels(value: number | ScatterDataPoint | BubbleDataPoint, context: Context): string {
1585
+ let config = context.chart.config as ChartConfiguration;
1586
+ if (config.type === Chart.Type.BUBBLE) {
1587
+ return this._formatLabel((value as BubbleDataPoint).z);
1588
+ } else if (config.type === Chart.Type.SCATTER) {
1589
+ return strings.join(' / ', this._formatLabel((value as ScatterDataPoint).x), this._formatLabel((value as ScatterDataPoint).y));
1655
1590
  }
1656
- return this._formatLabel(value);
1591
+ return this._formatLabel(value as number);
1657
1592
  }
1658
1593
 
1659
- _getBackgroundColorOfDataset(context) {
1660
- return context.dataset.backgroundColor;
1594
+ protected _getBackgroundColorOfDataset(context: Context): Color {
1595
+ return context.dataset.backgroundColor as Color;
1661
1596
  }
1662
1597
 
1663
- _adjustColors(config) {
1598
+ protected _adjustColors(config: ChartConfig) {
1664
1599
  this._adjustColorSchemeCssClass(config);
1665
1600
  this._adjustDatasetColors(config);
1666
1601
  this._adjustLegendColors(config);
@@ -1669,14 +1604,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1669
1604
  this._adjustPluginColors(config);
1670
1605
  }
1671
1606
 
1672
- _adjustColorSchemeCssClass(config) {
1607
+ protected _adjustColorSchemeCssClass(config: ChartConfig) {
1673
1608
  if (!config || !config.options) {
1674
1609
  return;
1675
1610
  }
1676
1611
  this.colorSchemeCssClass = colorSchemes.getCssClasses(config.options.colorScheme).join(' ');
1677
1612
  }
1678
1613
 
1679
- _adjustDatasetColors(config) {
1614
+ protected _adjustDatasetColors(config: ChartConfig) {
1680
1615
  if (!config || !config.data || !config.type) {
1681
1616
  return;
1682
1617
  }
@@ -1755,7 +1690,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1755
1690
  setProperty('pointHoverBackgroundColor', elem.uncheckedPointHoverBackgroundColor);
1756
1691
 
1757
1692
  let uncheckedPointRadius = arrays.init(datasetLength, ((config.options.elements || {}).point || {}).radius || ChartJs.defaults.elements.point.radius),
1758
- checkedPointRadius = arrays.init(datasetLength, (((config.options.elements || {}).point || {}).hoverRadius || ChartJs.defaults.elements.point.hoverRadius) - 1);
1693
+ checkedPointRadius = arrays.init(datasetLength, (((config.options.elements || {}).point || {}).hoverRadius || ChartJs.defaults.elements.point.hoverRadius) as number - 1);
1759
1694
  setProperty('uncheckedPointRadius', uncheckedPointRadius);
1760
1695
  setProperty('checkedPointRadius', checkedPointRadius);
1761
1696
 
@@ -1769,14 +1704,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1769
1704
  }
1770
1705
  }
1771
1706
 
1772
- _computeDatasetColors(config, multipleColorsPerDataset) {
1707
+ protected _computeDatasetColors(config: ChartConfig, multipleColorsPerDataset: boolean): DatasetColors {
1773
1708
  if (!config || !config.data || !config.type) {
1774
1709
  return {};
1775
1710
  }
1776
1711
 
1777
1712
  let data = config.data,
1778
1713
  type = config.type,
1779
- colors = {};
1714
+ colors: DatasetColors = {};
1780
1715
 
1781
1716
  if (config.options && config.options.autoColor) {
1782
1717
  colors = this._computeDatasetColorsAutoColor(config, multipleColorsPerDataset);
@@ -1792,7 +1727,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1792
1727
  return colors;
1793
1728
  }
1794
1729
 
1795
- _computeDatasetColorsAutoColor(config, multipleColorsPerDataset) {
1730
+ protected _computeDatasetColorsAutoColor(config: ChartConfig, multipleColorsPerDataset: boolean): DatasetColors {
1796
1731
  if (!config || !config.data || !config.type || !config.options || !config.options.autoColor) {
1797
1732
  return {};
1798
1733
  }
@@ -1835,11 +1770,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1835
1770
  return colors;
1836
1771
  }
1837
1772
 
1838
- _computeBackgroundColor(type, index, checkable) {
1773
+ protected _computeBackgroundColor(type: ChartType, index: number, checkable: boolean): string {
1839
1774
  return styles.get([this.colorSchemeCssClass, type + '-chart' + (checkable ? ' checkable' : ''), 'elements', 'color' + (index % this.numSupportedColors)], 'fill').fill;
1840
1775
  }
1841
1776
 
1842
- _computeBorderColor(type, index) {
1777
+ protected _computeBorderColor(type: ChartType, index: number): string {
1843
1778
  let additionalProperties;
1844
1779
  if (scout.isOneOf(type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA)) {
1845
1780
  additionalProperties = {stroke: this.firstOpaqueBackgroundColor};
@@ -1847,11 +1782,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1847
1782
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'stroke-color' + (index % this.numSupportedColors)], 'stroke', additionalProperties).stroke;
1848
1783
  }
1849
1784
 
1850
- _computeHoverBackgroundColor(type, index, checkable) {
1785
+ protected _computeHoverBackgroundColor(type: ChartType, index: number, checkable: boolean): string {
1851
1786
  return styles.get([this.colorSchemeCssClass, type + '-chart' + (checkable ? ' checkable' : ''), 'elements', 'color' + (index % this.numSupportedColors) + ' hover'], 'fill').fill;
1852
1787
  }
1853
1788
 
1854
- _computeHoverBorderColor(type, index) {
1789
+ protected _computeHoverBorderColor(type: ChartType, index: number): string {
1855
1790
  let additionalProperties;
1856
1791
  if (scout.isOneOf(type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA)) {
1857
1792
  additionalProperties = {stroke: this.firstOpaqueBackgroundColor};
@@ -1859,23 +1794,23 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1859
1794
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'stroke-color' + (index % this.numSupportedColors) + ' hover'], 'stroke', additionalProperties).stroke;
1860
1795
  }
1861
1796
 
1862
- _computeCheckedBackgroundColor(type, index, checkable) {
1797
+ protected _computeCheckedBackgroundColor(type: ChartType, index: number, checkable: boolean): string {
1863
1798
  return styles.get([this.colorSchemeCssClass, type + '-chart' + (checkable ? ' checkable' : ''), 'elements', 'color' + (index % this.numSupportedColors) + ' checked'], 'fill').fill;
1864
1799
  }
1865
1800
 
1866
- _computeCheckedHoverBackgroundColor(type, index, checkable) {
1801
+ protected _computeCheckedHoverBackgroundColor(type: ChartType, index: number, checkable: boolean): string {
1867
1802
  return styles.get([this.colorSchemeCssClass, type + '-chart' + (checkable ? ' checkable' : ''), 'elements', 'color' + (index % this.numSupportedColors) + ' hover checked'], 'fill').fill;
1868
1803
  }
1869
1804
 
1870
- _computeLegendColor(type, index) {
1805
+ protected _computeLegendColor(type: ChartType, index: number): string {
1871
1806
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'color' + (index % this.numSupportedColors) + ' legend'], 'fill').fill;
1872
1807
  }
1873
1808
 
1874
- _computePointHoverColor(type, index) {
1809
+ protected _computePointHoverColor(type: ChartType, index: number): string {
1875
1810
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'color' + (index % this.numSupportedColors) + ' point hover'], 'fill').fill;
1876
1811
  }
1877
1812
 
1878
- _computeDatasetColorsChartValueGroups(config, multipleColorsPerDataset) {
1813
+ protected _computeDatasetColorsChartValueGroups(config: ChartConfig, multipleColorsPerDataset: boolean): DatasetColors {
1879
1814
  if (!config || !config.type || !this.chart.data) {
1880
1815
  return {};
1881
1816
  }
@@ -1883,7 +1818,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1883
1818
  let type = config.type,
1884
1819
  checkable = config.options && config.options.checkable,
1885
1820
  transparent = config.options && config.options.transparent,
1886
- colors = {
1821
+ colors: DatasetColors = {
1887
1822
  backgroundColors: [],
1888
1823
  borderColors: [],
1889
1824
  hoverBackgroundColors: [],
@@ -1958,7 +1893,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1958
1893
  return colors;
1959
1894
  }
1960
1895
 
1961
- _adjustColorOpacity(color, opacity = 1) {
1896
+ protected _adjustColorOpacity(color: string, opacity = 1): string {
1962
1897
  if (!color || typeof color === 'function') {
1963
1898
  return color;
1964
1899
  }
@@ -1972,7 +1907,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1972
1907
  return color;
1973
1908
  }
1974
1909
 
1975
- _adjustRgbColorOpacity(rgbColor, opacity = 1) {
1910
+ protected _adjustRgbColorOpacity(rgbColor: string, opacity = 1): string {
1976
1911
  if (!rgbColor || rgbColor.indexOf('rgb') !== 0) {
1977
1912
  return rgbColor;
1978
1913
  }
@@ -1981,14 +1916,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
1981
1916
  return 'rgba(' + rgba.red + ', ' + rgba.green + ', ' + rgba.blue + ', ' + rgba.alpha + ')';
1982
1917
  }
1983
1918
 
1984
- _adjustHexColorOpacity(hexColor, opacity = 1) {
1919
+ protected _adjustHexColorOpacity(hexColor: string, opacity = 1): string {
1985
1920
  if (!hexColor || hexColor.indexOf('#') !== 0 || !(hexColor.length === 4 || hexColor.length === 5 || hexColor.length === 7 || hexColor.length === 9)) {
1986
1921
  return hexColor;
1987
1922
  }
1988
1923
  return this._adjustRgbColorOpacity(styles.hexToRgb(hexColor), opacity);
1989
1924
  }
1990
1925
 
1991
- _adjustLegendColors(config) {
1926
+ protected _adjustLegendColors(config: ChartConfig) {
1992
1927
  if (!config || !config.type || !config.options) {
1993
1928
  return;
1994
1929
  }
@@ -2005,14 +1940,13 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2005
1940
  });
2006
1941
  }
2007
1942
 
2008
- _computeLabelColor(type) {
1943
+ protected _computeLabelColor(type: ChartType): string {
2009
1944
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'label'], 'fill').fill;
2010
1945
  }
2011
1946
 
2012
- _generateLegendLabels(chart) {
1947
+ protected _generateLegendLabels(chart: ChartJsChart): LegendItem[] {
2013
1948
  let config = chart.config,
2014
1949
  defaultTypeGenerateLabels;
2015
- // noinspection DuplicatedCode
2016
1950
  if (ChartJs.overrides[config.type] && ChartJs.overrides[config.type].plugins && ChartJs.overrides[config.type].plugins.legend && ChartJs.overrides[config.type].plugins.legend.labels) {
2017
1951
  defaultTypeGenerateLabels = ChartJs.overrides[config.type].plugins.legend.labels.generateLabels;
2018
1952
  }
@@ -2024,13 +1958,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2024
1958
  let data = config.data,
2025
1959
  measureText = chart.ctx.measureText.bind(chart.ctx),
2026
1960
  legend = chart.legend,
2027
- legendLabelOptions = ((legend || {}).options || {}).labels || {},
1961
+ legendProps = legend.getProps(['width', 'maxWidth']) as { width: number; maxWidth: number },
1962
+ legendLabelOptions = ((legend || {}).options || {}).labels || {} as LegendOptions<any>['labels'],
2028
1963
  boxWidth = legendLabelOptions.boxWidth || 0,
2029
1964
  padding = legendLabelOptions.padding || 0,
2030
1965
  horizontalSpace;
2031
1966
  if (scout.isOneOf(config.options.plugins.legend.position, Chart.Position.LEFT, Chart.Position.RIGHT)) {
2032
- if (legend.maxWidth || legend.width) {
2033
- horizontalSpace = Math.max((legend.maxWidth || legend.width) - boxWidth - 2 * padding, 0);
1967
+ if (legendProps.maxWidth || legend.width) {
1968
+ horizontalSpace = Math.max((legendProps.maxWidth || legend.width) - boxWidth - 2 * padding, 0);
2034
1969
  }
2035
1970
  horizontalSpace = Math.min(250, horizontalSpace || 0, this.$canvas.cssWidth() / 3);
2036
1971
 
@@ -2043,7 +1978,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2043
1978
  legendColor, borderColor, backgroundColor;
2044
1979
  if (dataset && scout.isOneOf((dataset.type || config.type), Chart.Type.LINE, Chart.Type.BAR, Chart.Type.RADAR, Chart.Type.BUBBLE, Chart.Type.SCATTER)) {
2045
1980
  legendColor = dataset.legendColor;
2046
- borderColor = this._adjustColorOpacity(dataset.borderColor, 1);
1981
+ borderColor = this._adjustColorOpacity(dataset.borderColor as string, 1);
2047
1982
  } else if (data.datasets.length && scout.isOneOf(config.type, Chart.Type.PIE, Chart.Type.DOUGHNUT, Chart.Type.POLAR_AREA)) {
2048
1983
  dataset = data.datasets[0];
2049
1984
  legendColor = Array.isArray(dataset.legendColor) ? dataset.legendColor[idx] : dataset.legendColor;
@@ -2062,7 +1997,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2062
1997
  return labels;
2063
1998
  }
2064
1999
 
2065
- _adjustScalesRColors(config) {
2000
+ protected _adjustScalesRColors(config: ChartConfig) {
2066
2001
  if (!config || !config.type || !config.options || !config.options.scales || !config.options.scales.r) {
2067
2002
  return;
2068
2003
  }
@@ -2084,19 +2019,19 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2084
2019
  });
2085
2020
  }
2086
2021
 
2087
- _computeLabelBackdropColor(type) {
2022
+ protected _computeLabelBackdropColor(type: ChartType): string {
2088
2023
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'label-backdrop'], 'fill', {fill: this.firstOpaqueBackgroundColor}).fill;
2089
2024
  }
2090
2025
 
2091
- _computeGridColor(type) {
2026
+ protected _computeGridColor(type: ChartType): string {
2092
2027
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'grid'], 'fill').fill;
2093
2028
  }
2094
2029
 
2095
- _computeScaleTicksColor(type) {
2030
+ protected _computeScaleTicksColor(type: ChartType): string {
2096
2031
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'scale-ticks'], 'fill').fill;
2097
2032
  }
2098
2033
 
2099
- _adjustScalesXYColors(config) {
2034
+ protected _adjustScalesXYColors(config: ChartConfig) {
2100
2035
  if (!config || !config.type || !config.options || !config.options.scales) {
2101
2036
  return;
2102
2037
  }
@@ -2130,11 +2065,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2130
2065
  });
2131
2066
  }
2132
2067
 
2133
- _computeAxisLabelColor(type) {
2068
+ protected _computeAxisLabelColor(type: ChartType): string {
2134
2069
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'axis-label'], 'fill').fill;
2135
2070
  }
2136
2071
 
2137
- _adjustPluginColors(config) {
2072
+ protected _adjustPluginColors(config: ChartConfig) {
2138
2073
  if (!config || !config.type || !config.options || !config.options.plugins) {
2139
2074
  return;
2140
2075
  }
@@ -2142,7 +2077,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2142
2077
  this._adjustPluginsDatalabelColors(config);
2143
2078
  }
2144
2079
 
2145
- _adjustPluginsDatalabelColors(config) {
2080
+ protected _adjustPluginsDatalabelColors(config: ChartConfig) {
2146
2081
  if (!config || !config.type || !config.options || !config.options.plugins || !config.options.plugins.datalabels) {
2147
2082
  return;
2148
2083
  }
@@ -2152,11 +2087,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2152
2087
  });
2153
2088
  }
2154
2089
 
2155
- _computeDatalabelColor(type) {
2090
+ protected _computeDatalabelColor(type: ChartType): string {
2156
2091
  return styles.get([this.colorSchemeCssClass, type + '-chart', 'elements', 'datalabel'], 'fill').fill;
2157
2092
  }
2158
2093
 
2159
- _adjustClickHandler(config) {
2094
+ protected _adjustClickHandler(config: ChartConfig) {
2160
2095
  if (!config || !config.options) {
2161
2096
  return;
2162
2097
  }
@@ -2184,12 +2119,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2184
2119
  }
2185
2120
  }
2186
2121
 
2187
- /**
2188
- * @param {object[]} items
2189
- * @param {number} items.index
2190
- * @param {number} items.datasetIndex
2191
- */
2192
- _onClick(event, items) {
2122
+ protected _onClick(event: ChartEvent, items: ActiveElement[]) {
2193
2123
  if (!items.length) {
2194
2124
  return;
2195
2125
  }
@@ -2201,33 +2131,25 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2201
2131
 
2202
2132
  let itemIndex = relevantItem.index,
2203
2133
  datasetIndex = relevantItem.datasetIndex,
2204
- clickObject = {
2134
+ clickObject: ClickObject = {
2205
2135
  datasetIndex: datasetIndex,
2206
2136
  dataIndex: itemIndex
2207
2137
  };
2208
2138
  if (scout.isOneOf(this.chartJs.config.type, Chart.Type.BUBBLE, Chart.Type.SCATTER)) {
2209
- let data = this.chartJs.config.data.datasets[datasetIndex].data[itemIndex];
2139
+ let data = this.chartJs.config.data.datasets[datasetIndex].data[itemIndex] as ScatterDataPoint | BubbleDataPoint;
2210
2140
  clickObject.xIndex = data.x;
2211
2141
  clickObject.yIndex = data.y;
2212
2142
  } else {
2213
2143
  clickObject.xIndex = itemIndex;
2214
2144
  }
2215
2145
 
2216
- let e = new Event();
2217
- e.data = clickObject;
2218
- e.originalEvent = event.native;
2219
- this.chart._onValueClick(e);
2146
+ this.chart.handleValueClick(clickObject, event.native);
2220
2147
  }
2221
2148
 
2222
2149
  /**
2223
2150
  * Selects the most relevant item. Default is the first item.
2224
- *
2225
- * @param {object[]} items
2226
- * @param {number} items.index
2227
- * @param {number} items.datasetIndex
2228
- * @private
2229
2151
  */
2230
- _selectRelevantItem(items) {
2152
+ protected _selectRelevantItem(items: ActiveElement[]): ActiveElement {
2231
2153
  let chartDatasets = this.chartJs.config.data.datasets;
2232
2154
  let relevantItem = items[0];
2233
2155
 
@@ -2235,7 +2157,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2235
2157
  // The smallest bubble, which is drawn in the foreground, is the most relevant item for the bubble chart.
2236
2158
  // If two bubbles are the same size, we choose the one which comes later in the array (bubble with array index n + 1 is draw in front of bubble with array index n)
2237
2159
  items.forEach(item => {
2238
- if (chartDatasets[item.datasetIndex].data[item.index].z <= chartDatasets[relevantItem.datasetIndex].data[relevantItem.index].z) {
2160
+ if ((chartDatasets[item.datasetIndex].data[item.index] as BubbleDataPoint).z <= (chartDatasets[relevantItem.datasetIndex].data[relevantItem.index] as BubbleDataPoint).z) {
2239
2161
  relevantItem = item;
2240
2162
  }
2241
2163
  });
@@ -2243,7 +2165,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2243
2165
  return relevantItem;
2244
2166
  }
2245
2167
 
2246
- _onHover(event, items) {
2168
+ protected _onHover(event: ChartEvent, items: ActiveElement[]) {
2247
2169
  if (!this.chartJs.config || !this.chartJs.config.type) {
2248
2170
  return;
2249
2171
  }
@@ -2273,7 +2195,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2273
2195
  }
2274
2196
  }
2275
2197
 
2276
- _onHoverPointer(event, items) {
2198
+ protected _onHoverPointer(event: ChartEvent, items: ActiveElement[]) {
2277
2199
  this._onHover(event, items);
2278
2200
  if (!this.rendered || this.removing) {
2279
2201
  return;
@@ -2285,7 +2207,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2285
2207
  }
2286
2208
  }
2287
2209
 
2288
- _onLegendClick(e, legendItem, legend) {
2210
+ protected _onLegendClick(e: ChartEvent, legendItem: LegendItem, legend: LegendElement<any>) {
2289
2211
  if (!this.chartJs.config || !this.chartJs.config.type) {
2290
2212
  return;
2291
2213
  }
@@ -2298,10 +2220,10 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2298
2220
  let defaultLegendClick = defaultTypeLegendClick || ChartJs.defaults.plugins.legend.onClick;
2299
2221
  defaultLegendClick.call(this.chartJs, e, legendItem, legend);
2300
2222
  this._onLegendLeave(e, legendItem, legend);
2301
- this._onLegendHoverPointer(e, legendItem, true);
2223
+ this._onLegendHoverPointer(e, legendItem, legend);
2302
2224
  }
2303
2225
 
2304
- _onLegendHover(e, legendItem, legend) {
2226
+ protected _onLegendHover(e: ChartEvent, legendItem: LegendItem, legend: LegendElement<any>) {
2305
2227
  let index = legendItem.datasetIndex,
2306
2228
  config = this.chartJs.config,
2307
2229
  type = config.type;
@@ -2324,7 +2246,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2324
2246
  this.legendHoverDatasets.push(index);
2325
2247
  }
2326
2248
 
2327
- _onLegendHoverPointer(e, legendItem, legend) {
2249
+ protected _onLegendHoverPointer(e: ChartEvent, legendItem: LegendItem, legend: LegendElement<any>) {
2328
2250
  this._onLegendHover(e, legendItem, legend);
2329
2251
  if (!this.rendered || this.removing) {
2330
2252
  return;
@@ -2332,7 +2254,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2332
2254
  this.$canvas.css('cursor', 'pointer');
2333
2255
  }
2334
2256
 
2335
- _onLegendLeave(e, legendItem, legend) {
2257
+ protected _onLegendLeave(e: ChartEvent, legendItem: LegendItem, legend: LegendElement<any>) {
2336
2258
  let index = legendItem.datasetIndex,
2337
2259
  config = this.chartJs.config,
2338
2260
  type = config.type;
@@ -2358,16 +2280,15 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2358
2280
  /**
2359
2281
  * Sets the hover background color as the datasets background color.
2360
2282
  * This little workaround is necessary for the line chart, which does not support a native hover effect.
2361
- * The previous background color will be backuped on the dataset property "backgroundColorBackup"
2283
+ * The previous background color will be backed up on the dataset property "backgroundColorBackup"
2362
2284
  * and can be restored with {@link _restoreBackgroundColor}.
2363
- * @param {Dataset} dataset
2364
2285
  */
2365
- _setHoverBackgroundColor(dataset) {
2286
+ protected _setHoverBackgroundColor(dataset: ChartDataset) {
2366
2287
  if (!dataset) {
2367
2288
  return;
2368
2289
  }
2369
2290
  // backup the old background color first
2370
- dataset.backgroundColorBackup = dataset.backgroundColor;
2291
+ dataset.backgroundColorBackup = dataset.backgroundColor as Color;
2371
2292
  // overwrite the current background color with the hover color
2372
2293
  dataset.backgroundColor = dataset.hoverBackgroundColor;
2373
2294
  this._adjustDatasetBorderWidths(dataset);
@@ -2376,9 +2297,8 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2376
2297
  /**
2377
2298
  * Restores the background color of a dataset or of all datasets,
2378
2299
  * if they were previously overwritten by {@link _setHoverBackgroundColor}.
2379
- * @param {Dataset} [dataset]
2380
2300
  */
2381
- _restoreBackgroundColor(dataset) {
2301
+ protected _restoreBackgroundColor(dataset?: ChartDataset) {
2382
2302
  if (dataset) {
2383
2303
  dataset.backgroundColor = dataset.backgroundColorBackup || dataset.backgroundColor;
2384
2304
  delete dataset.backgroundColorBackup;
@@ -2388,7 +2308,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2388
2308
  }
2389
2309
  }
2390
2310
 
2391
- _onLegendLeavePointer(e, legendItem, legend) {
2311
+ protected _onLegendLeavePointer(e: ChartEvent, legendItem: LegendItem, legend: LegendElement<any>) {
2392
2312
  this._onLegendLeave(e, legendItem, legend);
2393
2313
  if (!this.rendered || this.removing) {
2394
2314
  return;
@@ -2396,7 +2316,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2396
2316
  this.$canvas.css('cursor', 'default');
2397
2317
  }
2398
2318
 
2399
- _updateHoverStyle(datasetIndex, enabled) {
2319
+ protected _updateHoverStyle(datasetIndex: number, enabled: boolean) {
2400
2320
  let config = this.chartJs.config,
2401
2321
  type = config.type,
2402
2322
  mode,
@@ -2423,12 +2343,11 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2423
2343
  }));
2424
2344
  }
2425
2345
  if (elements && elements.length) {
2426
- // noinspection JSCheckFunctionSignatures
2427
2346
  this.chartJs.updateHoverStyle(elements, mode, enabled);
2428
2347
  }
2429
2348
  }
2430
2349
 
2431
- _adjustResizeHandler(config) {
2350
+ protected _adjustResizeHandler(config: ChartConfig) {
2432
2351
  if (!config || !config.options) {
2433
2352
  return;
2434
2353
  }
@@ -2438,17 +2357,17 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2438
2357
  }
2439
2358
  }
2440
2359
 
2441
- _onResize(chart, size) {
2360
+ protected _onResize(chart: ChartJsChart, size: { width: number; height: number }) {
2442
2361
  chart.update();
2443
2362
  this._adjustSize(chart.config, chart.chartArea);
2444
2363
  }
2445
2364
 
2446
- _adjustSize(config, chartArea) {
2365
+ protected _adjustSize(config: ChartConfig, chartArea: ChartArea) {
2447
2366
  this._adjustBubbleSizes(config, chartArea);
2448
2367
  this._adjustGridMaxMin(config, chartArea);
2449
2368
  }
2450
2369
 
2451
- _adjustBubbleSizes(config, chartArea) {
2370
+ protected _adjustBubbleSizes(config: ChartConfig, chartArea: ChartArea) {
2452
2371
  if (config.type !== Chart.Type.BUBBLE) {
2453
2372
  return;
2454
2373
  }
@@ -2456,7 +2375,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2456
2375
  let datasets = config.data.datasets;
2457
2376
  // Scale all bubbles so that the largest radius is equal to sizeOfLargestBubble and the smallest greater than or equal to minBubbleSize.
2458
2377
  // First reset all radii.
2459
- datasets.forEach(dataset => dataset.data.forEach(data => {
2378
+ datasets.forEach(dataset => dataset.data.forEach((data: BubbleDataPoint) => {
2460
2379
  if (!isNaN(data.z)) {
2461
2380
  data.r = Math.sqrt(data.z);
2462
2381
  }
@@ -2508,14 +2427,14 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2508
2427
  bubbleScalingFactor = minBubbleSize / minR;
2509
2428
  }
2510
2429
  }
2511
- datasets.forEach(dataset => dataset.data.forEach(data => {
2430
+ datasets.forEach(dataset => dataset.data.forEach((data: BubbleDataPoint) => {
2512
2431
  if (!objects.isNullOrUndefined(data.r)) {
2513
2432
  data.r = data.r * bubbleScalingFactor + bubbleRadiusOffset;
2514
2433
  }
2515
2434
  }));
2516
2435
  }
2517
2436
 
2518
- _computeMaxMinValue(config, datasets, identifier, exact, boundRange, padding, space) {
2437
+ protected _computeMaxMinValue(config: ChartConfig, datasets: ChartDataset[], identifier?: string, exact?: boolean, boundRange?: boolean, padding?: number, space?: number): Boundary {
2519
2438
  if (!datasets) {
2520
2439
  return;
2521
2440
  }
@@ -2587,7 +2506,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2587
2506
  };
2588
2507
  }
2589
2508
 
2590
- _calculateBoundary(value, roundingFunctionPositive, roundingFunctionNegative) {
2509
+ protected _calculateBoundary(value: number, roundingFunctionPositive: (number) => number, roundingFunctionNegative: (number) => number): number {
2591
2510
  let roundingFunction = roundingFunctionPositive;
2592
2511
  let changeValueSign = false;
2593
2512
  if (value < 0) {
@@ -2602,7 +2521,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2602
2521
  return value;
2603
2522
  }
2604
2523
 
2605
- _calculateBoundaryPositive(value, roundingFunction) {
2524
+ protected _calculateBoundaryPositive(value: number, roundingFunction: (number) => number): number {
2606
2525
  if (!(value > 0) || !roundingFunction) {
2607
2526
  return value;
2608
2527
  }
@@ -2622,7 +2541,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2622
2541
  return value;
2623
2542
  }
2624
2543
 
2625
- _adjustGridMaxMin(config, chartArea) {
2544
+ protected _adjustGridMaxMin(config: ChartConfig, chartArea: ChartArea) {
2626
2545
  if (!config || !config.type || !config.options || !config.options.adjustGridMaxMin || !config.options.scales || !chartArea) {
2627
2546
  return;
2628
2547
  }
@@ -2675,7 +2594,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2675
2594
  this._adjustAxisMaxMin(xAxis, maxXTicks, xBoundary);
2676
2595
  }
2677
2596
 
2678
- _computeBoundaryPointElement(config, identifier, space) {
2597
+ protected _computeBoundaryPointElement(config: ChartConfig, identifier: string, space: number): Boundary {
2679
2598
  if (!config || !config.type || !scout.isOneOf(config.type, Chart.Type.BUBBLE, Chart.Type.SCATTER) || !config.data || !config.options || !config.options.scales || !(identifier === 'x' || identifier === 'y') || !space) {
2680
2599
  return;
2681
2600
  }
@@ -2689,7 +2608,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2689
2608
  let maxR = this._computeMaxMinValue(config, datasets, 'r', true).maxValue,
2690
2609
  padding = maxR;
2691
2610
  if (config.options.elements && config.options.elements.point && config.options.elements.point.hoverRadius) {
2692
- padding = padding + config.options.elements.point.hoverRadius;
2611
+ padding = padding + (config.options.elements.point.hoverRadius as number);
2693
2612
  }
2694
2613
 
2695
2614
  if (offset) {
@@ -2704,15 +2623,15 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2704
2623
  return boundary;
2705
2624
  }
2706
2625
 
2707
- _computeXBoundaryPointElement(config, width) {
2626
+ protected _computeXBoundaryPointElement(config: ChartConfig, width: number): Boundary {
2708
2627
  return this._computeBoundaryPointElement(config, 'x', width);
2709
2628
  }
2710
2629
 
2711
- _computeYBoundaryPointElement(config, height) {
2630
+ protected _computeYBoundaryPointElement(config: ChartConfig, height: number): Boundary {
2712
2631
  return this._computeBoundaryPointElement(config, 'y', height);
2713
2632
  }
2714
2633
 
2715
- _computeYBoundaries(config, height) {
2634
+ protected _computeYBoundaries(config: ChartConfig, height: number): { yBoundary?: Boundary; yBoundaryDiffType?: Boundary } {
2716
2635
  if (!config || !config.type) {
2717
2636
  return {};
2718
2637
  }
@@ -2754,7 +2673,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2754
2673
  };
2755
2674
  }
2756
2675
 
2757
- _adjustYAxisDiffType(config, datasets, datasetsDiffType) {
2676
+ protected _adjustYAxisDiffType(config: ChartConfig, datasets: ChartDataset[], datasetsDiffType: ChartDataset[]) {
2758
2677
  if (!config || !config.type || !datasets || !datasets.length || !datasetsDiffType || !datasetsDiffType.length) {
2759
2678
  return;
2760
2679
  }
@@ -2770,9 +2689,6 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2770
2689
  yAxisDiffType = $.extend(true, {}, yAxis);
2771
2690
  scales.yDiffType = yAxisDiffType;
2772
2691
 
2773
- yAxis.id = 'y';
2774
- yAxisDiffType.id = 'yDiffType';
2775
-
2776
2692
  if (config.data && config.data.datasets && config.data.datasets.length && config.data.datasets[0].type && config.data.datasets[0].type !== type) {
2777
2693
  yAxisDiffType.position = Chart.Position.LEFT;
2778
2694
  yAxis.position = Chart.Position.RIGHT;
@@ -2808,7 +2724,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2808
2724
  });
2809
2725
  }
2810
2726
 
2811
- _adjustAxisMaxMin(axis, maxTicks, maxMinValue) {
2727
+ protected _adjustAxisMaxMin(axis: LinearScaleOptions | RadialLinearScaleOptions, maxTicks: number, maxMinValue: Boundary) {
2812
2728
  if (!axis) {
2813
2729
  return;
2814
2730
  }
@@ -2827,7 +2743,7 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2827
2743
  axis.ticks.stepSize = this.onlyIntegers && maxRangeBetweenTwoTicks < 1 ? 1 : undefined;
2828
2744
  }
2829
2745
 
2830
- _remove(afterRemoveFunc) {
2746
+ protected override _remove(afterRemoveFunc: (chartAnimationStopping?: boolean) => void) {
2831
2747
  if (this.rendered && !this.removing) {
2832
2748
  this.removing = true;
2833
2749
  this.chartJs.destroy();
@@ -2839,3 +2755,92 @@ export default class ChartJsRenderer extends AbstractChartRenderer {
2839
2755
  this.removing = false;
2840
2756
  }
2841
2757
  }
2758
+
2759
+ export type LabelFormatter = (label: number | string) => string;
2760
+ export type AxisFitter = (axis: Scale<CartesianScaleOptions>) => void;
2761
+ export type DatalabelsDisplayHandler = (context: Context) => boolean;
2762
+ export type DatalabelsFormatter = (value: number | ScatterDataPoint | BubbleDataPoint, context: Context) => string;
2763
+ export type DatalabelBackgroundColorHandler = (context: Context) => Color;
2764
+ export type RadialChartDatalabelsFormatter = (value: number, context: Context) => string;
2765
+ export type LegendLabelGenerator = (chart: ChartJsChart) => LegendItem[];
2766
+ export type ChartEventHandler = (event: ChartEvent, items: ActiveElement[]) => void;
2767
+ export type LegendEventHandler = (e: ChartEvent, legendItem: LegendItem, legend: LegendElement<any>) => void;
2768
+ export type ResizeHandler = (chart: ChartJsChart | ChartJs, size: { width: number; height: number }) => void;
2769
+ export type TooltipTitleGenerator = (tooltipItems: TooltipItem<any>[]) => string | string[];
2770
+ export type TooltipItemsGenerator = (tooltipItems: TooltipItem<any>[], tooltipLabel: TooltipLabelGenerator, tooltipLabelValue: TooltipLabelValueGenerator, tooltipColor: TooltipLabelColorGenerator) => string;
2771
+ export type TooltipLabelGenerator = (tooltipItem: TooltipItem<any>) => string | string[];
2772
+ export type TooltipLabelValueGenerator = (tooltipItem: TooltipItem<any>) => string | { x: string; y: string };
2773
+ export type TooltipLabelColorGenerator = (tooltipItem: TooltipItem<any>) => TooltipLabelStyle;
2774
+ export type TooltipRenderer = (context: { chart: ChartJs; tooltip: TooltipModel<any> }) => void;
2775
+
2776
+ export type DatasetColors = {
2777
+ backgroundColors?: string[];
2778
+ borderColors?: string[];
2779
+ hoverBackgroundColors?: string[];
2780
+ hoverBorderColors?: string[];
2781
+ checkedBackgroundColors?: string[];
2782
+ checkedHoverBackgroundColors?: string[];
2783
+ legendColors?: string[];
2784
+ pointHoverColors?: string[];
2785
+ datalabelColor?: string;
2786
+ };
2787
+
2788
+ export type Boundary = { maxValue: number; minValue: number };
2789
+
2790
+ // extend chart.js
2791
+
2792
+ export type ChartJsChart = Omit<ChartJs, 'config'> & {
2793
+ config: ChartConfig;
2794
+ legend?: LegendElement<any>;
2795
+ };
2796
+
2797
+ declare module 'chart.js' {
2798
+ interface ChartData<TType extends ChartJsType = ChartJsType, TData = DefaultDataPoint<TType>, TLabel = unknown> {
2799
+ maxSegmentsExceeded?: boolean;
2800
+ }
2801
+
2802
+ interface ChartDatasetProperties<TType extends ChartJsType, TData> {
2803
+ datasetId?: string;
2804
+ yAxisID?: 'y' | 'yDiffType';
2805
+
2806
+ pointBackgroundColor?: Color;
2807
+ pointHoverBackgroundColor?: Color;
2808
+ pointRadius?: number;
2809
+ legendColor?: Color;
2810
+
2811
+ checkedBackgroundColor?: Color;
2812
+ checkedHoverBackgroundColor?: Color;
2813
+ checkedPointBackgroundColor?: Color;
2814
+ checkedPointHoverBackgroundColor?: Color;
2815
+ checkedPointRadius?: number;
2816
+
2817
+ uncheckedBackgroundColor?: Color;
2818
+ uncheckedHoverBackgroundColor?: Color;
2819
+ uncheckedPointBackgroundColor?: Color;
2820
+ uncheckedPointHoverBackgroundColor?: Color;
2821
+ uncheckedPointRadius?: number;
2822
+
2823
+ backgroundColorBackup?: Color;
2824
+ }
2825
+
2826
+ interface BubbleDataPoint {
2827
+ z: number;
2828
+ }
2829
+
2830
+ interface TooltipOptions<TType extends ChartJsType = ChartJsType> {
2831
+ cssClass?: string;
2832
+ }
2833
+
2834
+ interface TooltipCallbacks<TType extends ChartJsType, Model = TooltipModel<TType>, Item = TooltipItem<TType>> {
2835
+ items: TooltipItemsGenerator;
2836
+ labelValue: TooltipLabelValueGenerator;
2837
+ }
2838
+ }
2839
+
2840
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2841
+ interface RadarPointElement<T extends RadarProps = RadarProps, O extends PointOptions = PointOptions> extends PointElement<T, O> {
2842
+ }
2843
+
2844
+ interface RadarProps extends PointProps {
2845
+ angle: number;
2846
+ }