Skip to content

Commit 061e3db

Browse files
authored
Fix calling of onResize (#8529)
* Fix calling of onResize * Try to fix the bugging animation test * try again * and the actual fix * maybe now
1 parent bb82aaa commit 061e3db

5 files changed

+51
-13
lines changed

src/core/core.animations.js

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ defaults.set('transitions', {
6969
},
7070
visible: {
7171
type: 'boolean',
72+
easing: 'linear',
7273
fn: v => v | 0 // for keeping the dataset visible all the way through the animation
7374
},
7475
}

src/core/core.controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class Chart {
242242

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

245-
callCallback(options.onResize, [newSize], me);
245+
callCallback(options.onResize, [me, newSize], me);
246246

247247
if (me.attached) {
248248
if (me._doResize()) {

src/core/core.defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class Defaults {
159159

160160
// singleton instance
161161
export default new Defaults({
162-
_scriptable: (name) => name !== 'onClick' && name !== 'onHover',
162+
_scriptable: (name) => !name.startsWith('on'),
163163
_indexable: (name) => name !== 'events',
164164
hover: {
165165
_fallback: 'interaction'

test/specs/core.animations.tests.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ describe('Chart.animations', function() {
176176
describe('default transitions', function() {
177177
describe('hide', function() {
178178
it('should keep dataset visible through the animation', function(done) {
179-
let test = false;
180179
let count = 0;
181180
window.acquireChart({
182181
type: 'line',
@@ -188,27 +187,32 @@ describe('Chart.animations', function() {
188187
},
189188
options: {
190189
animation: {
191-
duration: 100,
190+
duration: 0,
192191
onProgress: (args) => {
193-
if (test) {
194-
if (args.currentStep < args.numSteps) {
195-
// while animating, visible should be truthly
196-
expect(args.chart.getDatasetMeta(0).visible).toBeTruthy();
197-
count++;
198-
}
192+
if (!args.chart.isDatasetVisible(0) && args.currentStep / args.numSteps < 0.9) {
193+
// while animating, visible should be truthly
194+
// sometimes its not, thats why we check only up to 90% of the animation
195+
expect(args.chart.getDatasetMeta(0).visible).toBeTruthy();
196+
count++;
199197
}
200198
},
201199
onComplete: (args) => {
202-
if (!test) {
203-
test = true;
204-
setTimeout(() => args.chart.hide(0), 1);
200+
if (args.chart.isDatasetVisible(0)) {
201+
args.chart.hide(0);
205202
} else {
206203
// and when finished, it should be false
207204
expect(args.chart.getDatasetMeta(0).visible).toBeFalsy();
208205
expect(count).toBeGreaterThan(0);
209206
done();
210207
}
211208
}
209+
},
210+
transitions: {
211+
hide: {
212+
animation: {
213+
duration: 100
214+
}
215+
}
212216
}
213217
}
214218
});

test/specs/core.controller.tests.js

+33
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,39 @@ describe('Chart', function() {
471471
});
472472
});
473473

474+
it('should call onResize with correct arguments and context', function() {
475+
let count = 0;
476+
let correctThis = false;
477+
let size = {
478+
width: 0,
479+
height: 0
480+
};
481+
acquireChart({
482+
options: {
483+
responsive: true,
484+
maintainAspectRatio: false,
485+
onResize(chart, newSize) {
486+
count++;
487+
correctThis = this === chart;
488+
size.width = newSize.width;
489+
size.height = newSize.height;
490+
}
491+
}
492+
}, {
493+
canvas: {
494+
style: 'width: 150px; height: 245px'
495+
},
496+
wrapper: {
497+
style: 'width: 300px; height: 350px'
498+
}
499+
});
500+
501+
expect(count).toEqual(1);
502+
expect(correctThis).toBeTrue();
503+
expect(size).toEqual({width: 300, height: 350});
504+
});
505+
506+
474507
it('should resize the canvas when parent width changes', function(done) {
475508
var chart = acquireChart({
476509
options: {

0 commit comments

Comments
 (0)