Skip to content

Commit f873b26

Browse files
committed
stop slicing and generating fake arrays in scatter3d and surface defaults
1 parent 2fbd97c commit f873b26

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed

src/plots/gl3d/scene.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,15 @@ proto.recoverContext = function() {
306306

307307
var axisProperties = [ 'xaxis', 'yaxis', 'zaxis' ];
308308

309-
function coordinateBound(axis, coord, d, bounds, calendar) {
309+
function coordinateBound(axis, coord, len, d, bounds, calendar) {
310310
var x;
311-
for(var i = 0; i < coord.length; ++i) {
311+
if(!Array.isArray(coord)) {
312+
bounds[0][d] = Math.min(bounds[0][d], 0);
313+
bounds[1][d] = Math.max(bounds[1][d], len - 1);
314+
return;
315+
}
316+
317+
for(var i = 0; i < (len || coord.length); ++i) {
312318
if(Array.isArray(coord[i])) {
313319
for(var j = 0; j < coord[i].length; ++j) {
314320
x = axis.d2l(coord[i][j], 0, calendar);
@@ -330,9 +336,9 @@ function coordinateBound(axis, coord, d, bounds, calendar) {
330336

331337
function computeTraceBounds(scene, trace, bounds) {
332338
var sceneLayout = scene.fullSceneLayout;
333-
coordinateBound(sceneLayout.xaxis, trace.x, 0, bounds, trace.xcalendar);
334-
coordinateBound(sceneLayout.yaxis, trace.y, 1, bounds, trace.ycalendar);
335-
coordinateBound(sceneLayout.zaxis, trace.z, 2, bounds, trace.zcalendar);
339+
coordinateBound(sceneLayout.xaxis, trace.x, trace._xlength, 0, bounds, trace.xcalendar);
340+
coordinateBound(sceneLayout.yaxis, trace.y, trace._ylength, 1, bounds, trace.ycalendar);
341+
coordinateBound(sceneLayout.zaxis, trace.z, trace._zlength, 2, bounds, trace.zcalendar);
336342
}
337343

338344
proto.plot = function(sceneData, fullLayout, layout) {

src/traces/scatter3d/defaults.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ function handleXYZDefaults(traceIn, traceOut, coerce, layout) {
7878
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
7979

8080
if(x && y && z) {
81+
// TODO: what happens if one is missing?
8182
len = Math.min(x.length, y.length, z.length);
82-
if(len < x.length) traceOut.x = x.slice(0, len);
83-
if(len < y.length) traceOut.y = y.slice(0, len);
84-
if(len < z.length) traceOut.z = z.slice(0, len);
83+
traceOut._xlength = traceOut._ylength = traceOut._zlength = len;
8584
}
8685

8786
return len;

src/traces/surface/convert.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ proto.handlePick = function(selection) {
4545
];
4646
var traceCoordinate = [0, 0, 0];
4747

48-
if(Array.isArray(this.data.x[0])) {
48+
if(!Array.isArray(this.data.x)) {
49+
traceCoordinate[0] = selectIndex[0];
50+
} else if(Array.isArray(this.data.x[0])) {
4951
traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
5052
} else {
5153
traceCoordinate[0] = this.data.x[selectIndex[0]];
5254
}
53-
if(Array.isArray(this.data.y[0])) {
55+
56+
if(!Array.isArray(this.data.y)) {
57+
traceCoordinate[1] = selectIndex[1];
58+
} else if(Array.isArray(this.data.y[0])) {
5459
traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
5560
} else {
5661
traceCoordinate[1] = this.data.y[selectIndex[1]];
@@ -195,8 +200,8 @@ proto.update = function(data) {
195200
yaxis = sceneLayout.yaxis,
196201
zaxis = sceneLayout.zaxis,
197202
scaleFactor = scene.dataScale,
198-
xlen = z[0].length,
199-
ylen = z.length,
203+
xlen = data._xlength,
204+
ylen = data._ylength,
200205
coords = [
201206
ndarray(new Float32Array(xlen * ylen), [xlen, ylen]),
202207
ndarray(new Float32Array(xlen * ylen), [xlen, ylen]),
@@ -226,7 +231,11 @@ proto.update = function(data) {
226231
});
227232

228233
// coords x
229-
if(Array.isArray(x[0])) {
234+
if(!Array.isArray(x)) {
235+
fill(xc, function(row) {
236+
return xaxis.d2l(row, 0, xcalendar) * scaleFactor[0];
237+
});
238+
} else if(Array.isArray(x[0])) {
230239
fill(xc, function(row, col) {
231240
return xaxis.d2l(x[col][row], 0, xcalendar) * scaleFactor[0];
232241
});
@@ -238,7 +247,11 @@ proto.update = function(data) {
238247
}
239248

240249
// coords y
241-
if(Array.isArray(y[0])) {
250+
if(!Array.isArray(x)) {
251+
fill(yc, function(row, col) {
252+
return yaxis.d2l(col, 0, xcalendar) * scaleFactor[1];
253+
});
254+
} else if(Array.isArray(y[0])) {
242255
fill(yc, function(row, col) {
243256
return yaxis.d2l(y[col][row], 0, ycalendar) * scaleFactor[1];
244257
});

src/traces/surface/defaults.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,16 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2929
return;
3030
}
3131

32-
var xlen = z[0].length;
33-
var ylen = z.length;
32+
traceOut._xlength = z[0].length;
33+
traceOut._ylength = z.length;
3434

3535
coerce('x');
3636
coerce('y');
3737

3838
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
3939
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
4040

41-
if(!Array.isArray(traceOut.x)) {
42-
// build a linearly scaled x
43-
traceOut.x = [];
44-
for(i = 0; i < xlen; ++i) {
45-
traceOut.x[i] = i;
46-
}
47-
}
48-
4941
coerce('text');
50-
if(!Array.isArray(traceOut.y)) {
51-
traceOut.y = [];
52-
for(i = 0; i < ylen; ++i) {
53-
traceOut.y[i] = i;
54-
}
55-
}
5642

5743
// Coerce remaining properties
5844
[

test/jasmine/tests/surface_test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ describe('Test surface', function() {
2525
expect(traceOut.visible).toBe(false);
2626
});
2727

28-
it('should fill \'x\' and \'y\' if not provided', function() {
28+
it('should NOT fill \'x\' and \'y\' if not provided', function() {
29+
// this happens later on now
2930
traceIn = {
3031
z: [[1, 2, 3], [2, 1, 2]]
3132
};
3233

3334
supplyDefaults(traceIn, traceOut, defaultColor, layout);
34-
expect(traceOut.x).toEqual([0, 1, 2]);
35-
expect(traceOut.y).toEqual([0, 1]);
35+
expect(traceOut.x).toBeUndefined();
36+
expect(traceOut.y).toBeUndefined();
3637
});
3738

3839
it('should coerce \'project\' if contours or highlight lines are enabled', function() {

0 commit comments

Comments
 (0)