Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a9adf5

Browse files
committed
Fix selection scattergl cases
1 parent 289e2c9 commit 5a9adf5

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

src/components/fx/hover.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ function createHoverText(hoverData, opts, gd) {
538538
var i, traceHoverinfo;
539539
for(i = 0; i < hoverData.length; i++) {
540540
traceHoverinfo = hoverData[i].hoverinfo || hoverData[i].trace.hoverinfo;
541-
var parts = traceHoverinfo.split('+');
541+
var parts = Array.isArray(traceHoverinfo) ? traceHoverinfo : traceHoverinfo.split('+');
542542
if(parts.indexOf('all') === -1 &&
543543
parts.indexOf(hovermode) === -1) {
544544
showCommonLabel = false;
@@ -1096,8 +1096,9 @@ function cleanPoint(d, hovermode) {
10961096
}
10971097

10981098
var infomode = d.hoverinfo || d.trace.hoverinfo;
1099+
10991100
if(infomode !== 'all') {
1100-
infomode = infomode.split('+');
1101+
infomode = Array.isArray(infomode) ? infomode : infomode.split('+');
11011102
if(infomode.indexOf('x') === -1) d.xLabel = undefined;
11021103
if(infomode.indexOf('y') === -1) d.yLabel = undefined;
11031104
if(infomode.indexOf('z') === -1) d.zLabel = undefined;

src/traces/scattergl/index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var createScatter = require('regl-scatter2d');
2626
var createLine = require('regl-line2d');
2727
var createError = require('regl-error2d');
2828
var svgSdf = require('svg-path-sdf');
29+
var fillHoverText = require('../scatter/fill_hover_text');
2930
var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;
3031

3132
var MAXDIST = Fx.constants.MAXDIST;
@@ -876,6 +877,24 @@ ScatterRegl.hoverPoints = function hover(pointData, xval, yval, hovermode) {
876877
yc = ya.c2p(di.y, true),
877878
rad = di.mrc || 1;
878879

880+
var hoverlabel = trace.hoverlabel;
881+
882+
if (hoverlabel) {
883+
di.hbg = Array.isArray(hoverlabel.bgcolor) ? hoverlabel.bgcolor[id] : hoverlabel.bgcolor;
884+
di.hbc = Array.isArray(hoverlabel.bordercolor) ? hoverlabel.bordercolor[id] : hoverlabel.bordercolor;
885+
di.hts = Array.isArray(hoverlabel.font.size) ? hoverlabel.font.size[id] : hoverlabel.font.size;
886+
di.htc = Array.isArray(hoverlabel.font.color) ? hoverlabel.font.color[id] : hoverlabel.font.color;
887+
di.htf = Array.isArray(hoverlabel.font.family) ? hoverlabel.font.family[id] : hoverlabel.font.family;
888+
di.hnl = Array.isArray(hoverlabel.namelength) ? hoverlabel.namelength[id] : hoverlabel.namelength;
889+
}
890+
var hoverinfo = trace.hoverinfo;
891+
if (hoverinfo) {
892+
di.hi = Array.isArray(hoverinfo) ? hoverinfo[id] : hoverinfo;
893+
}
894+
895+
var fakeCd = {};
896+
fakeCd[pointData.index] = di;
897+
879898
Lib.extendFlat(pointData, {
880899
color: getTraceColor(trace, di),
881900

@@ -885,13 +904,17 @@ ScatterRegl.hoverPoints = function hover(pointData, xval, yval, hovermode) {
885904

886905
y0: yc - rad,
887906
y1: yc + rad,
888-
yLabelVal: di.y
907+
yLabelVal: di.y,
908+
909+
cd: fakeCd
889910
});
890911

891912
if(di.htx) pointData.text = di.htx;
892913
else if(trace.hovertext) pointData.text = trace.hovertext;
893914
else if(di.tx) pointData.text = di.tx;
894915
else if(trace.text) pointData.text = trace.text;
916+
917+
fillHoverText(di, trace, pointData);
895918
ErrorBars.hoverInfo(di, trace, pointData);
896919

897920
return [pointData];

test/jasmine/tests/gl2d_click_test.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ describe('Test hover and click interactions', function() {
194194
}
195195
};
196196
_mock.data[0].hoverinfo = _mock.data[0].x.map(function(_, i) { return i % 2 ? 'y' : 'x'; });
197+
197198
_mock.data[0].hoverlabel = {
198199
bgcolor: 'blue',
199200
bordercolor: _mock.data[0].x.map(function(_, i) { return i % 2 ? 'red' : 'green'; })
@@ -464,7 +465,7 @@ describe('@noCI Test gl2d lasso/select:', function() {
464465
});
465466

466467
var gd;
467-
var selectPath = [[93, 193], [143, 193]];
468+
var selectPath = [[103, 193], [113, 193]];
468469
var lassoPath = [[316, 171], [318, 239], [335, 243], [328, 169]];
469470
var lassoPath2 = [[93, 193], [143, 193], [143, 500], [93, 500], [93, 193]];
470471

@@ -508,9 +509,6 @@ describe('@noCI Test gl2d lasso/select:', function() {
508509
});
509510
}
510511

511-
function countGlObjects() {
512-
return gd._fullLayout._plots.xy._scene2d.glplot.objects.length;
513-
}
514512

515513
it('should work under fast mode with *select* dragmode', function(done) {
516514
var _mock = Lib.extendDeep({}, mockFast);
@@ -520,19 +518,19 @@ describe('@noCI Test gl2d lasso/select:', function() {
520518
Plotly.plot(gd, _mock)
521519
.then(delay(100))
522520
.then(function() {
523-
expect(countGlObjects()).toBe(1, 'has on gl-scatter2d object');
521+
expect(gd._fullLayout._plots.xy._scene.select2d).not.toBe(undefined, 'scatter2d renderer');
524522

525523
return select(selectPath);
526524
})
527525
.then(function(eventData) {
528526
assertEventData(eventData, {
529527
points: [
530-
{x: 3.911, y: 0.401},
531-
{x: 5.34, y: 0.403},
532-
{x: 6.915, y: 0.411}
528+
{pointNumber: 25, x: 1.425, y: 0.538},
529+
{pointNumber: 26, x: 1.753, y: 0.5},
530+
{pointNumber: 27, x: 2.22, y: 0.45}
533531
]
534532
});
535-
expect(countGlObjects()).toBe(2, 'adds a dimmed gl-scatter2d objects');
533+
536534
})
537535
.catch(fail)
538536
.then(done);
@@ -546,19 +544,16 @@ describe('@noCI Test gl2d lasso/select:', function() {
546544
Plotly.plot(gd, _mock)
547545
.then(delay(100))
548546
.then(function() {
549-
expect(countGlObjects()).toBe(1);
550-
551547
return select(lassoPath2);
552548
})
553549
.then(function(eventData) {
554550
assertEventData(eventData, {
555551
points: [
556-
{x: 3.911, y: 0.401},
557-
{x: 5.34, y: 0.403},
558-
{x: 6.915, y: 0.411}
552+
{pointNumber: 25, x: 1.425, y: 0.538},
553+
{pointNumber: 26, x: 1.753, y: 0.5},
554+
{pointNumber: 27, x: 2.22, y: 0.45}
559555
]
560556
});
561-
expect(countGlObjects()).toBe(2);
562557
})
563558
.catch(fail)
564559
.then(done);
@@ -572,15 +567,12 @@ describe('@noCI Test gl2d lasso/select:', function() {
572567
Plotly.plot(gd, _mock)
573568
.then(delay(100))
574569
.then(function() {
575-
expect(countGlObjects()).toBe(2, 'has a gl-line2d and a gl-scatter2d-sdf');
576-
577570
return select(selectPath);
578571
})
579572
.then(function(eventData) {
580573
assertEventData(eventData, {
581574
points: [{x: 0.004, y: 12.5}]
582575
});
583-
expect(countGlObjects()).toBe(2, 'only changes colors of gl-scatter2d-sdf object');
584576
})
585577
.catch(fail)
586578
.then(done);
@@ -594,15 +586,12 @@ describe('@noCI Test gl2d lasso/select:', function() {
594586
Plotly.plot(gd, _mock)
595587
.then(delay(100))
596588
.then(function() {
597-
expect(countGlObjects()).toBe(2, 'has a gl-line2d and a gl-scatter2d-sdf');
598-
599589
return select(lassoPath);
600590
})
601591
.then(function(eventData) {
602592
assertEventData(eventData, {
603593
points: [{ x: 0.099, y: 2.75 }]
604594
});
605-
expect(countGlObjects()).toBe(2, 'only changes colors of gl-scatter2d-sdf object');
606595
})
607596
.catch(fail)
608597
.then(done);

0 commit comments

Comments
 (0)