|
| 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 | +}; |
0 commit comments