TimelineAxis.js
2.67 KB
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
define(function (require) {
var zrUtil = require('zrender/core/util');
var Axis = require('../../coord/Axis');
var axisHelper = require('../../coord/axisHelper');
/**
* Extend axis 2d
* @constructor module:echarts/coord/cartesian/Axis2D
* @extends {module:echarts/coord/cartesian/Axis}
* @param {string} dim
* @param {*} scale
* @param {Array.<number>} coordExtent
* @param {string} axisType
* @param {string} position
*/
var TimelineAxis = function (dim, scale, coordExtent, axisType) {
Axis.call(this, dim, scale, coordExtent);
/**
* Axis type
* - 'category'
* - 'value'
* - 'time'
* - 'log'
* @type {string}
*/
this.type = axisType || 'value';
/**
* @private
* @type {number}
*/
this._autoLabelInterval;
/**
* Axis model
* @param {module:echarts/component/TimelineModel}
*/
this.model = null;
};
TimelineAxis.prototype = {
constructor: TimelineAxis,
/**
* @public
* @return {number}
*/
getLabelInterval: function () {
var timelineModel = this.model;
var labelModel = timelineModel.getModel('label.normal');
var labelInterval = labelModel.get('interval');
if (labelInterval != null && labelInterval != 'auto') {
return labelInterval;
}
var labelInterval = this._autoLabelInterval;
if (!labelInterval) {
labelInterval = this._autoLabelInterval = axisHelper.getAxisLabelInterval(
zrUtil.map(this.scale.getTicks(), this.dataToCoord, this),
axisHelper.getFormattedLabels(this, labelModel.get('formatter')),
labelModel.getModel('textStyle').getFont(),
timelineModel.get('orient') === 'horizontal'
);
}
return labelInterval;
},
/**
* If label is ignored.
* Automatically used when axis is category and label can not be all shown
* @public
* @param {number} idx
* @return {boolean}
*/
isLabelIgnored: function (idx) {
if (this.type === 'category') {
var labelInterval = this.getLabelInterval();
return ((typeof labelInterval === 'function')
&& !labelInterval(idx, this.scale.getLabel(idx)))
|| idx % (labelInterval + 1);
}
}
};
zrUtil.inherits(TimelineAxis, Axis);
return TimelineAxis;
});