Skip to content

Commit 8ce3ded

Browse files
committed
Add class for customdata
1 parent 89b56b7 commit 8ce3ded

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/traces/scatter/style.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ module.exports = function style(gd) {
2424

2525
s.selectAll('g.points')
2626
.each(function(d) {
27-
d3.select(this).selectAll('path.point')
28-
.call(Drawing.pointStyle, d.trace || d[0].trace);
29-
d3.select(this).selectAll('text')
27+
var el = d3.select(this);
28+
var pt = el.selectAll('path.point');
29+
30+
pt.call(Drawing.pointStyle, d.trace || d[0].trace);
31+
32+
pt.each(function(cd) {
33+
d3.select(this).classed('plotly-customdata', cd.data !== null && cd.data !== undefined);
34+
});
35+
36+
el.selectAll('text')
3037
.call(Drawing.textPointStyle, d.trace || d[0].trace);
3138
});
3239

test/jasmine/tests/scatter_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
var d3 = require('d3');
12
var Scatter = require('@src/traces/scatter');
23
var makeBubbleSizeFn = require('@src/traces/scatter/make_bubble_size_func');
34
var linePoints = require('@src/traces/scatter/line_points');
45
var Lib = require('@src/lib');
56

7+
var Plotly = require('@lib/index');
8+
var createGraphDiv = require('../assets/create_graph_div');
9+
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var fail = require('../assets/fail_test');
11+
612
describe('Test scatter', function() {
713
'use strict';
814

@@ -326,3 +332,32 @@ describe('Test scatter', function() {
326332
});
327333

328334
});
335+
336+
describe('end-to-end scatter tests', function() {
337+
var gd;
338+
339+
beforeEach(function() {
340+
gd = createGraphDiv();
341+
});
342+
343+
afterEach(destroyGraphDiv);
344+
345+
it('should add a plotly-customdata class to points with custom data', function(done) {
346+
Plotly.plot(gd, [{
347+
x: [1, 2, 3, 4, 5, 6, 7],
348+
y: [2, 3, 4, 5, 6, 7, 8],
349+
customdata: [null, undefined, 0, false, {foo: 'bar'}, 'a']
350+
}]).then(function() {
351+
var points = d3.selectAll('g.scatterlayer').selectAll('.point');
352+
353+
// Rather than just duplicating the logic, let's be explicit about
354+
// what's expected. Specifially, only null and undefined (the default)
355+
// do *not* add the class.
356+
var expected = [false, false, true, true, true, true, false];
357+
358+
points.each(function(cd, i) {
359+
expect(d3.select(this).classed('plotly-customdata')).toBe(expected[i]);
360+
});
361+
}).catch(fail).then(done);
362+
});
363+
});

0 commit comments

Comments
 (0)