Skip to content

Commit 2b1713d

Browse files
authored
Merge pull request #2583 from plotly/scatter-select-perf
SVG trace on selection perf
2 parents 776ddca + 3e32b23 commit 2b1713d

File tree

23 files changed

+417
-232
lines changed

23 files changed

+417
-232
lines changed

src/components/drawing/index.js

Lines changed: 205 additions & 148 deletions
Large diffs are not rendered by default.

src/components/legend/style.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ module.exports = function style(s, gd) {
110110

111111
// constrain text, markers, etc so they'll fit on the legend
112112
if(showMarkers || showText || showLines) {
113-
var dEdit = {},
114-
tEdit = {};
113+
var dEdit = {};
114+
var tEdit = {};
115115

116116
if(showMarkers) {
117117
dEdit.mc = boundVal('marker.color', pickFirst);
@@ -142,6 +142,9 @@ module.exports = function style(s, gd) {
142142

143143
dMod = [Lib.minExtend(d0, dEdit)];
144144
tMod = Lib.minExtend(trace, tEdit);
145+
146+
// always show legend items in base state
147+
tMod.selectedpoints = null;
145148
}
146149

147150
var ptgroup = d3.select(this).select('g.legendpoints');

src/plots/cartesian/select.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,18 +404,20 @@ function updateSelectedState(gd, searchTraces, eventData) {
404404
var len = items.length;
405405
var item0 = items[0];
406406
var trace0 = item0.cd[0].trace;
407+
var _module = item0._module;
408+
var styleSelection = _module.styleOnSelect || _module.style;
407409

408410
if(Registry.traceIs(trace0, 'regl')) {
409411
// plot regl traces per module
410412
var cds = new Array(len);
411413
for(j = 0; j < len; j++) {
412414
cds[j] = items[j].cd;
413415
}
414-
item0._module.style(gd, cds);
416+
styleSelection(gd, cds);
415417
} else {
416418
// plot svg trace per trace
417419
for(j = 0; j < len; j++) {
418-
item0._module.style(gd, items[j].cd);
420+
styleSelection(gd, items[j].cd);
419421
}
420422
}
421423
}

src/plots/plots.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
819819
}
820820
// Then look for a subplot with the counteraxis overlaying the anchor
821821
// If that fails just use the first subplot including this axis
822-
if(!mainSubplotID || ids.indexOf(mainSubplotID) === -1) {
822+
if(!mainSubplotID || !newSubplots[mainSubplotID]) {
823823
mainSubplotID = '';
824824
for(j = 0; j < ids.length; j++) {
825825
id = ids[j];

src/traces/bar/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Bar.setPositions = require('./set_positions');
2020
Bar.colorbar = require('../scatter/colorbar');
2121
Bar.arraysToCalcdata = require('./arrays_to_calcdata');
2222
Bar.plot = require('./plot');
23-
Bar.style = require('./style');
23+
Bar.style = require('./style').style;
24+
Bar.styleOnSelect = require('./style').styleOnSelect;
2425
Bar.hoverPoints = require('./hover');
2526
Bar.selectPoints = require('./select');
2627

src/traces/bar/style.js

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var d3 = require('d3');
1313
var Drawing = require('../../components/drawing');
1414
var Registry = require('../../registry');
1515

16-
module.exports = function style(gd, cd) {
16+
function style(gd, cd) {
1717
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.bars');
1818
var barcount = s.size();
1919
var fullLayout = gd._fullLayout;
@@ -35,34 +35,52 @@ module.exports = function style(gd, cd) {
3535

3636
s.selectAll('g.points').each(function(d) {
3737
var sel = d3.select(this);
38-
var pts = sel.selectAll('path');
39-
var txs = sel.selectAll('text');
4038
var trace = d[0].trace;
39+
stylePoints(sel, trace, gd);
40+
});
41+
42+
Registry.getComponentMethod('errorbars', 'style')(s);
43+
}
4144

42-
Drawing.pointStyle(pts, trace, gd);
43-
Drawing.selectedPointStyle(pts, trace);
45+
function stylePoints(sel, trace, gd) {
46+
var pts = sel.selectAll('path');
47+
var txs = sel.selectAll('text');
4448

45-
txs.each(function(d) {
46-
var tx = d3.select(this);
47-
var textFont;
49+
Drawing.pointStyle(pts, trace, gd);
4850

49-
if(tx.classed('bartext-inside')) {
50-
textFont = trace.insidetextfont;
51-
} else if(tx.classed('bartext-outside')) {
52-
textFont = trace.outsidetextfont;
53-
}
54-
if(!textFont) textFont = trace.textfont;
51+
txs.each(function(d) {
52+
var tx = d3.select(this);
53+
var textFont;
5554

56-
function cast(k) {
57-
var cont = textFont[k];
58-
return Array.isArray(cont) ? cont[d.i] : cont;
59-
}
55+
if(tx.classed('bartext-inside')) {
56+
textFont = trace.insidetextfont;
57+
} else if(tx.classed('bartext-outside')) {
58+
textFont = trace.outsidetextfont;
59+
}
60+
if(!textFont) textFont = trace.textfont;
6061

61-
Drawing.font(tx, cast('family'), cast('size'), cast('color'));
62-
});
62+
function cast(k) {
63+
var cont = textFont[k];
64+
return Array.isArray(cont) ? cont[d.i] : cont;
65+
}
6366

64-
Drawing.selectedTextStyle(txs, trace);
67+
Drawing.font(tx, cast('family'), cast('size'), cast('color'));
6568
});
69+
}
6670

67-
Registry.getComponentMethod('errorbars', 'style')(s);
71+
function styleOnSelect(gd, cd) {
72+
var s = cd[0].node3;
73+
var trace = cd[0].trace;
74+
75+
if(trace.selectedpoints) {
76+
Drawing.selectedPointStyle(s.selectAll('path'), trace);
77+
Drawing.selectedTextStyle(s.selectAll('text'), trace);
78+
} else {
79+
stylePoints(s, trace, gd);
80+
}
81+
}
82+
83+
module.exports = {
84+
style: style,
85+
styleOnSelect: styleOnSelect
6886
};

src/traces/box/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Box.supplyLayoutDefaults = require('./layout_defaults').supplyLayoutDefaults;
1717
Box.calc = require('./calc');
1818
Box.setPositions = require('./set_positions').setPositions;
1919
Box.plot = require('./plot').plot;
20-
Box.style = require('./style');
20+
Box.style = require('./style').style;
21+
Box.styleOnSelect = require('./style').styleOnSelect;
2122
Box.hoverPoints = require('./hover').hoverPoints;
2223
Box.selectPoints = require('./select');
2324

src/traces/box/style.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var d3 = require('d3');
1212
var Color = require('../../components/color');
1313
var Drawing = require('../../components/drawing');
1414

15-
module.exports = function style(gd, cd) {
15+
function style(gd, cd) {
1616
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.boxes');
1717

1818
s.style('opacity', function(d) { return d[0].trace.opacity; });
@@ -50,7 +50,23 @@ module.exports = function style(gd, cd) {
5050

5151
var pts = el.selectAll('path.point');
5252
Drawing.pointStyle(pts, trace, gd);
53-
Drawing.selectedPointStyle(pts, trace);
5453
}
5554
});
55+
}
56+
57+
function styleOnSelect(gd, cd) {
58+
var s = cd[0].node3;
59+
var trace = cd[0].trace;
60+
var pts = s.selectAll('path.point');
61+
62+
if(trace.selectedpoints) {
63+
Drawing.selectedPointStyle(pts, trace);
64+
} else {
65+
Drawing.pointStyle(pts, trace, gd);
66+
}
67+
}
68+
69+
module.exports = {
70+
style: style,
71+
styleOnSelect: styleOnSelect
5672
};

src/traces/candlestick/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
calc: require('./calc'),
3838
plot: require('../box/plot').plot,
3939
layerName: 'boxlayer',
40-
style: require('../box/style'),
40+
style: require('../box/style').style,
4141
hoverPoints: require('../ohlc/hover'),
4242
selectPoints: require('../ohlc/select')
4343
};

src/traces/choropleth/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Choropleth.supplyDefaults = require('./defaults');
1616
Choropleth.colorbar = require('../heatmap/colorbar');
1717
Choropleth.calc = require('./calc');
1818
Choropleth.plot = require('./plot');
19-
Choropleth.style = require('./style');
19+
Choropleth.style = require('./style').style;
20+
Choropleth.styleOnSelect = require('./style').styleOnSelect;
2021
Choropleth.hoverPoints = require('./hover');
2122
Choropleth.eventData = require('./event_data');
2223
Choropleth.selectPoints = require('./select');

0 commit comments

Comments
 (0)