4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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');
49 Ext.define('Ext.chart.series.Series', {
51 /* Begin Definitions */
54 observable: 'Ext.util.Observable',
55 labels: 'Ext.chart.Label',
56 highlights: 'Ext.chart.Highlight',
57 tips: 'Ext.chart.Tip',
58 callouts: 'Ext.chart.Callout'
63 <span id='Ext-chart-series-Series-cfg-highlight'> /**
64 </span> * @cfg {Boolean|Object} highlight
65 * If set to `true` it will highlight the markers or the series when hovering
66 * with the mouse. This parameter can also be an object with the same style
67 * properties you would apply to a {@link Ext.draw.Sprite} to apply custom
68 * styles to markers and series.
71 <span id='Ext-chart-series-Series-cfg-tips'> /**
72 </span> * @cfg {Object} tips
73 * Add tooltips to the visualization's markers. The options for the tips are the
74 * same configuration used with {@link Ext.tip.ToolTip}. For example:
80 * renderer: function(storeItem, item) {
81 * this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1') + ' views');
86 <span id='Ext-chart-series-Series-cfg-type'> /**
87 </span> * @cfg {String} type
88 * The type of series. Set in subclasses.
92 <span id='Ext-chart-series-Series-cfg-title'> /**
93 </span> * @cfg {String} title
94 * The human-readable name of the series.
98 <span id='Ext-chart-series-Series-cfg-showInLegend'> /**
99 </span> * @cfg {Boolean} showInLegend
100 * Whether to show this series in the legend.
104 <span id='Ext-chart-series-Series-cfg-renderer'> /**
105 </span> * @cfg {Function} renderer
106 * A function that can be overridden to set custom styling properties to each rendered element.
107 * Passes in (sprite, record, attributes, index, store) to the function.
109 renderer: function(sprite, record, attributes, index, store) {
113 <span id='Ext-chart-series-Series-cfg-shadowAttributes'> /**
114 </span> * @cfg {Array} shadowAttributes
115 * An array with shadow attributes
117 shadowAttributes: null,
119 //@private triggerdrawlistener flag
120 triggerAfterDraw: false,
122 <span id='Ext-chart-series-Series-cfg-listeners'> /**
123 </span> * @cfg {Object} listeners
124 * An (optional) object with event callbacks. All event callbacks get the target *item* as first parameter. The callback functions are:
127 * <li>itemmouseover</li>
128 * <li>itemmouseout</li>
129 * <li>itemmousedown</li>
130 * <li>itemmouseup</li>
134 constructor: function(config) {
137 Ext.apply(me, config);
140 me.shadowGroups = [];
142 me.mixins.labels.constructor.call(me, config);
143 me.mixins.highlights.constructor.call(me, config);
144 me.mixins.tips.constructor.call(me, config);
145 me.mixins.callouts.constructor.call(me, config);
156 <span id='Ext-chart-series-Series-event-titlechange'> /**
157 </span> * @event titlechange
158 * Fires when the series title is changed via {@link #setTitle}.
159 * @param {String} title The new title value
160 * @param {Number} index The index in the collection of titles
165 me.mixins.observable.constructor.call(me, config);
169 itemmouseover: me.onItemMouseOver,
170 itemmouseout: me.onItemMouseOut,
171 mouseleave: me.onMouseLeave
175 // @private set the bbox and clipBox for the series
176 setBBox: function(noGutter) {
179 chartBBox = chart.chartBBox,
180 gutterX = noGutter ? 0 : chart.maxGutter[0],
181 gutterY = noGutter ? 0 : chart.maxGutter[1],
187 width: chartBBox.width,
188 height: chartBBox.height
190 me.clipBox = clipBox;
193 x: (clipBox.x + gutterX) - (chart.zoom.x * chart.zoom.width),
194 y: (clipBox.y + gutterY) - (chart.zoom.y * chart.zoom.height),
195 width: (clipBox.width - (gutterX * 2)) * chart.zoom.width,
196 height: (clipBox.height - (gutterY * 2)) * chart.zoom.height
201 // @private set the animation for the sprite
202 onAnimate: function(sprite, attr) {
204 sprite.stopAnimation();
205 if (me.triggerAfterDraw) {
206 return sprite.animate(Ext.applyIf(attr, me.chart.animate));
208 me.triggerAfterDraw = true;
209 return sprite.animate(Ext.apply(Ext.applyIf(attr, me.chart.animate), {
211 'afteranimate': function() {
212 me.triggerAfterDraw = false;
213 me.fireEvent('afterrender');
220 // @private return the gutter.
221 getGutters: function() {
225 // @private wrapper for the itemmouseover event.
226 onItemMouseOver: function(item) {
228 if (item.series === me) {
230 me.highlightItem(item);
238 // @private wrapper for the itemmouseout event.
239 onItemMouseOut: function(item) {
241 if (item.series === me) {
242 me.unHighlightItem();
249 // @private wrapper for the mouseleave event.
250 onMouseLeave: function() {
252 me.unHighlightItem();
258 <span id='Ext-chart-series-Series-method-getItemForPoint'> /**
259 </span> * For a given x/y point relative to the Surface, find a corresponding item from this
263 * @return {Object} An object describing the item, or null if there is no matching item. The exact contents of
264 * this object will vary by series type, but should always contain at least the following:
266 * <li>{Ext.chart.series.Series} series - the Series object to which the item belongs</li>
267 * <li>{Object} value - the value(s) of the item's data point</li>
268 * <li>{Array} point - the x/y coordinates relative to the chart box of a single point
269 * for this data item, which can be used as e.g. a tooltip anchor point.</li>
270 * <li>{Ext.draw.Sprite} sprite - the item's rendering Sprite.
273 getItemForPoint: function(x, y) {
274 //if there are no items to query just return null.
275 if (!this.items || !this.items.length || this.seriesIsHidden) {
283 if (!Ext.draw.Draw.withinBox(x, y, bbox)) {
286 for (i = 0, ln = items.length; i < ln; i++) {
287 if (items[i] && this.isItemInPoint(x, y, items[i], i)) {
295 isItemInPoint: function(x, y, item, i) {
299 <span id='Ext-chart-series-Series-method-hideAll'> /**
300 </span> * Hides all the elements in the series.
302 hideAll: function() {
305 item, len, i, sprite;
307 me.seriesIsHidden = true;
308 me._prevShowMarkers = me.showMarkers;
310 me.showMarkers = false;
314 for (i = 0, len = items.length; i < len; i++) {
316 sprite = item.sprite;
318 sprite.setAttributes({
325 <span id='Ext-chart-series-Series-method-showAll'> /**
326 </span> * Shows all the elements in the series.
328 showAll: function() {
330 prevAnimate = me.chart.animate;
331 me.chart.animate = false;
332 me.seriesIsHidden = false;
333 me.showMarkers = me._prevShowMarkers;
335 me.chart.animate = prevAnimate;
338 <span id='Ext-chart-series-Series-method-getLegendColor'> /**
339 </span> * Returns a string with the color to be used for the series legend item.
341 getLegendColor: function(index) {
342 var me = this, fill, stroke;
343 if (me.seriesStyle) {
344 fill = me.seriesStyle.fill;
345 stroke = me.seriesStyle.stroke;
346 if (fill && fill != 'none') {
354 <span id='Ext-chart-series-Series-method-visibleInLegend'> /**
355 </span> * Checks whether the data field should be visible in the legend
357 * @param {Number} index The index of the current item
359 visibleInLegend: function(index){
360 var excludes = this.__excludes;
362 return !excludes[index];
364 return !this.seriesIsHidden;
367 <span id='Ext-chart-series-Series-method-setTitle'> /**
368 </span> * Changes the value of the {@link #title} for the series.
369 * Arguments can take two forms:
371 * <li>A single String value: this will be used as the new single title for the series (applies
372 * to series with only one yField)</li>
373 * <li>A numeric index and a String value: this will set the title for a single indexed yField.</li>
375 * @param {Number} index
376 * @param {String} title
378 setTitle: function(index, title) {
382 if (Ext.isString(index)) {
387 if (Ext.isArray(oldTitle)) {
388 oldTitle[index] = title;
393 me.fireEvent('titlechange', title, index);