-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
97 lines (75 loc) · 2.67 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
/**
* Copyright 2012-2017, 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 Lib = require('../../lib');
var Registry = require('../../registry');
var Color = require('../../components/color');
var attributes = require('./attributes');
function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;
coerce('line.color', (traceIn.marker || {}).color || defaultColor);
coerce('line.width');
coerce('fillcolor', Color.addOpacity(traceOut.line.color, 0.5));
coerce('whiskerwidth');
coerce('boxmean');
handlePointsDefaults(traceIn, traceOut, coerce, {prefix: 'box'});
}
function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
var y = coerce('y');
var x = coerce('x');
var defaultOrientation;
if(y && y.length) {
defaultOrientation = 'v';
if(!x) coerce('x0');
} else if(x && x.length) {
defaultOrientation = 'h';
coerce('y0');
} else {
traceOut.visible = false;
return;
}
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
coerce('orientation', defaultOrientation);
}
function handlePointsDefaults(traceIn, traceOut, coerce, opts) {
var prefix = opts.prefix;
var outlierColorDflt = Lib.coerce2(traceIn, traceOut, attributes, 'marker.outliercolor');
var lineoutliercolor = coerce('marker.line.outliercolor');
var points = coerce(
prefix + 'points',
(outlierColorDflt || lineoutliercolor) ? 'suspectedoutliers' : undefined
);
if(points) {
coerce('jitter', points === 'all' ? 0.3 : 0);
coerce('pointpos', points === 'all' ? -1.5 : 0);
coerce('marker.symbol');
coerce('marker.opacity');
coerce('marker.size');
coerce('marker.color', traceOut.line.color);
coerce('marker.line.color');
coerce('marker.line.width');
if(points === 'suspectedoutliers') {
coerce('marker.line.outliercolor', traceOut.marker.color);
coerce('marker.line.outlierwidth');
}
coerce('text');
} else {
delete traceOut.marker;
}
coerce('hoveron');
}
module.exports = {
supplyDefaults: supplyDefaults,
handleSampleDefaults: handleSampleDefaults,
handlePointsDefaults: handlePointsDefaults
};