Skip to content

Commit a2c3694

Browse files
committed
clean up scene computeTraceBounds
1 parent 71e46af commit a2c3694

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/plots/gl3d/scene.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -306,41 +306,44 @@ proto.recoverContext = function() {
306306

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

309-
function coordinateBound(axis, coord, len, d, bounds, calendar) {
310-
var x;
311-
if(!Lib.isArrayOrTypedArray(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-
}
309+
function computeTraceBounds(scene, trace, bounds) {
310+
var sceneLayout = scene.fullSceneLayout;
316311

317-
for(var i = 0; i < (len || coord.length); ++i) {
318-
if(Lib.isArrayOrTypedArray(coord[i])) {
319-
for(var j = 0; j < coord[i].length; ++j) {
320-
x = axis.d2l(coord[i][j], 0, calendar);
321-
if(!isNaN(x) && isFinite(x)) {
322-
bounds[0][d] = Math.min(bounds[0][d], x);
323-
bounds[1][d] = Math.max(bounds[1][d], x);
312+
for(var d = 0; d < 3; d++) {
313+
var axisName = axisProperties[d];
314+
var axLetter = axisName.charAt(0);
315+
var ax = sceneLayout[axisName];
316+
var coords = trace[axLetter];
317+
var calendar = trace[axLetter + 'calendar'];
318+
var len = trace['_' + axLetter + 'length'];
319+
320+
if(!Lib.isArrayOrTypedArray(coords)) {
321+
bounds[0][d] = Math.min(bounds[0][d], 0);
322+
bounds[1][d] = Math.max(bounds[1][d], len - 1);
323+
} else {
324+
var v;
325+
326+
for(var i = 0; i < (len || coords.length); i++) {
327+
if(Lib.isArrayOrTypedArray(coords[i])) {
328+
for(var j = 0; j < coords[i].length; ++j) {
329+
v = ax.d2l(coords[i][j], 0, calendar);
330+
if(!isNaN(v) && isFinite(v)) {
331+
bounds[0][d] = Math.min(bounds[0][d], v);
332+
bounds[1][d] = Math.max(bounds[1][d], v);
333+
}
334+
}
335+
} else {
336+
v = ax.d2l(coords[i], 0, calendar);
337+
if(!isNaN(v) && isFinite(v)) {
338+
bounds[0][d] = Math.min(bounds[0][d], v);
339+
bounds[1][d] = Math.max(bounds[1][d], v);
340+
}
324341
}
325342
}
326343
}
327-
else {
328-
x = axis.d2l(coord[i], 0, calendar);
329-
if(!isNaN(x) && isFinite(x)) {
330-
bounds[0][d] = Math.min(bounds[0][d], x);
331-
bounds[1][d] = Math.max(bounds[1][d], x);
332-
}
333-
}
334344
}
335345
}
336346

337-
function computeTraceBounds(scene, trace, bounds) {
338-
var sceneLayout = scene.fullSceneLayout;
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);
342-
}
343-
344347
proto.plot = function(sceneData, fullLayout, layout) {
345348

346349
// Save parameters

0 commit comments

Comments
 (0)