Skip to content

Commit 46b8aca

Browse files
fix: mokeypatch Pointer.onDocumentMouseMove method (#7118) (CP: 24.3) (#7120)
Use composedPath instead of event target to get the element that is the source of the event. Co-authored-by: Diego Cardoso <diego@vaadin.com>
1 parent e495fb6 commit 46b8aca

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

packages/charts/src/vaadin-chart.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import 'highcharts/es-modules/masters/modules/bullet.src.js';
2929
import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
3030
import { beforeNextRender } from '@polymer/polymer/lib/utils/render-status.js';
3131
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
32+
import Pointer from 'highcharts/es-modules/Core/Pointer.js';
3233
import Highcharts from 'highcharts/es-modules/masters/highstock.src.js';
3334
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
3435
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
@@ -69,6 +70,28 @@ export function deepMerge(target, source) {
6970
/* eslint-enable no-invalid-this */
7071
});
7172

73+
// Monkeypatch the onDocumentMouseMove method to fix the check for the source of the event
74+
// Due to the fact that the event is attached to the document, the target of the event is
75+
// the <vaadin-chart> element, so we need to use the composedPath to get the actual target (#7107)
76+
Pointer.prototype.onDocumentMouseMove = function (e) {
77+
const chart = this.chart;
78+
const chartPosition = this.chartPosition;
79+
const pEvt = this.normalize(e, chartPosition);
80+
const tooltip = chart.tooltip;
81+
// If we're outside, hide the tooltip
82+
if (
83+
chartPosition &&
84+
(!tooltip || !tooltip.isStickyOnContact()) &&
85+
!chart.isInsidePlot(pEvt.chartX - chart.plotLeft, pEvt.chartY - chart.plotTop, {
86+
visiblePlotOnly: true,
87+
}) &&
88+
// Use the first element from the composed path instead of the actual target
89+
!this.inClass(pEvt.composedPath()[0], 'highcharts-tracker')
90+
) {
91+
this.reset();
92+
}
93+
};
94+
7295
// Init Highcharts global language defaults
7396
// No data message should be empty by default
7497
Highcharts.setOptions({ lang: { noData: '' } });

0 commit comments

Comments
 (0)