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-series-Series'>/**
19 </span> * @class Ext.chart.series.Series
21 * Series is the abstract class containing the common logic to all chart series. Series includes
22 * methods from Labels, Highlights, Tips and Callouts mixins. This class implements the logic of handling
23 * mouse events, animating, hiding, showing all elements and returning the color of the series to be used as a legend item.
27 * The series class supports listeners via the Observable syntax. Some of these listeners are:
29 * - `itemmouseup` When the user interacts with a marker.
30 * - `itemmousedown` When the user interacts with a marker.
31 * - `itemmousemove` When the user iteracts with a marker.
32 * - `afterrender` Will be triggered when the animation ends or when the series has been rendered completely.
40 * 'afterrender': function() {
41 * console('afterrender');
48 Ext.define('Ext.chart.series.Series', {
50 /* Begin Definitions */
53 observable: 'Ext.util.Observable',
54 labels: 'Ext.chart.Label',
55 highlights: 'Ext.chart.Highlight',
56 tips: 'Ext.chart.Tip',
57 callouts: 'Ext.chart.Callout'
62 <span id='Ext-chart-series-Series-cfg-highlight'> /**
63 </span> * @cfg {Boolean/Object} highlight
64 * If set to `true` it will highlight the markers or the series when hovering
65 * with the mouse. This parameter can also be an object with the same style
66 * properties you would apply to a {@link Ext.draw.Sprite} to apply custom
67 * styles to markers and series.
70 <span id='Ext-chart-series-Series-cfg-tips'> /**
71 </span> * @cfg {Object} tips
72 * Add tooltips to the visualization's markers. The options for the tips are the
73 * same configuration used with {@link Ext.tip.ToolTip}. For example:
79 * renderer: function(storeItem, item) {
80 * this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1') + ' views');
85 <span id='Ext-chart-series-Series-cfg-type'> /**
86 </span> * @cfg {String} type
87 * The type of series. Set in subclasses.
91 <span id='Ext-chart-series-Series-cfg-title'> /**
92 </span> * @cfg {String} title
93 * The human-readable name of the series.
97 <span id='Ext-chart-series-Series-cfg-showInLegend'> /**
98 </span> * @cfg {Boolean} showInLegend
99 * Whether to show this series in the legend.
103 <span id='Ext-chart-series-Series-cfg-renderer'> /**
104 </span> * @cfg {Function} renderer
105 * A function that can be overridden to set custom styling properties to each rendered element.
106 * Passes in (sprite, record, attributes, index, store) to the function.
108 renderer: function(sprite, record, attributes, index, store) {
112 <span id='Ext-chart-series-Series-cfg-shadowAttributes'> /**
113 </span> * @cfg {Array} shadowAttributes
114 * An array with shadow attributes
116 shadowAttributes: null,
118 //@private triggerdrawlistener flag
119 triggerAfterDraw: false,
121 <span id='Ext-chart-series-Series-cfg-listeners'> /**
122 </span> * @cfg {Object} listeners
123 * An (optional) object with event callbacks. All event callbacks get the target *item* as first parameter. The callback functions are:
131 constructor: function(config) {
134 Ext.apply(me, config);
137 me.shadowGroups = [];
139 me.mixins.labels.constructor.call(me, config);
140 me.mixins.highlights.constructor.call(me, config);
141 me.mixins.tips.constructor.call(me, config);
142 me.mixins.callouts.constructor.call(me, config);
153 <span id='Ext-chart-series-Series-event-titlechange'> /**
154 </span> * @event titlechange
155 * Fires when the series title is changed via {@link #setTitle}.
156 * @param {String} title The new title value
157 * @param {Number} index The index in the collection of titles
162 me.mixins.observable.constructor.call(me, config);
166 itemmouseover: me.onItemMouseOver,
167 itemmouseout: me.onItemMouseOut,
168 mouseleave: me.onMouseLeave
172 <span id='Ext-chart-series-Series-method-eachRecord'> /**
173 </span> * Iterate over each of the records for this series. The default implementation simply iterates
174 * through the entire data store, but individual series implementations can override this to
175 * provide custom handling, e.g. adding/removing records.
176 * @param {Function} fn The function to execute for each record.
177 * @param {Object} scope Scope for the fn.
179 eachRecord: function(fn, scope) {
180 var chart = this.chart;
181 (chart.substore || chart.store).each(fn, scope);
184 <span id='Ext-chart-series-Series-method-getRecordCount'> /**
185 </span> * Return the number of records being displayed in this series. Defaults to the number of
186 * records in the store; individual series implementations can override to provide custom handling.
188 getRecordCount: function() {
189 var chart = this.chart,
190 store = chart.substore || chart.store;
191 return store ? store.getCount() : 0;
194 <span id='Ext-chart-series-Series-method-isExcluded'> /**
195 </span> * Determines whether the series item at the given index has been excluded, i.e. toggled off in the legend.
198 isExcluded: function(index) {
199 var excludes = this.__excludes;
200 return !!(excludes && excludes[index]);
203 // @private set the bbox and clipBox for the series
204 setBBox: function(noGutter) {
207 chartBBox = chart.chartBBox,
208 gutterX = noGutter ? 0 : chart.maxGutter[0],
209 gutterY = noGutter ? 0 : chart.maxGutter[1],
215 width: chartBBox.width,
216 height: chartBBox.height
218 me.clipBox = clipBox;
221 x: (clipBox.x + gutterX) - (chart.zoom.x * chart.zoom.width),
222 y: (clipBox.y + gutterY) - (chart.zoom.y * chart.zoom.height),
223 width: (clipBox.width - (gutterX * 2)) * chart.zoom.width,
224 height: (clipBox.height - (gutterY * 2)) * chart.zoom.height
229 // @private set the animation for the sprite
230 onAnimate: function(sprite, attr) {
232 sprite.stopAnimation();
233 if (me.triggerAfterDraw) {
234 return sprite.animate(Ext.applyIf(attr, me.chart.animate));
236 me.triggerAfterDraw = true;
237 return sprite.animate(Ext.apply(Ext.applyIf(attr, me.chart.animate), {
239 'afteranimate': function() {
240 me.triggerAfterDraw = false;
241 me.fireEvent('afterrender');
248 // @private return the gutter.
249 getGutters: function() {
253 // @private wrapper for the itemmouseover event.
254 onItemMouseOver: function(item) {
256 if (item.series === me) {
258 me.highlightItem(item);
266 // @private wrapper for the itemmouseout event.
267 onItemMouseOut: function(item) {
269 if (item.series === me) {
270 me.unHighlightItem();
277 // @private wrapper for the mouseleave event.
278 onMouseLeave: function() {
280 me.unHighlightItem();
286 <span id='Ext-chart-series-Series-method-getItemForPoint'> /**
287 </span> * For a given x/y point relative to the Surface, find a corresponding item from this
291 * @return {Object} An object describing the item, or null if there is no matching item.
292 * The exact contents of this object will vary by series type, but should always contain the following:
293 * @return {Ext.chart.series.Series} return.series the Series object to which the item belongs
294 * @return {Object} return.value the value(s) of the item's data point
295 * @return {Array} return.point the x/y coordinates relative to the chart box of a single point
296 * for this data item, which can be used as e.g. a tooltip anchor point.
297 * @return {Ext.draw.Sprite} return.sprite the item's rendering Sprite.
299 getItemForPoint: function(x, y) {
300 //if there are no items to query just return null.
301 if (!this.items || !this.items.length || this.seriesIsHidden) {
309 if (!Ext.draw.Draw.withinBox(x, y, bbox)) {
312 for (i = 0, ln = items.length; i < ln; i++) {
313 if (items[i] && this.isItemInPoint(x, y, items[i], i)) {
321 isItemInPoint: function(x, y, item, i) {
325 <span id='Ext-chart-series-Series-method-hideAll'> /**
326 </span> * Hides all the elements in the series.
328 hideAll: function() {
331 item, len, i, j, l, sprite, shadows;
333 me.seriesIsHidden = true;
334 me._prevShowMarkers = me.showMarkers;
336 me.showMarkers = false;
340 for (i = 0, len = items.length; i < len; i++) {
342 sprite = item.sprite;
344 sprite.setAttributes({
349 if (sprite && sprite.shadows) {
350 shadows = sprite.shadows;
351 for (j = 0, l = shadows.length; j < l; ++j) {
352 shadows[j].setAttributes({
360 <span id='Ext-chart-series-Series-method-showAll'> /**
361 </span> * Shows all the elements in the series.
363 showAll: function() {
365 prevAnimate = me.chart.animate;
366 me.chart.animate = false;
367 me.seriesIsHidden = false;
368 me.showMarkers = me._prevShowMarkers;
370 me.chart.animate = prevAnimate;
373 <span id='Ext-chart-series-Series-method-getLegendColor'> /**
374 </span> * Returns a string with the color to be used for the series legend item.
376 getLegendColor: function(index) {
377 var me = this, fill, stroke;
378 if (me.seriesStyle) {
379 fill = me.seriesStyle.fill;
380 stroke = me.seriesStyle.stroke;
381 if (fill && fill != 'none') {
389 <span id='Ext-chart-series-Series-method-visibleInLegend'> /**
390 </span> * Checks whether the data field should be visible in the legend
392 * @param {Number} index The index of the current item
394 visibleInLegend: function(index){
395 var excludes = this.__excludes;
397 return !excludes[index];
399 return !this.seriesIsHidden;
402 <span id='Ext-chart-series-Series-method-setTitle'> /**
403 </span> * Changes the value of the {@link #title} for the series.
404 * Arguments can take two forms:
406 * <li>A single String value: this will be used as the new single title for the series (applies
407 * to series with only one yField)</li>
408 * <li>A numeric index and a String value: this will set the title for a single indexed yField.</li>
410 * @param {Number} index
411 * @param {String} title
413 setTitle: function(index, title) {
417 if (Ext.isString(index)) {
422 if (Ext.isArray(oldTitle)) {
423 oldTitle[index] = title;
428 me.fireEvent('titlechange', title, index);