Skip to content

Commit

Permalink
fix: mokeypatch Pointer.onDocumentMouseMove method (#7118) (#7127)
Browse files Browse the repository at this point in the history
Use composedPath instead of event target to get the element that is the source of the event.
  • Loading branch information
DiegoCardoso authored Feb 13, 2024
1 parent 75f262b commit 3fa274f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'highcharts/es-modules/masters/modules/bullet.src.js';
import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
import { beforeNextRender } from '@polymer/polymer/lib/utils/render-status.js';
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import Pointer from 'highcharts/es-modules/Core/Pointer.js';
import Highcharts from 'highcharts/es-modules/masters/highstock.src.js';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
Expand Down Expand Up @@ -69,6 +70,28 @@ export function deepMerge(target, source) {
/* eslint-enable no-invalid-this */
});

// Monkeypatch the onDocumentMouseMove method to fix the check for the source of the event
// Due to the fact that the event is attached to the document, the target of the event is
// the <vaadin-chart> element, so we need to use the composedPath to get the actual target (#7107)
Pointer.prototype.onDocumentMouseMove = function (e) {
const chart = this.chart;
const chartPosition = this.chartPosition;
const pEvt = this.normalize(e, chartPosition);
const tooltip = chart.tooltip;
// If we're outside, hide the tooltip
if (
chartPosition &&
(!tooltip || !tooltip.isStickyOnContact()) &&
!chart.isInsidePlot(pEvt.chartX - chart.plotLeft, pEvt.chartY - chart.plotTop, {
visiblePlotOnly: true,
}) &&
// Use the first element from the composed path instead of the actual target
!this.inClass(pEvt.composedPath()[0], 'highcharts-tracker')
) {
this.reset();
}
};

// Init Highcharts global language defaults
// No data message should be empty by default
Highcharts.setOptions({ lang: { noData: '' } });
Expand Down

0 comments on commit 3fa274f

Please sign in to comment.