-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
118 lines (97 loc) · 3.87 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
112
113
114
115
116
117
118
/**
* 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 Lib = require('../../lib');
var hasColorscale = require('../../components/colorscale/helpers').hasColorscale;
var colorscaleDefaults = require('../../components/colorscale/defaults');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');
var Axes = require('../../plots/cartesian/axes');
var attributes = require('./attributes');
var axisBrush = require('./axisbrush');
var maxDimensionCount = require('./constants').maxDimensionCount;
var mergeLength = require('./merge_length');
function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var lineColor = coerce('line.color', defaultColor);
if(hasColorscale(traceIn, 'line') && Lib.isArrayOrTypedArray(lineColor)) {
if(lineColor.length) {
coerce('line.colorscale');
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
// TODO: I think it would be better to keep showing lines beyond the last line color
// but I'm not sure what color to give these lines - probably black or white
// depending on the background color?
return lineColor.length;
} else {
traceOut.line.color = defaultColor;
}
}
return Infinity;
}
function dimensionDefaults(dimensionIn, dimensionOut, parentOut, opts) {
function coerce(attr, dflt) {
return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);
}
var values = coerce('values');
var visible = coerce('visible');
if(!(values && values.length)) {
visible = dimensionOut.visible = false;
}
if(visible) {
coerce('label');
coerce('tickvals');
coerce('ticktext');
coerce('tickformat');
var range = coerce('range');
dimensionOut._ax = {
_id: 'y',
type: 'linear',
showexponent: 'all',
exponentformat: 'B',
range: range
};
Axes.setConvert(dimensionOut._ax, opts.layout);
coerce('multiselect');
var constraintRange = coerce('constraintrange');
if(constraintRange) {
dimensionOut.constraintrange = axisBrush.cleanRanges(constraintRange, dimensionOut);
}
}
}
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var dimensionsIn = traceIn.dimensions;
if(Array.isArray(dimensionsIn) && dimensionsIn.length > maxDimensionCount) {
Lib.log('parcoords traces support up to ' + maxDimensionCount + ' dimensions at the moment');
dimensionsIn.splice(maxDimensionCount);
}
var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {
name: 'dimensions',
layout: layout,
handleItemDefaults: dimensionDefaults
});
var len = handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
handleDomainDefaults(traceOut, layout, coerce);
if(!Array.isArray(dimensions) || !dimensions.length) {
traceOut.visible = false;
}
mergeLength(traceOut, dimensions, 'values', len);
// make default font size 10px (default is 12),
// scale linearly with global font size
var fontDflt = {
family: layout.font.family,
size: Math.round(layout.font.size / 1.2),
color: layout.font.color
};
Lib.coerceFont(coerce, 'labelfont', fontDflt);
Lib.coerceFont(coerce, 'tickfont', fontDflt);
Lib.coerceFont(coerce, 'rangefont', fontDflt);
coerce('labelangle');
coerce('labelside');
};