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