Skip to content

Commit f956a13

Browse files
committed
keep invisible dimensions fixed in place; visible (drag&droppable) dimensions move around them
1 parent 4a3d73c commit f956a13

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/traces/parcoords/plot.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ module.exports = function plot(gd, cdparcoords) {
5353
// Have updated order data on `gd.data` and raise `Plotly.restyle` event
5454
// without having to incur heavy UI blocking due to an actual `Plotly.restyle` call
5555

56+
function visible(dimension) {return !('visible' in dimension) || dimension.visible;}
57+
5658
function newIdx(visibleIndices, orig, dim) {
5759
var origIndex = orig.indexOf(dim);
5860
var currentIndex = visibleIndices.indexOf(origIndex);
5961
if(currentIndex === -1) {
60-
// invisible dimensions go to the end, retaining their original order
62+
// invisible dimensions initially go to the end
6163
currentIndex += orig.length;
6264
}
6365
return currentIndex;
@@ -71,9 +73,22 @@ module.exports = function plot(gd, cdparcoords) {
7173
};
7274
}
7375

74-
var orig = sorter(gdDimensionsOriginalOrder[i].filter(function(d) {return d.visible === void(0) || d.visible;}));
76+
// drag&drop sorting of the visible dimensions
77+
var orig = sorter(gdDimensionsOriginalOrder[i].filter(visible));
7578
gdDimensions[i].sort(orig);
7679

80+
// invisible dimensions are not interpreted in the context of drag&drop sorting as an invisible dimension
81+
// cannot be dragged; they're interspersed into their original positions by this subsequent merging step
82+
gdDimensionsOriginalOrder[i].filter(function(d) {return !visible(d);})
83+
.sort(function(d) {
84+
// subsequent splicing to be done left to right, otherwise indices may be incorrect
85+
return gdDimensionsOriginalOrder[i].indexOf(d);
86+
})
87+
.forEach(function(d) {
88+
gdDimensions[i].splice(gdDimensions[i].indexOf(d), 1); // remove from the end
89+
gdDimensions[i].splice(gdDimensionsOriginalOrder[i].indexOf(d), 0, d); // insert at original index
90+
});
91+
7792
gd.emit('plotly_restyle');
7893
};
7994

0 commit comments

Comments
 (0)