-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
105 lines (86 loc) · 3.33 KB
/
defaults.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var Color = require('../../../components/color');
var handleSubplotDefaults = require('../../subplot_defaults');
var layoutAttributes = require('./layout_attributes');
var supplyGl3dAxisLayoutDefaults = require('./axis_defaults');
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
var hasNon3D = (
layoutOut._has('cartesian') ||
layoutOut._has('geo') ||
layoutOut._has('gl2d') ||
layoutOut._has('pie') ||
layoutOut._has('ternary')
);
// some layout-wide attribute are used in all scenes
// if 3D is the only visible plot type
function getDfltFromLayout(attr) {
if(hasNon3D) return;
var isValid = layoutAttributes[attr].values.indexOf(layoutIn[attr]) !== -1;
if(isValid) return layoutIn[attr];
}
handleSubplotDefaults(layoutIn, layoutOut, fullData, {
type: 'gl3d',
attributes: layoutAttributes,
handleDefaults: handleGl3dDefaults,
font: layoutOut.font,
fullData: fullData,
getDfltFromLayout: getDfltFromLayout,
paper_bgcolor: layoutOut.paper_bgcolor
});
};
function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) {
/*
* Scene numbering proceeds as follows
* scene
* scene2
* scene3
*
* and d.scene will be undefined or some number or number string
*
* Also write back a blank scene object to user layout so that some
* attributes like aspectratio can be written back dynamically.
*/
var bgcolor = coerce('bgcolor'),
bgColorCombined = Color.combine(bgcolor, opts.paper_bgcolor);
var cameraKeys = Object.keys(layoutAttributes.camera);
for(var j = 0; j < cameraKeys.length; j++) {
coerce('camera.' + cameraKeys[j] + '.x');
coerce('camera.' + cameraKeys[j] + '.y');
coerce('camera.' + cameraKeys[j] + '.z');
}
/*
* coerce to positive number (min 0) but also do not accept 0 (>0 not >=0)
* note that 0's go false with the !! call
*/
var hasAspect = !!coerce('aspectratio.x') &&
!!coerce('aspectratio.y') &&
!!coerce('aspectratio.z');
var defaultAspectMode = hasAspect ? 'manual' : 'auto';
var aspectMode = coerce('aspectmode', defaultAspectMode);
/*
* We need aspectratio object in all the Layouts as it is dynamically set
* in the calculation steps, ie, we cant set the correct data now, it happens later.
* We must also account for the case the user sends bad ratio data with 'manual' set
* for the mode. In this case we must force change it here as the default coerce
* misses it above.
*/
if(!hasAspect) {
sceneLayoutIn.aspectratio = sceneLayoutOut.aspectratio = {x: 1, y: 1, z: 1};
if(aspectMode === 'manual') sceneLayoutOut.aspectmode = 'auto';
}
supplyGl3dAxisLayoutDefaults(sceneLayoutIn, sceneLayoutOut, {
font: opts.font,
scene: opts.id,
data: opts.fullData,
bgColor: bgColorCombined
});
coerce('dragmode', opts.getDfltFromLayout('dragmode'));
coerce('hovermode', opts.getDfltFromLayout('hovermode'));
}