Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert to typescript #907

Merged
merged 13 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
LeeLenaleee marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bracketSpacing: true
singleQuote: true
printWidth: 120
semi: false
tabWidth: 2
useTabs: false
trailingComma: 'es5'
endOfLine: 'auto'
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
}
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

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:

Expand Down
18 changes: 10 additions & 8 deletions docs/.vuepress/config.js → docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const path = require('path');
import * as path from 'path';
import { DefaultThemeConfig, defineConfig, PluginTuple } from 'vuepress/config';

const docsVersion = "VERSION";
const base = process.env.NODE_ENV === "development" ? '/chartjs-plugin-zoom/master/' : `/chartjs-plugin-zoom/${docsVersion}/`;

module.exports = {
export default defineConfig({
title: 'chartjs-plugin-zoom',
description: 'A zoom and pan plugin for Chart.js >= 3.0.0',
theme: 'chartjs',
Expand All @@ -22,7 +24,7 @@ module.exports = {
[
'vuepress-plugin-typedoc',
{
entryPoints: ['../../types/index.d.ts'],
entryPoints: ['../../src/index.ts'],
hideInPageTOC: true,
tsconfig: 'tsconfig.json',
sidebar: {
Expand All @@ -34,7 +36,7 @@ module.exports = {
['@simonbrunel/vuepress-plugin-versions', {
filters: {
suffix: (tag) => tag ? ` (${tag})` : '',
title: (v, vars) => window.location.href.includes('master') ? 'Development (master)' : v + (vars.tag ? ` (${tag})` : ''),
title: (v, vars) => window.location.href.includes('master') ? 'Development (master)' : v + (vars.tag ? ` (${vars.tag})` : ''),
},
menu: {
text: '{{version|title}}',
Expand Down Expand Up @@ -72,7 +74,7 @@ module.exports = {
]
},
}],
],
] as PluginTuple[],
chainWebpack: (config) => {
config.module
.rule('chart.js')
Expand Down Expand Up @@ -163,6 +165,6 @@ module.exports = {
'fetch-data',
'api',
],
}
}
};
} as any
} as DefaultThemeConfig
});
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 @@
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
Loading