4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-chart-axis-Time'>/**
19 </span> * @class Ext.chart.axis.Time
20 * @extends Ext.chart.axis.Numeric
22 * A type of axis whose units are measured in time values. Use this axis
23 * for listing dates that you will want to group or dynamically change.
24 * If you just want to display dates as categories then use the
25 * Category class for axis instead.
37 * fromDate: new Date('1/1/11'),
38 * toDate: new Date('1/7/11')
41 * In this example we're creating a time axis that has as title *Day*.
42 * The field the axis is bound to is `date`.
43 * The date format to use to display the text for the axis labels is `M d`
44 * which is a three letter month abbreviation followed by the day number.
45 * The time axis will show values for dates between `fromDate` and `toDate`.
46 * Since `constrain` is set to true all other values for other dates not between
47 * the fromDate and toDate will not be displayed.
50 Ext.define('Ext.chart.axis.Time', {
52 /* Begin Definitions */
54 extend: 'Ext.chart.axis.Numeric',
56 alternateClassName: 'Ext.chart.TimeAxis',
60 requires: ['Ext.data.Store', 'Ext.data.JsonStore'],
64 <span id='Ext-chart-axis-Time-cfg-dateFormat'> /**
65 </span> * @cfg {String/Boolean} dateFormat
66 * Indicates the format the date will be rendered on.
67 * For example: 'M d' will render the dates as 'Jan 30', etc.
68 * For a list of possible format strings see {@link Ext.Date Date}
72 <span id='Ext-chart-axis-Time-cfg-fromDate'> /**
73 </span> * @cfg {Date} fromDate The starting date for the time axis.
77 <span id='Ext-chart-axis-Time-cfg-toDate'> /**
78 </span> * @cfg {Date} toDate The ending date for the time axis.
82 <span id='Ext-chart-axis-Time-cfg-step'> /**
83 </span> * @cfg {Array/Boolean} step
84 * An array with two components: The first is the unit of the step (day, month, year, etc).
85 * The second one is the number of units for the step (1, 2, etc.).
86 * Defaults to `[Ext.Date.DAY, 1]`.
88 step: [Ext.Date.DAY, 1],
90 <span id='Ext-chart-axis-Time-cfg-constrain'> /**
91 </span> * @cfg {Boolean} constrain
92 * If true, the values of the chart will be rendered only if they belong between the fromDate and toDate.
93 * If false, the time axis will adapt to the new values by adding/removing steps.
97 // Avoid roundtoDecimal call in Numeric Axis's constructor
98 roundToDecimal: false,
100 constructor: function (config) {
101 var me = this, label, f, df;
102 me.callParent([config]);
103 label = me.label || {};
104 df = this.dateFormat;
106 if (label.renderer) {
108 label.renderer = function(v) {
110 return Ext.Date.format(new Date(f(v)), df);
113 label.renderer = function(v) {
114 return Ext.Date.format(new Date(v >> 0), df);
120 doConstrain: function () {
122 store = me.chart.store,
124 series = me.chart.series.items,
130 range = me.getRange(),
131 min = range.min, max = range.max, i, l, excludes = [],
132 value, values, rec, data = [];
133 for (i = 0, l = series.length; i < l; i++) {
134 excludes[i] = series[i].__excludes;
136 store.each(function(record) {
137 for (i = 0; i < ln; i++) {
141 value = record.get(fields[i]);
142 if (+value < +min) return;
143 if (+value > +max) return;
147 me.chart.substore = Ext.create('Ext.data.JsonStore', { model: store.model, data: data });
150 // Before rendering, set current default step count to be number of records.
151 processView: function () {
154 me.minimum = +me.fromDate;
157 me.maximum = +me.toDate;
164 // @private modifies the store and creates the labels for the axes.
165 calcEnds: function() {
166 var me = this, range, step = me.step;
168 range = me.getRange();
169 range = Ext.draw.Draw.snapEndsByDateAndStep(new Date(range.min), new Date(range.max), Ext.isNumber(step) ? [Date.MILLI, step]: step);
171 range.from = me.minimum;
174 range.to = me.maximum;
176 range.step = (range.to - range.from) / range.steps;
179 return me.callParent(arguments);