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'>/**
19 </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
52 Ext.define('Ext.chart.Mask', {
53 <span id='Ext-chart-Mask-method-constructor'> /**
54 </span> * Creates new Mask.
55 * @param {Object} config (optional) Config object.
57 constructor: function(config) {
60 me.addEvents('select');
63 Ext.apply(me, config);
66 me.on('afterrender', function() {
67 //create a mask layer component
68 var comp = Ext.create('Ext.chart.MaskLayer', {
72 'mousemove': function(e) {
75 'mouseup': function(e) {
79 //create a resize handler for the component
80 var resizeHandler = Ext.create('Ext.resizer.Resizer', {
86 'resize': function(e) {
91 me.maskType = me.mask;
93 me.maskSprite = me.surface.add({
101 }, me, { single: true });
105 resized: function(e) {
107 bbox = me.bbox || me.chartBBox,
111 height = bbox.height,
112 box = me.mask.getBox(true),
118 staticX = max(staticX, x);
119 staticY = max(staticY, y);
120 staticX = min(staticX, width);
121 staticY = min(staticY, height);
124 me.fireEvent('select', me, box);
127 onMouseUp: function(e) {
129 bbox = me.bbox || me.chartBBox,
130 sel = me.maskSelection;
131 me.maskMouseDown = false;
132 me.mouseDown = false;
135 me.mouseMoved = false;
136 me.fireEvent('select', me, {
145 onMouseDown: function(e) {
148 me.mouseMoved = false;
150 x: e.getPageX() - me.el.getX(),
151 y: e.getPageY() - me.el.getY()
155 onMouseMove: function(e) {
158 bbox = me.bbox || me.chartBBox,
166 height = floor(y + bbox.height),
167 width = floor(x + bbox.width),
170 staticX = posX - me.el.getX(),
171 staticY = posY - me.el.getY(),
172 maskMouseDown = me.maskMouseDown,
175 me.mouseMoved = me.mouseDown;
176 staticX = max(staticX, x);
177 staticY = max(staticY, y);
178 staticX = min(staticX, width);
179 staticY = min(staticY, height);
180 if (maskMouseDown && me.mouseDown) {
181 if (mask == 'horizontal') {
183 maskMouseDown.y = height;
184 posY = me.el.getY() + bbox.height + me.insetPadding;
186 else if (mask == 'vertical') {
188 maskMouseDown.x = width;
190 width = maskMouseDown.x - staticX;
191 height = maskMouseDown.y - staticY;
192 path = ['M', staticX, staticY, 'l', width, 0, 0, height, -width, 0, 'z'];
194 x: width > 0 ? staticX : staticX + width,
195 y: height > 0 ? staticY : staticY + height,
200 x: posX - abs(width),
201 y: posY - abs(height),
206 me.maskSprite.setAttributes({
211 if (mask == 'horizontal') {
212 path = ['M', staticX, y, 'L', staticX, height];
214 else if (mask == 'vertical') {
215 path = ['M', x, staticY, 'L', width, staticY];
218 path = ['M', staticX, y, 'L', staticX, height, 'M', x, staticY, 'L', width, staticY];
220 me.maskSprite.setAttributes({
222 fill: me.maskMouseDown ? me.maskSprite.stroke : false,
223 'stroke-width': mask === true ? 1 : 3,
229 onMouseLeave: function(e) {
231 me.mouseMoved = false;
232 me.mouseDown = false;
233 me.maskMouseDown = false;
235 me.maskSprite.hide(true);