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

_resolveElementPoint utility for triggerMouseEvent #5994

Merged
merged 1 commit into from Jan 20, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/specs/controller.polarArea.tests.js
Expand Up @@ -281,12 +281,12 @@ describe('Chart.controllers.polarArea', function() {
var chart = this.chart;
var arc = chart.getDatasetMeta(0).data[0];

jasmine.triggerMouseEvent(chart, 'mousemove', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc._model.backgroundColor).toBe('rgb(49, 135, 221)');
expect(arc._model.borderColor).toBe('rgb(22, 89, 156)');
expect(arc._model.borderWidth).toBe(2);

jasmine.triggerMouseEvent(chart, 'mouseout', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc._model.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
expect(arc._model.borderWidth).toBe(2);
Expand All @@ -304,12 +304,12 @@ describe('Chart.controllers.polarArea', function() {

chart.update();

jasmine.triggerMouseEvent(chart, 'mousemove', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc._model.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc._model.borderColor).toBe('rgb(150, 50, 100)');
expect(arc._model.borderWidth).toBe(8.4);

jasmine.triggerMouseEvent(chart, 'mouseout', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc._model.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
expect(arc._model.borderWidth).toBe(2);
Expand All @@ -327,12 +327,12 @@ describe('Chart.controllers.polarArea', function() {

chart.update();

jasmine.triggerMouseEvent(chart, 'mousemove', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc._model.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc._model.borderColor).toBe('rgb(150, 50, 100)');
expect(arc._model.borderWidth).toBe(8.4);

jasmine.triggerMouseEvent(chart, 'mouseout', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc._model.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
expect(arc._model.borderWidth).toBe(2);
Expand All @@ -350,12 +350,12 @@ describe('Chart.controllers.polarArea', function() {

chart.update();

jasmine.triggerMouseEvent(chart, 'mousemove', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mousemove', arc);
expect(arc._model.backgroundColor).toBe('rgb(200, 100, 150)');
expect(arc._model.borderColor).toBe('rgb(150, 50, 100)');
expect(arc._model.borderWidth).toBe(8.4);

jasmine.triggerMouseEvent(chart, 'mouseout', {_model: arc.getCenterPoint()});
jasmine.triggerMouseEvent(chart, 'mouseout', arc);
expect(arc._model.backgroundColor).toBe('rgb(100, 150, 200)');
expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
expect(arc._model.borderWidth).toBe(2);
Expand Down
19 changes: 17 additions & 2 deletions test/utils.js
Expand Up @@ -106,12 +106,27 @@ function waitForResize(chart, callback) {
};
}

function _resolveElementPoint(el) {
var point = {x: 0, y: 0};
if (el) {
if (typeof el.getCenterPoint === 'function') {
point = el.getCenterPoint();
} else if (el.x !== undefined && el.y !== undefined) {
point = el;
} else if (el._model && el._model.x !== undefined && el._model.y !== undefined) {
point = el._model;
}
}
return point;
}

function triggerMouseEvent(chart, type, el) {
var node = chart.canvas;
var rect = node.getBoundingClientRect();
var point = _resolveElementPoint(el);
var event = new MouseEvent(type, {
clientX: rect.left + el._model.x,
clientY: rect.top + el._model.y,
clientX: rect.left + point.x,
clientY: rect.top + point.y,
cancelable: true,
bubbles: true,
view: window
Expand Down