3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.chart.axis.Time
17 * @extends Ext.chart.axis.Numeric
19 * A type of axis whose units are measured in time values. Use this axis
20 * for listing dates that you will want to group or dynamically change.
21 * If you just want to display dates as categories then use the
22 * Category class for axis instead.
34 * fromDate: new Date('1/1/11'),
35 * toDate: new Date('1/7/11')
38 * In this example we're creating a time axis that has as title *Day*.
39 * The field the axis is bound to is `date`.
40 * The date format to use to display the text for the axis labels is `M d`
41 * which is a three letter month abbreviation followed by the day number.
42 * The time axis will show values for dates between `fromDate` and `toDate`.
43 * Since `constrain` is set to true all other values for other dates not between
44 * the fromDate and toDate will not be displayed.
47 Ext.define('Ext.chart.axis.Time', {
49 /* Begin Definitions */
51 extend: 'Ext.chart.axis.Numeric',
53 alternateClassName: 'Ext.chart.TimeAxis',
57 requires: ['Ext.data.Store', 'Ext.data.JsonStore'],
62 * @cfg {String/Boolean} dateFormat
63 * Indicates the format the date will be rendered on.
64 * For example: 'M d' will render the dates as 'Jan 30', etc.
65 * For a list of possible format strings see {@link Ext.Date Date}
70 * @cfg {Date} fromDate The starting date for the time axis.
75 * @cfg {Date} toDate The ending date for the time axis.
80 * @cfg {Array/Boolean} step
81 * An array with two components: The first is the unit of the step (day, month, year, etc).
82 * The second one is the number of units for the step (1, 2, etc.).
83 * Defaults to `[Ext.Date.DAY, 1]`.
85 step: [Ext.Date.DAY, 1],
88 * @cfg {Boolean} constrain
89 * If true, the values of the chart will be rendered only if they belong between the fromDate and toDate.
90 * If false, the time axis will adapt to the new values by adding/removing steps.
94 // Avoid roundtoDecimal call in Numeric Axis's constructor
95 roundToDecimal: false,
97 constructor: function (config) {
98 var me = this, label, f, df;
99 me.callParent([config]);
100 label = me.label || {};
101 df = this.dateFormat;
103 if (label.renderer) {
105 label.renderer = function(v) {
107 return Ext.Date.format(new Date(f(v)), df);
110 label.renderer = function(v) {
111 return Ext.Date.format(new Date(v >> 0), df);
117 doConstrain: function () {
119 store = me.chart.store,
121 series = me.chart.series.items,
127 range = me.getRange(),
128 min = range.min, max = range.max, i, l, excludes = [],
129 value, values, rec, data = [];
130 for (i = 0, l = series.length; i < l; i++) {
131 excludes[i] = series[i].__excludes;
133 store.each(function(record) {
134 for (i = 0; i < ln; i++) {
138 value = record.get(fields[i]);
139 if (+value < +min) return;
140 if (+value > +max) return;
144 me.chart.substore = Ext.create('Ext.data.JsonStore', { model: store.model, data: data });
147 // Before rendering, set current default step count to be number of records.
148 processView: function () {
151 me.minimum = +me.fromDate;
154 me.maximum = +me.toDate;
161 // @private modifies the store and creates the labels for the axes.
162 calcEnds: function() {
163 var me = this, range, step = me.step;
165 range = me.getRange();
166 range = Ext.draw.Draw.snapEndsByDateAndStep(new Date(range.min), new Date(range.max), Ext.isNumber(step) ? [Date.MILLI, step]: step);
168 range.from = me.minimum;
171 range.to = me.maximum;
173 range.step = (range.to - range.from) / range.steps;
176 return me.callParent(arguments);