Skip to content

Commit 7f916b0

Browse files
committed
fixups for diagonal.visible: false
- add _diag internal 2d array of x/y axis ids to help us convert the plotly api to regl-scattermatrix - make show(upper|lower)half and diagonal.visible 'calc' edits - 🔪 activeLength (just use dimensions.length + skip over empty axes) - add two mocks
1 parent 2d39ea7 commit 7f916b0

File tree

9 files changed

+1621
-144
lines changed

9 files changed

+1621
-144
lines changed

src/traces/splom/attributes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = {
8484
valType: 'boolean',
8585
role: 'info',
8686
dflt: true,
87-
editType: 'plot',
87+
editType: 'calc',
8888
description: [
8989
'Determines whether or not subplots on the diagonal are displayed.'
9090
].join(' ')
@@ -101,7 +101,7 @@ module.exports = {
101101
valType: 'boolean',
102102
role: 'info',
103103
dflt: true,
104-
editType: 'plot',
104+
editType: 'calc',
105105
description: [
106106
'Determines whether or not subplots on the upper half',
107107
'from the diagonal are displayed.'
@@ -111,7 +111,7 @@ module.exports = {
111111
valType: 'boolean',
112112
role: 'info',
113113
dflt: true,
114-
editType: 'plot',
114+
editType: 'calc',
115115
description: [
116116
'Determines whether or not subplots on the lower half',
117117
'from the diagonal are displayed.'

src/traces/splom/base_plot.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,43 @@ function drag(gd) {
4747
var scene = cd0.t._scene;
4848

4949
if(trace.type === 'splom' && scene && scene.matrix) {
50-
var activeLength = trace._activeLength;
51-
var visibleLength = scene.matrixOptions.data.length;
52-
var ranges = new Array(visibleLength);
53-
var k = 0;
54-
55-
for(var j = 0; j < activeLength; j++) {
56-
if(trace.dimensions[j].visible) {
57-
var xrng = AxisIDs.getFromId(gd, trace.xaxes[j]).range;
58-
var yrng = AxisIDs.getFromId(gd, trace.yaxes[j]).range;
59-
ranges[k++] = [xrng[0], yrng[0], xrng[1], yrng[1]];
60-
}
50+
dragOne(gd, trace, scene);
51+
}
52+
}
53+
}
54+
55+
function dragOne(gd, trace, scene) {
56+
var dimensions = trace.dimensions;
57+
var visibleLength = scene.matrixOptions.data.length;
58+
var ranges = new Array(visibleLength);
59+
60+
for(var i = 0, k = 0; i < dimensions.length; i++) {
61+
if(dimensions[i].visible) {
62+
var rng = ranges[k] = new Array(4);
63+
64+
var xa = AxisIDs.getFromId(gd, trace._diag[i][0]);
65+
if(xa) {
66+
rng[0] = xa.range[0];
67+
rng[2] = xa.range[1];
6168
}
6269

63-
if(scene.selectBatch) {
64-
scene.matrix.update({ranges: ranges}, {ranges: ranges});
65-
scene.matrix.draw(scene.unselectBatch, scene.selectBatch);
66-
} else {
67-
scene.matrix.update({ranges: ranges});
68-
scene.matrix.draw();
70+
var ya = AxisIDs.getFromId(gd, trace._diag[i][1]);
71+
if(ya) {
72+
rng[1] = ya.range[0];
73+
rng[3] = ya.range[1];
6974
}
75+
76+
k++;
7077
}
7178
}
79+
80+
if(scene.selectBatch) {
81+
scene.matrix.update({ranges: ranges}, {ranges: ranges});
82+
scene.matrix.draw(scene.unselectBatch, scene.selectBatch);
83+
} else {
84+
scene.matrix.update({ranges: ranges});
85+
scene.matrix.draw();
86+
}
7287
}
7388

7489
function drawGrid(gd) {

src/traces/splom/defaults.js

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function handleDimensionsDefaults(traceIn, traceOut) {
8282
// to fill in axis title defaults
8383
coerce('label');
8484

85+
// wait until plot step to filter out visible false dimensions
8586
var visible = coerce('visible');
8687
if(!visible) continue;
8788

@@ -108,67 +109,79 @@ function handleDimensionsDefaults(traceIn, traceOut) {
108109
function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
109110
var dimensions = traceOut.dimensions;
110111
var dimLength = dimensions.length;
111-
var i, j;
112-
113112
var showUpper = traceOut.showupperhalf;
114113
var showLower = traceOut.showlowerhalf;
115-
var showDiagonal = traceOut.diagonal.visible;
116-
117-
var axLength = !showDiagonal && (!showUpper || !showLower) ?
118-
dimLength - 1 :
119-
dimLength;
114+
var showDiag = traceOut.diagonal.visible;
115+
var i, j;
120116

121-
var xaxesDflt = new Array(axLength);
122-
var yaxesDflt = new Array(axLength);
117+
// N.B. one less x axis AND one less y axis when hiding one half and the diagonal
118+
var axDfltLength = !showDiag && (!showUpper || !showLower) ? dimLength - 1 : dimLength;
123119

124-
for(i = 0; i < axLength; i++) {
125-
xaxesDflt[i] = 'x' + (i ? i + 1 : '');
126-
yaxesDflt[i] = 'y' + (i ? i + 1 : '');
127-
}
120+
var xaxes = coerce('xaxes', fillAxisIdArray('x', axDfltLength));
121+
var yaxes = coerce('yaxes', fillAxisIdArray('y', axDfltLength));
128122

129-
var xaxes = coerce('xaxes', xaxesDflt);
130-
var yaxes = coerce('yaxes', yaxesDflt);
131-
132-
// splom defaults set three types of 'length' values on the
133-
// full data items:
134-
//
135-
// - _commonLength: is the common length of each dimensions[i].values
136-
// - dimensions[i]._length: is a copy of _commonLength to each dimensions item
137-
// (this one is used during ax.makeCalcdata)
138-
// - _activeLength: is the number of dimensions that can generate axes for a given trace
139-
//
140-
// when looping from 0..activeLength dimensions and (x|y)axes indices should match.
141-
// note that `visible: false` dimensions contribute to activeLength and must
142-
// be skipped before drawing calls.
143-
var activeLength = traceOut._activeLength = Math.min(dimLength, xaxes.length, yaxes.length);
144-
145-
for(i = 0; i < activeLength; i++) {
146-
var dim = dimensions[i];
147-
var xa = xaxes[i];
148-
var ya = yaxes[i];
123+
// allow users to under-specify number of axes
124+
var axLength = Math.min(axDfltLength, xaxes.length, yaxes.length);
149125

150-
if(!(xa in layout._splomAxes.x)) {
151-
layout._splomAxes.x[xa] = dim.label || '';
152-
}
153-
if(!(ya in layout._splomAxes.y)) {
154-
layout._splomAxes.y[ya] = dim.label || '';
155-
}
156-
}
157-
158-
for(i = 0; i < activeLength; i++) {
159-
for(j = 0; j < activeLength; j++) {
126+
// fill in splom subplot keys
127+
for(i = 0; i < axLength; i++) {
128+
for(j = 0; j < axLength; j++) {
160129
var id = [xaxes[i] + yaxes[j]];
161130

162131
if(i > j && showUpper) {
163132
layout._splomSubplots[id] = 1;
164133
} else if(i < j && showLower) {
165134
layout._splomSubplots[id] = 1;
166-
} else if(i === j && showDiagonal) {
167-
layout._splomSubplots[id] = 1;
135+
} else {
136+
// need to include diagonal subplots when
137+
// hiding one half and the diagonal
138+
if(showDiag || !showLower || !showUpper) {
139+
layout._splomSubplots[id] = 1;
140+
}
168141
}
169142
}
170143
}
171144

172-
console.log(xaxes, yaxes);
173-
console.log(Object.keys(layout._splomSubplots))
145+
// build list of [x,y] axis corresponding to each dimensions[i],
146+
// very useful for passing options to regl-scattermatrix
147+
var diag = traceOut._diag = new Array(dimLength);
148+
149+
// cases where showDiag and showLower or showUpper are false
150+
// no special treatment as the xaxes and yaxes items no longer match
151+
// the dimensions items 1-to-1
152+
var xShift = !showDiag && !showLower ? -1 : 0;
153+
var yShift = !showDiag && !showUpper ? -1 : 0;
154+
155+
for(i = 0; i < dimLength; i++) {
156+
var dim = dimensions[i];
157+
var xa = xaxes[i + xShift];
158+
var ya = yaxes[i + yShift];
159+
160+
fillAxisStash(layout, xa, dim);
161+
fillAxisStash(layout, ya, dim);
162+
163+
// note that some the entries here may be undefined
164+
diag[i] = [xa, ya];
165+
}
166+
}
167+
168+
function fillAxisIdArray(axLetter, len) {
169+
var out = new Array(len);
170+
171+
for(var i = 0; i < len; i++) {
172+
out[i] = axLetter + (i ? i + 1 : '');
173+
}
174+
175+
return out;
176+
}
177+
178+
function fillAxisStash(layout, axId, dim) {
179+
if(!axId) return;
180+
181+
var axLetter = axId.charAt(0);
182+
var stash = layout._splomAxes[axLetter];
183+
184+
if(!(axId in stash)) {
185+
stash[axId] = (dim || {}).label || '';
186+
}
174187
}

0 commit comments

Comments
 (0)