Skip to content

Commit

Permalink
feat: move side-effects to statics
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Dec 10, 2022
1 parent 2ea7754 commit a5c57ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"import": "./dist/chartjs-chart-matrix.esm.js",
"require": "./dist/chartjs-chart-matrix.min.js"
},
"sideEffects": ["dist/chartjs-chart-matrix.js", "dist/chartjs-chart-matrix-min.js"],
"scripts": {
"autobuild": "rollup -c -w",
"build": "rollup -c",
Expand Down
65 changes: 32 additions & 33 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@ import {DatasetController} from 'chart.js';
import {version} from '../package.json';

export default class MatrixController extends DatasetController {

static id = 'matrix';
static version = version;

static defaults = {
dataElementType: 'matrix',

animations: {
numbers: {
type: 'number',
properties: ['x', 'y', 'width', 'height']
}
},
};

static overrides = {
interaction: {
mode: 'nearest',
intersect: true
},
scales: {
x: {
type: 'linear',
offset: true
},
y: {
type: 'linear',
reverse: true
}
},
};

initialize() {
this.enableOptionSharing = true;
super.initialize();
Expand Down Expand Up @@ -70,36 +102,3 @@ function resolveY(anchorY, y, height) {
}
return y - height / 2;
}

MatrixController.id = 'matrix';

MatrixController.version = version;

MatrixController.defaults = {
dataElementType: 'matrix',

animations: {
numbers: {
type: 'number',
properties: ['x', 'y', 'width', 'height']
}
},
};

MatrixController.overrides = {
interaction: {
mode: 'nearest',
intersect: true
},

scales: {
x: {
type: 'linear',
offset: true
},
y: {
type: 'linear',
reverse: true
}
},
};
26 changes: 14 additions & 12 deletions src/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ function inRange(rect, x, y, useFinalPosition) {
}

export default class MatrixElement extends Element {

static id = 'matrix';

static defaults = {
backgroundColor: undefined,
borderColor: undefined,
borderWidth: undefined,
borderRadius: 0,
anchorX: 'center',
anchorY: 'center',
width: 20,
height: 20
};

constructor(cfg) {
super();

Expand Down Expand Up @@ -136,15 +150,3 @@ export default class MatrixElement extends Element {
return axis === 'x' ? this.width / 2 : this.height / 2;
}
}

MatrixElement.id = 'matrix';
MatrixElement.defaults = {
backgroundColor: undefined,
borderColor: undefined,
borderWidth: undefined,
borderRadius: 0,
anchorX: 'center',
anchorY: 'center',
width: 20,
height: 20
};

0 comments on commit a5c57ee

Please sign in to comment.