Tip3.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/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. /* Begin Definitions */
  24. requires: ['Ext.tip.ToolTip', 'Ext.chart.TipSurface'],
  25. /* End Definitions */
  26. constructor: function(config) {
  27. var me = this,
  28. surface,
  29. sprites,
  30. tipSurface;
  31. if (config.tips) {
  32. me.tipTimeout = null;
  33. me.tipConfig = Ext.apply({}, config.tips, {
  34. renderer: Ext.emptyFn,
  35. constrainPosition: true,
  36. autoHide: true
  37. });
  38. me.tooltip = new Ext.tip.ToolTip(me.tipConfig);
  39. me.chart.surface.on('mousemove', me.tooltip.onMouseMove, me.tooltip);
  40. me.chart.surface.on('mouseleave', function() {
  41. me.hideTip();
  42. });
  43. if (me.tipConfig.surface) {
  44. //initialize a surface
  45. surface = me.tipConfig.surface;
  46. sprites = surface.sprites;
  47. tipSurface = new 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. showTip: function(item) {
  60. var me = this,
  61. tooltip,
  62. spriteTip,
  63. tipConfig,
  64. trackMouse,
  65. sprite,
  66. surface,
  67. surfaceExt,
  68. pos,
  69. x,
  70. y;
  71. if (!me.tooltip) {
  72. return;
  73. }
  74. clearTimeout(me.tipTimeout);
  75. tooltip = me.tooltip;
  76. spriteTip = me.spriteTip;
  77. tipConfig = me.tipConfig;
  78. trackMouse = tooltip.trackMouse;
  79. if (!trackMouse) {
  80. tooltip.trackMouse = true;
  81. sprite = item.sprite;
  82. surface = sprite.surface;
  83. surfaceExt = Ext.get(surface.getId());
  84. if (surfaceExt) {
  85. pos = surfaceExt.getXY();
  86. x = pos[0] + (sprite.attr.x || 0) + (sprite.attr.translation &amp;&amp; sprite.attr.translation.x || 0);
  87. y = pos[1] + (sprite.attr.y || 0) + (sprite.attr.translation &amp;&amp; sprite.attr.translation.y || 0);
  88. tooltip.targetXY = [x, y];
  89. }
  90. }
  91. if (spriteTip) {
  92. tipConfig.renderer.call(tooltip, item.storeItem, item, spriteTip.surface);
  93. } else {
  94. tipConfig.renderer.call(tooltip, item.storeItem, item);
  95. }
  96. tooltip.show();
  97. tooltip.trackMouse = trackMouse;
  98. },
  99. hideTip: function(item) {
  100. var tooltip = this.tooltip;
  101. if (!tooltip) {
  102. return;
  103. }
  104. clearTimeout(this.tipTimeout);
  105. this.tipTimeout = setTimeout(function() {
  106. tooltip.hide();
  107. }, 0);
  108. }
  109. });</pre>
  110. </body>
  111. </html>