Skip to content

Commit 3c383d7

Browse files
committed
add gl3d plot index + register it in plotly.js + remove Gl3dLayout
1 parent d5e894d commit 3c383d7

File tree

7 files changed

+138
-111
lines changed

7 files changed

+138
-111
lines changed

src/plot_api/plot_api.js

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -418,41 +418,6 @@ function setPlotContext(gd, config) {
418418
}
419419
}
420420

421-
function plotGl3d(gd) {
422-
var fullLayout = gd._fullLayout,
423-
fullData = gd._fullData,
424-
sceneIds = plots.getSubplotIds(fullLayout, 'gl3d');
425-
426-
var i, sceneId, fullSceneData, scene, sceneOptions;
427-
428-
fullLayout._paperdiv.style({
429-
width: fullLayout.width + 'px',
430-
height: fullLayout.height + 'px'
431-
});
432-
433-
gd._context.setBackground(gd, fullLayout.paper_bgcolor);
434-
435-
for (i = 0; i < sceneIds.length; i++) {
436-
sceneId = sceneIds[i];
437-
fullSceneData = plots.getSubplotData(fullData, 'gl3d', sceneId);
438-
scene = fullLayout[sceneId]._scene; // ref. to corresp. Scene instance
439-
440-
// If Scene is not instantiated, create one!
441-
if(scene === undefined) {
442-
sceneOptions = {
443-
container: gd.querySelector('.gl-container'),
444-
id: sceneId,
445-
staticPlot: gd._context.staticPlot,
446-
plotGlPixelRatio: gd._context.plotGlPixelRatio
447-
};
448-
scene = new Plotly.Scene(sceneOptions, fullLayout);
449-
fullLayout[sceneId]._scene = scene; // set ref to Scene instance
450-
}
451-
452-
scene.plot(fullSceneData, fullLayout, gd.layout); // takes care of business
453-
}
454-
}
455-
456421
function plotGeo(gd) {
457422
var fullLayout = gd._fullLayout,
458423
fullData = gd._fullData,
@@ -866,8 +831,9 @@ function cleanData(data, existingData) {
866831
if(trace.yaxis) trace.yaxis = Plotly.Axes.cleanId(trace.yaxis, 'y');
867832

868833
// scene ids scene1 -> scene
869-
if (trace.scene) {
870-
trace.scene = Plotly.Gl3dLayout.cleanId(trace.scene);
834+
var plotRegistry = plots.subplotsRegistry;
835+
if(trace.scene && plotRegistry.gl3d) {
836+
trace.scene = plotRegistry.gl3d.cleanId(trace.scene);
871837
}
872838

873839
if(!plots.traceIs(trace, 'pie')) {
@@ -2593,10 +2559,11 @@ function makePlotFramework(gd) {
25932559
var gd3 = d3.select(gd),
25942560
fullLayout = gd._fullLayout;
25952561

2596-
/*
2597-
* TODO - find a better place for 3D to initialize axes
2598-
*/
2599-
if(fullLayout._hasGL3D) Plotly.Gl3dLayout.initAxes(gd);
2562+
// TODO - find a better place for 3D to initialize axes
2563+
var plotRegistry = plots.subplotsRegistry;
2564+
if(fullLayout._hasGL3D && plotRegistry.gl3d) {
2565+
plotRegistry.gl3d.initAxes(gd);
2566+
}
26002567

26012568
// Plot container
26022569
fullLayout._container = gd3.selectAll('.plot-container').data([0]);

src/plots/gl3d/index.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
var Plotly = require('../../plotly');
13+
14+
var Scene = require('./scene');
15+
16+
var plots = Plotly.Plots;
17+
var axesNames = ['xaxis', 'yaxis', 'zaxis'];
18+
19+
20+
exports.type = 'gl3d';
21+
22+
exports.attr = 'scene';
23+
24+
exports.idRoot = 'scene';
25+
26+
exports.attributes = require('./layout/attributes');
27+
28+
exports.layoutAttributes = require('./layout/layout_attributes');
29+
30+
exports.supplyLayoutDefaults = require('./layout/defaults');
31+
32+
exports.plot = function plotGl3d(gd) {
33+
var fullLayout = gd._fullLayout,
34+
fullData = gd._fullData,
35+
sceneIds = plots.getSubplotIds(fullLayout, 'gl3d');
36+
37+
fullLayout._paperdiv.style({
38+
width: fullLayout.width + 'px',
39+
height: fullLayout.height + 'px'
40+
});
41+
42+
gd._context.setBackground(gd, fullLayout.paper_bgcolor);
43+
44+
for(var i = 0; i < sceneIds.length; i++) {
45+
var sceneId = sceneIds[i],
46+
fullSceneData = plots.getSubplotData(fullData, 'gl3d', sceneId),
47+
scene = fullLayout[sceneId]._scene; // ref. to corresp. Scene instance
48+
49+
// If Scene is not instantiated, create one!
50+
if(scene === undefined) {
51+
scene = new Scene({
52+
container: gd.querySelector('.gl-container'),
53+
id: sceneId,
54+
staticPlot: gd._context.staticPlot,
55+
plotGlPixelRatio: gd._context.plotGlPixelRatio
56+
}, fullLayout
57+
);
58+
59+
fullLayout[sceneId]._scene = scene; // set ref to Scene instance
60+
}
61+
62+
scene.plot(fullSceneData, fullLayout, gd.layout); // takes care of business
63+
}
64+
};
65+
66+
// clean scene ids, 'scene1' -> 'scene'
67+
exports.cleanId = function cleanId(id) {
68+
if (!id.match(/^scene[0-9]*$/)) return;
69+
70+
var sceneNum = id.substr(5);
71+
if (sceneNum === '1') sceneNum = '';
72+
73+
return 'scene' + sceneNum;
74+
};
75+
76+
exports.setConvert = require('./set_convert');
77+
78+
exports.initAxes = function (gd) {
79+
var fullLayout = gd._fullLayout;
80+
81+
// until they play better together
82+
delete fullLayout.xaxis;
83+
delete fullLayout.yaxis;
84+
85+
var sceneIds = Plotly.Plots.getSubplotIds(fullLayout, 'gl3d');
86+
87+
for(var i = 0; i < sceneIds.length; ++i) {
88+
var sceneId = sceneIds[i];
89+
var sceneLayout = fullLayout[sceneId];
90+
91+
for(var j = 0; j < 3; ++j) {
92+
var axisName = axesNames[j];
93+
var ax = sceneLayout[axisName];
94+
ax._td = gd;
95+
}
96+
}
97+
};

src/plots/gl3d/layout/index.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/plots/gl3d/scene.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@
1313
var Plotly = require('../../plotly');
1414
var createPlot = require('gl-plot3d');
1515

16-
var createAxesOptions = require('./layout/convert');
17-
var createSpikeOptions = require('./layout/spikes');
18-
var computeTickMarks = require('./layout/tick_marks');
19-
2016
var createScatterTrace = require('../../traces/scatter3d/convert');
2117
var createSurfaceTrace = require('../../traces/surface/convert');
2218
var createMeshTrace = require('../../traces/mesh3d/convert');
19+
var str2RGBAarray = require('../../lib/str2rgbarray');
20+
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');
2321

2422
var createCamera = require('./camera');
2523
var project = require('./project');
26-
27-
var str2RGBAarray = require('../../lib/str2rgbarray');
28-
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');
24+
var setConvert = require('./set_convert');
25+
var createAxesOptions = require('./layout/convert');
26+
var createSpikeOptions = require('./layout/spikes');
27+
var computeTickMarks = require('./layout/tick_marks');
2928

3029
var STATIC_CANVAS, STATIC_CONTEXT;
3130

@@ -310,7 +309,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
310309
// Update axes functions BEFORE updating traces
311310
for (i = 0; i < 3; ++i) {
312311
var axis = fullSceneLayout[axisProperties[i]];
313-
Plotly.Gl3dLayout.setConvert(axis);
312+
setConvert(axis);
314313
}
315314

316315
//Convert scene data
@@ -536,7 +535,7 @@ proto.destroy = function() {
536535

537536
// for reset camera button in mode bar
538537
proto.setCameraToDefault = function setCameraToDefault () {
539-
// as in Gl3dLayout.layoutAttributes
538+
// as in Gl3d.layoutAttributes
540539
this.glplot.camera.lookAt(
541540
[1.25, 1.25, 1.25],
542541
[0 , 0 , 0 ],

src/plots/gl3d/set_convert.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
var Plotly = require('../../plotly');
13+
14+
var noop = function () {};
15+
16+
17+
module.exports = function setConvert(containerOut) {
18+
Plotly.Axes.setConvert(containerOut);
19+
containerOut.setScale = noop;
20+
};

src/plots/layout_attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ module.exports = {
195195
_nestedModules: {
196196
'xaxis': 'Axes',
197197
'yaxis': 'Axes',
198-
'scene': 'Gl3dLayout',
198+
'scene': 'gl3d',
199199
'geo': 'geo',
200200
'legend': 'Legend',
201201
'annotations': 'Annotations',

test/jasmine/tests/gl3dlayout_test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
var Plotly = require('@src/plotly');
1+
var Gl3d = require('@src/plots/gl3d');
22

3-
describe('Test Gl3dLayout', function () {
3+
4+
describe('Test Gl3d layout defaults', function () {
45
'use strict';
56

67
describe('supplyLayoutDefaults', function() {
78
var layoutIn,
89
layoutOut;
910

10-
var supplyLayoutDefaults = Plotly.Gl3dLayout.supplyLayoutDefaults;
11+
var supplyLayoutDefaults = Gl3d.supplyLayoutDefaults;
1112

1213
beforeEach(function() {
1314
layoutOut = {

0 commit comments

Comments
 (0)