Skip to content

Commit 43b3e56

Browse files
committed
Pass customdata through to scatter calcdata
1 parent 8269ea0 commit 43b3e56

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/traces/scatter/arrays_to_calcdata.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Lib = require('../../lib');
1616
module.exports = function arraysToCalcdata(cd, trace) {
1717

1818
Lib.mergeArray(trace.text, cd, 'tx');
19+
Lib.mergeArray(trace.customdata, cd, 'data');
1920
Lib.mergeArray(trace.textposition, cd, 'tp');
2021
if(trace.textfont) {
2122
Lib.mergeArray(trace.textfont.size, cd, 'ts');

src/traces/scatter/attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ module.exports = {
5656
'where `y0` is the starting coordinate and `dy` the step.'
5757
].join(' ')
5858
},
59+
customdata: {
60+
valType: 'data_array',
61+
description: 'When markers present, assigns extra data to each scatter point DOM element'
62+
},
5963
dy: {
6064
valType: 'number',
6165
dflt: 1,

src/traces/scatter/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3636
return;
3737
}
3838

39+
coerce('customdata');
3940
coerce('text');
4041
coerce('mode', defaultMode);
4142
coerce('ids');

test/jasmine/tests/calcdata_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,4 +862,19 @@ describe('calculated data and points', function() {
862862
});
863863
});
864864
});
865+
866+
describe('customdata', function() {
867+
it('should pass customdata to the calcdata points', function() {
868+
Plotly.plot(gd, [{
869+
x: [0, 1, 2, 3],
870+
y: [4, 5, 6, 7],
871+
customdata: ['a', 'b', 'c', 'd']
872+
}], {});
873+
874+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({data: 'a'}));
875+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({data: 'b'}));
876+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({data: 'c'}));
877+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({data: 'd'}));
878+
});
879+
});
865880
});

0 commit comments

Comments
 (0)