Skip to content

Commit c7b51af

Browse files
authored
Make the plugin compatible with Chart.js v4 (#348)
1 parent 62752ed commit c7b51af

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

docs/.vuepress/config.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path');
2+
13
// https://docs.netlify.com/configure-builds/environment-variables/#git-metadata
24
const BRANCH = process.env.BRANCH || (process.env.NODE_ENV === 'development' ? 'local' : '');
35
const IS_DEV = BRANCH ? !BRANCH.match(/^v\d\.\d\.\d/) : false;
@@ -67,6 +69,17 @@ module.exports = {
6769
}
6870
}]
6971
],
72+
chainWebpack(config) {
73+
config.module
74+
.rule('chart.js')
75+
.include.add(path.resolve('node_modules/chart.js')).end()
76+
.use('babel-loader')
77+
.loader('babel-loader')
78+
.options({
79+
presets: ['@babel/preset-env']
80+
})
81+
.end();
82+
},
7083
themeConfig: {
7184
repo: REPO_NAME,
7285
docsDir: 'docs',

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function(karma) {
2525
files: [
2626
{pattern: './test/fixtures/**/*.js', included: false},
2727
{pattern: './test/fixtures/**/*.png', included: false},
28-
'node_modules/chart.js/dist/chart.js',
28+
'node_modules/chart.js/dist/chart.umd.js',
2929
'test/index.js',
3030
'src/plugin.js',
3131
specs

package-lock.json

+14-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "chartjs-plugin-datalabels",
33
"homepage": "https://chartjs-plugin-datalabels.netlify.app",
44
"description": "Chart.js plugin to display labels on data elements",
5-
"version": "2.1.0",
5+
"version": "2.2.0",
66
"license": "MIT",
77
"main": "dist/chartjs-plugin-datalabels.js",
88
"module": "dist/chartjs-plugin-datalabels.esm.js",
@@ -41,7 +41,7 @@
4141
"@typescript-eslint/parser": "^5.30.6",
4242
"@vuepress/plugin-google-analytics": "^1.9.7",
4343
"archiver": "^5.3.1",
44-
"chart.js": "^3.8.0",
44+
"chart.js": "^4.0.0",
4545
"chartjs-test-utils": "^0.4.0",
4646
"eslint": "^8.19.0",
4747
"eslint-config-chartjs": "^0.3.0",
@@ -66,6 +66,6 @@
6666
"yargs": "^17.5.1"
6767
},
6868
"peerDependencies": {
69-
"chart.js": "^3.0.0"
69+
"chart.js": ">=3.0.0"
7070
}
7171
}

test/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ jasmine.fixture = {
3737
};
3838
jasmine.triggerMouseEvent = triggerMouseEvent;
3939

40+
beforeAll(() => {
41+
// Disable colors plugin for tests.
42+
window.Chart.defaults.plugins.colors.enabled = false;
43+
});
44+
4045
beforeEach(function() {
4146
addMatchers();
4247

0 commit comments

Comments
 (0)