Skip to content

Commit d9aea4b

Browse files
committed
fix case of splom with multiple points at same (x|y) position
1 parent 45f7feb commit d9aea4b

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

Diff for: src/traces/splom/hover.js

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ function _hoverPoints(pointData, xpx, ypx, hoversubplotsX, hoversubplotsY) {
7373
var minDist = maxDistance;
7474

7575
for(var i = 0; i < x.length; i++) {
76+
if((hoversubplotsX || hoversubplotsY) && i !== pointData.index) continue;
77+
7678
var ptx = x[i];
7779
var pty = y[i];
7880
var thisXpx = xa.c2p(ptx);

Diff for: test/jasmine/tests/hover_label_test.js

+100
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,106 @@ describe('splom hover on subplots when hoversubplots is set to *axis* and (x|y)
26602660
});
26612661
});
26622662

2663+
describe('splom hover *axis* hoversubplots splom points on same position should pick points with same index', function() {
2664+
'use strict';
2665+
2666+
var mock = {
2667+
data: [{
2668+
type: 'splom',
2669+
dimensions: [{
2670+
values: [1, 1, 1, 1]
2671+
}, {
2672+
values: [1, 2, 3, 4]
2673+
}, {
2674+
values: [1, 2, 3, 4]
2675+
}, {
2676+
values: [1, null, 3, 4]
2677+
}
2678+
]}],
2679+
layout: {
2680+
hoversubplots: 'axis',
2681+
hovermode: 'x',
2682+
width: 600,
2683+
height: 600
2684+
}
2685+
};
2686+
2687+
var gd;
2688+
2689+
beforeEach(function(done) {
2690+
gd = createGraphDiv();
2691+
Plotly.newPlot(gd, mock).then(done);
2692+
});
2693+
2694+
afterEach(destroyGraphDiv);
2695+
2696+
it('splom *axis* hoversubplots', function() {
2697+
Lib.clearThrottle();
2698+
Plotly.Fx.hover(gd, {}, 'xy');
2699+
expect(gd._hoverdata.length).toBe(5);
2700+
assertHoverLabelContent({
2701+
nums: ['1', '1', '1', '1'],
2702+
name: ['', '', '', ''],
2703+
axis: '1'
2704+
});
2705+
2706+
Lib.clearThrottle();
2707+
Plotly.Fx.hover(gd, {}, 'xy2');
2708+
expect(gd._hoverdata.length).toBe(4);
2709+
assertHoverLabelContent({
2710+
nums: ['1', '2', '2'],
2711+
name: ['', '', ''],
2712+
axis: '1'
2713+
});
2714+
2715+
Lib.clearThrottle();
2716+
Plotly.Fx.hover(gd, {}, 'xy3');
2717+
expect(gd._hoverdata.length).toBe(4);
2718+
assertHoverLabelContent({
2719+
nums: ['1', '2', '2'],
2720+
name: ['', '', ''],
2721+
axis: '1'
2722+
});
2723+
2724+
Lib.clearThrottle();
2725+
Plotly.Fx.hover(gd, {}, 'xy4');
2726+
expect(gd._hoverdata.length).toBe(5);
2727+
assertHoverLabelContent({
2728+
nums: ['1', '3', '3', '3'],
2729+
name: ['', '', '', ''],
2730+
axis: '1'
2731+
});
2732+
2733+
Lib.clearThrottle();
2734+
Plotly.Fx.hover(gd, {}, 'x2y');
2735+
expect(gd._hoverdata.length).toBe(5);
2736+
assertHoverLabelContent({
2737+
nums: ['1', '3', '3', '3'],
2738+
name: ['', '', '', ''],
2739+
axis: '3'
2740+
});
2741+
2742+
Lib.clearThrottle();
2743+
Plotly.Fx.hover(gd, {}, 'x3y');
2744+
expect(gd._hoverdata.length).toBe(5);
2745+
assertHoverLabelContent({
2746+
nums: ['1', '3', '3', '3'],
2747+
name: ['', '', '', ''],
2748+
axis: '3'
2749+
});
2750+
2751+
Lib.clearThrottle();
2752+
Plotly.Fx.hover(gd, {}, 'x4y');
2753+
expect(gd._hoverdata.length).toBe(5);
2754+
assertHoverLabelContent({
2755+
nums: ['1', '3', '3', '3'],
2756+
name: ['', '', '', ''],
2757+
axis: '3'
2758+
});
2759+
});
2760+
});
2761+
2762+
26632763
describe('hover on many lines+bars', function() {
26642764
'use strict';
26652765

0 commit comments

Comments
 (0)