PageRenderTime 37ms CodeModel.GetById 19ms RepoModel.GetById 5ms app.codeStats 0ms

/ext-4.1.0_b3/docs/source/Time.html

https://bitbucket.org/srogerf/javascript
HTML | 192 lines | 175 code | 17 blank | 0 comment | 0 complexity | a65f18c9cff7145bf9ee175aeda12305 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  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; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  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.Axis
  21. *
  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.
  26. *
  27. * For example:
  28. *
  29. * axes: [{
  30. * type: 'Time',
  31. * position: 'bottom',
  32. * fields: 'date',
  33. * title: 'Day',
  34. * dateFormat: 'M d',
  35. * groupBy: 'year,month,day',
  36. * aggregateOp: 'sum',
  37. *
  38. * constrain: true,
  39. * fromDate: new Date('1/1/11'),
  40. * toDate: new Date('1/7/11')
  41. * }]
  42. *
  43. * In this example we're creating a time axis that has as title *Day*.
  44. * The field the axis is bound to is `date`.
  45. * The date format to use to display the text for the axis labels is `M d`
  46. * which is a three letter month abbreviation followed by the day number.
  47. * The time axis will show values for dates between `fromDate` and `toDate`.
  48. * Since `constrain` is set to true all other values for other dates not between
  49. * the fromDate and toDate will not be displayed.
  50. *
  51. */
  52. Ext.define('Ext.chart.axis.Time', {
  53. /* Begin Definitions */
  54. extend: 'Ext.chart.axis.Numeric',
  55. alternateClassName: 'Ext.chart.TimeAxis',
  56. alias: 'axis.time',
  57. requires: ['Ext.data.Store', 'Ext.data.JsonStore'],
  58. /* End Definitions */
  59. <span id='Ext-chart-axis-Time-cfg-dateFormat'> /**
  60. </span> * @cfg {String/Boolean} dateFormat
  61. * Indicates the format the date will be rendered on.
  62. * For example: 'M d' will render the dates as 'Jan 30', etc.
  63. * For a list of possible format strings see {@link Ext.Date Date}
  64. */
  65. dateFormat: false,
  66. <span id='Ext-chart-axis-Time-cfg-fromDate'> /**
  67. </span> * @cfg {Date} fromDate The starting date for the time axis.
  68. */
  69. fromDate: false,
  70. <span id='Ext-chart-axis-Time-cfg-toDate'> /**
  71. </span> * @cfg {Date} toDate The ending date for the time axis.
  72. */
  73. toDate: false,
  74. <span id='Ext-chart-axis-Time-cfg-step'> /**
  75. </span> * @cfg {Array/Boolean} step
  76. * 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.).
  77. * Default's [Ext.Date.DAY, 1]. If this is specified, {@link #steps} config is omitted.
  78. */
  79. step: [Ext.Date.DAY, 1],
  80. <span id='Ext-chart-axis-Time-cfg-constrain'> /**
  81. </span> * @cfg {Boolean} constrain
  82. * If true, the values of the chart will be rendered only if they belong between the fromDate and toDate.
  83. * If false, the time axis will adapt to the new values by adding/removing steps.
  84. * Default's false.
  85. */
  86. constrain: false,
  87. // Avoid roundtoDecimal call in Numeric Axis's constructor
  88. roundToDecimal: false,
  89. constructor: function (config) {
  90. var me = this, label, f, df;
  91. me.callParent([config]);
  92. label = me.label || {};
  93. df = this.dateFormat;
  94. if (df) {
  95. if (label.renderer) {
  96. f = label.renderer;
  97. label.renderer = function(v) {
  98. v = f(v);
  99. return Ext.Date.format(new Date(f(v)), df);
  100. };
  101. } else {
  102. label.renderer = function(v) {
  103. return Ext.Date.format(new Date(v &gt;&gt; 0), df);
  104. };
  105. }
  106. }
  107. },
  108. doConstrain: function () {
  109. var me = this,
  110. store = me.chart.store,
  111. items = store.data.items,
  112. d, dLen, record,
  113. data = [],
  114. series = me.chart.series.items,
  115. math = Math,
  116. mmax = math.max,
  117. mmin = math.min,
  118. fields = me.fields,
  119. ln = fields.length,
  120. range = me.getRange(),
  121. min = range.min, max = range.max, i, l, excludes = [],
  122. value, values, rec;
  123. for (i = 0, l = series.length; i &lt; l; i++) {
  124. excludes[i] = series[i].__excludes;
  125. }
  126. for (d = 0, dLen = items.length; d &lt; dLen; d++) {
  127. record = items[d];
  128. for (i = 0; i &lt; ln; i++) {
  129. if (excludes[i]) {
  130. continue;
  131. }
  132. value = record.get(fields[i]);
  133. value = +value;
  134. if (value &gt;= +min &amp;&amp; value &lt;= +max) {
  135. data.push(record);
  136. }
  137. }
  138. }
  139. me.chart.substore = Ext.create('Ext.data.JsonStore', { model: store.model, data: data });
  140. },
  141. // Before rendering, set current default step count to be number of records.
  142. processView: function () {
  143. var me = this;
  144. if (me.fromDate) {
  145. me.minimum = +me.fromDate;
  146. }
  147. if (me.toDate) {
  148. me.maximum = +me.toDate;
  149. }
  150. if (me.constrain) {
  151. me.doConstrain();
  152. }
  153. },
  154. // @private modifies the store and creates the labels for the axes.
  155. calcEnds: function() {
  156. var me = this, range, step = me.step;
  157. if (step) {
  158. range = me.getRange();
  159. range = Ext.draw.Draw.snapEndsByDateAndStep(new Date(range.min), new Date(range.max), Ext.isNumber(step) ? [Date.MILLI, step]: step);
  160. if (me.minimum) {
  161. range.from = me.minimum;
  162. }
  163. if (me.maximum) {
  164. range.to = me.maximum;
  165. }
  166. range.step = (range.to - range.from) / range.steps;
  167. return range;
  168. } else {
  169. return me.callParent(arguments);
  170. }
  171. }
  172. });
  173. </pre>
  174. </body>
  175. </html>