-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
59 lines (50 loc) · 2.36 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
'use strict';
var Lib = require('../../lib');
var handleXYZDefaults = require('../heatmap/xyz_defaults');
var attributes = require('./attributes');
var handleConstraintDefaults = require('../contour/constraint_defaults');
var handleContoursDefaults = require('../contour/contours_defaults');
var handleStyleDefaults = require('../contour/style_defaults');
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
function coerce2(attr) {
return Lib.coerce2(traceIn, traceOut, attributes, attr);
}
coerce('carpet');
// If either a or b is not present, then it's not a valid trace *unless* the carpet
// axis has the a or b values we're looking for. So if these are not found, just defer
// that decision until the calc step.
//
// NB: the calc step will modify the original data input by assigning whichever of
// a or b are missing. This is necessary because panning goes right from supplyDefaults
// to plot (skipping calc). That means on subsequent updates, this *will* need to be
// able to find a and b.
//
// The long-term proper fix is that this should perhaps use underscored attributes to
// at least modify the user input to a slightly lesser extent. Fully removing the
// input mutation is challenging. The underscore approach is not currently taken since
// it requires modification to all of the functions below that expect the coerced
// attribute name to match the property name -- except '_a' !== 'a' so that is not
// straightforward.
if(traceIn.a && traceIn.b) {
var len = handleXYZDefaults(traceIn, traceOut, coerce, layout, 'a', 'b');
if(!len) {
traceOut.visible = false;
return;
}
coerce('text');
var isConstraint = (coerce('contours.type') === 'constraint');
if(isConstraint) {
handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor, {hasHover: false});
} else {
handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});
}
} else {
traceOut._defaultColor = defaultColor;
traceOut._length = null;
}
coerce('zindex');
};