/ext-4.1.0_b3/docs/source/Mask.html

https://bitbucket.org/srogerf/javascript · HTML · 249 lines · 237 code · 12 blank · 0 comment · 0 complexity · 3125c347fdf0d01e9a8a2579ca1ef584 MD5 · raw file

  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-Mask'>/**
  19. </span> * Defines a mask for a chart's series.
  20. * The 'chart' member must be set prior to rendering.
  21. *
  22. * A Mask can be used to select a certain region in a chart.
  23. * When enabled, the `select` event will be triggered when a
  24. * region is selected by the mask, allowing the user to perform
  25. * other tasks like zooming on that region, etc.
  26. *
  27. * In order to use the mask one has to set the Chart `mask` option to
  28. * `true`, `vertical` or `horizontal`. Then a possible configuration for the
  29. * listener could be:
  30. *
  31. * items: {
  32. * xtype: 'chart',
  33. * animate: true,
  34. * store: store1,
  35. * mask: 'horizontal',
  36. * listeners: {
  37. * select: {
  38. * fn: function(me, selection) {
  39. * me.setZoom(selection);
  40. * me.mask.hide();
  41. * }
  42. * }
  43. * }
  44. * }
  45. *
  46. * In this example we zoom the chart to that particular region. You can also get
  47. * a handle to a mask instance from the chart object. The `chart.mask` element is a
  48. * `Ext.Panel`.
  49. *
  50. */
  51. Ext.define('Ext.chart.Mask', {
  52. requires: [
  53. 'Ext.chart.MaskLayer'
  54. ],
  55. <span id='Ext-chart-Mask-cfg-mask'> /**
  56. </span> * @cfg {Boolean/String} mask
  57. * Enables selecting a region on chart. True to enable any selection,
  58. * 'horizontal' or 'vertical' to restrict the selection to X or Y axis.
  59. *
  60. * The mask in itself will do nothing but fire 'select' event.
  61. * See {@link Ext.chart.Mask} for example.
  62. */
  63. <span id='Ext-chart-Mask-method-constructor'> /**
  64. </span> * Creates new Mask.
  65. * @param {Object} [config] Config object.
  66. */
  67. constructor: function(config) {
  68. var me = this;
  69. me.addEvents('select');
  70. if (config) {
  71. Ext.apply(me, config);
  72. }
  73. if (me.enableMask) {
  74. me.on('afterrender', function() {
  75. //create a mask layer component
  76. var comp = new Ext.chart.MaskLayer({
  77. renderTo: me.el,
  78. hidden: true
  79. });
  80. comp.el.on({
  81. 'mousemove': function(e) {
  82. me.onMouseMove(e);
  83. },
  84. 'mouseup': function(e) {
  85. me.resized(e);
  86. }
  87. });
  88. //create a resize handler for the component
  89. var resizeHandler = new Ext.resizer.Resizer({
  90. el: comp.el,
  91. handles: 'all',
  92. pinned: true
  93. });
  94. resizeHandler.on({
  95. 'resize': function(e) {
  96. me.resized(e);
  97. }
  98. });
  99. comp.initDraggable();
  100. me.maskType = me.mask;
  101. me.mask = comp;
  102. me.maskSprite = me.surface.add({
  103. type: 'path',
  104. path: ['M', 0, 0],
  105. zIndex: 1001,
  106. opacity: 0.7,
  107. hidden: true,
  108. stroke: '#444'
  109. });
  110. }, me, { single: true });
  111. }
  112. },
  113. resized: function(e) {
  114. var me = this,
  115. bbox = me.bbox || me.chartBBox,
  116. x = bbox.x,
  117. y = bbox.y,
  118. width = bbox.width,
  119. height = bbox.height,
  120. box = me.mask.getBox(true),
  121. max = Math.max,
  122. min = Math.min,
  123. staticX = box.x - x,
  124. staticY = box.y - y;
  125. staticX = max(staticX, x);
  126. staticY = max(staticY, y);
  127. staticX = min(staticX, width);
  128. staticY = min(staticY, height);
  129. box.x = staticX;
  130. box.y = staticY;
  131. me.fireEvent('select', me, box);
  132. },
  133. onMouseUp: function(e) {
  134. var me = this,
  135. bbox = me.bbox || me.chartBBox,
  136. sel = me.maskSelection;
  137. me.maskMouseDown = false;
  138. me.mouseDown = false;
  139. if (me.mouseMoved) {
  140. me.onMouseMove(e);
  141. me.mouseMoved = false;
  142. me.fireEvent('select', me, {
  143. x: sel.x - bbox.x,
  144. y: sel.y - bbox.y,
  145. width: sel.width,
  146. height: sel.height
  147. });
  148. }
  149. },
  150. onMouseDown: function(e) {
  151. var me = this;
  152. me.mouseDown = true;
  153. me.mouseMoved = false;
  154. me.maskMouseDown = {
  155. x: e.getPageX() - me.el.getX(),
  156. y: e.getPageY() - me.el.getY()
  157. };
  158. },
  159. onMouseMove: function(e) {
  160. var me = this,
  161. mask = me.maskType,
  162. bbox = me.bbox || me.chartBBox,
  163. x = bbox.x,
  164. y = bbox.y,
  165. math = Math,
  166. floor = math.floor,
  167. abs = math.abs,
  168. min = math.min,
  169. max = math.max,
  170. height = floor(y + bbox.height),
  171. width = floor(x + bbox.width),
  172. posX = e.getPageX(),
  173. posY = e.getPageY(),
  174. staticX = posX - me.el.getX(),
  175. staticY = posY - me.el.getY(),
  176. maskMouseDown = me.maskMouseDown,
  177. path;
  178. me.mouseMoved = me.mouseDown;
  179. staticX = max(staticX, x);
  180. staticY = max(staticY, y);
  181. staticX = min(staticX, width);
  182. staticY = min(staticY, height);
  183. if (maskMouseDown &amp;&amp; me.mouseDown) {
  184. if (mask == 'horizontal') {
  185. staticY = y;
  186. maskMouseDown.y = height;
  187. posY = me.el.getY() + bbox.height + me.insetPadding;
  188. }
  189. else if (mask == 'vertical') {
  190. staticX = x;
  191. maskMouseDown.x = width;
  192. }
  193. width = maskMouseDown.x - staticX;
  194. height = maskMouseDown.y - staticY;
  195. path = ['M', staticX, staticY, 'l', width, 0, 0, height, -width, 0, 'z'];
  196. me.maskSelection = {
  197. x: width &gt; 0 ? staticX : staticX + width,
  198. y: height &gt; 0 ? staticY : staticY + height,
  199. width: abs(width),
  200. height: abs(height)
  201. };
  202. me.mask.updateBox(me.maskSelection);
  203. me.mask.show();
  204. me.maskSprite.setAttributes({
  205. hidden: true
  206. }, true);
  207. }
  208. else {
  209. if (mask == 'horizontal') {
  210. path = ['M', staticX, y, 'L', staticX, height];
  211. }
  212. else if (mask == 'vertical') {
  213. path = ['M', x, staticY, 'L', width, staticY];
  214. }
  215. else {
  216. path = ['M', staticX, y, 'L', staticX, height, 'M', x, staticY, 'L', width, staticY];
  217. }
  218. me.maskSprite.setAttributes({
  219. path: path,
  220. fill: me.maskMouseDown ? me.maskSprite.stroke : false,
  221. 'stroke-width': mask === true ? 1 : 3,
  222. hidden: false
  223. }, true);
  224. }
  225. },
  226. onMouseLeave: function(e) {
  227. var me = this;
  228. me.mouseMoved = false;
  229. me.mouseDown = false;
  230. me.maskMouseDown = false;
  231. me.mask.hide();
  232. me.maskSprite.hide(true);
  233. }
  234. });
  235. </pre>
  236. </body>
  237. </html>