Skip to content

Commit b343fcc

Browse files
authored
Fix selection of histograms with multiple traces (#2771)
* sort indices only if a single trace exists
1 parent f18576b commit b343fcc

File tree

1 file changed

+13
-4
lines changed
  • packages/javascript/plotlywidget/src

1 file changed

+13
-4
lines changed

Diff for: packages/javascript/plotlywidget/src/Figure.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var widgets = require("@jupyter-widgets/base");
22
var _ = require("lodash");
33

4-
window.PlotlyConfig = { MathJaxConfig: "local" };
4+
window.PlotlyConfig = {MathJaxConfig: "local"};
55
var Plotly = require("plotly.js/dist/plotly");
66
var semver_range = "^" + require("../package.json").version;
77

@@ -919,9 +919,18 @@ var FigureView = widgets.DOMWidgetView.extend({
919919
pointsObject["trace_indexes"][flatPointIndex] = pointObjects[p]["curveNumber"];
920920
}
921921
}
922-
pointsObject["point_indexes"].sort(function(a, b) {
923-
return a - b;
924-
});
922+
923+
let single_trace = true;
924+
for (let i = 1; i < numPointNumbers; i++) {
925+
single_trace = single_trace && (pointsObject["trace_indexes"][i - 1] === pointsObject["trace_indexes"][i])
926+
if (!single_trace) break;
927+
}
928+
if (single_trace) {
929+
pointsObject["point_indexes"].sort((function (a, b) {
930+
return a - b
931+
}))
932+
}
933+
925934
} else {
926935
for (var p = 0; p < numPoints; p++) {
927936
pointsObject["trace_indexes"][p] = pointObjects[p]["curveNumber"];

0 commit comments

Comments
 (0)