Skip to content

Commit c0bfea9

Browse files
authored
Set the plugin as module (#838)
* Add exports for node * apply type module * fix integration tests * support commonjs * fixes typo * add integration tests for node module and commonjs * add chartjs-plugin-annotation.js creation * remove build of plugin.js * change chart.js peerDependencies * add doc referring to chart.js version 4 as required * changes minimum chartjs version
1 parent 84545be commit c0bfea9

File tree

21 files changed

+189
-59
lines changed

21 files changed

+189
-59
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
[![documentation](https://img.shields.io/static/v1?message=Documentation&color=informational)](https://www.chartjs.org/chartjs-plugin-annotation/index)
88
<a href="https://github.com/chartjs/awesome"><img src="https://awesome.re/badge-flat2.svg" alt="Awesome"></a>
99

10-
An annotation plugin for Chart.js >= 3.7.0
10+
An annotation plugin for Chart.js >= 4.0.0
1111

1212
---
1313
> This plugin needs to be registered. It does not function as inline plugin.
1414
---
1515

16+
For Chart.js 3.7.0 to 3.9.1 support, use [version 2.2.1 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v2.2.1)
17+
1618
For Chart.js 3.0.0 to 3.6.2 support, use [version 1.4.0 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v1.4.0)
19+
1720
For Chart.js 2.4.0 to 2.9.x support, use [version 0.5.7 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v0.5.7)
1821

1922
This plugin draws lines, boxes, points, labels, polygons and ellipses on the chart area.
2023

21-
Annotations work with line, bar, scatter and bubble charts that use linear, logarithmic, time, or category scales. Annotations will not work on any chart that does not have exactly two axes, including pie, radar, and polar area charts.
24+
Annotations work with line, bar, scatter and bubble charts that use linear, logarithmic, time, or category scales. Annotations will not work on any chart that does not have two or more axes, including pie, radar, and polar area charts.
2225

2326
![Example Screenshot](docs/guide/banner.png)
2427

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const path = require('path');
1+
import * as path from 'path';
2+
import markdownItInclude from 'markdown-it-include';
3+
import { DefaultThemeConfig, defineConfig, PluginTuple } from 'vuepress/config';
4+
25
const docsVersion = "VERSION";
36
const base = process.env.NODE_ENV === "development" ? '/chartjs-plugin-annotation/master/' : `/chartjs-plugin-annotation/${docsVersion}/`;
47

5-
module.exports = {
8+
export default defineConfig({
69
dest: 'dist/docs',
710
title: 'chartjs-plugin-annotation',
811
description: 'Annotations for Chart.js',
@@ -72,7 +75,7 @@ module.exports = {
7275
]
7376
},
7477
}],
75-
],
78+
] as PluginTuple[],
7679
chainWebpack(config) {
7780
config.module
7881
.rule('chart.js')
@@ -86,7 +89,7 @@ module.exports = {
8689
},
8790
markdown: {
8891
extendMarkdown: md => {
89-
md.use(require('markdown-it-include'), path.resolve(__dirname, '../'));
92+
md.use(markdownItInclude, path.resolve(__dirname, '../'));
9093
}
9194
},
9295
themeConfig: {
@@ -131,8 +134,15 @@ module.exports = {
131134
'types/polygon'
132135
]
133136
},
134-
'migrationV1',
135-
'migrationV2'
137+
{
138+
title: 'Migration',
139+
collapsable: true,
140+
children: [
141+
'migrationV3',
142+
'migrationV2',
143+
'migrationV1'
144+
]
145+
},
136146
],
137147
'/samples/': [
138148
'intro',
@@ -145,7 +155,7 @@ module.exports = {
145155
'box/canvas',
146156
'box/image',
147157
'box/initAnim',
148-
'box/gradient',
158+
'box/gradient'
149159
]
150160
},
151161
{
@@ -154,7 +164,7 @@ module.exports = {
154164
'ellipse/basic',
155165
'ellipse/rotation',
156166
'ellipse/label',
157-
'ellipse/image',
167+
'ellipse/image'
158168
]
159169
},
160170
{
@@ -187,7 +197,7 @@ module.exports = {
187197
'line/image',
188198
'line/datasetBars',
189199
'line/animation',
190-
'line/hook',
200+
'line/hook'
191201
]
192202
},
193203
{
@@ -197,7 +207,7 @@ module.exports = {
197207
'point/combined',
198208
'point/outsideChartArea',
199209
'point/shadow',
200-
'point/initAnim',
210+
'point/initAnim'
201211
]
202212
},
203213
{
@@ -206,14 +216,14 @@ module.exports = {
206216
'polygon/basic',
207217
'polygon/stop',
208218
'polygon/outsideChartArea',
209-
'polygon/shadow',
219+
'polygon/shadow'
210220
]
211221
},
212222
{
213223
title: 'Charts',
214224
children: [
215225
'charts/bar',
216-
'charts/line',
226+
'charts/line'
217227
],
218228
},
219229
{
@@ -222,11 +232,11 @@ module.exports = {
222232
'interaction/interaction',
223233
'interaction/dragging',
224234
'interaction/selection',
225-
'interaction/cartesianplane',
235+
'interaction/cartesianplane'
226236
],
227237
},
228-
'utils',
238+
'utils'
229239
]
230240
}
231-
}
232-
};
241+
} as DefaultThemeConfig
242+
});

docs/guide/index.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This plugin needs to be registered. It does not function as inline plugin.
66

77
:::
88

9-
An annotation plugin for Chart.js >= 3.0.0
9+
An annotation plugin for Chart.js >= 4.0.0
1010

1111
This plugin draws lines, boxes, labels, points, polygons and ellipses on the chart area. Annotations work with line, bar, scatter and bubble charts that use linear, logarithmic, time, or category scales. Annotations will not work on any chart that does not have exactly two axes, including pie, radar, and polar area charts.
1212

@@ -20,7 +20,12 @@ This plugin draws lines, boxes, labels, points, polygons and ellipses on the cha
2020

2121
::: tip Important Note
2222

23+
For Chart.js 3.7.0 to 3.9.1 support, use [version 2.2.1 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v2.2.1)
24+
25+
For Chart.js 3.0.0 to 3.6.2 support, use [version 1.4.0 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v1.4.0)
26+
2327
For Chart.js 2.4.0 to 2.9.x support, use [version 0.5.7 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v0.5.7)
28+
2429
Documentation for v0.5.7 can be found on [GitHub](https://github.com/chartjs/chartjs-plugin-annotation/blob/1ab782afce943456f958cac33f67edc5d6eab278/README.md).
2530

2631
:::

docs/guide/integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Integration
33
---
44

5-
chartjs-plugin-annotation can be integrated with plain JavaScript or with different module loaders. The examples below show to load the plugin in different systems.
5+
**`chartjs-plugin-annotation`** can be integrated with plain JavaScript or with different module loaders. The examples below show to load the plugin in different systems.
66

77
## Script Tag
88

docs/guide/migrationV1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 1.x Migration Guide
22

3-
`chartjs-plugin-annotation` plugin version 1 introduces a number of breaking changes in order to compatible with Chart.js 3 and to align with Chart.js 3 options.
3+
**`chartjs-plugin-annotation`** plugin version 1 introduces a number of breaking changes in order to compatible with Chart.js 3 and to align with Chart.js 3 options.
44

55
## Setup and installation
66

docs/guide/migrationV2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# 2.x Migration guide
1+
# 2.x Migration Guide
22

3-
`chartjs-plugin-annotation` plugin version 2 introduces a number of breaking changes. In order to improve performance, offer new features, and improve maintainability, it was necessary to break backwards compatibility, but we aimed to do so only when worth the benefit.
3+
**`chartjs-plugin-annotation`** plugin version 2 introduces a number of breaking changes. In order to improve performance, offer new features, and improve maintainability, it was necessary to break backwards compatibility, but we aimed to do so only when worth the benefit.
44

55
## Chart.js version
66

docs/guide/migrationV3.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 3.x Migration Guide
2+
3+
**`chartjs-plugin-annotation`** plugin version 3 becomes an [ESM-only package](https://nodejs.org/api/esm.html).
4+
The [UMD bundle](integration.md#script-tag) is still available.
5+
6+
## Chart.js version
7+
8+
The annotation plugin requires at least version 4.0.0 to work because of Chart.js becomes an ESM-only package.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ home: true
33
heroImage: /hero.svg
44
actionText: Get Started →
55
actionLink: /guide/
6-
footer: MIT Licensed | Copyright © 2016-2021 chartjs-plugin-annotation contributors
6+
footer: MIT Licensed | Copyright © 2016-2023 chartjs-plugin-annotation contributors
77
---

karma.conf.js renamed to karma.conf.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
const jasmineSeedReporter = require('./test/seed-reporter');
21
const istanbul = require('rollup-plugin-istanbul');
32
const json = require('@rollup/plugin-json');
43
const resolve = require('@rollup/plugin-node-resolve').default;
5-
const builds = require('./rollup.config');
64
const yargs = require('yargs');
75
const env = process.env.NODE_ENV;
86

9-
module.exports = function(karma) {
7+
module.exports = async function(karma) {
108
const args = yargs
119
.option('verbose', {default: false})
1210
.argv;
@@ -15,7 +13,9 @@ module.exports = function(karma) {
1513
// we will prefer the unminified build which is easier to browse and works
1614
// better with source mapping. In other cases, pick the minified build to
1715
// make sure that the minification process (terser) doesn't break anything.
18-
const regex = karma.autoWatch ? /chartjs-plugin-annotation\.js$/ : /chartjs-plugin-annotation\.min\.js$/;
16+
const builds = (await import('./rollup.config.js')).default;
17+
const jasmineSeedReporter = (await import('./test/seed-reporter.js')).default;
18+
const regex = karma.autoWatch ? /chartjs-plugin-annotation\.cjs$/ : /chartjs-plugin-annotation\.min\.js$/;
1919
const build = builds.filter(v => v.output.file && v.output.file.match(regex))[0];
2020

2121
if (env === 'test') {
@@ -67,7 +67,7 @@ module.exports = function(karma) {
6767
{pattern: 'test/fixtures/**/*.js', included: false},
6868
{pattern: 'test/fixtures/**/*.png', included: false},
6969
{pattern: 'node_modules/chart.js/dist/chart.umd.js'},
70-
{pattern: 'src/index.js', watched: false},
70+
{pattern: 'src/index.js', watched: false, type: 'js'},
7171
{pattern: 'test/index.js'},
7272
{pattern: 'test/specs/**/**.js'}
7373
],

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)