chartjs-chart-matrix 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-2021 Jukka Kurkela
3
+ Copyright (c) 2019-2025 Jukka Kurkela
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -5,9 +5,10 @@
5
5
  [![npm](https://img.shields.io/npm/v/chartjs-chart-matrix.svg)](https://www.npmjs.com/package/chartjs-chart-matrix)
6
6
  [![release](https://img.shields.io/github/release/kurkle/chartjs-chart-matrix.svg?style=flat-square)](https://github.com/kurkle/chartjs-chart-matrix/releases/latest)
7
7
  ![npm bundle size](https://img.shields.io/bundlephobia/min/chartjs-chart-matrix.svg)
8
- ![GitHub](https://img.shields.io/github/license/kurkle/chartjs-chart-matrix.svg)
9
8
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=kurkle_chartjs-chart-matrix&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=kurkle_chartjs-chart-matrix)
9
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=kurkle_chartjs-chart-matrix&metric=coverage)](https://sonarcloud.io/summary/new_code?id=kurkle_chartjs-chart-matrix)
10
10
  [![documentation](https://img.shields.io/static/v1?message=Documentation&color=informational)](https://chartjs-chart-matrix.pages.dev)
11
+ ![GitHub](https://img.shields.io/github/license/kurkle/chartjs-chart-matrix.svg)
11
12
 
12
13
  ## Example
13
14
 
@@ -13,181 +13,234 @@ typeof define === 'function' && define.amd ? define(['exports', 'chart.js', 'cha
13
13
  var version = "0.0.0-development";
14
14
 
15
15
  class MatrixController extends chart_js.DatasetController {
16
-
17
- static id = 'matrix';
18
- static version = version;
19
-
20
- static defaults = {
16
+ initialize() {
17
+ this.enableOptionSharing = true;
18
+ super.initialize();
19
+ }
20
+ update(mode) {
21
+ const meta = this._cachedMeta;
22
+ this.updateElements(meta.data, 0, meta.data.length, mode);
23
+ }
24
+ updateElements(rects, start, count, mode) {
25
+ const reset = mode === 'reset';
26
+ const { xScale, yScale } = this._cachedMeta;
27
+ const firstOpts = this.resolveDataElementOptions(start, mode);
28
+ const sharedOptions = this.getSharedOptions(firstOpts);
29
+ for(let i = start; i < start + count; i++){
30
+ const parsed = !reset && this.getParsed(i);
31
+ const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x);
32
+ const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y);
33
+ const options = this.resolveDataElementOptions(i, mode);
34
+ const { width, height, anchorX, anchorY } = options;
35
+ const properties = {
36
+ x: resolveX(anchorX, x, width),
37
+ y: resolveY(anchorY, y, height),
38
+ width,
39
+ height,
40
+ options
41
+ };
42
+ this.updateElement(rects[i], i, properties, mode);
43
+ }
44
+ this.updateSharedOptions(sharedOptions, mode, firstOpts);
45
+ }
46
+ draw() {
47
+ const ctx = this.chart.ctx;
48
+ const data = this.getMeta().data || [];
49
+ let i, ilen;
50
+ for(i = 0, ilen = data.length; i < ilen; ++i){
51
+ data[i].draw(ctx);
52
+ }
53
+ }
54
+ }
55
+ MatrixController.id = 'matrix';
56
+ MatrixController.version = version;
57
+ MatrixController.defaults = {
21
58
  dataElementType: 'matrix',
22
-
23
59
  animations: {
24
- numbers: {
25
- type: 'number',
26
- properties: ['x', 'y', 'width', 'height']
27
- }
28
- },
29
- };
30
-
31
- static overrides = {
60
+ numbers: {
61
+ type: 'number',
62
+ properties: [
63
+ 'x',
64
+ 'y',
65
+ 'width',
66
+ 'height'
67
+ ]
68
+ }
69
+ }
70
+ };
71
+ MatrixController.overrides = {
32
72
  interaction: {
33
- mode: 'nearest',
34
- intersect: true
73
+ mode: 'nearest',
74
+ intersect: true
35
75
  },
36
76
  scales: {
37
- x: {
38
- type: 'linear',
39
- offset: true
40
- },
41
- y: {
42
- type: 'linear',
43
- reverse: true
44
- }
45
- },
46
- };
47
-
48
- initialize() {
49
- this.enableOptionSharing = true;
50
- super.initialize();
51
- }
52
-
53
- update(mode) {
54
- const me = this;
55
- const meta = me._cachedMeta;
56
-
57
- me.updateElements(meta.data, 0, meta.data.length, mode);
58
- }
59
-
60
- updateElements(rects, start, count, mode) {
61
- const me = this;
62
- const reset = mode === 'reset';
63
- const {xScale, yScale} = me._cachedMeta;
64
- const firstOpts = me.resolveDataElementOptions(start, mode);
65
- const sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts);
66
-
67
- for (let i = start; i < start + count; i++) {
68
- const parsed = !reset && me.getParsed(i);
69
- const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x);
70
- const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y);
71
- const options = me.resolveDataElementOptions(i, mode);
72
- const {width, height, anchorX, anchorY} = options;
73
- const properties = {
74
- x: resolveX(anchorX, x, width),
75
- y: resolveY(anchorY, y, height),
76
- width,
77
- height,
78
- options
79
- };
80
- me.updateElement(rects[i], i, properties, mode);
77
+ x: {
78
+ type: 'linear',
79
+ offset: true
80
+ },
81
+ y: {
82
+ type: 'linear',
83
+ reverse: true
84
+ }
81
85
  }
82
-
83
- me.updateSharedOptions(sharedOptions, mode);
84
- }
85
-
86
- draw() {
87
- const me = this;
88
- const data = me.getMeta().data || [];
89
- let i, ilen;
90
-
91
- for (i = 0, ilen = data.length; i < ilen; ++i) {
92
- data[i].draw(me._ctx);
93
- }
94
- }
95
- }
96
-
86
+ };
97
87
  function resolveX(anchorX, x, width) {
98
- if (anchorX === 'left' || anchorX === 'start') {
99
- return x;
100
- }
101
- if (anchorX === 'right' || anchorX === 'end') {
102
- return x - width;
103
- }
104
- return x - width / 2;
88
+ if (anchorX === 'left' || anchorX === 'start') {
89
+ return x;
90
+ }
91
+ if (anchorX === 'right' || anchorX === 'end') {
92
+ return x - width;
93
+ }
94
+ return x - width / 2;
105
95
  }
106
-
107
96
  function resolveY(anchorY, y, height) {
108
- if (anchorY === 'top' || anchorY === 'start') {
109
- return y;
110
- }
111
- if (anchorY === 'bottom' || anchorY === 'end') {
112
- return y - height;
113
- }
114
- return y - height / 2;
97
+ if (anchorY === 'top' || anchorY === 'start') {
98
+ return y;
99
+ }
100
+ if (anchorY === 'bottom' || anchorY === 'end') {
101
+ return y - height;
102
+ }
103
+ return y - height / 2;
115
104
  }
116
105
 
117
- /**
118
- * Helper function to get the bounds of the rect
119
- * @param {MatrixElement} rect the rect
120
- * @param {boolean} [useFinalPosition]
121
- * @return {object} bounds of the rect
122
- * @private
123
- */
124
- function getBounds(rect, useFinalPosition) {
125
- const {x, y, width, height} = rect.getProps(['x', 'y', 'width', 'height'], useFinalPosition);
126
- return {left: x, top: y, right: x + width, bottom: y + height};
106
+ function getBounds(element, useFinalPosition) {
107
+ const { x, y, width, height } = element.getProps([
108
+ 'x',
109
+ 'y',
110
+ 'width',
111
+ 'height'
112
+ ], useFinalPosition);
113
+ return {
114
+ left: x,
115
+ top: y,
116
+ right: x + width,
117
+ bottom: y + height
118
+ };
127
119
  }
128
-
129
120
  function limit(value, min, max) {
130
- return Math.max(Math.min(value, max), min);
121
+ return Math.max(Math.min(value, max), min);
131
122
  }
132
-
133
- function parseBorderWidth(rect, maxW, maxH) {
134
- const value = rect.options.borderWidth;
135
- let t, r, b, l;
136
-
137
- if (helpers.isObject(value)) {
138
- t = +value.top || 0;
139
- r = +value.right || 0;
140
- b = +value.bottom || 0;
141
- l = +value.left || 0;
142
- } else {
143
- t = r = b = l = +value || 0;
144
- }
145
-
146
- return {
147
- t: limit(t, 0, maxH),
148
- r: limit(r, 0, maxW),
149
- b: limit(b, 0, maxH),
150
- l: limit(l, 0, maxW)
151
- };
152
- }
153
-
154
- function boundingRects(rect) {
155
- const bounds = getBounds(rect);
156
- const width = bounds.right - bounds.left;
157
- const height = bounds.bottom - bounds.top;
158
- const border = parseBorderWidth(rect, width / 2, height / 2);
159
-
160
- return {
161
- outer: {
162
- x: bounds.left,
163
- y: bounds.top,
164
- w: width,
165
- h: height
166
- },
167
- inner: {
168
- x: bounds.left + border.l,
169
- y: bounds.top + border.t,
170
- w: width - border.l - border.r,
171
- h: height - border.t - border.b
123
+ function parseBorderWidth(options, maxW, maxH) {
124
+ const value = options.borderWidth;
125
+ let t, r, b, l;
126
+ if (helpers.isObject(value)) {
127
+ t = +value.top || 0;
128
+ r = +value.right || 0;
129
+ b = +value.bottom || 0;
130
+ l = +value.left || 0;
131
+ } else {
132
+ t = r = b = l = +value || 0;
172
133
  }
173
- };
134
+ return {
135
+ t: limit(t, 0, maxH),
136
+ r: limit(r, 0, maxW),
137
+ b: limit(b, 0, maxH),
138
+ l: limit(l, 0, maxW)
139
+ };
174
140
  }
175
-
176
- function inRange(rect, x, y, useFinalPosition) {
177
- const skipX = x === null;
178
- const skipY = y === null;
179
- const bounds = !rect || (skipX && skipY) ? false : getBounds(rect, useFinalPosition);
180
-
181
- return bounds
182
- && (skipX || x >= bounds.left && x <= bounds.right)
183
- && (skipY || y >= bounds.top && y <= bounds.bottom);
141
+ function boundingRects(element) {
142
+ const bounds = getBounds(element, false);
143
+ const width = bounds.right - bounds.left;
144
+ const height = bounds.bottom - bounds.top;
145
+ const border = parseBorderWidth(element.options, width / 2, height / 2);
146
+ return {
147
+ outer: {
148
+ x: bounds.left,
149
+ y: bounds.top,
150
+ w: width,
151
+ h: height
152
+ },
153
+ inner: {
154
+ x: bounds.left + border.l,
155
+ y: bounds.top + border.t,
156
+ w: width - border.l - border.r,
157
+ h: height - border.t - border.b
158
+ }
159
+ };
160
+ }
161
+ function inRange(element, x, y, useFinalPosition) {
162
+ const skipX = x === null;
163
+ const skipY = y === null;
164
+ const bounds = !element || skipX && skipY ? false : getBounds(element, useFinalPosition);
165
+ return bounds && (skipX || x >= bounds.left && x <= bounds.right) && (skipY || y >= bounds.top && y <= bounds.bottom);
184
166
  }
185
167
 
186
168
  class MatrixElement extends chart_js.Element {
187
-
188
- static id = 'matrix';
189
-
190
- static defaults = {
169
+ draw(ctx) {
170
+ const options = this.options;
171
+ const { inner, outer } = boundingRects(this);
172
+ const radius = helpers.toTRBLCorners(options.borderRadius);
173
+ ctx.save();
174
+ if (outer.w !== inner.w || outer.h !== inner.h) {
175
+ ctx.beginPath();
176
+ helpers.addRoundedRectPath(ctx, {
177
+ x: outer.x,
178
+ y: outer.y,
179
+ w: outer.w,
180
+ h: outer.h,
181
+ radius
182
+ });
183
+ helpers.addRoundedRectPath(ctx, {
184
+ x: inner.x,
185
+ y: inner.y,
186
+ w: inner.w,
187
+ h: inner.h,
188
+ radius
189
+ });
190
+ ctx.fillStyle = options.backgroundColor;
191
+ ctx.fill();
192
+ ctx.fillStyle = options.borderColor;
193
+ ctx.fill('evenodd');
194
+ } else {
195
+ ctx.beginPath();
196
+ helpers.addRoundedRectPath(ctx, {
197
+ x: inner.x,
198
+ y: inner.y,
199
+ w: inner.w,
200
+ h: inner.h,
201
+ radius
202
+ });
203
+ ctx.fillStyle = options.backgroundColor;
204
+ ctx.fill();
205
+ }
206
+ ctx.restore();
207
+ }
208
+ inRange(mouseX, mouseY, useFinalPosition) {
209
+ return inRange(this, mouseX, mouseY, useFinalPosition);
210
+ }
211
+ inXRange(mouseX, useFinalPosition) {
212
+ return inRange(this, mouseX, null, useFinalPosition);
213
+ }
214
+ inYRange(mouseY, useFinalPosition) {
215
+ return inRange(this, null, mouseY, useFinalPosition);
216
+ }
217
+ getCenterPoint(useFinalPosition) {
218
+ const { x, y, width, height } = this.getProps([
219
+ 'x',
220
+ 'y',
221
+ 'width',
222
+ 'height'
223
+ ], useFinalPosition);
224
+ return {
225
+ x: x + width / 2,
226
+ y: y + height / 2
227
+ };
228
+ }
229
+ tooltipPosition() {
230
+ return this.getCenterPoint();
231
+ }
232
+ getRange(axis) {
233
+ return axis === 'x' ? this.width / 2 : this.height / 2;
234
+ }
235
+ constructor(cfg){
236
+ super();
237
+ if (cfg) {
238
+ Object.assign(this, cfg);
239
+ }
240
+ }
241
+ }
242
+ MatrixElement.id = 'matrix';
243
+ MatrixElement.defaults = {
191
244
  backgroundColor: undefined,
192
245
  borderColor: undefined,
193
246
  borderWidth: undefined,
@@ -196,73 +249,7 @@ class MatrixElement extends chart_js.Element {
196
249
  anchorY: 'center',
197
250
  width: 20,
198
251
  height: 20
199
- };
200
-
201
- constructor(cfg) {
202
- super();
203
-
204
- this.options = undefined;
205
- this.width = undefined;
206
- this.height = undefined;
207
-
208
- if (cfg) {
209
- Object.assign(this, cfg);
210
- }
211
- }
212
-
213
- draw(ctx) {
214
- const options = this.options;
215
- const {inner, outer} = boundingRects(this);
216
- const radius = helpers.toTRBLCorners(options.borderRadius);
217
-
218
- ctx.save();
219
-
220
- if (outer.w !== inner.w || outer.h !== inner.h) {
221
- ctx.beginPath();
222
- helpers.addRoundedRectPath(ctx, {x: outer.x, y: outer.y, w: outer.w, h: outer.h, radius});
223
- helpers.addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius});
224
- ctx.fillStyle = options.backgroundColor;
225
- ctx.fill();
226
- ctx.fillStyle = options.borderColor;
227
- ctx.fill('evenodd');
228
- } else {
229
- ctx.beginPath();
230
- helpers.addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius});
231
- ctx.fillStyle = options.backgroundColor;
232
- ctx.fill();
233
- }
234
-
235
- ctx.restore();
236
- }
237
-
238
- inRange(mouseX, mouseY, useFinalPosition) {
239
- return inRange(this, mouseX, mouseY, useFinalPosition);
240
- }
241
-
242
- inXRange(mouseX, useFinalPosition) {
243
- return inRange(this, mouseX, null, useFinalPosition);
244
- }
245
-
246
- inYRange(mouseY, useFinalPosition) {
247
- return inRange(this, null, mouseY, useFinalPosition);
248
- }
249
-
250
- getCenterPoint(useFinalPosition) {
251
- const {x, y, width, height} = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition);
252
- return {
253
- x: x + width / 2,
254
- y: y + height / 2
255
- };
256
- }
257
-
258
- tooltipPosition() {
259
- return this.getCenterPoint();
260
- }
261
-
262
- getRange(axis) {
263
- return axis === 'x' ? this.width / 2 : this.height / 2;
264
- }
265
- }
252
+ };
266
253
 
267
254
  chart_js.Chart.register(MatrixController, MatrixElement);
268
255
 
@@ -5,186 +5,239 @@
5
5
  * Released under the MIT license
6
6
  */
7
7
  import { DatasetController, Element } from 'chart.js';
8
- import { toTRBLCorners, addRoundedRectPath, isObject } from 'chart.js/helpers';
8
+ import { isObject, toTRBLCorners, addRoundedRectPath } from 'chart.js/helpers';
9
9
 
10
10
  var version = "0.0.0-development";
11
11
 
12
12
  class MatrixController extends DatasetController {
13
-
14
- static id = 'matrix';
15
- static version = version;
16
-
17
- static defaults = {
13
+ initialize() {
14
+ this.enableOptionSharing = true;
15
+ super.initialize();
16
+ }
17
+ update(mode) {
18
+ const meta = this._cachedMeta;
19
+ this.updateElements(meta.data, 0, meta.data.length, mode);
20
+ }
21
+ updateElements(rects, start, count, mode) {
22
+ const reset = mode === 'reset';
23
+ const { xScale, yScale } = this._cachedMeta;
24
+ const firstOpts = this.resolveDataElementOptions(start, mode);
25
+ const sharedOptions = this.getSharedOptions(firstOpts);
26
+ for(let i = start; i < start + count; i++){
27
+ const parsed = !reset && this.getParsed(i);
28
+ const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x);
29
+ const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y);
30
+ const options = this.resolveDataElementOptions(i, mode);
31
+ const { width, height, anchorX, anchorY } = options;
32
+ const properties = {
33
+ x: resolveX(anchorX, x, width),
34
+ y: resolveY(anchorY, y, height),
35
+ width,
36
+ height,
37
+ options
38
+ };
39
+ this.updateElement(rects[i], i, properties, mode);
40
+ }
41
+ this.updateSharedOptions(sharedOptions, mode, firstOpts);
42
+ }
43
+ draw() {
44
+ const ctx = this.chart.ctx;
45
+ const data = this.getMeta().data || [];
46
+ let i, ilen;
47
+ for(i = 0, ilen = data.length; i < ilen; ++i){
48
+ data[i].draw(ctx);
49
+ }
50
+ }
51
+ }
52
+ MatrixController.id = 'matrix';
53
+ MatrixController.version = version;
54
+ MatrixController.defaults = {
18
55
  dataElementType: 'matrix',
19
-
20
56
  animations: {
21
- numbers: {
22
- type: 'number',
23
- properties: ['x', 'y', 'width', 'height']
24
- }
25
- },
26
- };
27
-
28
- static overrides = {
57
+ numbers: {
58
+ type: 'number',
59
+ properties: [
60
+ 'x',
61
+ 'y',
62
+ 'width',
63
+ 'height'
64
+ ]
65
+ }
66
+ }
67
+ };
68
+ MatrixController.overrides = {
29
69
  interaction: {
30
- mode: 'nearest',
31
- intersect: true
70
+ mode: 'nearest',
71
+ intersect: true
32
72
  },
33
73
  scales: {
34
- x: {
35
- type: 'linear',
36
- offset: true
37
- },
38
- y: {
39
- type: 'linear',
40
- reverse: true
41
- }
42
- },
43
- };
44
-
45
- initialize() {
46
- this.enableOptionSharing = true;
47
- super.initialize();
48
- }
49
-
50
- update(mode) {
51
- const me = this;
52
- const meta = me._cachedMeta;
53
-
54
- me.updateElements(meta.data, 0, meta.data.length, mode);
55
- }
56
-
57
- updateElements(rects, start, count, mode) {
58
- const me = this;
59
- const reset = mode === 'reset';
60
- const {xScale, yScale} = me._cachedMeta;
61
- const firstOpts = me.resolveDataElementOptions(start, mode);
62
- const sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts);
63
-
64
- for (let i = start; i < start + count; i++) {
65
- const parsed = !reset && me.getParsed(i);
66
- const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x);
67
- const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y);
68
- const options = me.resolveDataElementOptions(i, mode);
69
- const {width, height, anchorX, anchorY} = options;
70
- const properties = {
71
- x: resolveX(anchorX, x, width),
72
- y: resolveY(anchorY, y, height),
73
- width,
74
- height,
75
- options
76
- };
77
- me.updateElement(rects[i], i, properties, mode);
74
+ x: {
75
+ type: 'linear',
76
+ offset: true
77
+ },
78
+ y: {
79
+ type: 'linear',
80
+ reverse: true
81
+ }
78
82
  }
79
-
80
- me.updateSharedOptions(sharedOptions, mode);
81
- }
82
-
83
- draw() {
84
- const me = this;
85
- const data = me.getMeta().data || [];
86
- let i, ilen;
87
-
88
- for (i = 0, ilen = data.length; i < ilen; ++i) {
89
- data[i].draw(me._ctx);
90
- }
91
- }
92
- }
93
-
83
+ };
94
84
  function resolveX(anchorX, x, width) {
95
- if (anchorX === 'left' || anchorX === 'start') {
96
- return x;
97
- }
98
- if (anchorX === 'right' || anchorX === 'end') {
99
- return x - width;
100
- }
101
- return x - width / 2;
85
+ if (anchorX === 'left' || anchorX === 'start') {
86
+ return x;
87
+ }
88
+ if (anchorX === 'right' || anchorX === 'end') {
89
+ return x - width;
90
+ }
91
+ return x - width / 2;
102
92
  }
103
-
104
93
  function resolveY(anchorY, y, height) {
105
- if (anchorY === 'top' || anchorY === 'start') {
106
- return y;
107
- }
108
- if (anchorY === 'bottom' || anchorY === 'end') {
109
- return y - height;
110
- }
111
- return y - height / 2;
94
+ if (anchorY === 'top' || anchorY === 'start') {
95
+ return y;
96
+ }
97
+ if (anchorY === 'bottom' || anchorY === 'end') {
98
+ return y - height;
99
+ }
100
+ return y - height / 2;
112
101
  }
113
102
 
114
- /**
115
- * Helper function to get the bounds of the rect
116
- * @param {MatrixElement} rect the rect
117
- * @param {boolean} [useFinalPosition]
118
- * @return {object} bounds of the rect
119
- * @private
120
- */
121
- function getBounds(rect, useFinalPosition) {
122
- const {x, y, width, height} = rect.getProps(['x', 'y', 'width', 'height'], useFinalPosition);
123
- return {left: x, top: y, right: x + width, bottom: y + height};
103
+ function getBounds(element, useFinalPosition) {
104
+ const { x, y, width, height } = element.getProps([
105
+ 'x',
106
+ 'y',
107
+ 'width',
108
+ 'height'
109
+ ], useFinalPosition);
110
+ return {
111
+ left: x,
112
+ top: y,
113
+ right: x + width,
114
+ bottom: y + height
115
+ };
124
116
  }
125
-
126
117
  function limit(value, min, max) {
127
- return Math.max(Math.min(value, max), min);
118
+ return Math.max(Math.min(value, max), min);
128
119
  }
129
-
130
- function parseBorderWidth(rect, maxW, maxH) {
131
- const value = rect.options.borderWidth;
132
- let t, r, b, l;
133
-
134
- if (isObject(value)) {
135
- t = +value.top || 0;
136
- r = +value.right || 0;
137
- b = +value.bottom || 0;
138
- l = +value.left || 0;
139
- } else {
140
- t = r = b = l = +value || 0;
141
- }
142
-
143
- return {
144
- t: limit(t, 0, maxH),
145
- r: limit(r, 0, maxW),
146
- b: limit(b, 0, maxH),
147
- l: limit(l, 0, maxW)
148
- };
149
- }
150
-
151
- function boundingRects(rect) {
152
- const bounds = getBounds(rect);
153
- const width = bounds.right - bounds.left;
154
- const height = bounds.bottom - bounds.top;
155
- const border = parseBorderWidth(rect, width / 2, height / 2);
156
-
157
- return {
158
- outer: {
159
- x: bounds.left,
160
- y: bounds.top,
161
- w: width,
162
- h: height
163
- },
164
- inner: {
165
- x: bounds.left + border.l,
166
- y: bounds.top + border.t,
167
- w: width - border.l - border.r,
168
- h: height - border.t - border.b
120
+ function parseBorderWidth(options, maxW, maxH) {
121
+ const value = options.borderWidth;
122
+ let t, r, b, l;
123
+ if (isObject(value)) {
124
+ t = +value.top || 0;
125
+ r = +value.right || 0;
126
+ b = +value.bottom || 0;
127
+ l = +value.left || 0;
128
+ } else {
129
+ t = r = b = l = +value || 0;
169
130
  }
170
- };
131
+ return {
132
+ t: limit(t, 0, maxH),
133
+ r: limit(r, 0, maxW),
134
+ b: limit(b, 0, maxH),
135
+ l: limit(l, 0, maxW)
136
+ };
171
137
  }
172
-
173
- function inRange(rect, x, y, useFinalPosition) {
174
- const skipX = x === null;
175
- const skipY = y === null;
176
- const bounds = !rect || (skipX && skipY) ? false : getBounds(rect, useFinalPosition);
177
-
178
- return bounds
179
- && (skipX || x >= bounds.left && x <= bounds.right)
180
- && (skipY || y >= bounds.top && y <= bounds.bottom);
138
+ function boundingRects(element) {
139
+ const bounds = getBounds(element, false);
140
+ const width = bounds.right - bounds.left;
141
+ const height = bounds.bottom - bounds.top;
142
+ const border = parseBorderWidth(element.options, width / 2, height / 2);
143
+ return {
144
+ outer: {
145
+ x: bounds.left,
146
+ y: bounds.top,
147
+ w: width,
148
+ h: height
149
+ },
150
+ inner: {
151
+ x: bounds.left + border.l,
152
+ y: bounds.top + border.t,
153
+ w: width - border.l - border.r,
154
+ h: height - border.t - border.b
155
+ }
156
+ };
157
+ }
158
+ function inRange(element, x, y, useFinalPosition) {
159
+ const skipX = x === null;
160
+ const skipY = y === null;
161
+ const bounds = !element || skipX && skipY ? false : getBounds(element, useFinalPosition);
162
+ return bounds && (skipX || x >= bounds.left && x <= bounds.right) && (skipY || y >= bounds.top && y <= bounds.bottom);
181
163
  }
182
164
 
183
165
  class MatrixElement extends Element {
184
-
185
- static id = 'matrix';
186
-
187
- static defaults = {
166
+ draw(ctx) {
167
+ const options = this.options;
168
+ const { inner, outer } = boundingRects(this);
169
+ const radius = toTRBLCorners(options.borderRadius);
170
+ ctx.save();
171
+ if (outer.w !== inner.w || outer.h !== inner.h) {
172
+ ctx.beginPath();
173
+ addRoundedRectPath(ctx, {
174
+ x: outer.x,
175
+ y: outer.y,
176
+ w: outer.w,
177
+ h: outer.h,
178
+ radius
179
+ });
180
+ addRoundedRectPath(ctx, {
181
+ x: inner.x,
182
+ y: inner.y,
183
+ w: inner.w,
184
+ h: inner.h,
185
+ radius
186
+ });
187
+ ctx.fillStyle = options.backgroundColor;
188
+ ctx.fill();
189
+ ctx.fillStyle = options.borderColor;
190
+ ctx.fill('evenodd');
191
+ } else {
192
+ ctx.beginPath();
193
+ addRoundedRectPath(ctx, {
194
+ x: inner.x,
195
+ y: inner.y,
196
+ w: inner.w,
197
+ h: inner.h,
198
+ radius
199
+ });
200
+ ctx.fillStyle = options.backgroundColor;
201
+ ctx.fill();
202
+ }
203
+ ctx.restore();
204
+ }
205
+ inRange(mouseX, mouseY, useFinalPosition) {
206
+ return inRange(this, mouseX, mouseY, useFinalPosition);
207
+ }
208
+ inXRange(mouseX, useFinalPosition) {
209
+ return inRange(this, mouseX, null, useFinalPosition);
210
+ }
211
+ inYRange(mouseY, useFinalPosition) {
212
+ return inRange(this, null, mouseY, useFinalPosition);
213
+ }
214
+ getCenterPoint(useFinalPosition) {
215
+ const { x, y, width, height } = this.getProps([
216
+ 'x',
217
+ 'y',
218
+ 'width',
219
+ 'height'
220
+ ], useFinalPosition);
221
+ return {
222
+ x: x + width / 2,
223
+ y: y + height / 2
224
+ };
225
+ }
226
+ tooltipPosition() {
227
+ return this.getCenterPoint();
228
+ }
229
+ getRange(axis) {
230
+ return axis === 'x' ? this.width / 2 : this.height / 2;
231
+ }
232
+ constructor(cfg){
233
+ super();
234
+ if (cfg) {
235
+ Object.assign(this, cfg);
236
+ }
237
+ }
238
+ }
239
+ MatrixElement.id = 'matrix';
240
+ MatrixElement.defaults = {
188
241
  backgroundColor: undefined,
189
242
  borderColor: undefined,
190
243
  borderWidth: undefined,
@@ -193,72 +246,6 @@ class MatrixElement extends Element {
193
246
  anchorY: 'center',
194
247
  width: 20,
195
248
  height: 20
196
- };
197
-
198
- constructor(cfg) {
199
- super();
200
-
201
- this.options = undefined;
202
- this.width = undefined;
203
- this.height = undefined;
204
-
205
- if (cfg) {
206
- Object.assign(this, cfg);
207
- }
208
- }
209
-
210
- draw(ctx) {
211
- const options = this.options;
212
- const {inner, outer} = boundingRects(this);
213
- const radius = toTRBLCorners(options.borderRadius);
214
-
215
- ctx.save();
216
-
217
- if (outer.w !== inner.w || outer.h !== inner.h) {
218
- ctx.beginPath();
219
- addRoundedRectPath(ctx, {x: outer.x, y: outer.y, w: outer.w, h: outer.h, radius});
220
- addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius});
221
- ctx.fillStyle = options.backgroundColor;
222
- ctx.fill();
223
- ctx.fillStyle = options.borderColor;
224
- ctx.fill('evenodd');
225
- } else {
226
- ctx.beginPath();
227
- addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius});
228
- ctx.fillStyle = options.backgroundColor;
229
- ctx.fill();
230
- }
231
-
232
- ctx.restore();
233
- }
234
-
235
- inRange(mouseX, mouseY, useFinalPosition) {
236
- return inRange(this, mouseX, mouseY, useFinalPosition);
237
- }
238
-
239
- inXRange(mouseX, useFinalPosition) {
240
- return inRange(this, mouseX, null, useFinalPosition);
241
- }
242
-
243
- inYRange(mouseY, useFinalPosition) {
244
- return inRange(this, null, mouseY, useFinalPosition);
245
- }
246
-
247
- getCenterPoint(useFinalPosition) {
248
- const {x, y, width, height} = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition);
249
- return {
250
- x: x + width / 2,
251
- y: y + height / 2
252
- };
253
- }
254
-
255
- tooltipPosition() {
256
- return this.getCenterPoint();
257
- }
258
-
259
- getRange(axis) {
260
- return axis === 'x' ? this.width / 2 : this.height / 2;
261
- }
262
- }
249
+ };
263
250
 
264
251
  export { MatrixController, MatrixElement };
@@ -4,5 +4,5 @@
4
4
  * (c) 2025 Jukka Kurkela
5
5
  * Released under the MIT license
6
6
  */
7
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-chart-matrix"]={},t.Chart,t.Chart.helpers)}(this,(function(t,e,i){"use strict";class r extends e.DatasetController{static id="matrix";static version="0.0.0-development";static defaults={dataElementType:"matrix",animations:{numbers:{type:"number",properties:["x","y","width","height"]}}};static overrides={interaction:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}}};initialize(){this.enableOptionSharing=!0,super.initialize()}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,e,i,r){const s=this,a="reset"===r,{xScale:h,yScale:l}=s._cachedMeta,d=s.resolveDataElementOptions(e,r),c=s.getSharedOptions(r,t[e],d);for(let d=e;d<e+i;d++){const e=!a&&s.getParsed(d),i=a?h.getBasePixel():h.getPixelForValue(e.x),c=a?l.getBasePixel():l.getPixelForValue(e.y),u=s.resolveDataElementOptions(d,r),{width:g,height:p,anchorX:f,anchorY:x}=u,y={x:n(f,i,g),y:o(x,c,p),width:g,height:p,options:u};s.updateElement(t[d],d,y,r)}s.updateSharedOptions(c,r)}draw(){const t=this,e=t.getMeta().data||[];let i,r;for(i=0,r=e.length;i<r;++i)e[i].draw(t._ctx)}}function n(t,e,i){return"left"===t||"start"===t?e:"right"===t||"end"===t?e-i:e-i/2}function o(t,e,i){return"top"===t||"start"===t?e:"bottom"===t||"end"===t?e-i:e-i/2}function s(t,e){const{x:i,y:r,width:n,height:o}=t.getProps(["x","y","width","height"],e);return{left:i,top:r,right:i+n,bottom:r+o}}function a(t,e,i){return Math.max(Math.min(t,i),e)}function h(t){const e=s(t),r=e.right-e.left,n=e.bottom-e.top,o=function(t,e,r){const n=t.options.borderWidth;let o,s,h,l;return i.isObject(n)?(o=+n.top||0,s=+n.right||0,h=+n.bottom||0,l=+n.left||0):o=s=h=l=+n||0,{t:a(o,0,r),r:a(s,0,e),b:a(h,0,r),l:a(l,0,e)}}(t,r/2,n/2);return{outer:{x:e.left,y:e.top,w:r,h:n},inner:{x:e.left+o.l,y:e.top+o.t,w:r-o.l-o.r,h:n-o.t-o.b}}}function l(t,e,i,r){const n=null===e,o=null===i,a=!(!t||n&&o)&&s(t,r);return a&&(n||e>=a.left&&e<=a.right)&&(o||i>=a.top&&i<=a.bottom)}class d extends e.Element{static id="matrix";static defaults={backgroundColor:void 0,borderColor:void 0,borderWidth:void 0,borderRadius:0,anchorX:"center",anchorY:"center",width:20,height:20};constructor(t){super(),this.options=void 0,this.width=void 0,this.height=void 0,t&&Object.assign(this,t)}draw(t){const e=this.options,{inner:r,outer:n}=h(this),o=i.toTRBLCorners(e.borderRadius);t.save(),n.w!==r.w||n.h!==r.h?(t.beginPath(),i.addRoundedRectPath(t,{x:n.x,y:n.y,w:n.w,h:n.h,radius:o}),i.addRoundedRectPath(t,{x:r.x,y:r.y,w:r.w,h:r.h,radius:o}),t.fillStyle=e.backgroundColor,t.fill(),t.fillStyle=e.borderColor,t.fill("evenodd")):(t.beginPath(),i.addRoundedRectPath(t,{x:r.x,y:r.y,w:r.w,h:r.h,radius:o}),t.fillStyle=e.backgroundColor,t.fill()),t.restore()}inRange(t,e,i){return l(this,t,e,i)}inXRange(t,e){return l(this,t,null,e)}inYRange(t,e){return l(this,null,t,e)}getCenterPoint(t){const{x:e,y:i,width:r,height:n}=this.getProps(["x","y","width","height"],t);return{x:e+r/2,y:i+n/2}}tooltipPosition(){return this.getCenterPoint()}getRange(t){return"x"===t?this.width/2:this.height/2}}e.Chart.register(r,d),t.MatrixController=r,t.MatrixElement=d}));
7
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-chart-matrix"]={},t.Chart,t.Chart.helpers)}(this,(function(t,e,r){"use strict";class i extends e.DatasetController{initialize(){this.enableOptionSharing=!0,super.initialize()}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,e,r,i){const s="reset"===i,{xScale:a,yScale:h}=this._cachedMeta,l=this.resolveDataElementOptions(e,i),d=this.getSharedOptions(l);for(let l=e;l<e+r;l++){const e=!s&&this.getParsed(l),r=s?a.getBasePixel():a.getPixelForValue(e.x),d=s?h.getBasePixel():h.getPixelForValue(e.y),u=this.resolveDataElementOptions(l,i),{width:c,height:g,anchorX:p,anchorY:f}=u,x={x:n(p,r,c),y:o(f,d,g),width:c,height:g,options:u};this.updateElement(t[l],l,x,i)}this.updateSharedOptions(d,i,l)}draw(){const t=this.chart.ctx,e=this.getMeta().data||[];let r,i;for(r=0,i=e.length;r<i;++r)e[r].draw(t)}}function n(t,e,r){return"left"===t||"start"===t?e:"right"===t||"end"===t?e-r:e-r/2}function o(t,e,r){return"top"===t||"start"===t?e:"bottom"===t||"end"===t?e-r:e-r/2}function s(t,e){const{x:r,y:i,width:n,height:o}=t.getProps(["x","y","width","height"],e);return{left:r,top:i,right:r+n,bottom:i+o}}function a(t,e,r){return Math.max(Math.min(t,r),e)}function h(t){const e=s(t,!1),i=e.right-e.left,n=e.bottom-e.top,o=function(t,e,i){const n=t.borderWidth;let o,s,h,l;return r.isObject(n)?(o=+n.top||0,s=+n.right||0,h=+n.bottom||0,l=+n.left||0):o=s=h=l=+n||0,{t:a(o,0,i),r:a(s,0,e),b:a(h,0,i),l:a(l,0,e)}}(t.options,i/2,n/2);return{outer:{x:e.left,y:e.top,w:i,h:n},inner:{x:e.left+o.l,y:e.top+o.t,w:i-o.l-o.r,h:n-o.t-o.b}}}function l(t,e,r,i){const n=null===e,o=null===r,a=!(!t||n&&o)&&s(t,i);return a&&(n||e>=a.left&&e<=a.right)&&(o||r>=a.top&&r<=a.bottom)}i.id="matrix",i.version="0.0.0-development",i.defaults={dataElementType:"matrix",animations:{numbers:{type:"number",properties:["x","y","width","height"]}}},i.overrides={interaction:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}}};class d extends e.Element{draw(t){const e=this.options,{inner:i,outer:n}=h(this),o=r.toTRBLCorners(e.borderRadius);t.save(),n.w!==i.w||n.h!==i.h?(t.beginPath(),r.addRoundedRectPath(t,{x:n.x,y:n.y,w:n.w,h:n.h,radius:o}),r.addRoundedRectPath(t,{x:i.x,y:i.y,w:i.w,h:i.h,radius:o}),t.fillStyle=e.backgroundColor,t.fill(),t.fillStyle=e.borderColor,t.fill("evenodd")):(t.beginPath(),r.addRoundedRectPath(t,{x:i.x,y:i.y,w:i.w,h:i.h,radius:o}),t.fillStyle=e.backgroundColor,t.fill()),t.restore()}inRange(t,e,r){return l(this,t,e,r)}inXRange(t,e){return l(this,t,null,e)}inYRange(t,e){return l(this,null,t,e)}getCenterPoint(t){const{x:e,y:r,width:i,height:n}=this.getProps(["x","y","width","height"],t);return{x:e+i/2,y:r+n/2}}tooltipPosition(){return this.getCenterPoint()}getRange(t){return"x"===t?this.width/2:this.height/2}constructor(t){super(),t&&Object.assign(this,t)}}d.id="matrix",d.defaults={backgroundColor:void 0,borderColor:void 0,borderWidth:void 0,borderRadius:0,anchorX:"center",anchorY:"center",width:20,height:20},e.Chart.register(i,d),t.MatrixController=i,t.MatrixElement=d}));
8
8
  //# sourceMappingURL=chartjs-chart-matrix.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chartjs-chart-matrix.min.js","sources":["../src/controller.js","../src/element.js","../src/index.js"],"sourcesContent":["import {DatasetController} from 'chart.js';\nimport {version} from '../package.json';\n\nexport default class MatrixController extends DatasetController {\n\n static id = 'matrix';\n static version = version;\n\n static defaults = {\n dataElementType: 'matrix',\n\n animations: {\n numbers: {\n type: 'number',\n properties: ['x', 'y', 'width', 'height']\n }\n },\n };\n\n static overrides = {\n interaction: {\n mode: 'nearest',\n intersect: true\n },\n scales: {\n x: {\n type: 'linear',\n offset: true\n },\n y: {\n type: 'linear',\n reverse: true\n }\n },\n };\n\n initialize() {\n this.enableOptionSharing = true;\n super.initialize();\n }\n\n update(mode) {\n const me = this;\n const meta = me._cachedMeta;\n\n me.updateElements(meta.data, 0, meta.data.length, mode);\n }\n\n updateElements(rects, start, count, mode) {\n const me = this;\n const reset = mode === 'reset';\n const {xScale, yScale} = me._cachedMeta;\n const firstOpts = me.resolveDataElementOptions(start, mode);\n const sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts);\n\n for (let i = start; i < start + count; i++) {\n const parsed = !reset && me.getParsed(i);\n const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x);\n const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y);\n const options = me.resolveDataElementOptions(i, mode);\n const {width, height, anchorX, anchorY} = options;\n const properties = {\n x: resolveX(anchorX, x, width),\n y: resolveY(anchorY, y, height),\n width,\n height,\n options\n };\n me.updateElement(rects[i], i, properties, mode);\n }\n\n me.updateSharedOptions(sharedOptions, mode);\n }\n\n draw() {\n const me = this;\n const data = me.getMeta().data || [];\n let i, ilen;\n\n for (i = 0, ilen = data.length; i < ilen; ++i) {\n data[i].draw(me._ctx);\n }\n }\n}\n\nfunction resolveX(anchorX, x, width) {\n if (anchorX === 'left' || anchorX === 'start') {\n return x;\n }\n if (anchorX === 'right' || anchorX === 'end') {\n return x - width;\n }\n return x - width / 2;\n}\n\nfunction resolveY(anchorY, y, height) {\n if (anchorY === 'top' || anchorY === 'start') {\n return y;\n }\n if (anchorY === 'bottom' || anchorY === 'end') {\n return y - height;\n }\n return y - height / 2;\n}\n","import {Element} from 'chart.js';\nimport {isObject, addRoundedRectPath, toTRBLCorners} from 'chart.js/helpers';\n\n/**\n * Helper function to get the bounds of the rect\n * @param {MatrixElement} rect the rect\n * @param {boolean} [useFinalPosition]\n * @return {object} bounds of the rect\n * @private\n */\nfunction getBounds(rect, useFinalPosition) {\n const {x, y, width, height} = rect.getProps(['x', 'y', 'width', 'height'], useFinalPosition);\n return {left: x, top: y, right: x + width, bottom: y + height};\n}\n\nfunction limit(value, min, max) {\n return Math.max(Math.min(value, max), min);\n}\n\nfunction parseBorderWidth(rect, maxW, maxH) {\n const value = rect.options.borderWidth;\n let t, r, b, l;\n\n if (isObject(value)) {\n t = +value.top || 0;\n r = +value.right || 0;\n b = +value.bottom || 0;\n l = +value.left || 0;\n } else {\n t = r = b = l = +value || 0;\n }\n\n return {\n t: limit(t, 0, maxH),\n r: limit(r, 0, maxW),\n b: limit(b, 0, maxH),\n l: limit(l, 0, maxW)\n };\n}\n\nfunction boundingRects(rect) {\n const bounds = getBounds(rect);\n const width = bounds.right - bounds.left;\n const height = bounds.bottom - bounds.top;\n const border = parseBorderWidth(rect, width / 2, height / 2);\n\n return {\n outer: {\n x: bounds.left,\n y: bounds.top,\n w: width,\n h: height\n },\n inner: {\n x: bounds.left + border.l,\n y: bounds.top + border.t,\n w: width - border.l - border.r,\n h: height - border.t - border.b\n }\n };\n}\n\nfunction inRange(rect, x, y, useFinalPosition) {\n const skipX = x === null;\n const skipY = y === null;\n const bounds = !rect || (skipX && skipY) ? false : getBounds(rect, useFinalPosition);\n\n return bounds\n\t\t&& (skipX || x >= bounds.left && x <= bounds.right)\n\t\t&& (skipY || y >= bounds.top && y <= bounds.bottom);\n}\n\nexport default class MatrixElement extends Element {\n\n static id = 'matrix';\n\n static defaults = {\n backgroundColor: undefined,\n borderColor: undefined,\n borderWidth: undefined,\n borderRadius: 0,\n anchorX: 'center',\n anchorY: 'center',\n width: 20,\n height: 20\n };\n\n constructor(cfg) {\n super();\n\n this.options = undefined;\n this.width = undefined;\n this.height = undefined;\n\n if (cfg) {\n Object.assign(this, cfg);\n }\n }\n\n draw(ctx) {\n const options = this.options;\n const {inner, outer} = boundingRects(this);\n const radius = toTRBLCorners(options.borderRadius);\n\n ctx.save();\n\n if (outer.w !== inner.w || outer.h !== inner.h) {\n ctx.beginPath();\n addRoundedRectPath(ctx, {x: outer.x, y: outer.y, w: outer.w, h: outer.h, radius});\n addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius});\n ctx.fillStyle = options.backgroundColor;\n ctx.fill();\n ctx.fillStyle = options.borderColor;\n ctx.fill('evenodd');\n } else {\n ctx.beginPath();\n addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius});\n ctx.fillStyle = options.backgroundColor;\n ctx.fill();\n }\n\n ctx.restore();\n }\n\n inRange(mouseX, mouseY, useFinalPosition) {\n return inRange(this, mouseX, mouseY, useFinalPosition);\n }\n\n inXRange(mouseX, useFinalPosition) {\n return inRange(this, mouseX, null, useFinalPosition);\n }\n\n inYRange(mouseY, useFinalPosition) {\n return inRange(this, null, mouseY, useFinalPosition);\n }\n\n getCenterPoint(useFinalPosition) {\n const {x, y, width, height} = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition);\n return {\n x: x + width / 2,\n y: y + height / 2\n };\n }\n\n tooltipPosition() {\n return this.getCenterPoint();\n }\n\n getRange(axis) {\n return axis === 'x' ? this.width / 2 : this.height / 2;\n }\n}\n","import {Chart} from 'chart.js';\nimport MatrixController from './controller.js';\nimport MatrixElement from './element.js';\n\nChart.register(MatrixController, MatrixElement);\n\nexport {MatrixController, MatrixElement};\n"],"names":["MatrixController","DatasetController","static","dataElementType","animations","numbers","type","properties","interaction","mode","intersect","scales","x","offset","y","reverse","initialize","this","enableOptionSharing","super","update","meta","_cachedMeta","updateElements","data","length","rects","start","count","me","reset","xScale","yScale","firstOpts","resolveDataElementOptions","sharedOptions","getSharedOptions","i","parsed","getParsed","getBasePixel","getPixelForValue","options","width","height","anchorX","anchorY","resolveX","resolveY","updateElement","updateSharedOptions","draw","getMeta","ilen","_ctx","getBounds","rect","useFinalPosition","getProps","left","top","right","bottom","limit","value","min","max","Math","boundingRects","bounds","border","maxW","maxH","borderWidth","t","r","b","l","isObject","parseBorderWidth","outer","w","h","inner","inRange","skipX","skipY","MatrixElement","Element","backgroundColor","undefined","borderColor","borderRadius","constructor","cfg","Object","assign","ctx","radius","toTRBLCorners","save","beginPath","addRoundedRectPath","fillStyle","fill","restore","mouseX","mouseY","inXRange","inYRange","getCenterPoint","tooltipPosition","getRange","axis","Chart","register"],"mappings":";;;;;;yWAGe,MAAMA,UAAyBC,EAAAA,kBAE5CC,UAAY,SACZA,mCAEAA,gBAAkB,CAChBC,gBAAiB,SAEjBC,WAAY,CACVC,QAAS,CACPC,KAAM,SACNC,WAAY,CAAC,IAAK,IAAK,QAAS,aAKtCL,iBAAmB,CACjBM,YAAa,CACXC,KAAM,UACNC,WAAW,GAEbC,OAAQ,CACNC,EAAG,CACDN,KAAM,SACNO,QAAQ,GAEVC,EAAG,CACDR,KAAM,SACNS,SAAS,KAKf,UAAAC,GACEC,KAAKC,qBAAsB,EAC3BC,MAAMH,YACP,CAED,MAAAI,CAAOX,GACL,MACMY,EADKJ,KACKK,YADLL,KAGRM,eAAeF,EAAKG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AQ+C,gBACxBQ,EAAIO,OACJP,EAAIM,UAAY7D,EAAQiD,YACxBM,EAAIO,KAAK,aAETP,EAAII,YACJC,EAAkBA,mBAACL,EAAK,CAACrF,EAAGuE,EAAMvE,EAAGE,EAAGqE,EAAMrE,EAAGmE,EAAGE,EAAMF,EAAGC,EAAGC,EAAMD,EAAGgB,WACzED,EAAIM,UAAY7D,EAAQ+C,gBACxBQ,EAAIO,QAGNP,EAAIQ,SACL,CAED,OAAArB,CAAQsB,EAAQC,EAAQlD,GACtB,OAAO2B,EAAQnE,KAAMyF,EAAQC,EAAQlD,EACtC,CAED,QAAAmD,CAASF,EAAQjD,GACf,OAAO2B,EAAQnE,KAAMyF,EAAQ,KAAMjD,EACpC,CAED,QAAAoD,CAASF,EAAQlD,GACf,OAAO2B,EAAQnE,KAAM,KAAM0F,EAAQlD,EACpC,CAED,cAAAqD,CAAerD,GACb,MAAM7C,EAACA,EAACE,EAAEA,EAAC6B,MAAEA,EAAKC,OAAEA,GAAU3B,KAAKyC,SAAS,CAAC,IAAK,IAAK,QAAS,UAAWD,GAC3E,MAAO,CACL7C,EAAGA,EAAI+B,EAAQ,EACf7B,EAAGA,EAAI8B,EAAS,EAEnB,CAED,eAAAmE,GACE,OAAO9F,KAAK6F,gBACb,CAED,QAAAE,CAASC,GACP,MAAgB,MAATA,EAAehG,KAAK0B,MAAQ,EAAI1B,KAAK2B,OAAS,CACtD,EClJHsE,EAAAA,MAAMC,SAASnH,EAAkBuF"}
1
+ {"version":3,"file":"chartjs-chart-matrix.min.js","sources":["../src/controller.ts","../src/helpers.ts","../src/element.ts","../src/index.ts"],"sourcesContent":["import { DatasetController, UpdateMode } from 'chart.js'\nimport { AnchorX, AnchorY, MatrixControllerDatasetOptions, MatrixDataPoint } from 'types/index.esm'\n\nimport { version } from '../package.json'\n\nimport MatrixElement from './element'\n\nexport default class MatrixController extends DatasetController<\n 'matrix',\n MatrixElement,\n MatrixElement,\n MatrixDataPoint\n> {\n static readonly id = 'matrix'\n static readonly version = version\n\n static readonly defaults = {\n dataElementType: 'matrix',\n\n animations: {\n numbers: {\n type: 'number',\n properties: ['x', 'y', 'width', 'height'],\n },\n },\n }\n\n static readonly overrides = {\n interaction: {\n mode: 'nearest',\n intersect: true,\n },\n scales: {\n x: {\n type: 'linear',\n offset: true,\n },\n y: {\n type: 'linear',\n reverse: true,\n },\n },\n }\n\n options: MatrixControllerDatasetOptions\n\n override initialize() {\n this.enableOptionSharing = true\n super.initialize()\n }\n\n override update(mode: UpdateMode) {\n const meta = this._cachedMeta\n\n this.updateElements(meta.data, 0, meta.data.length, mode)\n }\n\n override updateElements(rects: MatrixElement[], start: number, count: number, mode: UpdateMode) {\n const reset = mode === 'reset'\n const { xScale, yScale } = this._cachedMeta\n const firstOpts = this.resolveDataElementOptions(start, mode)\n const sharedOptions = this.getSharedOptions(firstOpts)\n\n for (let i = start; i < start + count; i++) {\n const parsed = !reset && this.getParsed(i)\n const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x)\n const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y)\n const options = this.resolveDataElementOptions(i, mode)\n const { width, height, anchorX, anchorY } = options\n const properties = {\n x: resolveX(anchorX, x, width),\n y: resolveY(anchorY, y, height),\n width,\n height,\n options,\n }\n this.updateElement(rects[i], i, properties, mode)\n }\n\n this.updateSharedOptions(sharedOptions, mode, firstOpts)\n }\n\n override draw() {\n const ctx = this.chart.ctx\n const data = this.getMeta().data || []\n let i: number, ilen: number\n\n for (i = 0, ilen = data.length; i < ilen; ++i) {\n data[i].draw(ctx)\n }\n }\n}\n\nfunction resolveX(anchorX: AnchorX, x: number, width: number) {\n if (anchorX === 'left' || anchorX === 'start') {\n return x\n }\n if (anchorX === 'right' || anchorX === 'end') {\n return x - width\n }\n return x - width / 2\n}\n\nfunction resolveY(anchorY: AnchorY, y: number, height: number) {\n if (anchorY === 'top' || anchorY === 'start') {\n return y\n }\n if (anchorY === 'bottom' || anchorY === 'end') {\n return y - height\n }\n return y - height / 2\n}\n","import { isObject } from 'chart.js/helpers'\nimport { MatrixOptions } from 'types/index.esm'\n\nimport MatrixElement from './element'\n\ntype Bounds = { left: number; top: number; right: number; bottom: number }\n\nfunction getBounds(element: MatrixElement, useFinalPosition: boolean): Bounds {\n const { x, y, width, height } = element.getProps(['x', 'y', 'width', 'height'], useFinalPosition)\n return { left: x, top: y, right: x + width, bottom: y + height }\n}\n\nfunction limit(value: number, min: number, max: number) {\n return Math.max(Math.min(value, max), min)\n}\n\nexport function parseBorderWidth(options: Pick<MatrixOptions, 'borderWidth'>, maxW: number, maxH: number) {\n const value = options.borderWidth\n let t: number, r: number, b: number, l: number\n\n if (isObject(value)) {\n t = +value.top || 0\n r = +value.right || 0\n b = +value.bottom || 0\n l = +value.left || 0\n } else {\n t = r = b = l = +value || 0\n }\n\n return {\n t: limit(t, 0, maxH),\n r: limit(r, 0, maxW),\n b: limit(b, 0, maxH),\n l: limit(l, 0, maxW),\n }\n}\n\nexport function boundingRects(element: MatrixElement) {\n const bounds = getBounds(element, false)\n const width = bounds.right - bounds.left\n const height = bounds.bottom - bounds.top\n const border = parseBorderWidth(element.options, width / 2, height / 2)\n\n return {\n outer: {\n x: bounds.left,\n y: bounds.top,\n w: width,\n h: height,\n },\n inner: {\n x: bounds.left + border.l,\n y: bounds.top + border.t,\n w: width - border.l - border.r,\n h: height - border.t - border.b,\n },\n }\n}\n\nexport function inRange(element: MatrixElement, x: number, y: number, useFinalPosition: boolean) {\n const skipX = x === null\n const skipY = y === null\n const bounds = !element || (skipX && skipY) ? false : getBounds(element, useFinalPosition)\n\n return (\n bounds && (skipX || (x >= bounds.left && x <= bounds.right)) && (skipY || (y >= bounds.top && y <= bounds.bottom))\n )\n}\n","import { Element } from 'chart.js'\nimport { addRoundedRectPath, toTRBLCorners } from 'chart.js/helpers'\nimport { MatrixOptions, MatrixProps } from 'types/index.esm'\n\nimport { boundingRects, inRange } from './helpers'\n\nexport default class MatrixElement extends Element<MatrixProps, MatrixOptions> {\n static readonly id = 'matrix'\n\n static override readonly defaults = {\n backgroundColor: undefined,\n borderColor: undefined,\n borderWidth: undefined,\n borderRadius: 0,\n anchorX: 'center',\n anchorY: 'center',\n width: 20,\n height: 20,\n }\n\n width: number\n height: number\n\n constructor(cfg: MatrixProps) {\n super()\n\n if (cfg) {\n Object.assign(this, cfg)\n }\n }\n\n draw(ctx: CanvasRenderingContext2D) {\n const options = this.options\n const { inner, outer } = boundingRects(this)\n const radius = toTRBLCorners(options.borderRadius)\n\n ctx.save()\n\n if (outer.w !== inner.w || outer.h !== inner.h) {\n ctx.beginPath()\n addRoundedRectPath(ctx, { x: outer.x, y: outer.y, w: outer.w, h: outer.h, radius })\n addRoundedRectPath(ctx, { x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius })\n ctx.fillStyle = options.backgroundColor\n ctx.fill()\n ctx.fillStyle = options.borderColor\n ctx.fill('evenodd')\n } else {\n ctx.beginPath()\n addRoundedRectPath(ctx, { x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius })\n ctx.fillStyle = options.backgroundColor\n ctx.fill()\n }\n\n ctx.restore()\n }\n\n inRange(mouseX: number, mouseY: number, useFinalPosition?: boolean) {\n return inRange(this, mouseX, mouseY, useFinalPosition)\n }\n\n inXRange(mouseX: number, useFinalPosition?: boolean) {\n return inRange(this, mouseX, null, useFinalPosition)\n }\n\n inYRange(mouseY: number, useFinalPosition?: boolean) {\n return inRange(this, null, mouseY, useFinalPosition)\n }\n\n getCenterPoint(useFinalPosition?: boolean) {\n const { x, y, width, height } = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition)\n return {\n x: x + width / 2,\n y: y + height / 2,\n }\n }\n\n override tooltipPosition() {\n return this.getCenterPoint()\n }\n\n getRange(axis: 'x' | 'y') {\n return axis === 'x' ? this.width / 2 : this.height / 2\n }\n}\n","import { Chart } from 'chart.js'\n\nimport MatrixController from './controller.js'\nimport MatrixElement from './element.js'\n\nChart.register(MatrixController, MatrixElement)\n\nexport { MatrixController, MatrixElement }\n"],"names":["MatrixController","DatasetController","initialize","this","enableOptionSharing","super","update","mode","meta","_cachedMeta","updateElements","data","length","rects","start","count","reset","xScale","yScale","firstOpts","resolveDataElementOptions","sharedOptions","getSharedOptions","i","parsed","getParsed","x","getBasePixel","getPixelForValue","y","options","width","height","anchorX","anchorY","properties","resolveX","resolveY","updateElement","updateSharedOptions","draw","ctx","chart","getMeta","ilen","getBounds","element","useFinalPosition","getProps","left","top","right","bottom","limit","value","min","max","Math","boundingRects","bounds","border","maxW","maxH","borderWidth","t","r","b","l","isObject","parseBorderWidth","outer","w","h","inner","inRange","skipX","skipY","id","version","defaults","dataElementType","animations","numbers","type","overrides","interaction","intersect","scales","offset","reverse","MatrixElement","Element","radius","toTRBLCorners","borderRadius","save","beginPath","addRoundedRectPath","fillStyle","backgroundColor","fill","borderColor","restore","mouseX","mouseY","inXRange","inYRange","getCenterPoint","tooltipPosition","getRange","axis","constructor","cfg","Object","assign","undefined","Chart","register"],"mappings":";;;;;;yWAOe,MAAMA,UAAyBC,EAAAA,kBAuCnCC,UAAAA,GACPC,KAAKC,qBAAsB,EAC3BC,MAAMH,YACR,CAESI,MAAAA,CAAOC,GACd,MAAMC,EAAOL,KAAKM,YAElBN,KAAKO,eAAeF,EAAKG,KAAM,EAAGH,EAAKG,KAAKC,OAAQL,EACtD,CAESG,cAAAA,CAAeG,EAAwBC,EAAeC,EAAeR,GAC5E,MAAMS,EAAiB,UAATT,GACRU,OAAEA,EAAMC,OAAEA,GAAWf,KAAKM,YAC1BU,EAAYhB,KAAKiB,0BAA0BN,EAAOP,GAClDc,EAAgBlB,KAAKmB,iBAAiBH,GAE5C,IAAK,IAAII,EAAIT,EAAOS,EAAIT,EAAQC,EAAOQ,IAAK,CAC1C,MAAMC,GAAUR,GAASb,KAAKsB,UAAUF,GAClCG,EAAIV,EAAQC,EAAOU,eAAiBV,EAAOW,iBAAiBJ,EAAOE,GACnEG,EAAIb,EAAQE,EAAOS,eAAiBT,EA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,GACvB,OAAO2B,EAAQvE,KAAMoG,EAAQ,KAAMxD,EACrC,CAEA2D,QAAAA,CAASF,EAAgBzD,GACvB,OAAO2B,EAAQvE,KAAM,KAAMqG,EAAQzD,EACrC,CAEA4D,cAAAA,CAAe5D,GACb,MAAMrB,EAAEA,EAACG,EAAEA,EAACE,MAAEA,EAAKC,OAAEA,GAAW7B,KAAK6C,SAAS,CAAC,IAAK,IAAK,QAAS,UAAWD,GAC7E,MAAO,CACLrB,EAAGA,EAAIK,EAAQ,EACfF,EAAGA,EAAIG,EAAS,EAEpB,CAES4E,eAAAA,GACP,OAAOzG,KAAKwG,gBACd,CAEAE,QAAAA,CAASC,GACP,MAAgB,MAATA,EAAe3G,KAAK4B,MAAQ,EAAI5B,KAAK6B,OAAS,CACvD,CA3DA+E,WAAAA,CAAYC,GACV3G,QAEI2G,GACFC,OAAOC,OAAO/G,KAAM6G,EAExB,EAvBmBtB,EACHb,GAAK,SADFa,EAGMX,SAAW,CAClCoB,qBAAiBgB,EACjBd,iBAAac,EACbpD,iBAAaoD,EACbrB,aAAc,EACd7D,QAAS,SACTC,QAAS,SACTH,MAAO,GACPC,OAAQ,ICZZoF,EAAAA,MAAMC,SAASrH,EAAkB0F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chartjs-chart-matrix",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "description": "Chart.js module for creating matrix charts",
5
5
  "type": "module",
6
6
  "main": "dist/chartjs-chart-matrix.cjs",
@@ -22,14 +22,14 @@
22
22
  "autobuild": "rollup -c -w",
23
23
  "build": "rollup -c",
24
24
  "dev": "karma start ./karma.conf.cjs --no-single-run --auto-watch --browsers chrome",
25
+ "dev:ff": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers firefox",
25
26
  "docs": "npm run build && vuepress build docs --no-cache",
26
27
  "docs:dev": "npm run build && vuepress dev docs --no-cache",
27
- "lint": "concurrently -r \"npm:lint-*\"",
28
- "lint-js": "eslint \"src/**/*.js\" \"test/**/*.js\" \"docs/**/*.js\"",
29
- "lint-md": "eslint \"**/*.md\"",
30
- "lint-types": "eslint \"types/**/*.ts\" && tsc -p types/tests/",
28
+ "lint": "eslint",
29
+ "typecheck": "tsc --noEmit && tsc --noEmit -p types/tests/",
31
30
  "test": "cross-env NODE_ENV=test concurrently \"npm:test-*\"",
32
- "test-lint": "npm run lint",
31
+ "pretest-unit": "swc --config-file .swcrc-spec src -d build",
32
+ "test-unit": "cross-env JASMINE_CONFIG_PATH=jasmine.json c8 --src=src --reporter=text --reporter=lcov -o=coverage/unit jasmine",
33
33
  "test-karma": "karma start ./karma.conf.cjs --no-auto-watch --single-run",
34
34
  "test-integration:node-commonjs": "npm run test --prefix test/integration/node-commonjs",
35
35
  "test-integration:node-module": "npm run test --prefix test/integration/node-module"
@@ -55,24 +55,35 @@
55
55
  },
56
56
  "homepage": "https://chartjs-chart-matrix.pages.dev/",
57
57
  "devDependencies": {
58
+ "@eslint/js": "^9.22.0",
59
+ "@eslint/markdown": "^6.3.0",
58
60
  "@napi-rs/canvas": "^0.1.30",
59
61
  "@rollup/plugin-commonjs": "^28.0.1",
60
62
  "@rollup/plugin-json": "^6.0.0",
61
- "@rollup/plugin-node-resolve": "^15.0.1",
62
- "@rollup/plugin-terser": "^0.4.0",
63
- "@typescript-eslint/eslint-plugin": "^5.6.0",
64
- "@typescript-eslint/parser": "^5.6.0",
63
+ "@rollup/plugin-node-resolve": "^16.0.1",
64
+ "@rollup/plugin-swc": "^0.4.0",
65
+ "@rollup/plugin-terser": "^0.4.4",
66
+ "@swc/cli": "^0.6.0",
67
+ "@swc/core": "^1.11.9",
68
+ "@types/jasmine": "^5.1.7",
69
+ "@types/node": "^22.13.10",
70
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
71
+ "@typescript-eslint/parser": "^8.26.1",
72
+ "c8": "^10.1.3",
65
73
  "chart.js": "^4.0.1",
66
74
  "chartjs-adapter-date-fns": "^3.0.0",
67
75
  "chartjs-test-utils": "^0.5.0",
68
76
  "concurrently": "^9.0.1",
69
77
  "cross-env": "^7.0.3",
70
78
  "date-fns": "^2.19.0",
71
- "eslint": "^8.4.1",
79
+ "eslint": "^9.22.0",
72
80
  "eslint-config-chartjs": "^0.3.0",
73
- "eslint-plugin-es": "^4.1.0",
74
- "eslint-plugin-html": "^8.1.2",
75
- "eslint-plugin-markdown": "^3.0.0",
81
+ "eslint-config-prettier": "^10.1.1",
82
+ "eslint-plugin-prettier": "^5.2.3",
83
+ "eslint-plugin-simple-import-sort": "^12.1.1",
84
+ "eslint-plugin-unused-imports": "^4.1.4",
85
+ "globals": "^16.0.0",
86
+ "jasmine": "^5.6.0",
76
87
  "jasmine-core": "^5.1.2",
77
88
  "karma": "^6.2.0",
78
89
  "karma-chrome-launcher": "^3.1.0",
@@ -80,11 +91,11 @@
80
91
  "karma-firefox-launcher": "^2.1.0",
81
92
  "karma-jasmine": "^5.1.0",
82
93
  "karma-jasmine-html-reporter": "^2.0.0",
83
- "karma-rollup-preprocessor": "7.0.8",
94
+ "karma-rollup-preprocessor": "^7.0.7",
84
95
  "karma-spec-reporter": "^0.0.36",
85
- "pixelmatch": "^6.0.0",
86
96
  "rollup": "^4.21.2",
87
97
  "rollup-plugin-analyzer": "^4.0.0",
98
+ "rollup-plugin-cleanup": "^3.2.1",
88
99
  "rollup-plugin-istanbul": "^5.0.0",
89
100
  "typescript": "^5.3.3",
90
101
  "vuepress": "^1.9.7",
@@ -3,7 +3,6 @@ import {
3
3
  CartesianScaleTypeRegistry,
4
4
  Chart,
5
5
  ChartComponent,
6
- ChartType,
7
6
  CommonElementOptions,
8
7
  CommonHoverOptions,
9
8
  ControllerDatasetOptions,
@@ -12,64 +11,63 @@ import {
12
11
  Element,
13
12
  ScriptableAndArrayOptions,
14
13
  ScriptableContext,
15
- VisualElement
16
- } from 'chart.js';
14
+ VisualElement,
15
+ } from 'chart.js'
17
16
 
18
- type AnyObject = Record<string, unknown>;
17
+ type AnyObject = Record<string, unknown>
19
18
 
20
- export interface MatrixControllerDatasetOptions<TType extends ChartType>
21
- extends ControllerDatasetOptions,
22
- ScriptableAndArrayOptions<MatrixOptions, ScriptableContext<TType>>,
23
- ScriptableAndArrayOptions<CommonHoverOptions, ScriptableContext<TType>> {
19
+ export type AnchorX = 'left' | 'center' | 'right' | 'start' | 'end'
20
+ export type AnchorY = 'top' | 'center' | 'bottom' | 'start' | 'end'
21
+ export interface MatrixOptions extends Omit<CommonElementOptions, 'borderWidth'> {
22
+ borderRadius: number | BorderRadius
23
+ borderWidth: number | { top?: number; right?: number; bottom?: number; left?: number }
24
+ anchorX: AnchorX
25
+ anchorY: AnchorY
26
+ width: number
27
+ height: number
24
28
  }
29
+ export interface MatrixControllerDatasetOptions
30
+ extends ControllerDatasetOptions,
31
+ ScriptableAndArrayOptions<MatrixOptions, ScriptableContext<'matrix'>>,
32
+ ScriptableAndArrayOptions<CommonHoverOptions, ScriptableContext<'matrix'>> {}
25
33
 
26
34
  export interface MatrixDataPoint {
27
- x: number,
28
- y: number,
35
+ x: number
36
+ y: number
29
37
  }
30
38
 
31
39
  declare module 'chart.js' {
32
40
  export interface ChartTypeRegistry {
33
41
  matrix: {
34
- chartOptions: CoreChartOptions<'matrix'>;
35
- datasetOptions: MatrixControllerDatasetOptions<'matrix'>;
36
- defaultDataPoint: MatrixDataPoint;
37
- parsedDataType: MatrixDataPoint;
38
- metaExtensions: AnyObject;
39
- scales: keyof CartesianScaleTypeRegistry;
42
+ chartOptions: CoreChartOptions<'matrix'>
43
+ datasetOptions: MatrixControllerDatasetOptions
44
+ defaultDataPoint: MatrixDataPoint
45
+ parsedDataType: MatrixDataPoint
46
+ metaExtensions: AnyObject
47
+ scales: keyof CartesianScaleTypeRegistry
40
48
  }
41
49
  }
42
50
  }
43
51
 
44
52
  export interface MatrixProps {
45
- x: number;
46
- y: number;
47
- width: number;
48
- height: number;
49
- }
50
-
51
- export type AnchorX = 'left' | 'center' | 'right';
52
- export type AnchorY = 'top' | 'center' | 'bottom';
53
- export interface MatrixOptions extends CommonElementOptions {
54
- borderRadius: number | BorderRadius;
55
- anchorX: AnchorX;
56
- anchorY: AnchorY;
57
- width: number;
58
- height: number;
53
+ x: number
54
+ y: number
55
+ width: number
56
+ height: number
57
+ options?: Partial<MatrixOptions>
59
58
  }
60
59
 
61
- export type MatrixController = DatasetController;
60
+ export type MatrixController = DatasetController
62
61
  export const MatrixController: ChartComponent & {
63
- prototype: MatrixController;
64
- new (chart: Chart, datasetIndex: number): MatrixController;
65
- };
62
+ prototype: MatrixController
63
+ new (chart: Chart, datasetIndex: number): MatrixController
64
+ }
66
65
 
67
- export interface MatrixElement<
68
- T extends MatrixProps = MatrixProps,
69
- O extends MatrixOptions = MatrixOptions
70
- > extends Element<T, O>, VisualElement {}
66
+ export interface MatrixElement<T extends MatrixProps = MatrixProps, O extends MatrixOptions = MatrixOptions>
67
+ extends Element<T, O>,
68
+ VisualElement {}
71
69
 
72
70
  export const MatrixElement: ChartComponent & {
73
- prototype: MatrixElement;
74
- new (cfg: AnyObject): MatrixElement;
75
- };
71
+ prototype: MatrixElement
72
+ new (cfg: AnyObject): MatrixElement
73
+ }