Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Highlight.html
1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-chart.Highlight'>/**
2 </span> * @class Ext.chart.Highlight
3  * @ignore
4  */
5 Ext.define('Ext.chart.Highlight', {
6
7     /* Begin Definitions */
8
9     requires: ['Ext.fx.Anim'],
10
11     /* End Definitions */
12
13 <span id='Ext-chart.Highlight-property-highlight'>    /**
14 </span>     * Highlight the given series item.
15      * @param {Boolean|Object} Default's false. Can also be an object width style properties (i.e fill, stroke, radius) 
16      * or just use default styles per series by setting highlight = true.
17      */
18     highlight: false,
19
20     highlightCfg : null,
21
22     constructor: function(config) {
23         if (config.highlight) {
24             if (config.highlight !== true) { //is an object
25                 this.highlightCfg = Ext.apply({}, config.highlight);
26             }
27             else {
28                 this.highlightCfg = {
29                     fill: '#fdd',
30                     radius: 20,
31                     lineWidth: 5,
32                     stroke: '#f55'
33                 };
34             }
35         }
36     },
37
38 <span id='Ext-chart.Highlight-method-highlightItem'>    /**
39 </span>     * Highlight the given series item.
40      * @param {Object} item Info about the item; same format as returned by #getItemForPoint.
41      */
42     highlightItem: function(item) {
43         if (!item) {
44             return;
45         }
46         
47         var me = this,
48             sprite = item.sprite,
49             opts = me.highlightCfg,
50             surface = me.chart.surface,
51             animate = me.chart.animate,
52             p,
53             from,
54             to,
55             pi;
56
57         if (!me.highlight || !sprite || sprite._highlighted) {
58             return;
59         }
60         if (sprite._anim) {
61             sprite._anim.paused = true;
62         }
63         sprite._highlighted = true;
64         if (!sprite._defaults) {
65             sprite._defaults = Ext.apply(sprite._defaults || {},
66             sprite.attr);
67             from = {};
68             to = {};
69             for (p in opts) {
70                 if (! (p in sprite._defaults)) {
71                     sprite._defaults[p] = surface.availableAttrs[p];
72                 }
73                 from[p] = sprite._defaults[p];
74                 to[p] = opts[p];
75                 if (Ext.isObject(opts[p])) {
76                     from[p] = {};
77                     to[p] = {};
78                     Ext.apply(sprite._defaults[p], sprite.attr[p]);
79                     Ext.apply(from[p], sprite._defaults[p]);
80                     for (pi in sprite._defaults[p]) {
81                         if (! (pi in opts[p])) {
82                             to[p][pi] = from[p][pi];
83                         } else {
84                             to[p][pi] = opts[p][pi];
85                         }
86                     }
87                     for (pi in opts[p]) {
88                         if (! (pi in to[p])) {
89                             to[p][pi] = opts[p][pi];
90                         }
91                     }
92                 }
93             }
94             sprite._from = from;
95             sprite._to = to;
96         }
97         if (animate) {
98             sprite._anim = Ext.create('Ext.fx.Anim', {
99                 target: sprite,
100                 from: sprite._from,
101                 to: sprite._to,
102                 duration: 150
103             });
104         } else {
105             sprite.setAttributes(sprite._to, true);
106         }
107     },
108
109 <span id='Ext-chart.Highlight-method-unHighlightItem'>    /**
110 </span>     * Un-highlight any existing highlights
111      */
112     unHighlightItem: function() {
113         if (!this.highlight || !this.items) {
114             return;
115         }
116
117         var me = this,
118             items = me.items,
119             len = items.length,
120             opts = me.highlightCfg,
121             animate = me.chart.animate,
122             i = 0,
123             obj,
124             p,
125             sprite;
126
127         for (; i &lt; len; i++) {
128             if (!items[i]) {
129                 continue;
130             }
131             sprite = items[i].sprite;
132             if (sprite &amp;&amp; sprite._highlighted) {
133                 if (sprite._anim) {
134                     sprite._anim.paused = true;
135                 }
136                 obj = {};
137                 for (p in opts) {
138                     if (Ext.isObject(sprite._defaults[p])) {
139                         obj[p] = {};
140                         Ext.apply(obj[p], sprite._defaults[p]);
141                     }
142                     else {
143                         obj[p] = sprite._defaults[p];
144                     }
145                 }
146                 if (animate) {
147                     sprite._anim = Ext.create('Ext.fx.Anim', {
148                         target: sprite,
149                         to: obj,
150                         duration: 150
151                     });
152                 }
153                 else {
154                     sprite.setAttributes(obj, true);
155                 }
156                 delete sprite._highlighted;
157                 //delete sprite._defaults;
158             }
159         }
160     },
161
162     cleanHighlights: function() {
163         if (!this.highlight) {
164             return;
165         }
166
167         var group = this.group,
168             markerGroup = this.markerGroup,
169             i = 0,
170             l;
171         for (l = group.getCount(); i &lt; l; i++) {
172             delete group.getAt(i)._defaults;
173         }
174         if (markerGroup) {
175             for (l = markerGroup.getCount(); i &lt; l; i++) {
176                 delete markerGroup.getAt(i)._defaults;
177             }
178         }
179     }
180 });</pre></pre></body></html>