Skip to content

Commit 6403347

Browse files
committed
refactor parcoords - better variable names in parcoords plot
1 parent 6aad768 commit 6403347

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/traces/parcoords/plot.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ module.exports = function plot(gd, cdModule) {
1919
var success = prepareRegl(gd);
2020
if(!success) return;
2121

22-
var gdDimensions = {};
23-
var gdDimensionsOriginalOrder = {};
22+
var currentDims = {};
23+
var initialDims = {};
2424
var fullIndices = {};
2525
var inputIndices = {};
2626

@@ -30,37 +30,37 @@ module.exports = function plot(gd, cdModule) {
3030
var trace = d[0].trace;
3131
fullIndices[i] = trace.index;
3232
var iIn = inputIndices[i] = trace._fullInput.index;
33-
gdDimensions[i] = gd.data[iIn].dimensions;
34-
gdDimensionsOriginalOrder[i] = gd.data[iIn].dimensions.slice();
33+
currentDims[i] = gd.data[iIn].dimensions;
34+
initialDims[i] = gd.data[iIn].dimensions.slice();
3535
});
3636

37-
var filterChanged = function(i, originalDimensionIndex, newRanges) {
37+
var filterChanged = function(i, initialDimIndex, newRanges) {
3838
// Have updated `constraintrange` data on `gd.data` and raise `Plotly.restyle` event
3939
// without having to incur heavy UI blocking due to an actual `Plotly.restyle` call
4040

41-
var gdDimension = gdDimensionsOriginalOrder[i][originalDimensionIndex];
41+
var dim = initialDims[i][initialDimIndex];
4242
var newConstraints = newRanges.map(function(r) { return r.slice(); });
4343

4444
// Store constraint range in preGUI
4545
// This one doesn't work if it's stored in pieces in _storeDirectGUIEdit
4646
// because it's an array of variable dimensionality. So store the whole
4747
// thing at once manually.
48-
var aStr = 'dimensions[' + originalDimensionIndex + '].constraintrange';
48+
var aStr = 'dimensions[' + initialDimIndex + '].constraintrange';
4949
var preGUI = fullLayout._tracePreGUI[gd._fullData[fullIndices[i]]._fullInput.uid];
5050
if(preGUI[aStr] === undefined) {
51-
var initialVal = gdDimension.constraintrange;
51+
var initialVal = dim.constraintrange;
5252
preGUI[aStr] = initialVal || null;
5353
}
5454

55-
var fullDimension = gd._fullData[fullIndices[i]].dimensions[originalDimensionIndex];
55+
var fullDimension = gd._fullData[fullIndices[i]].dimensions[initialDimIndex];
5656

5757
if(!newConstraints.length) {
58-
delete gdDimension.constraintrange;
58+
delete dim.constraintrange;
5959
delete fullDimension.constraintrange;
6060
newConstraints = null;
6161
} else {
6262
if(newConstraints.length === 1) newConstraints = newConstraints[0];
63-
gdDimension.constraintrange = newConstraints;
63+
dim.constraintrange = newConstraints;
6464
fullDimension.constraintrange = newConstraints.slice();
6565
// wrap in another array for restyle event data
6666
newConstraints = [newConstraints];
@@ -85,7 +85,7 @@ module.exports = function plot(gd, cdModule) {
8585

8686
function visible(dimension) {return !('visible' in dimension) || dimension.visible;}
8787

88-
function newIdx(visibleIndices, orig, dim) {
88+
function newIndex(visibleIndices, orig, dim) {
8989
var origIndex = orig.indexOf(dim);
9090
var currentIndex = visibleIndices.indexOf(origIndex);
9191
if(currentIndex === -1) {
@@ -98,26 +98,26 @@ module.exports = function plot(gd, cdModule) {
9898
function sorter(orig) {
9999
return function sorter(d1, d2) {
100100
return (
101-
newIdx(visibleIndices, orig, d1) -
102-
newIdx(visibleIndices, orig, d2)
101+
newIndex(visibleIndices, orig, d1) -
102+
newIndex(visibleIndices, orig, d2)
103103
);
104104
};
105105
}
106106

107107
// drag&drop sorting of the visible dimensions
108-
var orig = sorter(gdDimensionsOriginalOrder[i].filter(visible));
109-
gdDimensions[i].sort(orig);
108+
var orig = sorter(initialDims[i].filter(visible));
109+
currentDims[i].sort(orig);
110110

111111
// invisible dimensions are not interpreted in the context of drag&drop sorting as an invisible dimension
112112
// cannot be dragged; they're interspersed into their original positions by this subsequent merging step
113-
gdDimensionsOriginalOrder[i].filter(function(d) {return !visible(d);})
113+
initialDims[i].filter(function(d) {return !visible(d);})
114114
.sort(function(d) {
115115
// subsequent splicing to be done left to right, otherwise indices may be incorrect
116-
return gdDimensionsOriginalOrder[i].indexOf(d);
116+
return initialDims[i].indexOf(d);
117117
})
118118
.forEach(function(d) {
119-
gdDimensions[i].splice(gdDimensions[i].indexOf(d), 1); // remove from the end
120-
gdDimensions[i].splice(gdDimensionsOriginalOrder[i].indexOf(d), 0, d); // insert at original index
119+
currentDims[i].splice(currentDims[i].indexOf(d), 1); // remove from the end
120+
currentDims[i].splice(initialDims[i].indexOf(d), 0, d); // insert at original index
121121
});
122122

123123
// TODO: we can't really store this part of the interaction state
@@ -127,10 +127,10 @@ module.exports = function plot(gd, cdModule) {
127127
// Registry.call('_storeDirectGUIEdit',
128128
// gd.data[inputIndices[i]],
129129
// fullLayout._tracePreGUI[gd._fullData[fullIndices[i]]._fullInput.uid],
130-
// {dimensions: gdDimensions[i]}
130+
// {dimensions: currentDims[i]}
131131
// );
132132

133-
gd.emit('plotly_restyle', [{dimensions: [gdDimensions[i]]}, [inputIndices[i]]]);
133+
gd.emit('plotly_restyle', [{dimensions: [currentDims[i]]}, [inputIndices[i]]]);
134134
};
135135

136136
parcoords(

0 commit comments

Comments
 (0)