Skip to content

Commit cf08c6a

Browse files
authored
refactor: convert to typescript (#907)
* refactor: convert to typescript * fix: windows lint * fix: docs-build (= remove typedoc) * fix: try to fix windows test * fix: one more fix for windows * chore: tuning * fix: removing comments * chore: use -Infinity/Infinity * chore: fix issues * fix: tests * fix: reduce complexity * fix: api documentation * fix: linting issues, license year
1 parent 4aa6d11 commit cf08c6a

Some content is hidden

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

91 files changed

+6401
-4546
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bracketSpacing: true
2+
singleQuote: true
3+
printWidth: 120
4+
semi: false
5+
tabWidth: 2
6+
useTabs: false
7+
trailingComma: 'es5'
8+
endOfLine: 'auto'

.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+
}

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013-2021 chartjs-plugin-zoom contributors
3+
Copyright (c) 2013-2024 chartjs-plugin-zoom contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

docs/.vuepress/config.js renamed to docs/.vuepress/config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const path = require('path');
1+
import * as path from 'path';
2+
import { DefaultThemeConfig, defineConfig, PluginTuple } from 'vuepress/config';
3+
24
const docsVersion = "VERSION";
35
const base = process.env.NODE_ENV === "development" ? '/chartjs-plugin-zoom/master/' : `/chartjs-plugin-zoom/${docsVersion}/`;
46

5-
module.exports = {
7+
export default defineConfig({
68
title: 'chartjs-plugin-zoom',
79
description: 'A zoom and pan plugin for Chart.js >= 3.0.0',
810
theme: 'chartjs',
@@ -22,7 +24,7 @@ module.exports = {
2224
[
2325
'vuepress-plugin-typedoc',
2426
{
25-
entryPoints: ['../../types/index.d.ts'],
27+
entryPoints: ['../../src/index.ts'],
2628
hideInPageTOC: true,
2729
tsconfig: 'tsconfig.json',
2830
sidebar: {
@@ -34,7 +36,7 @@ module.exports = {
3436
['@simonbrunel/vuepress-plugin-versions', {
3537
filters: {
3638
suffix: (tag) => tag ? ` (${tag})` : '',
37-
title: (v, vars) => window.location.href.includes('master') ? 'Development (master)' : v + (vars.tag ? ` (${tag})` : ''),
39+
title: (v, vars) => window.location.href.includes('master') ? 'Development (master)' : v + (vars.tag ? ` (${vars.tag})` : ''),
3840
},
3941
menu: {
4042
text: '{{version|title}}',
@@ -72,7 +74,7 @@ module.exports = {
7274
]
7375
},
7476
}],
75-
],
77+
] as PluginTuple[],
7678
chainWebpack: (config) => {
7779
config.module
7880
.rule('chart.js')
@@ -163,6 +165,6 @@ module.exports = {
163165
'fetch-data',
164166
'api',
165167
],
166-
}
167-
}
168-
};
168+
} as any
169+
} as DefaultThemeConfig
170+
});

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

0 commit comments

Comments
 (0)