chartjs-chart-matrix 2.1.0 → 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 +1 -1
- package/README.md +2 -1
- package/dist/chartjs-chart-matrix.cjs +259 -0
- package/dist/chartjs-chart-matrix.esm.js +251 -0
- package/dist/chartjs-chart-matrix.min.js +8 -0
- package/dist/chartjs-chart-matrix.min.js.map +1 -0
- package/package.json +27 -16
- package/types/index.esm.d.ts +39 -41
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/chartjs-chart-matrix)
|
|
6
6
|
[](https://github.com/kurkle/chartjs-chart-matrix/releases/latest)
|
|
7
7
|

|
|
8
|
-

|
|
9
8
|
[](https://sonarcloud.io/summary/new_code?id=kurkle_chartjs-chart-matrix)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=kurkle_chartjs-chart-matrix)
|
|
10
10
|
[](https://chartjs-chart-matrix.pages.dev)
|
|
11
|
+

|
|
11
12
|
|
|
12
13
|
## Example
|
|
13
14
|
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* chartjs-chart-matrix v0.0.0-development
|
|
3
|
+
* https://chartjs-chart-matrix.pages.dev/
|
|
4
|
+
* (c) 2025 Jukka Kurkela
|
|
5
|
+
* Released under the MIT license
|
|
6
|
+
*/
|
|
7
|
+
(function (global, factory) {
|
|
8
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('chart.js'), require('chart.js/helpers')) :
|
|
9
|
+
typeof define === 'function' && define.amd ? define(['exports', 'chart.js', 'chart.js/helpers'], factory) :
|
|
10
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["chartjs-chart-matrix"] = {}, global.Chart, global.Chart.helpers));
|
|
11
|
+
})(this, (function (exports, chart_js, helpers) { 'use strict';
|
|
12
|
+
|
|
13
|
+
var version = "0.0.0-development";
|
|
14
|
+
|
|
15
|
+
class MatrixController extends chart_js.DatasetController {
|
|
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 = {
|
|
58
|
+
dataElementType: 'matrix',
|
|
59
|
+
animations: {
|
|
60
|
+
numbers: {
|
|
61
|
+
type: 'number',
|
|
62
|
+
properties: [
|
|
63
|
+
'x',
|
|
64
|
+
'y',
|
|
65
|
+
'width',
|
|
66
|
+
'height'
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
MatrixController.overrides = {
|
|
72
|
+
interaction: {
|
|
73
|
+
mode: 'nearest',
|
|
74
|
+
intersect: true
|
|
75
|
+
},
|
|
76
|
+
scales: {
|
|
77
|
+
x: {
|
|
78
|
+
type: 'linear',
|
|
79
|
+
offset: true
|
|
80
|
+
},
|
|
81
|
+
y: {
|
|
82
|
+
type: 'linear',
|
|
83
|
+
reverse: true
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function resolveX(anchorX, x, width) {
|
|
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;
|
|
95
|
+
}
|
|
96
|
+
function resolveY(anchorY, y, height) {
|
|
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;
|
|
104
|
+
}
|
|
105
|
+
|
|
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
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function limit(value, min, max) {
|
|
121
|
+
return Math.max(Math.min(value, max), min);
|
|
122
|
+
}
|
|
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;
|
|
133
|
+
}
|
|
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
|
+
};
|
|
140
|
+
}
|
|
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);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class MatrixElement extends chart_js.Element {
|
|
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 = {
|
|
244
|
+
backgroundColor: undefined,
|
|
245
|
+
borderColor: undefined,
|
|
246
|
+
borderWidth: undefined,
|
|
247
|
+
borderRadius: 0,
|
|
248
|
+
anchorX: 'center',
|
|
249
|
+
anchorY: 'center',
|
|
250
|
+
width: 20,
|
|
251
|
+
height: 20
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
chart_js.Chart.register(MatrixController, MatrixElement);
|
|
255
|
+
|
|
256
|
+
exports.MatrixController = MatrixController;
|
|
257
|
+
exports.MatrixElement = MatrixElement;
|
|
258
|
+
|
|
259
|
+
}));
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* chartjs-chart-matrix v0.0.0-development
|
|
3
|
+
* https://chartjs-chart-matrix.pages.dev/
|
|
4
|
+
* (c) 2025 Jukka Kurkela
|
|
5
|
+
* Released under the MIT license
|
|
6
|
+
*/
|
|
7
|
+
import { DatasetController, Element } from 'chart.js';
|
|
8
|
+
import { isObject, toTRBLCorners, addRoundedRectPath } from 'chart.js/helpers';
|
|
9
|
+
|
|
10
|
+
var version = "0.0.0-development";
|
|
11
|
+
|
|
12
|
+
class MatrixController extends DatasetController {
|
|
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 = {
|
|
55
|
+
dataElementType: 'matrix',
|
|
56
|
+
animations: {
|
|
57
|
+
numbers: {
|
|
58
|
+
type: 'number',
|
|
59
|
+
properties: [
|
|
60
|
+
'x',
|
|
61
|
+
'y',
|
|
62
|
+
'width',
|
|
63
|
+
'height'
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
MatrixController.overrides = {
|
|
69
|
+
interaction: {
|
|
70
|
+
mode: 'nearest',
|
|
71
|
+
intersect: true
|
|
72
|
+
},
|
|
73
|
+
scales: {
|
|
74
|
+
x: {
|
|
75
|
+
type: 'linear',
|
|
76
|
+
offset: true
|
|
77
|
+
},
|
|
78
|
+
y: {
|
|
79
|
+
type: 'linear',
|
|
80
|
+
reverse: true
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function resolveX(anchorX, x, width) {
|
|
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;
|
|
92
|
+
}
|
|
93
|
+
function resolveY(anchorY, y, height) {
|
|
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;
|
|
101
|
+
}
|
|
102
|
+
|
|
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
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function limit(value, min, max) {
|
|
118
|
+
return Math.max(Math.min(value, max), min);
|
|
119
|
+
}
|
|
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;
|
|
130
|
+
}
|
|
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
|
+
};
|
|
137
|
+
}
|
|
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);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
class MatrixElement extends Element {
|
|
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 = {
|
|
241
|
+
backgroundColor: undefined,
|
|
242
|
+
borderColor: undefined,
|
|
243
|
+
borderWidth: undefined,
|
|
244
|
+
borderRadius: 0,
|
|
245
|
+
anchorX: 'center',
|
|
246
|
+
anchorY: 'center',
|
|
247
|
+
width: 20,
|
|
248
|
+
height: 20
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export { MatrixController, MatrixElement };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* chartjs-chart-matrix v0.0.0-development
|
|
3
|
+
* https://chartjs-chart-matrix.pages.dev/
|
|
4
|
+
* (c) 2025 Jukka Kurkela
|
|
5
|
+
* Released under the MIT license
|
|
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,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
|
+
//# sourceMappingURL=chartjs-chart-matrix.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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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AQvE,KAAMoG,EAAQC,EAAQzD,EACvC,CAEA0D,QAAAA,CAASF,EAAgBxD,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": "
|
|
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": "
|
|
28
|
-
"
|
|
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
|
-
"
|
|
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": "^
|
|
62
|
-
"@rollup/plugin-
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
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": "^
|
|
79
|
+
"eslint": "^9.22.0",
|
|
72
80
|
"eslint-config-chartjs": "^0.3.0",
|
|
73
|
-
"eslint-
|
|
74
|
-
"eslint-plugin-
|
|
75
|
-
"eslint-plugin-
|
|
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.
|
|
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",
|
package/types/index.esm.d.ts
CHANGED
|
@@ -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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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
|
-
|
|
69
|
-
|
|
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
|
+
}
|