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

Workaround for array syntax bug with Chart.js<v3.7 #575

Merged
merged 2 commits into from Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/annotation.js
Expand Up @@ -5,6 +5,7 @@ import {annotationTypes} from './types';
import {version} from '../package.json';

const chartStates = new Map();
const versionParts = Chart.version.split('.');

export default {
id: 'annotation',
Expand All @@ -13,6 +14,15 @@ export default {

afterRegister() {
Chart.register(annotationTypes);

if (versionParts[0] === '3' && parseInt(versionParts[1], 10) <= 6) {
// Workaround for https://github.com/chartjs/chartjs-plugin-annotation/issues/572
Chart.defaults.set('elements.lineAnnotation', {
callout: {},
font: {},
padding: 6
});
}
},

afterUnregister() {
Expand Down
2 changes: 1 addition & 1 deletion src/types/label.js
Expand Up @@ -118,7 +118,7 @@ function measureRect(point, size, options, padding) {
};
}

function calculatePosition(start, size, adjust, position) {
function calculatePosition(start, size, adjust = 0, position) {
return start - getRelativePosition(size, position) + adjust;
}

Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/label/borderDash.js
Expand Up @@ -15,8 +15,8 @@ module.exports = {
},
plugins: {
annotation: {
annotations: {
text1: {
annotations: [
{
type: 'label',
xScaleID: 'x',
yScaleID: 'y',
Expand All @@ -28,7 +28,7 @@ module.exports = {
borderWidth: 5,
content: 'This is my text'
},
text2: {
{
type: 'label',
xScaleID: 'x',
yScaleID: 'y',
Expand All @@ -40,7 +40,7 @@ module.exports = {
borderWidth: 4,
content: 'This is my text'
},
text3: {
{
type: 'label',
xScaleID: 'x',
yScaleID: 'y',
Expand All @@ -55,7 +55,7 @@ module.exports = {
x: 'end'
}
}
}
]
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/label/calloutSide.js
Expand Up @@ -15,8 +15,8 @@ module.exports = {
},
plugins: {
annotation: {
annotations: {
text1: {
annotations: [
{
type: 'label',
xScaleID: 'x',
yScaleID: 'y',
Expand All @@ -39,15 +39,15 @@ module.exports = {
position: 'bottom',
}
},
point1: {
{
type: 'point',
xScaleID: 'x',
yScaleID: 'y',
xValue: 2.5,
yValue: 20,
radius: 3
},
text2: {
{
type: 'label',
xScaleID: 'x',
yScaleID: 'y',
Expand All @@ -70,15 +70,15 @@ module.exports = {
position: 'top',
}
},
point2: {
{
type: 'point',
xScaleID: 'x',
yScaleID: 'y',
xValue: 2.5,
yValue: 20,
radius: 3
}
}
]
}
}
}
Expand Down