Skip to content

Commit

Permalink
refactor: convert to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Nov 27, 2024
1 parent 4aa6d11 commit 911cbb3
Show file tree
Hide file tree
Showing 84 changed files with 6,144 additions and 3,827 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/**/*
30 changes: 22 additions & 8 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
extends:
- chartjs
- plugin:markdown/recommended
- plugin:@typescript-eslint/recommended

env:
es2021: true
browser: true
node: true
parser: "@typescript-eslint/parser"

parserOptions:
ecmaVersion: 2022
sourceType: module
ecmaFeatures:
impliedStrict: true
modules: true

plugins: ['html']
env:
es2022: true
browser: true
node: true
jasmine: true

plugins:
- "@typescript-eslint"
- prettier
- html

rules:
prettier/prettier: "error"
semi: ["error", "never"]
complexity: ["warn", 10]
max-statements: ["warn", 30]
no-var: "warn"
prefer-const: ["warn", {"destructuring": "all"}]
# turning off things conflicting with prettier
indent: "off"
comma-dangle: "off"
comma-spacing: "off"
comma-style: "off"
object-curly-spacing: "off"
space-before-function-paren: "off"
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: lint
run: npm run lint

- name: typecheck
run: npm run typecheck

- name: build
run: npm run build

Expand All @@ -40,6 +43,15 @@ jobs:
fi
shell: bash

- name: Coveralls Paraller - Unit
if: matrix.os == 'ubuntu-latest'
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
file: './coverage/unit/lcov.info'
flag-name: unit
parallel: true

- name: Coveralls Parallel - Chrome
uses: coverallsapp/github-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Deployment
/build
/coverage
/custom
/dist
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bracketSpacing: true
singleQuote: true
printWidth: 120
semi: false
tabWidth: 2
useTabs: false
trailingComma: 'es5'
18 changes: 18 additions & 0 deletions .swcrc-spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true,
"importMeta": true
},
"target": "es2022",
"baseUrl": "."
},
"module": {
"type": "es6",
"resolveFully": true
},
"sourceMaps": true
}
14 changes: 7 additions & 7 deletions docs/guide/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ Returns whether the user is currently in the middle of a drag operation or pan o
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.

```js
import {Scale} from 'chart.js';
import zoomPlugin from 'chartjs-plugin-zoom';
import {Scale} from 'chart.js'
import zoomPlugin from 'chartjs-plugin-zoom'

class MyScale extends Scale {
/* extensions ... */
}
MyScale.id = 'myScale';
MyScale.defaults = defaultConfigObject;
MyScale.id = 'myScale'
MyScale.defaults = defaultConfigObject

zoomPlugin.zoomFunctions.myScale = (scale, zoom, center, limits) => false;
zoomPlugin.zoomRectFunctions.myScale = (scale, from, to, limits) => false;
zoomPlugin.panFunctions.myScale = (scale, delta, limits) => false;
zoomPlugin.zoomFunctions.myScale = (scale, zoom, center, limits) => false

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'scale' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'zoom' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'center' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'limits' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'scale' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'zoom' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'center' is defined but never used

Check warning on line 77 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'limits' is defined but never used
zoomPlugin.zoomRectFunctions.myScale = (scale, from, to, limits) => false

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'scale' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'from' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'to' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'limits' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'scale' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'from' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'to' is defined but never used

Check warning on line 78 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'limits' is defined but never used
zoomPlugin.panFunctions.myScale = (scale, delta, limits) => false

Check warning on line 79 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'scale' is defined but never used

Check warning on line 79 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'delta' is defined but never used

Check warning on line 79 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'scale' is defined but never used

Check warning on line 79 in docs/guide/developers.md

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

'delta' is defined but never used
// zoomRectFunctions can normally be omitted, since zooming by specific pixel
// coordinates rarely needs special handling.
```
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The options for chartjs-plugin-zoom should be placed in `options.plugins.zoom` i
The options are split in three sub-objects, [limits](#limits), [pan](#pan) and [zoom](#zoom).

```js
const chart = new Chart('id', {
export const chart = new Chart('id', {
type: 'bar',
data: {},
options: {
Expand All @@ -23,7 +23,7 @@ const chart = new Chart('id', {
}
}
}
});
})
```

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

```js
const chart = new Chart('id', {
export const chart = new Chart('id', {
type: 'line',
data: {},
options: {
Expand All @@ -146,7 +146,7 @@ const chart = new Chart('id', {
}
}
}
});
})
```

#### Scale Limits
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ const config = {
}
}
}
};
}
/* </block:config> */

module.exports = {
actions: [
{
name: 'Reset zoom',
handler: function(chart) {
chart.resetZoom();
chart.resetZoom()
}
}
],
config
};
}
```
34 changes: 17 additions & 17 deletions docs/samples/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

```js chart-editor
// <block:data:1>
const NUMBER_CFG = {count: 20, min: -100, max: 100};
const NUMBER_CFG = {count: 20, min: -100, max: 100}
const data = {
datasets: [{
label: 'My First dataset',
Expand All @@ -21,7 +21,7 @@ const data = {
pointBorderWidth: 1,
data: Utils.points(NUMBER_CFG),
}]
};
}
// </block:data>

// <block:scales:2>
Expand All @@ -38,16 +38,16 @@ const scaleOpts = {
display: true,
text: (ctx) => ctx.scale.axis + ' axis',
}
};
}
const scales = {
x: {
position: 'top',
},
y: {
position: 'right',
},
};
Object.keys(scales).forEach(scale => Object.assign(scales[scale], scaleOpts));
}
Object.keys(scales).forEach(scale => Object.assign(scales[scale], scaleOpts))
// </block:scales>

// <block:config:1>
Expand All @@ -57,7 +57,7 @@ const config = {
options: {
scales: scales,
}
};
}
// </block:config>

// <block:actions:0>
Expand All @@ -66,50 +66,50 @@ const actions = [
{
name: 'Zoom +10%',
handler(chart) {
chart.zoom(1.1);
chart.zoom(1.1)
}
}, {
name: 'Zoom -10%',
handler(chart) {
chart.zoom(2 - 1 / 0.9);
chart.zoom(2 - 1 / 0.9)
},
}, {
name: 'Zoom x +10%',
handler(chart) {
chart.zoom({x: 1.1});
chart.zoom({x: 1.1})
}
}, {
name: 'Zoom x -10%',
handler(chart) {
chart.zoom({x: 2 - 1 / 0.9});
chart.zoom({x: 2 - 1 / 0.9})
},
}, {
name: 'Pan x 100px (anim)',
handler(chart) {
chart.pan({x: 100}, undefined, 'default');
chart.pan({x: 100}, undefined, 'default')
}
}, {
name: 'Pan x -100px (anim)',
handler(chart) {
chart.pan({x: -100}, undefined, 'default');
chart.pan({x: -100}, undefined, 'default')
},
}, {
name: 'Zoom x: 0..-100, y: 0..100',
handler(chart) {
chart.zoomScale('x', {min: -100, max: 0}, 'default');
chart.zoomScale('y', {min: 0, max: 100}, 'default');
chart.zoomScale('x', {min: -100, max: 0}, 'default')
chart.zoomScale('y', {min: 0, max: 100}, 'default')
}
}, {
name: 'Reset zoom',
handler(chart) {
chart.resetZoom();
chart.resetZoom()
}
}
];
]
// </block:actions>

module.exports = {
actions,
config
};
}
```
Loading

0 comments on commit 911cbb3

Please sign in to comment.