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

Throttle all events (to 1 / frame each) #6953

Merged
merged 2 commits into from
Jan 14, 2020
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
4 changes: 2 additions & 2 deletions src/platforms/platform.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ export default {

var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
var proxies = expando.proxies || (expando.proxies = {});
var proxy = proxies[chart.id + '_' + type] = function(event) {
var proxy = proxies[chart.id + '_' + type] = throttled(function(event) {
listener(fromNativeEvent(event, chart));
};
}, chart);

addListener(canvas, type, proxy);
},
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:

globals:
acquireChart: true
afterEvent: true
Chart: true
moment: true
waitForResize: true
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var utils = require('./utils');
window.devicePixelRatio = 1;

window.acquireChart = acquireChart;
window.afterEvent = utils.afterEvent;
window.releaseChart = releaseChart;
window.waitForResize = utils.waitForResize;
window.createMockContext = createMockContext;
Expand Down
85 changes: 52 additions & 33 deletions test/specs/controller.bubble.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,30 @@ describe('Chart.controllers.bubble', function() {
});
});

it ('should handle default hover styles', function() {
it ('should handle default hover styles', function(done) {
var chart = this.chart;
var point = chart.getDatasetMeta(0).data[0];

afterEvent(chart, 'mousemove', function() {
expect(point.options.backgroundColor).toBe('rgb(49, 135, 221)');
expect(point.options.borderColor).toBe('rgb(22, 89, 156)');
expect(point.options.borderWidth).toBe(1);
expect(point.options.radius).toBe(20 + 4);

afterEvent(chart, 'mouseout', function() {
expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
expect(point.options.borderWidth).toBe(2);
expect(point.options.radius).toBe(20);

done();
});
jasmine.triggerMouseEvent(chart, 'mouseout', point);
});
jasmine.triggerMouseEvent(chart, 'mousemove', point);
expect(point.options.backgroundColor).toBe('rgb(49, 135, 221)');
expect(point.options.borderColor).toBe('rgb(22, 89, 156)');
expect(point.options.borderWidth).toBe(1);
expect(point.options.radius).toBe(20 + 4);

jasmine.triggerMouseEvent(chart, 'mouseout', point);
expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
expect(point.options.borderWidth).toBe(2);
expect(point.options.radius).toBe(20);
});

it ('should handle hover styles defined via dataset properties', function() {
it ('should handle hover styles defined via dataset properties', function(done) {
var chart = this.chart;
var point = chart.getDatasetMeta(0).data[0];

Expand All @@ -318,20 +324,27 @@ describe('Chart.controllers.bubble', function() {

chart.update();

afterEvent(chart, 'mousemove', function() {
expect(point.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(point.options.borderColor).toBe('rgb(150, 50, 100)');
expect(point.options.borderWidth).toBe(8.4);
expect(point.options.radius).toBe(20 + 4.2);

afterEvent(chart, 'mouseout', function() {
expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
expect(point.options.borderWidth).toBe(2);
expect(point.options.radius).toBe(20);

done();
});
jasmine.triggerMouseEvent(chart, 'mouseout', point);

});
jasmine.triggerMouseEvent(chart, 'mousemove', point);
expect(point.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(point.options.borderColor).toBe('rgb(150, 50, 100)');
expect(point.options.borderWidth).toBe(8.4);
expect(point.options.radius).toBe(20 + 4.2);

jasmine.triggerMouseEvent(chart, 'mouseout', point);
expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
expect(point.options.borderWidth).toBe(2);
expect(point.options.radius).toBe(20);
});

it ('should handle hover styles defined via element options', function() {
it ('should handle hover styles defined via element options', function(done) {
var chart = this.chart;
var point = chart.getDatasetMeta(0).data[0];

Expand All @@ -344,17 +357,23 @@ describe('Chart.controllers.bubble', function() {

chart.update();

afterEvent(chart, 'mousemove', function() {
expect(point.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(point.options.borderColor).toBe('rgb(150, 50, 100)');
expect(point.options.borderWidth).toBe(8.4);
expect(point.options.radius).toBe(20 + 4.2);

afterEvent(chart, 'mouseout', function() {
expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
expect(point.options.borderWidth).toBe(2);
expect(point.options.radius).toBe(20);

done();
});
jasmine.triggerMouseEvent(chart, 'mouseout', point);
});
jasmine.triggerMouseEvent(chart, 'mousemove', point);
expect(point.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(point.options.borderColor).toBe('rgb(150, 50, 100)');
expect(point.options.borderWidth).toBe(8.4);
expect(point.options.radius).toBe(20 + 4.2);

jasmine.triggerMouseEvent(chart, 'mouseout', point);
expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
expect(point.options.borderWidth).toBe(2);
expect(point.options.radius).toBe(20);
});
});
});
72 changes: 45 additions & 27 deletions test/specs/controller.doughnut.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,22 +347,28 @@ describe('Chart.controllers.doughnut', function() {
});
});

it ('should handle default hover styles', function() {
it ('should handle default hover styles', function(done) {
var chart = this.chart;
var arc = chart.getDatasetMeta(0).data[0];

afterEvent(chart, 'mousemove', function() {
expect(arc.options.backgroundColor).toBe('rgb(49, 135, 221)');
expect(arc.options.borderColor).toBe('rgb(22, 89, 156)');
expect(arc.options.borderWidth).toBe(2);

afterEvent(chart, 'mouseout', function() {
expect(arc.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc.options.borderColor).toBe('rgb(50, 100, 150)');
expect(arc.options.borderWidth).toBe(2);

done();
});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc.options.backgroundColor).toBe('rgb(49, 135, 221)');
expect(arc.options.borderColor).toBe('rgb(22, 89, 156)');
expect(arc.options.borderWidth).toBe(2);

jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc.options.borderColor).toBe('rgb(50, 100, 150)');
expect(arc.options.borderWidth).toBe(2);
});

it ('should handle hover styles defined via dataset properties', function() {
it ('should handle hover styles defined via dataset properties', function(done) {
var chart = this.chart;
var arc = chart.getDatasetMeta(0).data[0];

Expand All @@ -374,18 +380,24 @@ describe('Chart.controllers.doughnut', function() {

chart.update();

afterEvent(chart, 'mousemove', function() {
expect(arc.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc.options.borderColor).toBe('rgb(150, 50, 100)');
expect(arc.options.borderWidth).toBe(8.4);

afterEvent(chart, 'mouseout', function() {
expect(arc.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc.options.borderColor).toBe('rgb(50, 100, 150)');
expect(arc.options.borderWidth).toBe(2);

done();
});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc.options.borderColor).toBe('rgb(150, 50, 100)');
expect(arc.options.borderWidth).toBe(8.4);

jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc.options.borderColor).toBe('rgb(50, 100, 150)');
expect(arc.options.borderWidth).toBe(2);
});

it ('should handle hover styles defined via element options', function() {
it ('should handle hover styles defined via element options', function(done) {
var chart = this.chart;
var arc = chart.getDatasetMeta(0).data[0];

Expand All @@ -397,15 +409,21 @@ describe('Chart.controllers.doughnut', function() {

chart.update();

afterEvent(chart, 'mousemove', function() {
expect(arc.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc.options.borderColor).toBe('rgb(150, 50, 100)');
expect(arc.options.borderWidth).toBe(8.4);

afterEvent(chart, 'mouseout', function() {
expect(arc.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc.options.borderColor).toBe('rgb(50, 100, 150)');
expect(arc.options.borderWidth).toBe(2);

done();
});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc.options.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc.options.borderColor).toBe('rgb(150, 50, 100)');
expect(arc.options.borderWidth).toBe(8.4);

jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc.options.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc.options.borderColor).toBe('rgb(50, 100, 150)');
expect(arc.options.borderWidth).toBe(2);
});
});
});
Loading