Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Callout.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.Callout'>/**
2 </span> * @class Ext.chart.Callout
3  * @ignore
4  */
5 Ext.define('Ext.chart.Callout', {
6
7     /* Begin Definitions */
8
9     /* End Definitions */
10
11     constructor: function(config) {
12         if (config.callouts) {
13             config.callouts.styles = Ext.applyIf(config.callouts.styles || {}, {
14                 color: &quot;#000&quot;,
15                 font: &quot;11px Helvetica, sans-serif&quot;
16             });
17             this.callouts = Ext.apply(this.callouts || {}, config.callouts);
18             this.calloutsArray = [];
19         }
20     },
21
22     renderCallouts: function() {
23         if (!this.callouts) {
24             return;
25         }
26
27         var me = this,
28             items = me.items,
29             animate = me.chart.animate,
30             config = me.callouts,
31             styles = config.styles,
32             group = me.calloutsArray,
33             store = me.chart.store,
34             len = store.getCount(),
35             ratio = items.length / len,
36             previouslyPlacedCallouts = [],
37             i,
38             count,
39             j,
40             p;
41             
42         for (i = 0, count = 0; i &lt; len; i++) {
43             for (j = 0; j &lt; ratio; j++) {
44                 var item = items[count],
45                     label = group[count],
46                     storeItem = store.getAt(i),
47                     display;
48                 
49                 display = config.filter(storeItem);
50                 
51                 if (!display &amp;&amp; !label) {
52                     count++;
53                     continue;               
54                 }
55                 
56                 if (!label) {
57                     group[count] = label = me.onCreateCallout(storeItem, item, i, display, j, count);
58                 }
59                 for (p in label) {
60                     if (label[p] &amp;&amp; label[p].setAttributes) {
61                         label[p].setAttributes(styles, true);
62                     }
63                 }
64                 if (!display) {
65                     for (p in label) {
66                         if (label[p]) {
67                             if (label[p].setAttributes) {
68                                 label[p].setAttributes({
69                                     hidden: true
70                                 }, true);
71                             } else if(label[p].setVisible) {
72                                 label[p].setVisible(false);
73                             }
74                         }
75                     }
76                 }
77                 config.renderer(label, storeItem);
78                 me.onPlaceCallout(label, storeItem, item, i, display, animate,
79                                   j, count, previouslyPlacedCallouts);
80                 previouslyPlacedCallouts.push(label);
81                 count++;
82             }
83         }
84         this.hideCallouts(count);
85     },
86
87     onCreateCallout: function(storeItem, item, i, display) {
88         var me = this,
89             group = me.calloutsGroup,
90             config = me.callouts,
91             styles = config.styles,
92             width = styles.width,
93             height = styles.height,
94             chart = me.chart,
95             surface = chart.surface,
96             calloutObj = {
97                 //label: false,
98                 //box: false,
99                 lines: false
100             };
101
102         calloutObj.lines = surface.add(Ext.apply({},
103         {
104             type: 'path',
105             path: 'M0,0',
106             stroke: me.getLegendColor() || '#555'
107         },
108         styles));
109
110         if (config.items) {
111             calloutObj.panel = Ext.create('widget.panel', {
112                 style: &quot;position: absolute;&quot;,    
113                 width: width,
114                 height: height,
115                 items: config.items,
116                 renderTo: chart.el
117             });
118         }
119
120         return calloutObj;
121     },
122
123     hideCallouts: function(index) {
124         var calloutsArray = this.calloutsArray,
125             len = calloutsArray.length,
126             co,
127             p;
128         while (len--&gt;index) {
129             co = calloutsArray[len];
130             for (p in co) {
131                 if (co[p]) {
132                     co[p].hide(true);
133                 }
134             }
135         }
136     }
137 });
138 </pre></pre></body></html>