Skip to content

Commit 01df2d2

Browse files
committed
style selected text nodes with selectedTextStyle + add test
1 parent 7103fab commit 01df2d2

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/traces/bar/style.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ function styleOnSelect(gd, cd) {
7676
var trace = cd[0].trace;
7777

7878
if(trace.selectedpoints) {
79-
Drawing.selectedPointStyle(s.selectAll('path'), trace, gd);
80-
Drawing.selectedPointStyle(s.selectAll('text'), trace, gd);
79+
Drawing.selectedPointStyle(s.selectAll('path'), trace);
80+
Drawing.selectedTextStyle(s.selectAll('text'), trace);
8181
} else {
8282
stylePoints(s, trace, gd);
8383
}

src/traces/scatter/style.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function styleOnSelect(gd, cd) {
5050
var trace = cd[0].trace;
5151

5252
if(trace.selectedpoints) {
53-
Drawing.selectedPointStyle(s.selectAll('path.point'), trace, gd);
54-
Drawing.selectedPointStyle(s.selectAll('text'), trace, gd);
53+
Drawing.selectedPointStyle(s.selectAll('path.point'), trace);
54+
Drawing.selectedTextStyle(s.selectAll('text'), trace);
5555
} else {
5656
stylePoints(s, trace, gd);
5757
}

test/jasmine/tests/select_test.js

+49
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,55 @@ describe('@flaky Test select box and lasso per trace:', function() {
14851485
.catch(failTest)
14861486
.then(done);
14871487
});
1488+
1489+
it('should work on scatter/bar traces with text nodes', function(done) {
1490+
var assertSelectedPoints = makeAssertSelectedPoints();
1491+
1492+
function assertFillOpacity(exp) {
1493+
var txtPts = d3.select(gd).select('g.plot').selectAll('text');
1494+
1495+
expect(txtPts.size()).toBe(exp.length, '# of text nodes');
1496+
1497+
txtPts.each(function(_, i) {
1498+
var act = Number(this.style['fill-opacity']);
1499+
expect(act).toBe(exp[i], 'node ' + i + ' fill opacity');
1500+
});
1501+
}
1502+
1503+
Plotly.plot(gd, [{
1504+
mode: 'markers+text',
1505+
x: [1, 2, 3],
1506+
y: [1, 2, 1],
1507+
text: ['a', 'b', 'c']
1508+
}, {
1509+
type: 'bar',
1510+
x: [1, 2, 3],
1511+
y: [1, 2, 1],
1512+
text: ['A', 'B', 'C'],
1513+
textposition: 'outside'
1514+
}], {
1515+
dragmode: 'select',
1516+
showlegend: false,
1517+
width: 400,
1518+
height: 400,
1519+
margin: {l: 0, t: 0, r: 0, b: 0}
1520+
})
1521+
.then(function() {
1522+
return _run(
1523+
[[10, 10], [100, 300]],
1524+
function() {
1525+
assertSelectedPoints({0: [0], 1: [0]});
1526+
assertFillOpacity([1, 0.2, 0.2, 1, 0.2, 0.2]);
1527+
},
1528+
null, BOXEVENTS, 'selecting first scatter/bar text nodes'
1529+
);
1530+
})
1531+
.then(function() {
1532+
assertFillOpacity([1, 1, 1, 1, 1, 1]);
1533+
})
1534+
.catch(failTest)
1535+
.then(done);
1536+
});
14881537
});
14891538

14901539
describe('Test that selections persist:', function() {

0 commit comments

Comments
 (0)