-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
50 lines (42 loc) · 1.43 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
'use strict';
var Lib = require('../../lib');
var attributes = require('./attributes');
var constants = require('./constants');
var dataUri = require('../../snapshot/helpers').IMAGE_URL_PREFIX;
module.exports = function supplyDefaults(traceIn, traceOut) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
coerce('source');
// sanitize source to only allow for data URI representing images
if(traceOut.source && !traceOut.source.match(dataUri)) delete traceOut.source;
traceOut._hasSource = !!traceOut.source;
var z = coerce('z');
traceOut._hasZ = !(z === undefined || !z.length || !z[0] || !z[0].length);
if(!traceOut._hasZ && !traceOut._hasSource) {
traceOut.visible = false;
return;
}
coerce('x0');
coerce('y0');
coerce('dx');
coerce('dy');
var cm;
if(traceOut._hasZ) {
coerce('colormodel', 'rgb');
cm = constants.colormodel[traceOut.colormodel];
coerce('zmin', (cm.zminDflt || cm.min));
coerce('zmax', (cm.zmaxDflt || cm.max));
} else if(traceOut._hasSource) {
traceOut.colormodel = 'rgba256';
cm = constants.colormodel[traceOut.colormodel];
traceOut.zmin = cm.zminDflt;
traceOut.zmax = cm.zmaxDflt;
}
coerce('zsmooth');
coerce('text');
coerce('hovertext');
coerce('hovertemplate');
traceOut._length = null;
coerce('zindex');
};