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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-chart-Mask-method-constructor'><span id='Ext-chart-Mask'>/**
19 </span></span> * @class Ext.chart.Mask
21 * Defines a mask for a chart's series.
22 * The 'chart' member must be set prior to rendering.
24 * A Mask can be used to select a certain region in a chart.
25 * When enabled, the `select` event will be triggered when a
26 * region is selected by the mask, allowing the user to perform
27 * other tasks like zooming on that region, etc.
29 * In order to use the mask one has to set the Chart `mask` option to
30 * `true`, `vertical` or `horizontal`. Then a possible configuration for the
40 fn: function(me, selection) {
41 me.setZoom(selection);
47 * In this example we zoom the chart to that particular region. You can also get
48 * a handle to a mask instance from the chart object. The `chart.mask` element is a
53 Ext.define('Ext.chart.Mask', {
54 constructor: function(config) {
57 me.addEvents('select');
60 Ext.apply(me, config);
63 me.on('afterrender', function() {
64 //create a mask layer component
65 var comp = Ext.create('Ext.chart.MaskLayer', {
69 'mousemove': function(e) {
72 'mouseup': function(e) {
76 //create a resize handler for the component
77 var resizeHandler = Ext.create('Ext.resizer.Resizer', {
83 'resize': function(e) {
88 me.maskType = me.mask;
90 me.maskSprite = me.surface.add({
98 }, me, { single: true });
102 resized: function(e) {
104 bbox = me.bbox || me.chartBBox,
108 height = bbox.height,
109 box = me.mask.getBox(true),
115 staticX = max(staticX, x);
116 staticY = max(staticY, y);
117 staticX = min(staticX, width);
118 staticY = min(staticY, height);
121 me.fireEvent('select', me, box);
124 onMouseUp: function(e) {
126 bbox = me.bbox || me.chartBBox,
127 sel = me.maskSelection;
128 me.maskMouseDown = false;
129 me.mouseDown = false;
132 me.mouseMoved = false;
133 me.fireEvent('select', me, {
142 onMouseDown: function(e) {
145 me.mouseMoved = false;
147 x: e.getPageX() - me.el.getX(),
148 y: e.getPageY() - me.el.getY()
152 onMouseMove: function(e) {
155 bbox = me.bbox || me.chartBBox,
163 height = floor(y + bbox.height),
164 width = floor(x + bbox.width),
167 staticX = posX - me.el.getX(),
168 staticY = posY - me.el.getY(),
169 maskMouseDown = me.maskMouseDown,
172 me.mouseMoved = me.mouseDown;
173 staticX = max(staticX, x);
174 staticY = max(staticY, y);
175 staticX = min(staticX, width);
176 staticY = min(staticY, height);
177 if (maskMouseDown && me.mouseDown) {
178 if (mask == 'horizontal') {
180 maskMouseDown.y = height;
181 posY = me.el.getY() + bbox.height + me.insetPadding;
183 else if (mask == 'vertical') {
185 maskMouseDown.x = width;
187 width = maskMouseDown.x - staticX;
188 height = maskMouseDown.y - staticY;
189 path = ['M', staticX, staticY, 'l', width, 0, 0, height, -width, 0, 'z'];
191 x: width > 0 ? staticX : staticX + width,
192 y: height > 0 ? staticY : staticY + height,
197 x: posX - abs(width),
198 y: posY - abs(height),
203 me.maskSprite.setAttributes({
208 if (mask == 'horizontal') {
209 path = ['M', staticX, y, 'L', staticX, height];
211 else if (mask == 'vertical') {
212 path = ['M', x, staticY, 'L', width, staticY];
215 path = ['M', staticX, y, 'L', staticX, height, 'M', x, staticY, 'L', width, staticY];
217 me.maskSprite.setAttributes({
219 fill: me.maskMouseDown ? me.maskSprite.stroke : false,
220 'stroke-width': mask === true ? 1 : 3,
226 onMouseLeave: function(e) {
228 me.mouseMoved = false;
229 me.mouseDown = false;
230 me.maskMouseDown = false;
232 me.maskSprite.hide(true);