chartjs-chart-matrix 2.0.1 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chartjs-chart-matrix",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Chart.js module for creating matrix charts",
5
5
  "type": "module",
6
6
  "main": "dist/chartjs-chart-matrix.cjs",
@@ -21,7 +21,7 @@
21
21
  "scripts": {
22
22
  "autobuild": "rollup -c -w",
23
23
  "build": "rollup -c",
24
- "dev": "karma start ./karma.conf.cjs --no-signle-run --auto-watch --browsers chrome",
24
+ "dev": "karma start ./karma.conf.cjs --no-single-run --auto-watch --browsers chrome",
25
25
  "docs": "npm run build && vuepress build docs --no-cache",
26
26
  "docs:dev": "npm run build && vuepress dev docs --no-cache",
27
27
  "lint": "concurrently -r \"npm:lint-*\"",
@@ -30,7 +30,7 @@
30
30
  "lint-types": "eslint \"types/**/*.ts\" && tsc -p types/tests/",
31
31
  "test": "cross-env NODE_ENV=test concurrently \"npm:test-*\"",
32
32
  "test-lint": "npm run lint",
33
- "test-karma": "karma start ./karma.conf.cjs --auto-watch --single-run",
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"
36
36
  },
@@ -56,37 +56,37 @@
56
56
  "homepage": "https://chartjs-chart-matrix.pages.dev/",
57
57
  "devDependencies": {
58
58
  "@napi-rs/canvas": "^0.1.30",
59
- "@rollup/plugin-commonjs": "^24.0.1",
59
+ "@rollup/plugin-commonjs": "^28.0.1",
60
60
  "@rollup/plugin-json": "^6.0.0",
61
61
  "@rollup/plugin-node-resolve": "^15.0.1",
62
62
  "@rollup/plugin-terser": "^0.4.0",
63
63
  "@typescript-eslint/eslint-plugin": "^5.6.0",
64
64
  "@typescript-eslint/parser": "^5.6.0",
65
65
  "chart.js": "^4.0.1",
66
- "chartjs-adapter-date-fns": "^2.0.0",
66
+ "chartjs-adapter-date-fns": "^3.0.0",
67
67
  "chartjs-test-utils": "^0.5.0",
68
- "concurrently": "^7.4.0",
68
+ "concurrently": "^9.0.1",
69
69
  "cross-env": "^7.0.3",
70
70
  "date-fns": "^2.19.0",
71
71
  "eslint": "^8.4.1",
72
72
  "eslint-config-chartjs": "^0.3.0",
73
73
  "eslint-plugin-es": "^4.1.0",
74
- "eslint-plugin-html": "^7.1.0",
74
+ "eslint-plugin-html": "^8.1.2",
75
75
  "eslint-plugin-markdown": "^3.0.0",
76
- "jasmine-core": "^4.4.0",
76
+ "jasmine-core": "^5.1.2",
77
77
  "karma": "^6.2.0",
78
78
  "karma-chrome-launcher": "^3.1.0",
79
79
  "karma-coverage": "^2.0.3",
80
80
  "karma-firefox-launcher": "^2.1.0",
81
81
  "karma-jasmine": "^5.1.0",
82
82
  "karma-jasmine-html-reporter": "^2.0.0",
83
- "karma-rollup-preprocessor": "7.0.7",
83
+ "karma-rollup-preprocessor": "7.0.8",
84
84
  "karma-spec-reporter": "^0.0.36",
85
- "pixelmatch": "^5.2.1",
86
- "rollup": "^3.3.0",
85
+ "pixelmatch": "^6.0.0",
86
+ "rollup": "^4.21.2",
87
87
  "rollup-plugin-analyzer": "^4.0.0",
88
- "rollup-plugin-istanbul": "^4.0.0",
89
- "typescript": "^4.5.2",
88
+ "rollup-plugin-istanbul": "^5.0.0",
89
+ "typescript": "^5.3.3",
90
90
  "vuepress": "^1.9.7",
91
91
  "vuepress-plugin-flexsearch": "^0.3.0",
92
92
  "vuepress-plugin-redirect": "^1.2.5",
@@ -1,272 +0,0 @@
1
- /*!
2
- * chartjs-chart-matrix v2.0.1
3
- * https://chartjs-chart-matrix.pages.dev/
4
- * (c) 2023 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 = "2.0.1";
14
-
15
- class MatrixController extends chart_js.DatasetController {
16
-
17
- static id = 'matrix';
18
- static version = version;
19
-
20
- static defaults = {
21
- dataElementType: 'matrix',
22
-
23
- animations: {
24
- numbers: {
25
- type: 'number',
26
- properties: ['x', 'y', 'width', 'height']
27
- }
28
- },
29
- };
30
-
31
- static overrides = {
32
- interaction: {
33
- mode: 'nearest',
34
- intersect: true
35
- },
36
- 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);
81
- }
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
-
97
- 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;
105
- }
106
-
107
- 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;
115
- }
116
-
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};
127
- }
128
-
129
- function limit(value, min, max) {
130
- return Math.max(Math.min(value, max), min);
131
- }
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
172
- }
173
- };
174
- }
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);
184
- }
185
-
186
- class MatrixElement extends chart_js.Element {
187
-
188
- static id = 'matrix';
189
-
190
- static defaults = {
191
- backgroundColor: undefined,
192
- borderColor: undefined,
193
- borderWidth: undefined,
194
- borderRadius: 0,
195
- anchorX: 'center',
196
- anchorY: 'center',
197
- width: 20,
198
- 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
- }
266
-
267
- chart_js.Chart.register(MatrixController, MatrixElement);
268
-
269
- exports.MatrixController = MatrixController;
270
- exports.MatrixElement = MatrixElement;
271
-
272
- }));
@@ -1,264 +0,0 @@
1
- /*!
2
- * chartjs-chart-matrix v2.0.1
3
- * https://chartjs-chart-matrix.pages.dev/
4
- * (c) 2023 Jukka Kurkela
5
- * Released under the MIT license
6
- */
7
- import { DatasetController, Element } from 'chart.js';
8
- import { toTRBLCorners, addRoundedRectPath, isObject } from 'chart.js/helpers';
9
-
10
- var version = "2.0.1";
11
-
12
- class MatrixController extends DatasetController {
13
-
14
- static id = 'matrix';
15
- static version = version;
16
-
17
- static defaults = {
18
- dataElementType: 'matrix',
19
-
20
- animations: {
21
- numbers: {
22
- type: 'number',
23
- properties: ['x', 'y', 'width', 'height']
24
- }
25
- },
26
- };
27
-
28
- static overrides = {
29
- interaction: {
30
- mode: 'nearest',
31
- intersect: true
32
- },
33
- 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);
78
- }
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
-
94
- 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;
102
- }
103
-
104
- 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;
112
- }
113
-
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};
124
- }
125
-
126
- function limit(value, min, max) {
127
- return Math.max(Math.min(value, max), min);
128
- }
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
169
- }
170
- };
171
- }
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);
181
- }
182
-
183
- class MatrixElement extends Element {
184
-
185
- static id = 'matrix';
186
-
187
- static defaults = {
188
- backgroundColor: undefined,
189
- borderColor: undefined,
190
- borderWidth: undefined,
191
- borderRadius: 0,
192
- anchorX: 'center',
193
- anchorY: 'center',
194
- width: 20,
195
- 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
- }
263
-
264
- export { MatrixController, MatrixElement };
@@ -1,8 +0,0 @@
1
- /*!
2
- * chartjs-chart-matrix v2.0.1
3
- * https://chartjs-chart-matrix.pages.dev/
4
- * (c) 2023 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,i){"use strict";class r extends e.DatasetController{static id="matrix";static version="2.0.1";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}));
8
- //# sourceMappingURL=chartjs-chart-matrix.min.js.map
@@ -1 +0,0 @@
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,uBAEAA,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,KAKfC,aACEC,KAAKC,qBAAsB,EAC3BC,MAAMH,YACP,CAEDI,OAAOX,GACL,MACMY,EADKJ,KACKK,YADLL,KAGRM,eAAeF,EAAKG,KAAM,EAAGH,EAAKG,KAAKC,OAAQhB,EACnD,CAEDc,eAAeG,EAAOC,EAAOC,EAAOnB,GAClC,MAAMoB,EAAKZ,KACLa,EAAiB,UAATrB,GACRsB,OAACA,EAAMC,OAAEA,GAAUH,EAAGP,YACtBW,EAAYJ,EAAGK,0BAA0BP,EAAOlB,GAChD0B,EAAgBN,EAAGO,iBAAiB3B,EAAMiB,EAAMC,GAAQM,GAE9D,IAAK,IAAII,EAAIV,EAAOU,EAAIV,EAAQC,EAAOS,IAAK,CAC1C,MAAMC,GAAUR,GAASD,EAAGU,UAAUF,GAChCzB,EAAIkB,EAAQC,EAAOS,eAAiBT,EAAOU,iBAAiBH,EAAO1B,GACnEE,EAAIgB,EAAQE,EAAOQ,eAAiBR,EAAOS,iBAAiBH,EAAOxB,GACnE4B,EAAUb,EAAGK,0BAA0BG,EAAG5B,IAC1CkC,MAACA,EAAKC,OAAEA,EAAMC,QAAE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