-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathconstraint_defaults.js
92 lines (76 loc) · 2.77 KB
/
constraint_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
/**
* Copyright 2012-2019, 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 isNumeric = require('fast-isnumeric');
var handleLabelDefaults = require('./label_defaults');
var Color = require('../../components/color');
var addOpacity = Color.addOpacity;
var opacity = Color.opacity;
var filterOps = require('../../constants/filter_ops');
var CONSTRAINT_REDUCTION = filterOps.CONSTRAINT_REDUCTION;
var COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;
module.exports = function handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor, opts) {
var contours = traceOut.contours;
var showLines, lineColor, fillColor;
var operation = coerce('contours.operation');
contours._operation = CONSTRAINT_REDUCTION[operation];
handleConstraintValueDefaults(coerce, contours);
if(operation === '=') {
showLines = contours.showlines = true;
} else {
showLines = coerce('contours.showlines');
fillColor = coerce('fillcolor', addOpacity(
(traceIn.line || {}).color || defaultColor, 0.5
));
}
if(showLines) {
var lineDfltColor = fillColor && opacity(fillColor) ?
addOpacity(traceOut.fillcolor, 1) :
defaultColor;
lineColor = coerce('line.color', lineDfltColor);
coerce('line.width', 2);
coerce('line.dash');
}
coerce('line.smoothing');
handleLabelDefaults(coerce, layout, lineColor, opts);
};
function handleConstraintValueDefaults(coerce, contours) {
var zvalue;
if(COMPARISON_OPS2.indexOf(contours.operation) === -1) {
// Requires an array of two numbers:
coerce('contours.value', [0, 1]);
if(!Array.isArray(contours.value)) {
if(isNumeric(contours.value)) {
zvalue = parseFloat(contours.value);
contours.value = [zvalue, zvalue + 1];
}
} else if(contours.value.length > 2) {
contours.value = contours.value.slice(2);
} else if(contours.length === 0) {
contours.value = [0, 1];
} else if(contours.length < 2) {
zvalue = parseFloat(contours.value[0]);
contours.value = [zvalue, zvalue + 1];
} else {
contours.value = [
parseFloat(contours.value[0]),
parseFloat(contours.value[1])
];
}
} else {
// Requires a single scalar:
coerce('contours.value', 0);
if(!isNumeric(contours.value)) {
if(Array.isArray(contours.value)) {
contours.value = parseFloat(contours.value[0]);
} else {
contours.value = 0;
}
}
}
}