Skip to content

Commit b5d24e1

Browse files
committed
refactor parcoords - move nested functions outside plot callbacks
1 parent 6403347 commit b5d24e1

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/traces/parcoords/plot.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111
var parcoords = require('./parcoords');
1212
var prepareRegl = require('../../lib/prepare_regl');
1313

14+
function visible(dimension) {
15+
return dimension.visible || !('visible' in dimension);
16+
}
17+
18+
function newIndex(visibleIndices, orig, dim) {
19+
var origIndex = orig.indexOf(dim);
20+
var currentIndex = visibleIndices.indexOf(origIndex);
21+
if(currentIndex === -1) {
22+
// invisible dimensions initially go to the end
23+
currentIndex += orig.length;
24+
}
25+
return currentIndex;
26+
}
27+
28+
function sorter(visibleIndices, orig) {
29+
return function sorter(d1, d2) {
30+
return (
31+
newIndex(visibleIndices, orig, d1) -
32+
newIndex(visibleIndices, orig, d2)
33+
);
34+
};
35+
}
36+
1437
module.exports = function plot(gd, cdModule) {
1538
var fullLayout = gd._fullLayout;
1639
var svg = fullLayout._toppaper;
@@ -83,29 +106,8 @@ module.exports = function plot(gd, cdModule) {
83106
// Have updated order data on `gd.data` and raise `Plotly.restyle` event
84107
// without having to incur heavy UI blocking due to an actual `Plotly.restyle` call
85108

86-
function visible(dimension) {return !('visible' in dimension) || dimension.visible;}
87-
88-
function newIndex(visibleIndices, orig, dim) {
89-
var origIndex = orig.indexOf(dim);
90-
var currentIndex = visibleIndices.indexOf(origIndex);
91-
if(currentIndex === -1) {
92-
// invisible dimensions initially go to the end
93-
currentIndex += orig.length;
94-
}
95-
return currentIndex;
96-
}
97-
98-
function sorter(orig) {
99-
return function sorter(d1, d2) {
100-
return (
101-
newIndex(visibleIndices, orig, d1) -
102-
newIndex(visibleIndices, orig, d2)
103-
);
104-
};
105-
}
106-
107109
// drag&drop sorting of the visible dimensions
108-
var orig = sorter(initialDims[i].filter(visible));
110+
var orig = sorter(visibleIndices, initialDims[i].filter(visible));
109111
currentDims[i].sort(orig);
110112

111113
// invisible dimensions are not interpreted in the context of drag&drop sorting as an invisible dimension

0 commit comments

Comments
 (0)