Skip to content

Commit 5878223

Browse files
committed
make trace (x|y)axes always have the same length dimensions`
... regardless of the partial visibilities. ie `trace.xaxes: ['x', 'x2', 'x3', 'x4']` even though we aren’t going to create an `xaxis4`. Should make it easier for users who don’t want to use the default axes but still want to be able to turn on/off the upper/lower/diag
1 parent 00cae48 commit 5878223

File tree

3 files changed

+257
-77
lines changed

3 files changed

+257
-77
lines changed

src/traces/splom/attributes.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ function makeAxesValObject(axLetter) {
3131
},
3232
description: [
3333
'Sets the list of ' + axLetter + ' axes',
34-
'corresponding to this splom trace.',
34+
'corresponding to dimensions of this splom trace.',
3535
'By default, a splom will match the first N ' + axLetter + 'axes',
36-
'where N is the number of input dimensions.'
36+
'where N is the number of input dimensions.',
37+
'Note that, in case where `diagonal.visible` is false and `showupperhalf`',
38+
'or `showlowerhalf` is false, this splom trace will generate',
39+
'one less x-axis and one less y-axis.',
3740
].join(' ')
3841
};
3942
}

src/traces/splom/defaults.js

+67-69
Original file line numberDiff line numberDiff line change
@@ -73,97 +73,95 @@ function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
7373
var showDiag = traceOut.diagonal.visible;
7474
var i, j;
7575

76-
// N.B. one less x axis AND one less y axis when hiding one half and the diagonal
77-
var axDfltLength = !showDiag && (!showUpper || !showLower) ? dimLength - 1 : dimLength;
76+
var xAxesDflt = new Array(dimLength);
77+
var yAxesDflt = new Array(dimLength);
7878

79-
var xaxes = coerce('xaxes', fillAxisIdArray('x', axDfltLength));
80-
var yaxes = coerce('yaxes', fillAxisIdArray('y', axDfltLength));
79+
for(i = 0; i < dimLength; i++) {
80+
var suffix = i ? i + 1 : '';
81+
xAxesDflt[i] = 'x' + suffix;
82+
yAxesDflt[i] = 'y' + suffix;
83+
}
8184

82-
// to avoid costly indexOf
83-
traceOut._xaxes = arrayToHashObject(xaxes);
84-
traceOut._yaxes = arrayToHashObject(yaxes);
85+
var xaxes = coerce('xaxes', xAxesDflt);
86+
var yaxes = coerce('yaxes', yAxesDflt);
8587

86-
// allow users to under-specify number of axes
87-
var axLength = Math.min(axDfltLength, xaxes.length, yaxes.length);
88+
// build list of [x,y] axis corresponding to each dimensions[i],
89+
// very useful for passing options to regl-splom
90+
var diag = traceOut._diag = new Array(dimLength);
8891

89-
// fill in splom subplot keys
90-
for(i = 0; i < axLength; i++) {
91-
for(j = 0; j < axLength; j++) {
92-
var id = xaxes[i] + yaxes[j];
92+
// lookup for 'drawn' x|y axes, to avoid costly indexOf downstream
93+
traceOut._xaxes = {};
94+
traceOut._yaxes = {};
9395

94-
if(i > j && showUpper) {
95-
layout._splomSubplots[id] = 1;
96-
} else if(i < j && showLower) {
97-
layout._splomSubplots[id] = 1;
98-
} else if(i === j && (showDiag || !showLower || !showUpper)) {
99-
// need to include diagonal subplots when
100-
// hiding one half and the diagonal
101-
layout._splomSubplots[id] = 1;
96+
// list of 'drawn' x|y axes, use to generate list of subplots
97+
var xList = [];
98+
var yList = [];
99+
100+
function fillAxisStashes(axId, dim, list) {
101+
if(!axId) return;
102+
103+
var axLetter = axId.charAt(0);
104+
var stash = layout._splomAxes[axLetter];
105+
106+
traceOut['_' + axLetter + 'axes'][axId] = 1;
107+
list.push(axId);
108+
109+
if(!(axId in stash)) {
110+
var s = stash[axId] = {};
111+
if(dim) {
112+
s.label = dim.label || '';
113+
if(dim.visible && dim.axis) {
114+
s.type = dim.axis.type;
115+
}
102116
}
103117
}
104118
}
105119

106-
// build list of [x,y] axis corresponding to each dimensions[i],
107-
// very useful for passing options to regl-splom
108-
var diag = traceOut._diag = new Array(dimLength);
109-
110120
// cases where showDiag and showLower or showUpper are false
111-
// no special treatment as the xaxes and yaxes items no longer match
112-
// the dimensions items 1-to-1
113-
var xShift = !showDiag && !showLower ? -1 : 0;
114-
var yShift = !showDiag && !showUpper ? -1 : 0;
121+
// no special treatment as the 'drawn' x-axes and y-axes no longer match
122+
// the dimensions items and xaxes|yaxes 1-to-1
123+
var mustShiftX = !showDiag && !showLower;
124+
var mustShiftY = !showDiag && !showUpper;
115125

116126
for(i = 0; i < dimLength; i++) {
117127
var dim = dimensions[i];
118-
var xaId = xaxes[i + xShift];
119-
var yaId = yaxes[i + yShift];
120-
121-
fillAxisStash(layout, xaId, dim);
122-
fillAxisStash(layout, yaId, dim);
123-
124-
// note that some the entries here may be undefined
125-
diag[i] = [xaId, yaId];
126-
}
128+
var i0 = i === 0;
129+
var iN = i === dimLength - 1;
127130

128-
// when lower half is omitted, override grid default
129-
// to make sure axes remain on the left/bottom of the plot area
130-
if(!showLower) {
131-
layout._splomGridDflt.xside = 'bottom';
132-
layout._splomGridDflt.yside = 'left';
133-
}
134-
}
131+
var xaId = (i0 && mustShiftX) || (iN && mustShiftY) ?
132+
undefined :
133+
xaxes[i];
135134

136-
function fillAxisIdArray(axLetter, len) {
137-
var out = new Array(len);
135+
var yaId = (i0 && mustShiftY) || (iN && mustShiftX) ?
136+
undefined :
137+
yaxes[i];
138138

139-
for(var i = 0; i < len; i++) {
140-
out[i] = axLetter + (i ? i + 1 : '');
139+
fillAxisStashes(xaId, dim, xList);
140+
fillAxisStashes(yaId, dim, yList);
141+
diag[i] = [xaId, yaId];
141142
}
142143

143-
return out;
144-
}
145-
146-
function fillAxisStash(layout, axId, dim) {
147-
if(!axId) return;
148-
149-
var axLetter = axId.charAt(0);
150-
var stash = layout._splomAxes[axLetter];
144+
// fill in splom subplot keys
145+
for(i = 0; i < xList.length; i++) {
146+
for(j = 0; j < yList.length; j++) {
147+
var id = xList[i] + yList[j];
151148

152-
if(!(axId in stash)) {
153-
var s = stash[axId] = {};
154-
if(dim) {
155-
s.label = dim.label || '';
156-
if(dim.visible && dim.axis) {
157-
s.type = dim.axis.type;
149+
if(i > j && showUpper) {
150+
layout._splomSubplots[id] = 1;
151+
} else if(i < j && showLower) {
152+
layout._splomSubplots[id] = 1;
153+
} else if(i === j && (showDiag || !showLower || !showUpper)) {
154+
// need to include diagonal subplots when
155+
// hiding one half and the diagonal
156+
layout._splomSubplots[id] = 1;
158157
}
159158
}
160159
}
161-
}
162160

163-
function arrayToHashObject(arr) {
164-
var obj = {};
165-
for(var i = 0; i < arr.length; i++) {
166-
obj[arr[i]] = 1;
161+
// when lower half is omitted, override grid default
162+
// to make sure axes remain on the left/bottom of the plot area
163+
if(!showLower) {
164+
layout._splomGridDflt.xside = 'bottom';
165+
layout._splomGridDflt.yside = 'left';
167166
}
168-
return obj;
169167
}

0 commit comments

Comments
 (0)