chartjs-chart-matrix 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
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
8
  ![GitHub](https://img.shields.io/github/license/kurkle/chartjs-chart-matrix.svg)
9
- [![Coverage Status](https://coveralls.io/repos/github/kurkle/chartjs-chart-matrix/badge.svg?branch=next)](https://coveralls.io/github/kurkle/chartjs-chart-matrix?branch=next)
9
+ [![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)
10
10
  [![documentation](https://img.shields.io/static/v1?message=Documentation&color=informational)](https://chartjs-chart-matrix.pages.dev)
11
11
 
12
12
  ## Documentation
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * chartjs-chart-matrix v1.1.0
2
+ * chartjs-chart-matrix v1.1.1
3
3
  * https://chartjs-chart-matrix.pages.dev/
4
4
  * (c) 2021 Jukka Kurkela
5
5
  * Released under the MIT license
@@ -7,7 +7,7 @@
7
7
  import { DatasetController, Element } from 'chart.js';
8
8
  import { toTRBLCorners, addRoundedRectPath, isObject } from 'chart.js/helpers';
9
9
 
10
- var version = "1.1.0";
10
+ var version = "1.1.1";
11
11
 
12
12
  class MatrixController extends DatasetController {
13
13
  initialize() {
@@ -36,8 +36,8 @@ class MatrixController extends DatasetController {
36
36
  const options = me.resolveDataElementOptions(i, mode);
37
37
  const {width, height, anchorX, anchorY} = options;
38
38
  const properties = {
39
- x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2),
40
- y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2),
39
+ x: resolveX(anchorX, x, width),
40
+ y: resolveY(anchorY, y, height),
41
41
  width,
42
42
  height,
43
43
  options
@@ -59,6 +59,26 @@ class MatrixController extends DatasetController {
59
59
  }
60
60
  }
61
61
 
62
+ function resolveX(anchorX, x, width) {
63
+ if (anchorX === 'left' || anchorX === 'start') {
64
+ return x;
65
+ }
66
+ if (anchorX === 'right' || anchorX === 'end') {
67
+ return x - width;
68
+ }
69
+ return x - width / 2;
70
+ }
71
+
72
+ function resolveY(anchorY, y, height) {
73
+ if (anchorY === 'top' || anchorY === 'start') {
74
+ return y;
75
+ }
76
+ if (anchorY === 'bottom' || anchorY === 'end') {
77
+ return y - height;
78
+ }
79
+ return y - height / 2;
80
+ }
81
+
62
82
  MatrixController.id = 'matrix';
63
83
 
64
84
  MatrixController.version = version;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * chartjs-chart-matrix v1.1.0
2
+ * chartjs-chart-matrix v1.1.1
3
3
  * https://chartjs-chart-matrix.pages.dev/
4
4
  * (c) 2021 Jukka Kurkela
5
5
  * Released under the MIT license
@@ -8,13 +8,13 @@
8
8
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('chart.js'), require('chart.js/helpers')) :
9
9
  typeof define === 'function' && define.amd ? define(['chart.js', 'chart.js/helpers'], factory) :
10
10
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Chart, global.Chart.helpers));
11
- }(this, (function (Chart, helpers) { 'use strict';
11
+ })(this, (function (Chart, helpers) { 'use strict';
12
12
 
13
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
14
 
15
15
  var Chart__default = /*#__PURE__*/_interopDefaultLegacy(Chart);
16
16
 
17
- var version = "1.1.0";
17
+ var version = "1.1.1";
18
18
 
19
19
  class MatrixController extends Chart.DatasetController {
20
20
  initialize() {
@@ -43,8 +43,8 @@ class MatrixController extends Chart.DatasetController {
43
43
  const options = me.resolveDataElementOptions(i, mode);
44
44
  const {width, height, anchorX, anchorY} = options;
45
45
  const properties = {
46
- x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2),
47
- y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2),
46
+ x: resolveX(anchorX, x, width),
47
+ y: resolveY(anchorY, y, height),
48
48
  width,
49
49
  height,
50
50
  options
@@ -66,6 +66,26 @@ class MatrixController extends Chart.DatasetController {
66
66
  }
67
67
  }
68
68
 
69
+ function resolveX(anchorX, x, width) {
70
+ if (anchorX === 'left' || anchorX === 'start') {
71
+ return x;
72
+ }
73
+ if (anchorX === 'right' || anchorX === 'end') {
74
+ return x - width;
75
+ }
76
+ return x - width / 2;
77
+ }
78
+
79
+ function resolveY(anchorY, y, height) {
80
+ if (anchorY === 'top' || anchorY === 'start') {
81
+ return y;
82
+ }
83
+ if (anchorY === 'bottom' || anchorY === 'end') {
84
+ return y - height;
85
+ }
86
+ return y - height / 2;
87
+ }
88
+
69
89
  MatrixController.id = 'matrix';
70
90
 
71
91
  MatrixController.version = version;
@@ -249,6 +269,6 @@ MatrixElement.defaults = {
249
269
  height: 20
250
270
  };
251
271
 
252
- Chart__default['default'].register(MatrixController, MatrixElement);
272
+ Chart__default["default"].register(MatrixController, MatrixElement);
253
273
 
254
- })));
274
+ }));
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * chartjs-chart-matrix v1.1.0
2
+ * chartjs-chart-matrix v1.1.1
3
3
  * https://chartjs-chart-matrix.pages.dev/
4
4
  * (c) 2021 Jukka Kurkela
5
5
  * Released under the MIT license
6
6
  */
7
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=i(t);class o extends t.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,i,r){const o=this,n="reset"===r,{xScale:a,yScale:h}=o._cachedMeta,s=o.resolveDataElementOptions(e,r),d=o.getSharedOptions(r,t[e],s);for(let s=e;s<e+i;s++){const e=!n&&o.getParsed(s),i=n?a.getBasePixel():a.getPixelForValue(e.x),d=n?h.getBasePixel():h.getPixelForValue(e.y),l=o.resolveDataElementOptions(s,r),{width:u,height:c,anchorX:g,anchorY:f}=l,p={x:"left"===g?i:i-u/("right"===g?1:2),y:"top"===f?d:d-c/("bottom"===f?1:2),width:u,height:c,options:l};o.updateElement(t[s],s,p,r)}o.updateSharedOptions(d,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){const{x:i,y:r,width:o,height:n}=t.getProps(["x","y","width","height"],e);return{left:i,top:r,right:i+o,bottom:r+n}}function a(t,e,i){return Math.max(Math.min(t,i),e)}function h(t){const i=n(t),r=i.right-i.left,o=i.bottom-i.top,h=function(t,i,r){const o=t.options.borderWidth;let n,h,s,d;return e.isObject(o)?(n=+o.top||0,h=+o.right||0,s=+o.bottom||0,d=+o.left||0):n=h=s=d=+o||0,{t:a(n,0,r),r:a(h,0,i),b:a(s,0,r),l:a(d,0,i)}}(t,r/2,o/2);return{outer:{x:i.left,y:i.top,w:r,h:o},inner:{x:i.left+h.l,y:i.top+h.t,w:r-h.l-h.r,h:o-h.t-h.b}}}function s(t,e,i,r){const o=null===e,a=null===i,h=!(!t||o&&a)&&n(t,r);return h&&(o||e>=h.left&&e<=h.right)&&(a||i>=h.top&&i<=h.bottom)}o.id="matrix",o.version="1.1.0",o.defaults={dataElementType:"matrix",animations:{numbers:{type:"number",properties:["x","y","width","height"]}},anchorX:"center",anchorY:"center"},o.overrides={interaction:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}}};class d extends t.Element{constructor(t){super(),this.options=void 0,this.width=void 0,this.height=void 0,t&&Object.assign(this,t)}draw(t){const i=this.options,{inner:r,outer:o}=h(this),n=e.toTRBLCorners(i.borderRadius);t.save(),o.w!==r.w||o.h!==r.h?(t.beginPath(),e.addRoundedRectPath(t,{x:o.x,y:o.y,w:o.w,h:o.h,radius:n}),e.addRoundedRectPath(t,{x:r.x,y:r.y,w:r.w,h:r.h,radius:n}),t.fillStyle=i.backgroundColor,t.fill(),t.fillStyle=i.borderColor,t.fill("evenodd")):(t.beginPath(),e.addRoundedRectPath(t,{x:r.x,y:r.y,w:r.w,h:r.h,radius:n}),t.fillStyle=i.backgroundColor,t.fill()),t.restore()}inRange(t,e,i){return s(this,t,e,i)}inXRange(t,e){return s(this,t,null,e)}inYRange(t,e){return s(this,null,t,e)}getCenterPoint(t){const{x:e,y:i,width:r,height:o}=this.getProps(["x","y","width","height"],t);return{x:e+r/2,y:i+o/2}}tooltipPosition(){return this.getCenterPoint()}getRange(t){return"x"===t?this.width/2:this.height/2}}d.id="matrix",d.defaults={backgroundColor:void 0,borderColor:void 0,borderWidth:void 0,borderRadius:0,anchorX:void 0,anchorY:void 0,width:20,height:20},r.default.register(o,d)}));
7
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=i(t);class n extends t.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,i,r){const n=this,s="reset"===r,{xScale:h,yScale:d}=n._cachedMeta,l=n.resolveDataElementOptions(e,r),u=n.getSharedOptions(r,t[e],l);for(let l=e;l<e+i;l++){const e=!s&&n.getParsed(l),i=s?h.getBasePixel():h.getPixelForValue(e.x),u=s?d.getBasePixel():d.getPixelForValue(e.y),c=n.resolveDataElementOptions(l,r),{width:f,height:g,anchorX:p,anchorY:x}=c,y={x:o(p,i,f),y:a(x,u,g),width:f,height:g,options:c};n.updateElement(t[l],l,y,r)}n.updateSharedOptions(u,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 o(t,e,i){return"left"===t||"start"===t?e:"right"===t||"end"===t?e-i:e-i/2}function a(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 h(t,e,i){return Math.max(Math.min(t,i),e)}function d(t){const i=s(t),r=i.right-i.left,n=i.bottom-i.top,o=function(t,i,r){const n=t.options.borderWidth;let o,a,s,d;return e.isObject(n)?(o=+n.top||0,a=+n.right||0,s=+n.bottom||0,d=+n.left||0):o=a=s=d=+n||0,{t:h(o,0,r),r:h(a,0,i),b:h(s,0,r),l:h(d,0,i)}}(t,r/2,n/2);return{outer:{x:i.left,y:i.top,w:r,h:n},inner:{x:i.left+o.l,y:i.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)}n.id="matrix",n.version="1.1.1",n.defaults={dataElementType:"matrix",animations:{numbers:{type:"number",properties:["x","y","width","height"]}},anchorX:"center",anchorY:"center"},n.overrides={interaction:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}}};class u extends t.Element{constructor(t){super(),this.options=void 0,this.width=void 0,this.height=void 0,t&&Object.assign(this,t)}draw(t){const i=this.options,{inner:r,outer:n}=d(this),o=e.toTRBLCorners(i.borderRadius);t.save(),n.w!==r.w||n.h!==r.h?(t.beginPath(),e.addRoundedRectPath(t,{x:n.x,y:n.y,w:n.w,h:n.h,radius:o}),e.addRoundedRectPath(t,{x:r.x,y:r.y,w:r.w,h:r.h,radius:o}),t.fillStyle=i.backgroundColor,t.fill(),t.fillStyle=i.borderColor,t.fill("evenodd")):(t.beginPath(),e.addRoundedRectPath(t,{x:r.x,y:r.y,w:r.w,h:r.h,radius:o}),t.fillStyle=i.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}}u.id="matrix",u.defaults={backgroundColor:void 0,borderColor:void 0,borderWidth:void 0,borderRadius:0,anchorX:void 0,anchorY:void 0,width:20,height:20},r.default.register(n,u)}));
8
8
  //# sourceMappingURL=chartjs-chart-matrix.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chartjs-chart-matrix",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Chart.js module for creating matrix charts",
5
5
  "main": "dist/chartjs-chart-matrix.js",
6
6
  "module": "dist/chartjs-chart-matrix.esm.js",
@@ -39,18 +39,18 @@
39
39
  },
40
40
  "homepage": "https://chartjs-chart-matrix.pages.dev/",
41
41
  "devDependencies": {
42
- "@rollup/plugin-commonjs": "^20.0.0",
42
+ "@rollup/plugin-commonjs": "^21.0.1",
43
43
  "@rollup/plugin-json": "^4.1.0",
44
44
  "@rollup/plugin-node-resolve": "^13.0.0",
45
- "@typescript-eslint/eslint-plugin": "^4.22.0",
46
- "@typescript-eslint/parser": "^4.22.0",
45
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
46
+ "@typescript-eslint/parser": "^5.6.0",
47
47
  "chart.js": "^3.0.0",
48
48
  "chartjs-adapter-date-fns": "^2.0.0",
49
49
  "chartjs-test-utils": "^0.3.0",
50
50
  "concurrently": "^6.0.0",
51
51
  "cross-env": "^7.0.3",
52
52
  "date-fns": "^2.19.0",
53
- "eslint": "^7.22.0",
53
+ "eslint": "^8.4.1",
54
54
  "eslint-config-chartjs": "^0.3.0",
55
55
  "eslint-plugin-es": "^4.1.0",
56
56
  "eslint-plugin-html": "^6.1.2",
@@ -69,9 +69,9 @@
69
69
  "rollup-plugin-analyzer": "^4.0.0",
70
70
  "rollup-plugin-istanbul": "^3.0.0",
71
71
  "rollup-plugin-terser": "^7.0.2",
72
- "typescript": "~4.3",
72
+ "typescript": "^4.5.2",
73
73
  "vuepress": "^1.8.2",
74
- "vuepress-plugin-flexsearch": "^0.2.0",
74
+ "vuepress-plugin-flexsearch": "^0.3.0",
75
75
  "vuepress-plugin-redirect": "^1.2.5",
76
76
  "vuepress-theme-chartjs": "^0.2.0"
77
77
  },
@@ -33,7 +33,7 @@ declare module 'chart.js' {
33
33
  defaultDataPoint: MatrixDataPoint;
34
34
  parsedDataType: MatrixDataPoint;
35
35
  metaExtensions: AnyObject;
36
- scales: never;
36
+ scales: keyof CartesianScaleTypeRegistry;
37
37
  }
38
38
  }
39
39
  }