Skip to content

Commit 0b898e9

Browse files
committed
append *all* values inside array attr in event data
- data attributes (e.g. ids, customdata) and arrayOk ('marker.size', 'text') values of click/hover'ed points are now included in the event data (along side the pts' coords) - to do so, cache `findArrayAttributes` results in full trace object and use that cache in hover routine.
1 parent 9779c96 commit 0b898e9

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/components/fx/helpers.js

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
'use strict';
1010

11+
var Lib = require('../../lib');
1112
var constants = require('./constants');
1213

1314
// look for either subplot or xaxis and yaxis attributes
@@ -83,3 +84,26 @@ function quadrature(dx, dy) {
8384
return Math.sqrt(x * x + y * y);
8485
};
8586
}
87+
88+
/** Appends values inside array attributes corresponding to given point number
89+
*
90+
* @param {object} pointData : point data object (gets mutated here
91+
* @param {object} trace : full trace object
92+
* @param {number} ptNumber : point number
93+
*/
94+
exports.appendArrayPointValue = function(pointData, trace, ptNumber) {
95+
var arrayAttrs = trace._arrayAttrs;
96+
97+
for(var i = 0; i < arrayAttrs.length; i++) {
98+
var astr = arrayAttrs[i];
99+
var key;
100+
101+
if(astr === 'ids') key = 'id';
102+
else if(astr === 'location') key = 'location';
103+
else key = astr;
104+
105+
if(pointData[key] === undefined) {
106+
pointData[key] = Lib.nestedProperty(trace, astr).get()[ptNumber];
107+
}
108+
}
109+
};

src/components/fx/hover.js

+1
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ function _hover(gd, evt, subplot) {
457457
if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;
458458
}
459459

460+
helpers.appendArrayPointValue(out, trace, pt.index);
460461
newhoverdata.push(out);
461462
}
462463

src/plots/plots.js

+1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
676676
Lib.pushUnique(modules, _module);
677677
Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);
678678

679+
fullTrace._arrayAttrs = PlotSchema.findArrayAttributes(fullTrace);
679680
cnt++;
680681
}
681682

0 commit comments

Comments
 (0)