Skip to content

Commit 8d4ab24

Browse files
authored
Merge pull request #4022 from plotly/rangeslider-styleOnSelect-fixup
Rangeslider style on select fix
2 parents c1ef691 + 3e17627 commit 8d4ab24

File tree

24 files changed

+149
-48
lines changed

24 files changed

+149
-48
lines changed

src/lib/make_trace_groups.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

11+
var d3 = require('d3');
12+
1213
/**
1314
* General helper to manage trace groups based on calcdata
1415
*
@@ -31,5 +32,10 @@ module.exports = function makeTraceGroups(traceLayer, cdModule, cls) {
3132

3233
traces.order();
3334

35+
// stash ref node to trace group in calcdata,
36+
// useful for (fast) styleOnSelect
37+
var k = traceLayer.classed('rangeplot') ? 'nodeRangePlot3' : 'node3';
38+
traces.each(function(cd) { cd[0][k] = d3.select(this); });
39+
3440
return traces;
3541
};

src/plots/cartesian/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
239239

240240
layers.enter().append('g')
241241
.attr('class', function(d) { return d.className; })
242-
.classed('mlayer', true);
242+
.classed('mlayer', true)
243+
.classed('rangeplot', plotinfo.isRangePlot);
243244

244245
layers.exit().remove();
245246

src/plots/cartesian/select.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,10 @@ function updateSelectedState(gd, searchTraces, eventData) {
734734

735735
var _module = searchInfo._module;
736736
var fn = _module.styleOnSelect || _module.style;
737-
if(fn) fn(gd, cd);
737+
if(fn) {
738+
fn(gd, cd, cd[0].node3);
739+
if(cd[0].nodeRangePlot3) fn(gd, cd, cd[0].nodeRangePlot3);
740+
}
738741
}
739742

740743
if(hasRegl) {

src/traces/bar/plot.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
7878

7979
var isHorizontal = (trace.orientation === 'h');
8080

81-
if(!plotinfo.isRangePlot) cd[0].node3 = plotGroup;
82-
8381
var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');
8482

8583
var bars = pointGroup.selectAll('g.point').data(Lib.identity);

src/traces/bar/style.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var attributeInsideTextFont = attributes.insidetextfont;
2020
var attributeOutsideTextFont = attributes.outsidetextfont;
2121
var helpers = require('./helpers');
2222

23-
function style(gd, cd) {
24-
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.barlayer').selectAll('g.trace');
23+
function style(gd) {
24+
var s = d3.select(gd).selectAll('g.barlayer').selectAll('g.trace');
2525
var barcount = s.size();
2626
var fullLayout = gd._fullLayout;
2727

@@ -62,16 +62,14 @@ function styleTextPoints(sel, trace, gd) {
6262
});
6363
}
6464

65-
function styleOnSelect(gd, cd) {
66-
var s = cd[0].node3;
65+
function styleOnSelect(gd, cd, sel) {
6766
var trace = cd[0].trace;
6867

6968
if(trace.selectedpoints) {
70-
stylePointsInSelectionMode(s, trace, gd);
69+
stylePointsInSelectionMode(sel, trace, gd);
7170
} else {
72-
stylePoints(s, trace, gd);
73-
74-
Registry.getComponentMethod('errorbars', 'style')(s);
71+
stylePoints(sel, trace, gd);
72+
Registry.getComponentMethod('errorbars', 'style')(sel);
7573
}
7674
}
7775

src/traces/barpolar/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ module.exports = {
2424

2525
plot: require('./plot'),
2626
colorbar: require('../scatter/marker_colorbar'),
27+
2728
style: require('../bar/style').style,
29+
styleOnSelect: require('../bar/style').styleOnSelect,
2830

2931
hoverPoints: require('./hover'),
3032
selectPoints: require('../bar/select'),

src/traces/barpolar/plot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = function plot(gd, subplot, cdbar) {
2323
var pathFn = makePathFn(subplot);
2424
var barLayer = subplot.layers.frontplot.select('g.barlayer');
2525

26-
Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function(cd) {
27-
var plotGroup = cd[0].node3 = d3.select(this);
26+
Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function() {
27+
var plotGroup = d3.select(this);
2828
var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');
2929
var bars = pointGroup.selectAll('g.point').data(Lib.identity);
3030

src/traces/box/plot.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function plot(gd, plotinfo, cdbox, boxLayer) {
2626
var cd0 = cd[0];
2727
var t = cd0.t;
2828
var trace = cd0.trace;
29-
if(!plotinfo.isRangePlot) cd0.node3 = plotGroup;
3029

3130
// whisker width
3231
t.wdPos = t.bdPos * trace.whiskerwidth;

src/traces/box/style.js

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

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

1818
s.style('opacity', function(d) { return d[0].trace.opacity; });
1919

@@ -55,10 +55,9 @@ function style(gd, cd) {
5555
});
5656
}
5757

58-
function styleOnSelect(gd, cd) {
59-
var s = cd[0].node3;
58+
function styleOnSelect(gd, cd, sel) {
6059
var trace = cd[0].trace;
61-
var pts = s.selectAll('path.point');
60+
var pts = sel.selectAll('path.point');
6261

6362
if(trace.selectedpoints) {
6463
Drawing.selectedPointStyle(pts, trace);

src/traces/choropleth/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function plot(gd, geo, calcData) {
2424

2525
var choroplethLayer = geo.layers.backplot.select('.choroplethlayer');
2626
Lib.makeTraceGroups(choroplethLayer, calcData, 'trace choropleth').each(function(calcTrace) {
27-
var sel = calcTrace[0].node3 = d3.select(this);
27+
var sel = d3.select(this);
2828

2929
var paths = sel.selectAll('path.choroplethlocation')
3030
.data(Lib.identity);

0 commit comments

Comments
 (0)