Skip to content

Commit b61abff

Browse files
committed
refactor: convert to typescript
1 parent 4aa6d11 commit b61abff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+6144
-3827
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/**/*

.eslintrc.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
extends:
22
- chartjs
33
- plugin:markdown/recommended
4+
- plugin:@typescript-eslint/recommended
45

5-
env:
6-
es2021: true
7-
browser: true
8-
node: true
6+
parser: "@typescript-eslint/parser"
97

108
parserOptions:
9+
ecmaVersion: 2022
1110
sourceType: module
12-
ecmaFeatures:
13-
impliedStrict: true
14-
modules: true
1511

16-
plugins: ['html']
12+
env:
13+
es2022: true
14+
browser: true
15+
node: true
16+
jasmine: true
17+
18+
plugins:
19+
- "@typescript-eslint"
20+
- prettier
21+
- html
1722

1823
rules:
24+
prettier/prettier: "error"
25+
semi: ["error", "never"]
1926
complexity: ["warn", 10]
2027
max-statements: ["warn", 30]
2128
no-var: "warn"
2229
prefer-const: ["warn", {"destructuring": "all"}]
30+
# turning off things conflicting with prettier
31+
indent: "off"
32+
comma-dangle: "off"
33+
comma-spacing: "off"
34+
comma-style: "off"
35+
object-curly-spacing: "off"
36+
space-before-function-paren: "off"

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
- name: lint
2929
run: npm run lint
3030

31+
- name: typecheck
32+
run: npm run typecheck
33+
3134
- name: build
3235
run: npm run build
3336

@@ -40,6 +43,15 @@ jobs:
4043
fi
4144
shell: bash
4245

46+
- name: Coveralls Paraller - Unit
47+
if: matrix.os == 'ubuntu-latest'
48+
uses: coverallsapp/github-action@v2
49+
with:
50+
github-token: ${{ secrets.github_token }}
51+
file: './coverage/unit/lcov.info'
52+
flag-name: unit
53+
parallel: true
54+
4355
- name: Coveralls Parallel - Chrome
4456
uses: coverallsapp/github-action@v2
4557
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Deployment
2+
/build
23
/coverage
34
/custom
45
/dist

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bracketSpacing: true
2+
singleQuote: true
3+
printWidth: 120
4+
semi: false
5+
tabWidth: 2
6+
useTabs: false
7+
trailingComma: 'es5'

.swcrc-spec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": false,
6+
"decorators": true,
7+
"dynamicImport": true,
8+
"importMeta": true
9+
},
10+
"target": "es2022",
11+
"baseUrl": "."
12+
},
13+
"module": {
14+
"type": "es6",
15+
"resolveFully": true
16+
},
17+
"sourceMaps": true
18+
}

docs/guide/developers.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ Returns whether the user is currently in the middle of a drag operation or pan o
6565
You can extend chartjs-plugin-zoom with support for [custom scales](https://www.chartjs.org/docs/latest/developers/axes.html) by using the zoom plugin's `zoomFunctions`, `zoomRectFunctions`, and `panFunctions` members. These objects are indexed by scale types (scales' `id` members) and give optional handlers for zoom and pan functionality.
6666

6767
```js
68-
import {Scale} from 'chart.js';
69-
import zoomPlugin from 'chartjs-plugin-zoom';
68+
import {Scale} from 'chart.js'
69+
import zoomPlugin from 'chartjs-plugin-zoom'
7070

7171
class MyScale extends Scale {
7272
/* extensions ... */
7373
}
74-
MyScale.id = 'myScale';
75-
MyScale.defaults = defaultConfigObject;
74+
MyScale.id = 'myScale'
75+
MyScale.defaults = defaultConfigObject
7676

77-
zoomPlugin.zoomFunctions.myScale = (scale, zoom, center, limits) => false;
78-
zoomPlugin.zoomRectFunctions.myScale = (scale, from, to, limits) => false;
79-
zoomPlugin.panFunctions.myScale = (scale, delta, limits) => false;
77+
zoomPlugin.zoomFunctions.myScale = (scale, zoom, center, limits) => false
78+
zoomPlugin.zoomRectFunctions.myScale = (scale, from, to, limits) => false
79+
zoomPlugin.panFunctions.myScale = (scale, delta, limits) => false
8080
// zoomRectFunctions can normally be omitted, since zooming by specific pixel
8181
// coordinates rarely needs special handling.
8282
```

docs/guide/options.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The options for chartjs-plugin-zoom should be placed in `options.plugins.zoom` i
55
The options are split in three sub-objects, [limits](#limits), [pan](#pan) and [zoom](#zoom).
66

77
```js
8-
const chart = new Chart('id', {
8+
export const chart = new Chart('id', {
99
type: 'bar',
1010
data: {},
1111
options: {
@@ -23,7 +23,7 @@ const chart = new Chart('id', {
2323
}
2424
}
2525
}
26-
});
26+
})
2727
```
2828

2929
## Pan
@@ -122,7 +122,7 @@ Limits options define the limits per axis for pan and zoom.
122122
If you're using multiple or custom axes (scales), you can define limits for those, too.
123123

124124
```js
125-
const chart = new Chart('id', {
125+
export const chart = new Chart('id', {
126126
type: 'line',
127127
data: {},
128128
options: {
@@ -146,7 +146,7 @@ const chart = new Chart('id', {
146146
}
147147
}
148148
}
149-
});
149+
})
150150
```
151151

152152
#### Scale Limits

docs/guide/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ const config = {
3131
}
3232
}
3333
}
34-
};
34+
}
3535
/* </block:config> */
3636

3737
module.exports = {
3838
actions: [
3939
{
4040
name: 'Reset zoom',
4141
handler: function(chart) {
42-
chart.resetZoom();
42+
chart.resetZoom()
4343
}
4444
}
4545
],
4646
config
47-
};
47+
}
4848
```

docs/samples/api.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```js chart-editor
44
// <block:data:1>
5-
const NUMBER_CFG = {count: 20, min: -100, max: 100};
5+
const NUMBER_CFG = {count: 20, min: -100, max: 100}
66
const data = {
77
datasets: [{
88
label: 'My First dataset',
@@ -21,7 +21,7 @@ const data = {
2121
pointBorderWidth: 1,
2222
data: Utils.points(NUMBER_CFG),
2323
}]
24-
};
24+
}
2525
// </block:data>
2626

2727
// <block:scales:2>
@@ -38,16 +38,16 @@ const scaleOpts = {
3838
display: true,
3939
text: (ctx) => ctx.scale.axis + ' axis',
4040
}
41-
};
41+
}
4242
const scales = {
4343
x: {
4444
position: 'top',
4545
},
4646
y: {
4747
position: 'right',
4848
},
49-
};
50-
Object.keys(scales).forEach(scale => Object.assign(scales[scale], scaleOpts));
49+
}
50+
Object.keys(scales).forEach(scale => Object.assign(scales[scale], scaleOpts))
5151
// </block:scales>
5252

5353
// <block:config:1>
@@ -57,7 +57,7 @@ const config = {
5757
options: {
5858
scales: scales,
5959
}
60-
};
60+
}
6161
// </block:config>
6262

6363
// <block:actions:0>
@@ -66,50 +66,50 @@ const actions = [
6666
{
6767
name: 'Zoom +10%',
6868
handler(chart) {
69-
chart.zoom(1.1);
69+
chart.zoom(1.1)
7070
}
7171
}, {
7272
name: 'Zoom -10%',
7373
handler(chart) {
74-
chart.zoom(2 - 1 / 0.9);
74+
chart.zoom(2 - 1 / 0.9)
7575
},
7676
}, {
7777
name: 'Zoom x +10%',
7878
handler(chart) {
79-
chart.zoom({x: 1.1});
79+
chart.zoom({x: 1.1})
8080
}
8181
}, {
8282
name: 'Zoom x -10%',
8383
handler(chart) {
84-
chart.zoom({x: 2 - 1 / 0.9});
84+
chart.zoom({x: 2 - 1 / 0.9})
8585
},
8686
}, {
8787
name: 'Pan x 100px (anim)',
8888
handler(chart) {
89-
chart.pan({x: 100}, undefined, 'default');
89+
chart.pan({x: 100}, undefined, 'default')
9090
}
9191
}, {
9292
name: 'Pan x -100px (anim)',
9393
handler(chart) {
94-
chart.pan({x: -100}, undefined, 'default');
94+
chart.pan({x: -100}, undefined, 'default')
9595
},
9696
}, {
9797
name: 'Zoom x: 0..-100, y: 0..100',
9898
handler(chart) {
99-
chart.zoomScale('x', {min: -100, max: 0}, 'default');
100-
chart.zoomScale('y', {min: 0, max: 100}, 'default');
99+
chart.zoomScale('x', {min: -100, max: 0}, 'default')
100+
chart.zoomScale('y', {min: 0, max: 100}, 'default')
101101
}
102102
}, {
103103
name: 'Reset zoom',
104104
handler(chart) {
105-
chart.resetZoom();
105+
chart.resetZoom()
106106
}
107107
}
108-
];
108+
]
109109
// </block:actions>
110110

111111
module.exports = {
112112
actions,
113113
config
114-
};
114+
}
115115
```

0 commit comments

Comments
 (0)