-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtick_value_defaults.js
47 lines (41 loc) · 1.78 KB
/
tick_value_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
'use strict';
var cleanTicks = require('./clean_ticks');
var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;
var isTypedArraySpec = require('../../lib/array').isTypedArraySpec;
var decodeTypedArraySpec = require('../../lib/array').decodeTypedArraySpec;
module.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType, opts) {
if(!opts) opts = {};
var isMinor = opts.isMinor;
var cIn = isMinor ? containerIn.minor || {} : containerIn;
var cOut = isMinor ? containerOut.minor : containerOut;
var prefix = isMinor ? 'minor.' : '';
function readInput(attr) {
var v = cIn[attr];
if(isTypedArraySpec(v)) v = decodeTypedArraySpec(v);
return (
v !== undefined
) ? v : (cOut._template || {})[attr];
}
var _tick0 = readInput('tick0');
var _dtick = readInput('dtick');
var _tickvals = readInput('tickvals');
var tickmodeDefault = isArrayOrTypedArray(_tickvals) ? 'array' :
_dtick ? 'linear' :
'auto';
var tickmode = coerce(prefix + 'tickmode', tickmodeDefault);
if(tickmode === 'auto' || tickmode === 'sync' || tickmode === 'full domain') {
coerce(prefix + 'nticks');
} else if(tickmode === 'linear') {
// dtick is usually a positive number, but there are some
// special strings available for log or date axes
// tick0 also has special logic
var dtick = cOut.dtick = cleanTicks.dtick(
_dtick, axType);
cOut.tick0 = cleanTicks.tick0(
_tick0, axType, containerOut.calendar, dtick);
} else if(axType !== 'multicategory') {
var tickvals = coerce(prefix + 'tickvals');
if(tickvals === undefined) cOut.tickmode = 'auto';
else if(!isMinor) coerce('ticktext');
}
};