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; }
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 require: ['Ext.chart.MaskLayer'],
54 <span id='Ext-chart-Mask-method-constructor'> /**
55 </span> * Creates new Mask.
56 * @param {Object} config (optional) Config object.
58 constructor: function(config) {
61 me.addEvents('select');
64 Ext.apply(me, config);
67 me.on('afterrender', function() {
68 //create a mask layer component
69 var comp = Ext.create('Ext.chart.MaskLayer', {
73 'mousemove': function(e) {
76 'mouseup': function(e) {
80 //create a resize handler for the component
81 var resizeHandler = Ext.create('Ext.resizer.Resizer', {
87 'resize': function(e) {
92 me.maskType = me.mask;
94 me.maskSprite = me.surface.add({
102 }, me, { single: true });
106 resized: function(e) {
108 bbox = me.bbox || me.chartBBox,
112 height = bbox.height,
113 box = me.mask.getBox(true),
119 staticX = max(staticX, x);
120 staticY = max(staticY, y);
121 staticX = min(staticX, width);
122 staticY = min(staticY, height);
125 me.fireEvent('select', me, box);
128 onMouseUp: function(e) {
130 bbox = me.bbox || me.chartBBox,
131 sel = me.maskSelection;
132 me.maskMouseDown = false;
133 me.mouseDown = false;
136 me.mouseMoved = false;
137 me.fireEvent('select', me, {
146 onMouseDown: function(e) {
149 me.mouseMoved = false;
151 x: e.getPageX() - me.el.getX(),
152 y: e.getPageY() - me.el.getY()
156 onMouseMove: function(e) {
159 bbox = me.bbox || me.chartBBox,
167 height = floor(y + bbox.height),
168 width = floor(x + bbox.width),
171 staticX = posX - me.el.getX(),
172 staticY = posY - me.el.getY(),
173 maskMouseDown = me.maskMouseDown,
176 me.mouseMoved = me.mouseDown;
177 staticX = max(staticX, x);
178 staticY = max(staticY, y);
179 staticX = min(staticX, width);
180 staticY = min(staticY, height);
181 if (maskMouseDown && me.mouseDown) {
182 if (mask == 'horizontal') {
184 maskMouseDown.y = height;
185 posY = me.el.getY() + bbox.height + me.insetPadding;
187 else if (mask == 'vertical') {
189 maskMouseDown.x = width;
191 width = maskMouseDown.x - staticX;
192 height = maskMouseDown.y - staticY;
193 path = ['M', staticX, staticY, 'l', width, 0, 0, height, -width, 0, 'z'];
195 x: width > 0 ? staticX : staticX + width,
196 y: height > 0 ? staticY : staticY + height,
200 me.mask.updateBox(me.maskSelection);
202 me.maskSprite.setAttributes({
207 if (mask == 'horizontal') {
208 path = ['M', staticX, y, 'L', staticX, height];
210 else if (mask == 'vertical') {
211 path = ['M', x, staticY, 'L', width, staticY];
214 path = ['M', staticX, y, 'L', staticX, height, 'M', x, staticY, 'L', width, staticY];
216 me.maskSprite.setAttributes({
218 fill: me.maskMouseDown ? me.maskSprite.stroke : false,
219 'stroke-width': mask === true ? 1 : 3,
225 onMouseLeave: function(e) {
227 me.mouseMoved = false;
228 me.mouseDown = false;
229 me.maskMouseDown = false;
231 me.maskSprite.hide(true);