-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtick_label_defaults.js
101 lines (84 loc) · 2.93 KB
/
tick_label_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
/**
* Copyright 2012-2018, 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 layoutAttributes = require('./layout_attributes');
module.exports = function handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options) {
var showAttrDflt = getShowAttrDflt(containerIn);
var tickPrefix = coerce('tickprefix');
if(tickPrefix) coerce('showtickprefix', showAttrDflt);
var tickSuffix = coerce('ticksuffix', options.tickSuffixDflt);
if(tickSuffix) coerce('showticksuffix', showAttrDflt);
var showTickLabels = coerce('showticklabels');
if(showTickLabels) {
var font = options.font || {};
// as with titlefont.color, inherit axis.color only if one was
// explicitly provided
var dfltFontColor = (containerOut.color === containerIn.color) ?
containerOut.color : font.color;
Lib.coerceFont(coerce, 'tickfont', {
family: font.family,
size: font.size,
color: dfltFontColor
});
coerce('tickangle');
if(axType !== 'category') {
var tickFormat = coerce('tickformat');
tickformatstopsDefaults(containerIn, containerOut);
if(!tickFormat && axType !== 'date') {
coerce('showexponent', showAttrDflt);
coerce('exponentformat');
coerce('separatethousands');
}
}
}
};
/*
* Attributes 'showexponent', 'showtickprefix' and 'showticksuffix'
* share values.
*
* If only 1 attribute is set,
* the remaining attributes inherit that value.
*
* If 2 attributes are set to the same value,
* the remaining attribute inherits that value.
*
* If 2 attributes are set to different values,
* the remaining is set to its dflt value.
*
*/
function getShowAttrDflt(containerIn) {
var showAttrsAll = ['showexponent',
'showtickprefix',
'showticksuffix'],
showAttrs = showAttrsAll.filter(function(a) {
return containerIn[a] !== undefined;
}),
sameVal = function(a) {
return containerIn[a] === containerIn[showAttrs[0]];
};
if(showAttrs.every(sameVal) || showAttrs.length === 1) {
return containerIn[showAttrs[0]];
}
}
function tickformatstopsDefaults(tickformatIn, tickformatOut) {
var valuesIn = tickformatIn.tickformatstops;
var valuesOut = tickformatOut.tickformatstops = [];
if(!Array.isArray(valuesIn)) return;
var valueIn, valueOut;
function coerce(attr, dflt) {
return Lib.coerce(valueIn, valueOut, layoutAttributes.tickformatstops, attr, dflt);
}
for(var i = 0; i < valuesIn.length; i++) {
valueIn = valuesIn[i];
valueOut = {};
coerce('dtickrange');
coerce('value');
valuesOut.push(valueOut);
}
}