Skip to content

Commit 875067b

Browse files
committed
fixes for reversed bounds in 3d scenes
1 parent 9772ef6 commit 875067b

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

package-lock.json

Lines changed: 14 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@
7070
"es6-promise": "^3.0.2",
7171
"fast-isnumeric": "^1.1.1",
7272
"font-atlas-sdf": "^1.3.3",
73-
"gl-cone3d": "^1.1.0",
73+
"gl-cone3d": "git://github.com/archmoj/gl-cone3d.git#823cabfbb19d8b457730320010cb58df748ff9ee",
7474
"gl-contour2d": "^1.1.4",
75-
"gl-error3d": "^1.0.7",
75+
"gl-error3d": "git://github.com/archmoj/gl-error3d.git#d09c224fe25671fcd588a8c803fe83129156fbab",
7676
"gl-heatmap2d": "^1.0.4",
77-
"gl-line3d": "^1.1.2",
77+
"gl-line3d": "git://github.com/archmoj/gl-line3d.git#681398a5477f64cfd92ff7494215d5b6854e834b",
7878
"gl-mat4": "^1.2.0",
79-
"gl-mesh3d": "^2.0.0",
79+
"gl-mesh3d": "git://github.com/archmoj/gl-mesh3d.git#5828f6255d8c5360631d5feec65801bb104a88e8",
8080
"gl-plot2d": "^1.3.1",
8181
"gl-plot3d": "^1.5.5",
8282
"gl-pointcloud2d": "^1.0.1",
83-
"gl-scatter3d": "^1.0.11",
83+
"gl-scatter3d": "git://github.com/archmoj/gl-scatter3d.git#b649f8fb619242525b64ccf1def62cb2ed3f224f",
8484
"gl-select-box": "^1.0.2",
8585
"gl-spikes2d": "^1.0.1",
86-
"gl-streamtube3d": "^1.0.0",
87-
"gl-surface3d": "^1.3.5",
86+
"gl-streamtube3d": "git://github.com/archmoj/gl-streamtube3d.git#f4f5a63ffb19704a1ab1cadcc7aa848d7b68f7bf",
87+
"gl-surface3d": "git://github.com/archmoj/gl-surface3d.git#2455aad56d3727b940fad8d02727806abca0fdf4",
8888
"gl-text": "^1.1.6",
8989
"glslify": "^6.3.1",
9090
"has-hover": "^1.0.1",

src/plots/gl3d/scene.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function render(scene) {
4141
svgContainer.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
4242
svgContainer.setAttributeNS(null, 'width', width);
4343
svgContainer.setAttributeNS(null, 'height', height);
44-
44+
4545
computeTickMarks(scene);
4646
scene.glplot.axes.update(scene.axesOptions);
4747

@@ -383,6 +383,13 @@ function computeTraceBounds(scene, trace, bounds) {
383383
}
384384
}
385385

386+
function isCloseToZero (a) {
387+
if (Math.abs(a) > Number.MIN_VALUE) { // the smallest positive numeric value representable in JavaScript
388+
return false;
389+
}
390+
return true;
391+
}
392+
386393
proto.plot = function(sceneData, fullLayout, layout) {
387394

388395
// Save parameters
@@ -399,7 +406,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
399406
else this.glplot.clearColor = [0, 0, 0, 0];
400407

401408
this.glplot.snapToData = true;
402-
409+
403410
// Update layout
404411
this.fullLayout = fullLayout;
405412
this.fullSceneLayout = fullSceneLayout;
@@ -421,7 +428,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
421428
// Convert scene data
422429
if(!sceneData) sceneData = [];
423430
else if(!Array.isArray(sceneData)) sceneData = [sceneData];
424-
431+
425432
// Compute trace bounding box
426433
var dataBounds = [
427434
[Infinity, Infinity, Infinity],
@@ -435,19 +442,10 @@ proto.plot = function(sceneData, fullLayout, layout) {
435442
}
436443
var dataScale = [1, 1, 1];
437444
for(j = 0; j < 3; ++j) {
438-
if(dataBounds[0][j] > dataBounds[1][j]) {
439-
dataScale[j] = 1.0;
440-
}
441-
else {
442-
if(dataBounds[1][j] === dataBounds[0][j]) {
443-
dataScale[j] = 1.0;
444-
}
445-
else {
446-
dataScale[j] = 1.0 / (dataBounds[1][j] - dataBounds[0][j]);
447-
}
448-
}
445+
var diff = dataBounds[1][j] - dataBounds[0][j];
446+
if(!isCloseToZero(diff)) dataScale[j] = 1.0 / diff;
449447
}
450-
448+
451449
// Save scale
452450
this.dataScale = dataScale;
453451

@@ -558,7 +556,14 @@ proto.plot = function(sceneData, fullLayout, layout) {
558556
} else {
559557
var d = sceneBounds[1][i] - sceneBounds[0][i];
560558
sceneBounds[0][i] -= d / 32.0;
561-
sceneBounds[1][i] += d / 32.0;
559+
sceneBounds[1][i] += d / 32.0;
560+
}
561+
562+
if(axis.autorange === 'reversed') {
563+
// swap bounds:
564+
var tmp = sceneBounds[0][i];
565+
sceneBounds[0][i] = sceneBounds[1][i];
566+
sceneBounds[1][i] = tmp;
562567
}
563568
} else {
564569
var range = axis.range;
@@ -570,14 +575,14 @@ proto.plot = function(sceneData, fullLayout, layout) {
570575
sceneBounds[1][i] += 1;
571576
}
572577
axisDataRange[i] = sceneBounds[1][i] - sceneBounds[0][i];
573-
578+
574579
// Update plot bounds
575580
this.glplot.bounds[0][i] = sceneBounds[0][i] * dataScale[i];
576581
this.glplot.bounds[1][i] = sceneBounds[1][i] * dataScale[i];
577582
}
578-
583+
579584
var axesScaleRatio = [1, 1, 1];
580-
585+
581586
// Compute axis scale per category
582587
for(i = 0; i < 3; ++i) {
583588
axis = fullSceneLayout[axisProperties[i]];

0 commit comments

Comments
 (0)