Skip to content

Commit fd656dd

Browse files
committed
scatter: make sure that restyle('mode', '') remove unwanted pt & text
- by moving the marker and text data.joins out of the hasMarkers / hasText switch board
1 parent eb7723c commit fd656dd

File tree

1 file changed

+50
-40
lines changed

1 file changed

+50
-40
lines changed

src/traces/scatter/plot.js

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -387,64 +387,74 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
387387
}
388388
}
389389

390+
function hideFilter() {
391+
return false;
392+
}
393+
390394
function makePoints(d) {
391395
var join, selection;
396+
392397
var trace = d[0].trace,
393398
s = d3.select(this),
394399
showMarkers = subTypes.hasMarkers(trace),
395400
showText = subTypes.hasText(trace);
396401

397-
if((!showMarkers && !showText) || trace.visible !== true) s.remove();
398-
else {
399-
if(showMarkers) {
400-
selection = s.selectAll('path.point');
402+
var keyFunc = getKeyFunc(trace),
403+
markerFilter = hideFilter,
404+
textFilter = hideFilter;
401405

402-
join = selection
403-
.data(trace.marker.maxdisplayed ? visFilter : Lib.identity, getKeyFunc(trace));
406+
if(showMarkers) {
407+
markerFilter = trace.marker.maxdisplayed ? visFilter : Lib.identity;
408+
}
404409

405-
var enter = join.enter().append('path')
406-
.classed('point', true);
410+
if(showText) {
411+
textFilter = trace.marker.maxdisplayed ? visFilter : Lib.identity;
412+
}
407413

408-
enter.call(Drawing.pointStyle, trace)
409-
.call(Drawing.translatePoints, xa, ya, trace);
414+
// marker points
410415

411-
if(hasTransition) {
412-
enter.style('opacity', 0).transition()
413-
.style('opacity', 1);
414-
}
416+
selection = s.selectAll('path.point');
415417

416-
join.each(function(d) {
417-
var sel = transition(d3.select(this));
418-
Drawing.translatePoint(d, sel, xa, ya);
419-
Drawing.singlePointStyle(d, sel, trace);
420-
});
418+
join = selection.data(markerFilter, keyFunc);
421419

422-
if(hasTransition) {
423-
join.exit().transition()
424-
.style('opacity', 0)
425-
.remove();
426-
} else {
427-
join.exit().remove();
428-
}
429-
}
430-
if(showText) {
431-
selection = s.selectAll('g');
420+
var enter = join.enter().append('path')
421+
.classed('point', true);
432422

433-
join = selection
434-
.data(trace.marker.maxdisplayed ? visFilter : Lib.identity);
423+
enter.call(Drawing.pointStyle, trace)
424+
.call(Drawing.translatePoints, xa, ya, trace);
435425

436-
// each text needs to go in its own 'g' in case
437-
// it gets converted to mathjax
438-
join.enter().append('g')
439-
.append('text')
440-
.call(Drawing.translatePoints, xa, ya);
426+
if(hasTransition) {
427+
enter.style('opacity', 0).transition()
428+
.style('opacity', 1);
429+
}
441430

442-
selection
443-
.call(Drawing.translatePoints, xa, ya);
431+
join.each(function(d) {
432+
var sel = transition(d3.select(this));
433+
Drawing.translatePoint(d, sel, xa, ya);
434+
Drawing.singlePointStyle(d, sel, trace);
435+
});
444436

445-
join.exit().remove();
446-
}
437+
if(hasTransition) {
438+
join.exit().transition()
439+
.style('opacity', 0)
440+
.remove();
441+
} else {
442+
join.exit().remove();
447443
}
444+
445+
// text points
446+
447+
selection = s.selectAll('g');
448+
449+
join = selection.data(textFilter, keyFunc);
450+
451+
// each text needs to go in its own 'g' in case
452+
// it gets converted to mathjax
453+
join.enter().append('g')
454+
.append('text')
455+
.call(Drawing.translatePoints, xa, ya);
456+
457+
join.exit().remove();
448458
}
449459

450460
// NB: selectAll is evaluated on instantiation:

0 commit comments

Comments
 (0)