Time.html
4.8 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-chart-axis-Time'>/**
</span> * A type of axis whose units are measured in time values. Use this axis
* for listing dates that you will want to group or dynamically change.
* If you just want to display dates as categories then use the
* Category class for axis instead.
*
* For example:
*
* axes: [{
* type: 'Time',
* position: 'bottom',
* fields: 'date',
* title: 'Day',
* dateFormat: 'M d',
*
* constrain: true,
* fromDate: new Date('1/1/11'),
* toDate: new Date('1/7/11')
* }]
*
* In this example we're creating a time axis that has as title *Day*.
* The field the axis is bound to is `date`.
* The date format to use to display the text for the axis labels is `M d`
* which is a three letter month abbreviation followed by the day number.
* The time axis will show values for dates between `fromDate` and `toDate`.
* Since `constrain` is set to true all other values for other dates not between
* the fromDate and toDate will not be displayed.
*
*/
Ext.define('Ext.chart.axis.Time', {
/* Begin Definitions */
extend: 'Ext.chart.axis.Numeric',
alternateClassName: 'Ext.chart.TimeAxis',
alias: 'axis.time',
uses: ['Ext.data.Store'],
/* End Definitions */
<span id='Ext-chart-axis-Time-cfg-dateFormat'> /**
</span> * @cfg {String/Boolean} dateFormat
* Indicates the format the date will be rendered on.
* For example: 'M d' will render the dates as 'Jan 30', etc.
* For a list of possible format strings see {@link Ext.Date Date}
*/
dateFormat: false,
<span id='Ext-chart-axis-Time-cfg-fromDate'> /**
</span> * @cfg {Date} fromDate The starting date for the time axis.
*/
fromDate: false,
<span id='Ext-chart-axis-Time-cfg-toDate'> /**
</span> * @cfg {Date} toDate The ending date for the time axis.
*/
toDate: false,
<span id='Ext-chart-axis-Time-cfg-step'> /**
</span> * @cfg {Array/Boolean} step
* An array with two components: The first is the unit of the step (day, month, year, etc). The second one is the number of units for the step (1, 2, etc.).
*
* Defaults to: [Ext.Date.DAY, 1].
*/
step: [Ext.Date.DAY, 1],
<span id='Ext-chart-axis-Time-cfg-constrain'> /**
</span> * @cfg {Boolean} constrain
* If true, the values of the chart will be rendered only if they belong between the fromDate and toDate.
* If false, the time axis will adapt to the new values by adding/removing steps.
*/
constrain: false,
constructor: function (config) {
var me = this, label, f, df;
me.callParent([config]);
label = me.label || {};
df = this.dateFormat;
if (df) {
if (label.renderer) {
f = label.renderer;
label.renderer = function(v) {
v = f(v);
return Ext.Date.format(new Date(f(v)), df);
};
} else {
label.renderer = function(v) {
return Ext.Date.format(new Date(v >> 0), df);
};
}
}
},
// Before rendering, set current default step count to be number of records.
processView: function () {
var me = this;
if (me.fromDate) {
me.minimum = +me.fromDate;
}
if (me.toDate) {
me.maximum = +me.toDate;
}
if(me.constrain){
me.doConstrain();
}
},
// @private modifies the store and creates the labels for the axes.
calcEnds: function() {
var me = this, range, step = me.step;
if (step) {
range = me.getRange();
range = Ext.draw.Draw.snapEndsByDateAndStep(new Date(range.min), new Date(range.max), Ext.isNumber(step) ? [Date.MILLI, step]: step);
if (me.minimum) {
range.from = me.minimum;
}
if (me.maximum) {
range.to = me.maximum;
}
range.step = (range.to - range.from) / range.steps;
return range;
} else {
return me.callParent(arguments);
}
}
});
</pre>
</body>
</html>