-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
111 lines (85 loc) · 2.93 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
106
107
108
109
110
111
/**
* Copyright 2012-2018, 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 Registry = require('../../registry');
var Lib = require('../../lib');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
var i, j;
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var z = coerce('z');
if(!z) {
traceOut.visible = false;
return;
}
var x = coerce('x');
coerce('y');
traceOut._xlength = (Array.isArray(x) && Lib.isArrayOrTypedArray(x[0])) ? z.length : z[0].length;
traceOut._ylength = z.length;
traceOut._objectOffset = [0, 0, 0];
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
coerce('text');
// Coerce remaining properties
[
'lighting.ambient',
'lighting.diffuse',
'lighting.specular',
'lighting.roughness',
'lighting.fresnel',
'lightposition.x',
'lightposition.y',
'lightposition.z',
'hidesurface',
'opacity'
].forEach(function(x) { coerce(x); });
var surfaceColor = coerce('surfacecolor');
coerce('colorscale');
var dims = ['x', 'y', 'z'];
for(i = 0; i < 3; ++i) {
var contourDim = 'contours.' + dims[i];
var show = coerce(contourDim + '.show');
var highlight = coerce(contourDim + '.highlight');
if(show || highlight) {
for(j = 0; j < 3; ++j) {
coerce(contourDim + '.project.' + dims[j]);
}
}
if(show) {
coerce(contourDim + '.color');
coerce(contourDim + '.width');
coerce(contourDim + '.usecolormap');
}
if(highlight) {
coerce(contourDim + '.highlightcolor');
coerce(contourDim + '.highlightwidth');
}
}
// backward compatibility block
if(!surfaceColor) {
mapLegacy(traceIn, 'zmin', 'cmin');
mapLegacy(traceIn, 'zmax', 'cmax');
mapLegacy(traceIn, 'zauto', 'cauto');
}
// TODO if contours.?.usecolormap are false and hidesurface is true
// the colorbar shouldn't be shown by default
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'}
);
// disable 1D transforms - currently surface does NOT support column data like heatmap does
// you can use mesh3d for this use case, but not surface
traceOut._length = null;
};
function mapLegacy(traceIn, oldAttr, newAttr) {
if(oldAttr in traceIn && !(newAttr in traceIn)) {
traceIn[newAttr] = traceIn[oldAttr];
}
}