Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Tip4.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-Tip'>/**
19 </span> * @class Ext.chart.Tip
20  * Provides tips for Ext.chart.series.Series.
21  */
22 Ext.define('Ext.chart.Tip', {
23
24     /* Begin Definitions */
25
26     requires: ['Ext.tip.ToolTip', 'Ext.chart.TipSurface'],
27
28     /* End Definitions */
29
30     constructor: function(config) {
31         var me = this,
32             surface,
33             sprites,
34             tipSurface;
35         if (config.tips) {
36             me.tipTimeout = null;
37             me.tipConfig = Ext.apply({}, config.tips, {
38                 renderer: Ext.emptyFn,
39                 constrainPosition: false
40             });
41             me.tooltip = Ext.create('Ext.tip.ToolTip', me.tipConfig);
42             Ext.getBody().on('mousemove', me.tooltip.onMouseMove, me.tooltip);
43             if (me.tipConfig.surface) {
44                 //initialize a surface
45                 surface = me.tipConfig.surface;
46                 sprites = surface.sprites;
47                 tipSurface = Ext.create('Ext.chart.TipSurface', {
48                     id: 'tipSurfaceComponent',
49                     sprites: sprites
50                 });
51                 if (surface.width &amp;&amp; surface.height) {
52                     tipSurface.setSize(surface.width, surface.height);
53                 }
54                 me.tooltip.add(tipSurface);
55                 me.spriteTip = tipSurface;
56             }
57         }
58     },
59
60     showTip: function(item) {
61         var me = this;
62         if (!me.tooltip) {
63             return;
64         }
65         clearTimeout(me.tipTimeout);
66         var tooltip = me.tooltip,
67             spriteTip = me.spriteTip,
68             tipConfig = me.tipConfig,
69             trackMouse = tooltip.trackMouse,
70             sprite, surface, surfaceExt, pos, x, y;
71         if (!trackMouse) {
72             tooltip.trackMouse = true;
73             sprite = item.sprite;
74             surface = sprite.surface;
75             surfaceExt = Ext.get(surface.getId());
76             if (surfaceExt) {
77                 pos = surfaceExt.getXY();
78                 x = pos[0] + (sprite.attr.x || 0) + (sprite.attr.translation &amp;&amp; sprite.attr.translation.x || 0);
79                 y = pos[1] + (sprite.attr.y || 0) + (sprite.attr.translation &amp;&amp; sprite.attr.translation.y || 0);
80                 tooltip.targetXY = [x, y];
81             }
82         }
83         if (spriteTip) {
84             tipConfig.renderer.call(tooltip, item.storeItem, item, spriteTip.surface);
85         } else {
86             tipConfig.renderer.call(tooltip, item.storeItem, item);
87         }
88         tooltip.show();
89         tooltip.trackMouse = trackMouse;
90     },
91
92     hideTip: function(item) {
93         var tooltip = this.tooltip;
94         if (!tooltip) {
95             return;
96         }
97         clearTimeout(this.tipTimeout);
98         this.tipTimeout = setTimeout(function() {
99             tooltip.hide();
100         }, 0);
101     }
102 });</pre>
103 </body>
104 </html>