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

Fix calling of onResize #8529

Merged
merged 5 commits into from
Feb 26, 2021
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 src/core/core.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ defaults.set('transitions', {
},
visible: {
type: 'boolean',
easing: 'linear',
fn: v => v | 0 // for keeping the dataset visible all the way through the animation
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Chart {

me.notifyPlugins('resize', {size: newSize});

callCallback(options.onResize, [newSize], me);
callCallback(options.onResize, [me, newSize], me);

if (me.attached) {
if (me._doResize()) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Defaults {

// singleton instance
export default new Defaults({
_scriptable: (name) => name !== 'onClick' && name !== 'onHover',
_scriptable: (name) => !name.startsWith('on'),
_indexable: (name) => name !== 'events',
hover: {
_fallback: 'interaction'
Expand Down
26 changes: 15 additions & 11 deletions test/specs/core.animations.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ describe('Chart.animations', function() {
describe('default transitions', function() {
describe('hide', function() {
it('should keep dataset visible through the animation', function(done) {
let test = false;
let count = 0;
window.acquireChart({
type: 'line',
Expand All @@ -188,27 +187,32 @@ describe('Chart.animations', function() {
},
options: {
animation: {
duration: 100,
duration: 0,
onProgress: (args) => {
if (test) {
if (args.currentStep < args.numSteps) {
// while animating, visible should be truthly
expect(args.chart.getDatasetMeta(0).visible).toBeTruthy();
count++;
}
if (!args.chart.isDatasetVisible(0) && args.currentStep / args.numSteps < 0.9) {
// while animating, visible should be truthly
// sometimes its not, thats why we check only up to 90% of the animation
expect(args.chart.getDatasetMeta(0).visible).toBeTruthy();
count++;
}
},
onComplete: (args) => {
if (!test) {
test = true;
setTimeout(() => args.chart.hide(0), 1);
if (args.chart.isDatasetVisible(0)) {
args.chart.hide(0);
} else {
// and when finished, it should be false
expect(args.chart.getDatasetMeta(0).visible).toBeFalsy();
expect(count).toBeGreaterThan(0);
done();
}
}
},
transitions: {
hide: {
animation: {
duration: 100
}
}
}
}
});
Expand Down
33 changes: 33 additions & 0 deletions test/specs/core.controller.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,39 @@ describe('Chart', function() {
});
});

it('should call onResize with correct arguments and context', function() {
let count = 0;
let correctThis = false;
let size = {
width: 0,
height: 0
};
acquireChart({
options: {
responsive: true,
maintainAspectRatio: false,
onResize(chart, newSize) {
count++;
correctThis = this === chart;
size.width = newSize.width;
size.height = newSize.height;
}
}
}, {
canvas: {
style: 'width: 150px; height: 245px'
},
wrapper: {
style: 'width: 300px; height: 350px'
}
});

expect(count).toEqual(1);
expect(correctThis).toBeTrue();
expect(size).toEqual({width: 300, height: 350});
});


it('should resize the canvas when parent width changes', function(done) {
var chart = acquireChart({
options: {
Expand Down