8000 Include values of all array attributes in hover/click/select event data by etpinard · Pull Request #1770 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Include values of all array attributes in hover/click/select event data #1770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
misc. fixups for appendArrayPointValue
  • Loading branch information
etpinard committed Jun 14, 2017
commit b831cbccfaacc42a944b2a1af0f34a64ac77e12f
13 changes: 8 additions & 5 deletions src/components/fx/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,26 @@ function quadrature(dx, dy) {

/** Appends values inside array attributes corresponding to given point number
*
* @param {object} pointData : point data object (gets mutated here
* @param {object} pointData : point data object (gets mutated here)
* @param {object} trace : full trace object
* @param {number} ptNumber : point number
* @param {number} pointNumber : point number
*/
exports.appendArrayPointValue = function(pointData, trace, ptNumber) {
exports.appendArrayPointValue = function(pointData, trace, pointNumber) {
var arrayAttrs = trace._arrayAttrs;

for(var i = 0; i < arrayAttrs.length; i++) {
var astr = arrayAttrs[i];
var key;

if(astr === 'ids') key = 'id';
else if(astr === 'location') key = 'location';
else if(astr === 'locations') key = 'location';
else key = astr;

if(pointData[key] === undefined) {
pointData[key] = Lib.nestedProperty(trace, astr).get()[ptNumber];
var val = Lib.nestedProperty(trace, astr).get();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking, but if we find that this starts dragging on performance (particularly for selecting I guess) then I suspect nestedProperty would be the primary cost. Could possibly store these instead of attribute strings in _arrayAttrs? It would be a little weird, since they could be referencing data arrays inside an outdated trace if we've redrawn without a recalc, but in as far as recalc is always triggered by changing an array attribute it seems like it would be ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I didn't notice any serious slow downs so far, so I won't address this in this PR.

pointData[key] = Array.isArray(pointNumber) ?
val[pointNumber[0]][pointNumber[1]] :
val[pointNumber];
}
}
};
4 changes: 1 addition & 3 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,17 @@ function _hover(gd, evt, subplot) {
pointNumber: pt.index
};

// could maybe :hocho: _module.eventData
if(pt.trace._module.eventData) out = pt.trace._module.eventData(out, pt);
else {
out.x = pt.xVal;
out.y = pt.yVal;

out.xaxis = pt.xa;
out.yaxis = pt.ya;

if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;
}

helpers.appendArrayPointValue(out, trace, pt.index);
helpers.appendArrayPointValue(out, pt.trace, pt.index);
newhoverdata.push(out);
}

Expand Down
7 changes: 4 additions & 3 deletions src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ exports.findArrayAttributes = function(trace) {
}

exports.crawl(baseAttributes, callback);
exports.crawl(trace._module.attributes, callback);
if(trace._module && trace._module.attributes) {
exports.crawl(trace._module.attributes, callback);
}

if(trace.transforms) {
var transforms = trace.transforms;
Expand All @@ -177,9 +179,8 @@ exports.findArrayAttributes = function(trace) {
// At the moment, we need this block to make sure that
// ohlc and candlestick 'open', 'high', 'low', 'close' can be
// used with filter ang groupby transforms.
if(trace._fullInput) {
if(trace._fullInput && trace._fullInput._module && trace._fullInput._module.attributes) {
exports.crawl(trace._fullInput._module.attributes, callback);

arrayAttributes = Lib.filterUnique(arrayAttributes);
}

Expand Down
2 changes: 1 addition & 1 deletion src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function render(scene) {
pointNumber: ptNumber
};

Fx.appendArrayPointValue(pointData);
Fx.appendArrayPointValue(pointData, trace, ptNumber);

var eventData = {points: [pointData]};

Expand Down
0