Skip to content

Commit 850e845

Browse files
committed
Emit hover events even when there aren't any active elements
1 parent dc677f8 commit 850e845

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

projects/ng2-charts/src/lib/base-chart.directive.spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ describe('BaseChartDirective', () => {
104104
"click",
105105
{
106106
clientX: canvas.getBoundingClientRect().left + 50,
107-
clientY: canvas.getBoundingClientRect().top + 50,
108-
bubbles: true
107+
clientY: canvas.getBoundingClientRect().top + 50
109108
}
110109
)
111110
);
@@ -115,4 +114,24 @@ describe('BaseChartDirective', () => {
115114
expect(element.click).toHaveBeenCalled();
116115
}));
117116

117+
it('should emit when the chart is hovered', fakeAsync(() => {
118+
119+
fixture.detectChanges();
120+
121+
let canvas = fixture.nativeElement.querySelector('canvas');
122+
123+
canvas.dispatchEvent(
124+
new MouseEvent(
125+
"mousemove",
126+
{
127+
clientX: canvas.getBoundingClientRect().left + 50,
128+
clientY: canvas.getBoundingClientRect().top + 50
129+
}
130+
)
131+
);
132+
133+
tick(25);
134+
135+
expect(element.hover).toHaveBeenCalled();
136+
}));
118137
});

projects/ng2-charts/src/lib/base-chart.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class BaseChartDirective<TType extends ChartType = ChartType,
121121
private getChartOptions(): ChartConfiguration<TType, TData, TLabel>['options'] {
122122
return merge({
123123
onHover: (event: ChartEvent, active: {}[]) => {
124-
if (!this.chartHover.observed || !active || !active.length) {
124+
if (!this.chartHover.observed) {
125125
return;
126126
}
127127

0 commit comments

Comments
 (0)