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

Applies element defaults before resolving element properties #325

Merged
merged 4 commits into from
Jan 31, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
applies element default before resolving element properties
  • Loading branch information
stockiNail committed Jan 30, 2021
commit 2053e83aea6026f4d37a1b7bf748387512df8f61
1 change: 0 additions & 1 deletion samples/point.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
yValue: 0,
backgroundColor: 'rgba(101, 33, 171, 0.5)',
borderColor: 'rgb(101, 33, 171)',
borderWidth: 15,
radius: 50,
click(context) {
console.log('Annotation', context);
Expand Down
6 changes: 3 additions & 3 deletions src/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ function updateElements(chart, state, options, mode) {
if (!el || !(el instanceof elType)) {
el = elements[i] = new elType();
}
const properties = el.resolveElementProperties(chart, annotation);
properties.options = merge(Object.create(null), [elType.defaults, annotation]);
const mergedOptions = merge(Object.create(null), [elType.defaults, annotation]);
const properties = el.resolveElementProperties(chart, mergedOptions);
properties.options = mergedOptions;
animations.update(el, properties);

el._display = isAnnotationVisible(chart, annotation, el);
}
}
Expand Down
63 changes: 63 additions & 0 deletions test/specs/point.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,67 @@ describe('Point annotation', function() {

});
});

describe('applying defaults', function() {

it('should not throw any exception', function() {
function createAndUpdateChart() {
const config = {
type: 'scatter',
options: {
animation: false,
scales: {
x: {
display: false,
min: 0,
max: 10
},
y: {
display: false,
min: 0,
max: 10
}
},
plugins: {
legend: false,
annotation: {
annotations: {
point: {
type: 'point',
borderWidth: 5,
display(context) {
if (context.element) {
context.chart.annotationRadius1 = context.element.options.radius;
}
return true;
},
},
point2: {
type: 'point',
xScaleID: 'x',
yScaleID: 'y',
xValue: 8,
yValue: 8,
borderWidth: 0,
display(context) {
if (context.element) {
context.chart.annotationRadius2 = context.element.options.radius;
}
return true;
},
}
}
}
}
},
};

var chart = acquireChart(config);
if (isNaN(chart.annotationRadius1) || isNaN(chart.annotationRadius2)) {
throw new Error('Defaults radius is not applied to annotaions : 1-' + chart.annotationRadius1 + ', 2-' + chart.annotationRadius2);
}
}
expect(createAndUpdateChart).not.toThrow();
});
});
});