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.Mask-method-constructor'><span id='Ext-chart.Mask'>/**
2 </span></span> * @class Ext.chart.Mask
4 * Defines a mask for a chart's series.
5 * The 'chart' member must be set prior to rendering.
7 * A Mask can be used to select a certain region in a chart.
8 * When enabled, the `select` event will be triggered when a
9 * region is selected by the mask, allowing the user to perform
10 * other tasks like zooming on that region, etc.
12 * In order to use the mask one has to set the Chart `mask` option to
13 * `true`, `vertical` or `horizontal`. Then a possible configuration for the
23 fn: function(me, selection) {
24 me.setZoom(selection);
30 * In this example we zoom the chart to that particular region. You can also get
31 * a handle to a mask instance from the chart object. The `chart.mask` element is a
36 Ext.define('Ext.chart.Mask', {
37 constructor: function(config) {
40 me.addEvents('select');
43 Ext.apply(me, config);
46 me.on('afterrender', function() {
47 //create a mask layer component
48 var comp = Ext.create('Ext.chart.MaskLayer', {
52 'mousemove': function(e) {
55 'mouseup': function(e) {
59 //create a resize handler for the component
60 var resizeHandler = Ext.create('Ext.resizer.Resizer', {
66 'resize': function(e) {
71 me.maskType = me.mask;
73 me.maskSprite = me.surface.add({
81 }, me, { single: true });
85 resized: function(e) {
87 bbox = me.bbox || me.chartBBox,
92 box = me.mask.getBox(true),
98 staticX = max(staticX, x);
99 staticY = max(staticY, y);
100 staticX = min(staticX, width);
101 staticY = min(staticY, height);
104 me.fireEvent('select', me, box);
107 onMouseUp: function(e) {
109 bbox = me.bbox || me.chartBBox,
110 sel = me.maskSelection;
111 me.maskMouseDown = false;
112 me.mouseDown = false;
115 me.mouseMoved = false;
116 me.fireEvent('select', me, {
125 onMouseDown: function(e) {
128 me.mouseMoved = false;
130 x: e.getPageX() - me.el.getX(),
131 y: e.getPageY() - me.el.getY()
135 onMouseMove: function(e) {
138 bbox = me.bbox || me.chartBBox,
146 height = floor(y + bbox.height),
147 width = floor(x + bbox.width),
150 staticX = posX - me.el.getX(),
151 staticY = posY - me.el.getY(),
152 maskMouseDown = me.maskMouseDown,
155 me.mouseMoved = me.mouseDown;
156 staticX = max(staticX, x);
157 staticY = max(staticY, y);
158 staticX = min(staticX, width);
159 staticY = min(staticY, height);
160 if (maskMouseDown && me.mouseDown) {
161 if (mask == 'horizontal') {
163 maskMouseDown.y = height;
164 posY = me.el.getY() + bbox.height + me.insetPadding;
166 else if (mask == 'vertical') {
168 maskMouseDown.x = width;
170 width = maskMouseDown.x - staticX;
171 height = maskMouseDown.y - staticY;
172 path = ['M', staticX, staticY, 'l', width, 0, 0, height, -width, 0, 'z'];
174 x: width > 0 ? staticX : staticX + width,
175 y: height > 0 ? staticY : staticY + height,
180 x: posX - abs(width),
181 y: posY - abs(height),
186 me.maskSprite.setAttributes({
191 if (mask == 'horizontal') {
192 path = ['M', staticX, y, 'L', staticX, height];
194 else if (mask == 'vertical') {
195 path = ['M', x, staticY, 'L', width, staticY];
198 path = ['M', staticX, y, 'L', staticX, height, 'M', x, staticY, 'L', width, staticY];
200 me.maskSprite.setAttributes({
202 fill: me.maskMouseDown ? me.maskSprite.stroke : false,
203 'stroke-width': mask === true ? 1 : 3,
209 onMouseLeave: function(e) {
211 me.mouseMoved = false;
212 me.mouseDown = false;
213 me.maskMouseDown = false;
215 me.maskSprite.hide(true);
218 </pre></pre></body></html>