Skip to content

Fix selection behaviour of histograms #2711

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 5 commits into from
Sep 3, 2020
Merged
Changes from all commits
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
47 changes: 38 additions & 9 deletions packages/javascript/plotlywidget/src/Figure.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,18 +888,47 @@ var FigureView = widgets.DOMWidgetView.extend({
// Most cartesian plots
var pointObjects = data["points"];
var numPoints = pointObjects.length;

var hasNestedPointObjects = true;
for (let i = 0; i < numPoints; i++) {
hasNestedPointObjects = (hasNestedPointObjects && pointObjects[i].hasOwnProperty("pointNumbers"));
if (!hasNestedPointObjects) break;
}
var numPointNumbers = numPoints;
if (hasNestedPointObjects) {
numPointNumbers = 0;
for (let i = 0; i < numPoints; i++) {
numPointNumbers += pointObjects[i]["pointNumbers"].length;
}
}
pointsObject = {
trace_indexes: new Array(numPoints),
point_indexes: new Array(numPoints),
xs: new Array(numPoints),
ys: new Array(numPoints),
trace_indexes: new Array(numPointNumbers),
point_indexes: new Array(numPointNumbers),
xs: new Array(numPointNumbers),
ys: new Array(numPointNumbers),
};

for (var p = 0; p < numPoints; p++) {
pointsObject["trace_indexes"][p] = pointObjects[p]["curveNumber"];
pointsObject["point_indexes"][p] = pointObjects[p]["pointNumber"];
pointsObject["xs"][p] = pointObjects[p]["x"];
pointsObject["ys"][p] = pointObjects[p]["y"];
if (hasNestedPointObjects) {
var flatPointIndex = 0;
for (var p = 0; p < numPoints; p++) {
for (let i = 0; i < pointObjects[p]["pointNumbers"].length; i++, flatPointIndex++) {
pointsObject["point_indexes"][flatPointIndex] = pointObjects[p]["pointNumbers"][i]
// also add xs, ys and traces so that the array doesn't get truncated later
pointsObject["xs"][flatPointIndex] = pointObjects[p]["x"];
pointsObject["ys"][flatPointIndex] = pointObjects[p]["y"];
pointsObject["trace_indexes"][flatPointIndex] = pointObjects[p]["curveNumber"];
}
}
pointsObject["point_indexes"].sort(function(a, b) {
return a - b;
});
} else {
for (var p = 0; p < numPoints; p++) {
pointsObject["trace_indexes"][p] = pointObjects[p]["curveNumber"];
pointsObject["point_indexes"][p] = pointObjects[p]["pointNumber"];
pointsObject["xs"][p] = pointObjects[p]["x"];
pointsObject["ys"][p] = pointObjects[p]["y"];
}
}

// Add z if present
Expand Down