-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathlayout_defaults.js
122 lines (100 loc) · 4.43 KB
/
layout_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
119
120
121
122
'use strict';
var Color = require('../../components/color');
var Template = require('../../plot_api/plot_template');
var Lib = require('../../lib');
var handleSubplotDefaults = require('../subplot_defaults');
var handleTickLabelDefaults = require('../cartesian/tick_label_defaults');
var handleTickMarkDefaults = require('../cartesian/tick_mark_defaults');
var handleTickValueDefaults = require('../cartesian/tick_value_defaults');
var handleLineGridDefaults = require('../cartesian/line_grid_defaults');
var layoutAttributes = require('./layout_attributes');
var axesNames = ['aaxis', 'baxis', 'caxis'];
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
handleSubplotDefaults(layoutIn, layoutOut, fullData, {
type: 'ternary',
attributes: layoutAttributes,
handleDefaults: handleTernaryDefaults,
font: layoutOut.font,
paper_bgcolor: layoutOut.paper_bgcolor
});
};
function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, options) {
var bgColor = coerce('bgcolor');
var sum = coerce('sum');
options.bgColor = Color.combine(bgColor, options.paper_bgcolor);
var axName, containerIn, containerOut;
// TODO: allow most (if not all) axis attributes to be set
// in the outer container and used as defaults in the individual axes?
for(var j = 0; j < axesNames.length; j++) {
axName = axesNames[j];
containerIn = ternaryLayoutIn[axName] || {};
containerOut = Template.newContainer(ternaryLayoutOut, axName);
containerOut._name = axName;
handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut);
}
// if the min values contradict each other, set them all to default (0)
// and delete *all* the inputs so the user doesn't get confused later by
// changing one and having them all change.
var aaxis = ternaryLayoutOut.aaxis;
var baxis = ternaryLayoutOut.baxis;
var caxis = ternaryLayoutOut.caxis;
if(aaxis.min + baxis.min + caxis.min >= sum) {
aaxis.min = 0;
baxis.min = 0;
caxis.min = 0;
if(ternaryLayoutIn.aaxis) delete ternaryLayoutIn.aaxis.min;
if(ternaryLayoutIn.baxis) delete ternaryLayoutIn.baxis.min;
if(ternaryLayoutIn.caxis) delete ternaryLayoutIn.caxis.min;
}
}
function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut) {
var axAttrs = layoutAttributes[containerOut._name];
function coerce(attr, dflt) {
return Lib.coerce(containerIn, containerOut, axAttrs, attr, dflt);
}
coerce('uirevision', ternaryLayoutOut.uirevision);
containerOut.type = 'linear'; // no other types allowed for ternary
var dfltColor = coerce('color');
// if axis.color was provided, use it for fonts too; otherwise,
// inherit from global font color in case that was provided.
var dfltFontColor = (dfltColor !== axAttrs.color.dflt) ? dfltColor : options.font.color;
var axName = containerOut._name;
var letterUpper = axName.charAt(0).toUpperCase();
var dfltTitle = 'Component ' + letterUpper;
var title = coerce('title.text', dfltTitle);
containerOut._hovertitle = title === dfltTitle ? title : letterUpper;
Lib.coerceFont(coerce, 'title.font', {
family: options.font.family,
size: Lib.bigFont(options.font.size),
color: dfltFontColor
});
// range is just set by 'min' - max is determined by the other axes mins
coerce('min');
handleTickValueDefaults(containerIn, containerOut, coerce, 'linear');
handleTickLabelDefaults(containerIn, containerOut, coerce, 'linear', {});
handleTickMarkDefaults(containerIn, containerOut, coerce,
{ outerTicks: true });
var showTickLabels = coerce('showticklabels');
if(showTickLabels) {
Lib.coerceFont(coerce, 'tickfont', {
family: options.font.family,
size: options.font.size,
color: dfltFontColor
});
coerce('tickangle');
coerce('tickformat');
}
handleLineGridDefaults(containerIn, containerOut, coerce, {
dfltColor: dfltColor,
bgColor: options.bgColor,
// default grid color is darker here (60%, vs cartesian default ~91%)
// because the grid is not square so the eye needs heavier cues to follow
blend: 60,
showLine: true,
showGrid: true,
noZeroLine: true,
attributes: axAttrs
});
coerce('hoverformat');
coerce('layer');
}