From b343fcc24ea9f855d1c4085d0803e927bcfd5d6e Mon Sep 17 00:00:00 2001 From: meffmadd <37695050+meffmadd@users.noreply.github.com> Date: Fri, 23 Apr 2021 15:47:43 +0200 Subject: [PATCH] Fix selection of histograms with multiple traces (#2771) * sort indices only if a single trace exists --- packages/javascript/plotlywidget/src/Figure.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/javascript/plotlywidget/src/Figure.js b/packages/javascript/plotlywidget/src/Figure.js index a997ae7533..62b301a8ec 100644 --- a/packages/javascript/plotlywidget/src/Figure.js +++ b/packages/javascript/plotlywidget/src/Figure.js @@ -1,7 +1,7 @@ var widgets = require("@jupyter-widgets/base"); var _ = require("lodash"); -window.PlotlyConfig = { MathJaxConfig: "local" }; +window.PlotlyConfig = {MathJaxConfig: "local"}; var Plotly = require("plotly.js/dist/plotly"); var semver_range = "^" + require("../package.json").version; @@ -919,9 +919,18 @@ var FigureView = widgets.DOMWidgetView.extend({ pointsObject["trace_indexes"][flatPointIndex] = pointObjects[p]["curveNumber"]; } } - pointsObject["point_indexes"].sort(function(a, b) { - return a - b; - }); + + let single_trace = true; + for (let i = 1; i < numPointNumbers; i++) { + single_trace = single_trace && (pointsObject["trace_indexes"][i - 1] === pointsObject["trace_indexes"][i]) + if (!single_trace) break; + } + if (single_trace) { + 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"];