3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.chart.Mask
18 * Defines a mask for a chart's series.
19 * The 'chart' member must be set prior to rendering.
21 * A Mask can be used to select a certain region in a chart.
22 * When enabled, the `select` event will be triggered when a
23 * region is selected by the mask, allowing the user to perform
24 * other tasks like zooming on that region, etc.
26 * In order to use the mask one has to set the Chart `mask` option to
27 * `true`, `vertical` or `horizontal`. Then a possible configuration for the
37 fn: function(me, selection) {
38 me.setZoom(selection);
44 * In this example we zoom the chart to that particular region. You can also get
45 * a handle to a mask instance from the chart object. The `chart.mask` element is a
49 Ext.define('Ext.chart.Mask', {
52 * @param {Object} config (optional) Config object.
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);