Skip to content

Commit 34355d5

Browse files
authored
Merge pull request #7882 from plotly/cam/7702/fix-missing-hover-xval-yval-map-geo-traces
fix: Populate `xval`/`yval` from `calcdata` when array-mode selection uses `pointNumber`
2 parents 0d5afad + 1e16d9c commit 34355d5

3 files changed

Lines changed: 4680 additions & 4297 deletions

File tree

draftlogs/7882_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix `Plotly.Fx.hover` crash on `scattermap` traces when called programmatically with a `pointNumber` selection [[#7882](https://github.com/plotly/plotly.js/pull/7882)]

src/components/fx/hover.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,24 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
580580
if (_mode === 'array') {
581581
var selection = evt[curvenum];
582582
if ('pointNumber' in selection) {
583-
pointData.index = selection.pointNumber;
583+
// populate xval/yval from the targeted calcdata point so trace
584+
// hoverPoints implementations that read them outside getClosest
585+
// (e.g. scattermap's longitude winding) get valid coordinates
586+
const cdi = cd[selection.pointNumber];
587+
if (cdi) {
588+
pointData.index = selection.pointNumber;
589+
// map and geo traces store coords as lonlat: [lon, lat];
590+
// everything else uses Cartesian .x/.y. This is good enough
591+
// for now, but may need to be updated to a per trace accessor
592+
// in the future.
593+
if (cdi.lonlat) {
594+
xval = cdi.lonlat[0];
595+
yval = cdi.lonlat[1];
596+
} else {
597+
xval = cdi.x;
598+
yval = cdi.y;
599+
}
600+
}
584601
_mode = 'closest';
585602
} else {
586603
_mode = '';

0 commit comments

Comments
 (0)