|
9 | 9 |
|
10 | 10 | 'use strict';
|
11 | 11 |
|
12 |
| -var Lib = require('../../../lib'); |
13 |
| -var Plots = require('../../plots'); |
| 12 | +var handleSubplotDefaults = require('../../subplot_defaults'); |
14 | 13 | var layoutAttributes = require('./layout_attributes');
|
15 | 14 | var supplyGl3dAxisLayoutDefaults = require('./axis_defaults');
|
16 | 15 |
|
17 | 16 |
|
18 | 17 | module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
|
19 | 18 | if(!layoutOut._hasGL3D) return;
|
20 | 19 |
|
21 |
| - var scenes = Plots.findSubplotIds(fullData, 'gl3d'), |
22 |
| - scenesLength = scenes.length; |
23 |
| - |
24 |
| - var sceneLayoutIn, sceneLayoutOut; |
25 |
| - |
26 |
| - function coerce(attr, dflt) { |
27 |
| - return Lib.coerce(sceneLayoutIn, sceneLayoutOut, layoutAttributes, attr, dflt); |
28 |
| - } |
| 20 | + var hasNon3D = ( |
| 21 | + layoutOut._hasCartesian || |
| 22 | + layoutOut._hasGeo || |
| 23 | + layoutOut._hasGL2D || |
| 24 | + layoutOut._hasPie || |
| 25 | + layoutOut._hasTernary |
| 26 | + ); |
29 | 27 |
|
30 | 28 | // some layout-wide attribute are used in all scenes
|
31 | 29 | // if 3D is the only visible plot type
|
32 | 30 | function getDfltFromLayout(attr) {
|
33 |
| - var isOnlyGL3D = !( |
34 |
| - layoutOut._hasCartesian || |
35 |
| - layoutOut._hasGeo || |
36 |
| - layoutOut._hasGL2D || |
37 |
| - layoutOut._hasPie |
38 |
| - ); |
| 31 | + if(hasNon3D) return; |
39 | 32 |
|
40 | 33 | var isValid = layoutAttributes[attr].values.indexOf(layoutIn[attr]) !== -1;
|
| 34 | + if(isValid) return layoutIn[attr]; |
| 35 | + } |
41 | 36 |
|
42 |
| - if(isOnlyGL3D && isValid) return layoutIn[attr]; |
| 37 | + handleSubplotDefaults(layoutIn, layoutOut, fullData, { |
| 38 | + type: 'gl3d', |
| 39 | + attributes: layoutAttributes, |
| 40 | + handleDefaults: handleGl3dDefaults, |
| 41 | + font: layoutOut.font, |
| 42 | + fullData: fullData, |
| 43 | + getDfltFromLayout: getDfltFromLayout |
| 44 | + }); |
| 45 | +}; |
| 46 | + |
| 47 | +function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) { |
| 48 | + /* |
| 49 | + * Scene numbering proceeds as follows |
| 50 | + * scene |
| 51 | + * scene2 |
| 52 | + * scene3 |
| 53 | + * |
| 54 | + * and d.scene will be undefined or some number or number string |
| 55 | + * |
| 56 | + * Also write back a blank scene object to user layout so that some |
| 57 | + * attributes like aspectratio can be written back dynamically. |
| 58 | + */ |
| 59 | + |
| 60 | + coerce('bgcolor'); |
| 61 | + |
| 62 | + var cameraKeys = Object.keys(layoutAttributes.camera); |
| 63 | + |
| 64 | + for(var j = 0; j < cameraKeys.length; j++) { |
| 65 | + coerce('camera.' + cameraKeys[j] + '.x'); |
| 66 | + coerce('camera.' + cameraKeys[j] + '.y'); |
| 67 | + coerce('camera.' + cameraKeys[j] + '.z'); |
43 | 68 | }
|
44 | 69 |
|
45 |
| - for(var i = 0; i < scenesLength; i++) { |
46 |
| - var scene = scenes[i]; |
47 |
| - |
48 |
| - /* |
49 |
| - * Scene numbering proceeds as follows |
50 |
| - * scene |
51 |
| - * scene2 |
52 |
| - * scene3 |
53 |
| - * |
54 |
| - * and d.scene will be undefined or some number or number string |
55 |
| - * |
56 |
| - * Also write back a blank scene object to user layout so that some |
57 |
| - * attributes like aspectratio can be written back dynamically. |
58 |
| - */ |
59 |
| - |
60 |
| - // gl3d traces get a layout scene for free! |
61 |
| - if(layoutIn[scene]) sceneLayoutIn = layoutIn[scene]; |
62 |
| - else layoutIn[scene] = sceneLayoutIn = {}; |
63 |
| - |
64 |
| - sceneLayoutOut = layoutOut[scene] || {}; |
65 |
| - |
66 |
| - coerce('bgcolor'); |
67 |
| - |
68 |
| - var cameraKeys = Object.keys(layoutAttributes.camera); |
69 |
| - |
70 |
| - for(var j = 0; j < cameraKeys.length; j++) { |
71 |
| - coerce('camera.' + cameraKeys[j] + '.x'); |
72 |
| - coerce('camera.' + cameraKeys[j] + '.y'); |
73 |
| - coerce('camera.' + cameraKeys[j] + '.z'); |
74 |
| - } |
75 |
| - |
76 |
| - coerce('domain.x', [i / scenesLength, (i+1) / scenesLength]); |
77 |
| - coerce('domain.y'); |
78 |
| - |
79 |
| - /* |
80 |
| - * coerce to positive number (min 0) but also do not accept 0 (>0 not >=0) |
81 |
| - * note that 0's go false with the !! call |
82 |
| - */ |
83 |
| - var hasAspect = !!coerce('aspectratio.x') && |
84 |
| - !!coerce('aspectratio.y') && |
85 |
| - !!coerce('aspectratio.z'); |
86 |
| - |
87 |
| - var defaultAspectMode = hasAspect ? 'manual' : 'auto'; |
88 |
| - var aspectMode = coerce('aspectmode', defaultAspectMode); |
89 |
| - |
90 |
| - /* |
91 |
| - * We need aspectratio object in all the Layouts as it is dynamically set |
92 |
| - * in the calculation steps, ie, we cant set the correct data now, it happens later. |
93 |
| - * We must also account for the case the user sends bad ratio data with 'manual' set |
94 |
| - * for the mode. In this case we must force change it here as the default coerce |
95 |
| - * misses it above. |
96 |
| - */ |
97 |
| - if(!hasAspect) { |
98 |
| - sceneLayoutIn.aspectratio = sceneLayoutOut.aspectratio = {x: 1, y: 1, z: 1}; |
99 |
| - |
100 |
| - if(aspectMode === 'manual') sceneLayoutOut.aspectmode = 'auto'; |
101 |
| - } |
102 |
| - |
103 |
| - /* |
104 |
| - * scene arrangements need to be implemented: For now just splice |
105 |
| - * along the horizontal direction. ie. |
106 |
| - * x:[0,1] -> x:[0,0.5], x:[0.5,1] -> |
107 |
| - * x:[0, 0.333] x:[0.333,0.666] x:[0.666, 1] |
108 |
| - */ |
109 |
| - supplyGl3dAxisLayoutDefaults(sceneLayoutIn, sceneLayoutOut, { |
110 |
| - font: layoutOut.font, |
111 |
| - scene: scene, |
112 |
| - data: fullData |
113 |
| - }); |
114 |
| - |
115 |
| - coerce('dragmode', getDfltFromLayout('dragmode')); |
116 |
| - coerce('hovermode', getDfltFromLayout('hovermode')); |
117 |
| - |
118 |
| - layoutOut[scene] = sceneLayoutOut; |
| 70 | + /* |
| 71 | + * coerce to positive number (min 0) but also do not accept 0 (>0 not >=0) |
| 72 | + * note that 0's go false with the !! call |
| 73 | + */ |
| 74 | + var hasAspect = !!coerce('aspectratio.x') && |
| 75 | + !!coerce('aspectratio.y') && |
| 76 | + !!coerce('aspectratio.z'); |
| 77 | + |
| 78 | + var defaultAspectMode = hasAspect ? 'manual' : 'auto'; |
| 79 | + var aspectMode = coerce('aspectmode', defaultAspectMode); |
| 80 | + |
| 81 | + /* |
| 82 | + * We need aspectratio object in all the Layouts as it is dynamically set |
| 83 | + * in the calculation steps, ie, we cant set the correct data now, it happens later. |
| 84 | + * We must also account for the case the user sends bad ratio data with 'manual' set |
| 85 | + * for the mode. In this case we must force change it here as the default coerce |
| 86 | + * misses it above. |
| 87 | + */ |
| 88 | + if(!hasAspect) { |
| 89 | + sceneLayoutIn.aspectratio = sceneLayoutOut.aspectratio = {x: 1, y: 1, z: 1}; |
| 90 | + |
| 91 | + if(aspectMode === 'manual') sceneLayoutOut.aspectmode = 'auto'; |
119 | 92 | }
|
120 |
| -}; |
| 93 | + |
| 94 | + supplyGl3dAxisLayoutDefaults(sceneLayoutIn, sceneLayoutOut, { |
| 95 | + font: opts.font, |
| 96 | + scene: opts.id, |
| 97 | + data: opts.fullData |
| 98 | + }); |
| 99 | + |
| 100 | + coerce('dragmode', opts.getDfltFromLayout('dragmode')); |
| 101 | + coerce('hovermode', opts.getDfltFromLayout('hovermode')); |
| 102 | +} |
0 commit comments