Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a64174

Browse files
committed
fixup createCamera function and added jasmine tests
1 parent b674b21 commit 3a64174

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

src/plots/gl3d/scene.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,23 @@ function tryCreatePlot(scene, camera, canvas, gl) {
231231
scene.glplot = createPlot(glplotOptions);
232232
}
233233
catch(e) {
234-
/*
235-
* createPlot will throw when webgl is not enabled in the client.
236-
* Lets return an instance of the module with all functions noop'd.
237-
* The destroy method - which will remove the container from the DOM
238-
* is overridden with a function that removes the container only.
239-
*/
240-
return showNoWebGlMsg(scene);
234+
return false;
241235
}
236+
237+
return true;
242238
}
243239

244240
function initializeGLPlot(scene, camera, canvas, gl) {
245241

246-
tryCreatePlot(scene, camera, canvas, gl);
242+
var success = tryCreatePlot(scene, camera, canvas, gl);
243+
/*
244+
* createPlot will throw when webgl is not enabled in the client.
245+
* Lets return an instance of the module with all functions noop'd.
246+
* The destroy method - which will remove the container from the DOM
247+
* is overridden with a function that removes the container only.
248+
*/
249+
if(!success) return showNoWebGlMsg(scene);
250+
247251

248252
var gd = scene.graphDiv;
249253

test/jasmine/tests/gl3d_plot_interact_test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,99 @@ describe('Test gl3d plots', function() {
568568
.then(done);
569569
});
570570

571+
it('@gl should set the camera projection type to perspective if the camera.projection.type is not set', function(done) {
572+
Plotly.plot(gd, {
573+
data: [{
574+
type: 'scatter3d',
575+
x: [1, 2, 3],
576+
y: [2, 3, 1],
577+
z: [3, 1, 2]
578+
}],
579+
layout: {
580+
scene: {
581+
camera: {
582+
}
583+
}
584+
}
585+
})
586+
.then(delay(20))
587+
.then(function() {
588+
expect(gd._fullLayout.scene.camera.projection.type === 'perspective').toBe(true);
589+
})
590+
.then(function() {
591+
expect(gd._fullLayout.scene._scene.glplot.camera._ortho).toBe(false);
592+
})
593+
.then(done);
594+
});
595+
596+
it('@gl should set the camera projection type to orthographic if the camera.projection.type is set to orthographic', function(done) {
597+
Plotly.plot(gd, {
598+
data: [{
599+
type: 'scatter3d',
600+
x: [1, 2, 3],
601+
y: [2, 3, 1],
602+
z: [3, 1, 2]
603+
}],
604+
layout: {
605+
scene: {
606+
camera: {
607+
projection: {
608+
type: 'orthographic'
609+
}
610+
}
611+
}
612+
}
613+
})
614+
.then(delay(20))
615+
.then(function() {
616+
expect(gd._fullLayout.scene.camera.projection.type === 'orthographic').toBe(true);
617+
})
618+
.then(function() {
619+
expect(gd._fullLayout.scene._scene.glplot.camera._ortho).toBe(true);
620+
})
621+
.then(done);
622+
});
623+
624+
it('@gl should enable orthographic & perspective projections using relayout', function(done) {
625+
Plotly.plot(gd, {
626+
data: [{
627+
type: 'scatter3d',
628+
x: [1, 2, 3],
629+
y: [2, 3, 1],
630+
z: [3, 1, 2]
631+
}],
632+
layout: {
633+
scene: {
634+
camera: {
635+
projection: {
636+
type: 'perspective'
637+
}
638+
}
639+
}
640+
}
641+
})
642+
.then(delay(20))
643+
.then(function() {
644+
return Plotly.relayout(gd, 'scene.camera.projection.type', 'orthographic');
645+
})
646+
.then(function() {
647+
expect(gd._fullLayout.scene.camera.projection.type === 'orthographic').toBe(true);
648+
})
649+
.then(function() {
650+
expect(gd._fullLayout.scene._scene.glplot.camera._ortho).toBe(true);
651+
})
652+
.then(function() {
653+
return Plotly.relayout(gd, 'scene.camera.projection.type', 'perspective');
654+
})
655+
.then(function() {
656+
expect(gd._fullLayout.scene.camera.projection.type === 'perspective').toBe(true);
657+
})
658+
.then(function() {
659+
expect(gd._fullLayout.scene._scene.glplot.camera._ortho).toBe(false);
660+
})
661+
.then(done);
662+
});
663+
571664
it('@gl should be able to reversibly change trace type', function(done) {
572665
var _mock = Lib.extendDeep({}, mock2);
573666
var sceneLayout = { aspectratio: { x: 1, y: 1, z: 1 } };

test/jasmine/tests/plot_api_react_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ describe('Test Plotly.react + interactions under uirevision:', function() {
18961896
var sceneLayout = gd._fullLayout.scene;
18971897
var cameraOld = sceneLayout.camera;
18981898
sceneLayout._scene.setCamera({
1899+
projection: {type: 'perspective'},
18991900
eye: {x: 2, y: 2, z: 2},
19001901
center: cameraOld.center,
19011902
up: cameraOld.up

0 commit comments

Comments
 (0)