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