1 | (function webpackUniversalModuleDefinition(root, factory) {
|
2 | if(typeof exports === 'object' && typeof module === 'object')
|
3 | module.exports = factory();
|
4 | else if(typeof define === 'function' && define.amd)
|
5 | define([], factory);
|
6 | else if(typeof exports === 'object')
|
7 | exports["Brush"] = factory();
|
8 | else
|
9 | root["Brush"] = factory();
|
10 | })(typeof self !== 'undefined' ? self : this, function() {
|
11 | return (function(modules) {
|
12 |
|
13 | var installedModules = {};
|
14 |
|
15 |
|
16 | function __webpack_require__(moduleId) {
|
17 |
|
18 |
|
19 | if(installedModules[moduleId]) {
|
20 | return installedModules[moduleId].exports;
|
21 | }
|
22 |
|
23 | var module = installedModules[moduleId] = {
|
24 | i: moduleId,
|
25 | l: false,
|
26 | exports: {}
|
27 | };
|
28 |
|
29 |
|
30 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 |
|
32 |
|
33 | module.l = true;
|
34 |
|
35 |
|
36 | return module.exports;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | __webpack_require__.m = modules;
|
42 |
|
43 |
|
44 | __webpack_require__.c = installedModules;
|
45 |
|
46 |
|
47 | __webpack_require__.d = function(exports, name, getter) {
|
48 | if(!__webpack_require__.o(exports, name)) {
|
49 | Object.defineProperty(exports, name, {
|
50 | configurable: false,
|
51 | enumerable: true,
|
52 | get: getter
|
53 | /******/ });
|
54 | /******/ }
|
55 | /******/ };
|
56 | /******/
|
57 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
58 | /******/ __webpack_require__.n = function(module) {
|
59 | var getter = module && module.__esModule ?
|
60 | function getDefault() { return module['default']; } :
|
61 | function getModuleExports() { return module; };
|
62 | __webpack_require__.d(getter, 'a', getter);
|
63 | return getter;
|
64 | };
|
65 |
|
66 |
|
67 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
68 |
|
69 |
|
70 | __webpack_require__.p = "";
|
71 |
|
72 |
|
73 | return __webpack_require__(__webpack_require__.s = 0);
|
74 | })
|
75 |
|
76 | ([
|
77 |
|
78 | (function(module, exports, __webpack_require__) {
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | var Brush = __webpack_require__(1);
|
85 | module.exports = Brush;
|
86 |
|
87 | }),
|
88 |
|
89 | (function(module, exports, __webpack_require__) {
|
90 |
|
91 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | var Util = __webpack_require__(2);
|
98 |
|
99 | var Brush = function () {
|
100 | function Brush(chart, type) {
|
101 | _classCallCheck(this, Brush);
|
102 |
|
103 | this.startPoint = null;
|
104 | this.isBrushing = false;
|
105 | this.brushShape = null;
|
106 | this.container = null;
|
107 | this.polygonPath = null;
|
108 | this.polygonPoints = null;
|
109 |
|
110 | this.type = type || 'XY';
|
111 | this.chart = chart;
|
112 |
|
113 | this.canvas = chart.get('canvas');
|
114 | this.plotRange = chart.get('plotRange');
|
115 | this.frontPlot = chart.get('frontPlot');
|
116 |
|
117 | this.bindEvent();
|
118 | }
|
119 |
|
120 | Brush.prototype.bindEvent = function bindEvent() {
|
121 | var me = this;
|
122 | var chart = me.chart,
|
123 | frontPlot = me.frontPlot,
|
124 | type = me.type;
|
125 |
|
126 |
|
127 | chart.on('mousedown', function (ev) {
|
128 | var x = ev.x,
|
129 | y = ev.y;
|
130 |
|
131 | var container = me.container;
|
132 | me.startPoint = {
|
133 | x: x,
|
134 | y: y
|
135 | };
|
136 | me.isBrushing = true;
|
137 | if (!container) {
|
138 | container = frontPlot.addGroup();
|
139 | container.initTransform();
|
140 | } else {
|
141 | container.clear();
|
142 | }
|
143 | me.container = container;
|
144 |
|
145 | if (type === 'polygon') {
|
146 |
|
147 | me.polygonPoints = [];
|
148 | me.polygonPath = 'M ' + x + ' ' + y;
|
149 | me.polygonPoints.push([x, y]);
|
150 | }
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | me._bindCanvasEvent();
|
157 | });
|
158 | };
|
159 |
|
160 | Brush.prototype._bindCanvasEvent = function _bindCanvasEvent() {
|
161 | var canvas = this.canvas;
|
162 |
|
163 | var canvasDOM = canvas.get('canvasDOM');
|
164 |
|
165 |
|
166 | this.onMouseMoveListener = Util.addEventListener(canvasDOM, 'mousemove', Util.wrapBehavior(this, '_onCanvasMouseMove'));
|
167 | this.onMouseUpListener = Util.addEventListener(canvasDOM, 'mouseup', Util.wrapBehavior(this, '_onCanvasMouseUp'));
|
168 | };
|
169 |
|
170 | Brush.prototype._limitCoordScope = function _limitCoordScope(point) {
|
171 | var plotRange = this.plotRange;
|
172 | var tl = plotRange.tl,
|
173 | br = plotRange.br;
|
174 |
|
175 |
|
176 | if (point.x < tl.x) {
|
177 | point.x = tl.x;
|
178 | }
|
179 | if (point.x > br.x) {
|
180 | point.x = br.x;
|
181 | }
|
182 | if (point.y < tl.y) {
|
183 | point.y = tl.y;
|
184 | }
|
185 | if (point.y > br.y) {
|
186 | point.y = br.y;
|
187 | }
|
188 | return point;
|
189 | };
|
190 |
|
191 | Brush.prototype._onCanvasMouseMove = function _onCanvasMouseMove(ev) {
|
192 | var me = this;
|
193 | var isBrushing = me.isBrushing,
|
194 | type = me.type,
|
195 | plotRange = me.plotRange,
|
196 | startPoint = me.startPoint;
|
197 |
|
198 | if (!isBrushing) {
|
199 | return;
|
200 | }
|
201 | var canvas = me.canvas;
|
202 | var tl = plotRange.tl,
|
203 | tr = plotRange.tr,
|
204 | bl = plotRange.bl;
|
205 |
|
206 | var polygonPath = me.polygonPath;
|
207 | var polygonPoints = me.polygonPoints;
|
208 | var brushShape = me.brushShape;
|
209 | var container = me.container;
|
210 | var pointX = ev.offsetX;
|
211 | var pointY = ev.offsetY;
|
212 | var currentPoint = me._limitCoordScope({
|
213 | x: pointX,
|
214 | y: pointY
|
215 | });
|
216 | var rectStartX = void 0;
|
217 | var rectStartY = void 0;
|
218 | var rectWidth = void 0;
|
219 | var rectHeight = void 0;
|
220 |
|
221 | if (type === 'Y') {
|
222 | rectStartX = tl.x;
|
223 | rectStartY = currentPoint.y >= startPoint.y ? startPoint.y : currentPoint.y;
|
224 | rectWidth = Math.abs(tl.x - tr.x);
|
225 | rectHeight = Math.abs(startPoint.y - currentPoint.y);
|
226 | } else if (type === 'X') {
|
227 | rectStartX = currentPoint.x >= startPoint.x ? startPoint.x : currentPoint.x;
|
228 | rectStartY = tl.y;
|
229 | rectWidth = Math.abs(startPoint.x - currentPoint.x);
|
230 | rectHeight = Math.abs(tl.y - bl.y);
|
231 | } else if (type === 'XY') {
|
232 | if (currentPoint.x >= startPoint.x) {
|
233 | rectStartX = startPoint.x;
|
234 | rectStartY = pointY >= startPoint.y ? startPoint.y : currentPoint.y;
|
235 | } else {
|
236 | rectStartX = currentPoint.x;
|
237 | rectStartY = currentPoint.y >= startPoint.y ? startPoint.y : currentPoint.y;
|
238 | }
|
239 | rectWidth = Math.abs(startPoint.x - currentPoint.x);
|
240 | rectHeight = Math.abs(startPoint.y - currentPoint.y);
|
241 | } else if (type === 'polygon') {
|
242 |
|
243 | polygonPath += 'L ' + pointX + ' ' + pointY;
|
244 | polygonPoints.push([pointX, pointY]);
|
245 | me.polygonPath = polygonPath;
|
246 | me.polygonPoints = polygonPoints;
|
247 | if (!brushShape) {
|
248 | brushShape = container.addShape('path', {
|
249 | attrs: {
|
250 | path: polygonPath,
|
251 | stroke: '#979797',
|
252 | lineWidth: 2,
|
253 | fill: '#D8D8D8',
|
254 | fillOpacity: 0.5,
|
255 | lineDash: [5, 5]
|
256 | }
|
257 | });
|
258 | } else {
|
259 | brushShape.attr(Util.mix({}, brushShape.__attrs, {
|
260 | path: polygonPath
|
261 | }));
|
262 | }
|
263 | }
|
264 | if (type !== 'polygon') {
|
265 | if (!brushShape) {
|
266 | brushShape = container.addShape('rect', {
|
267 | attrs: {
|
268 | x: rectStartX,
|
269 | y: rectStartY,
|
270 | width: rectWidth,
|
271 | height: rectHeight,
|
272 | fill: '#CCD7EB',
|
273 | opacity: 0.4
|
274 | }
|
275 | });
|
276 | } else {
|
277 | brushShape.attr(Util.mix({}, brushShape.__attrs, {
|
278 | x: rectStartX,
|
279 | y: rectStartY,
|
280 | width: rectWidth,
|
281 | height: rectHeight
|
282 | }));
|
283 | }
|
284 | }
|
285 |
|
286 | me.brushShape = brushShape;
|
287 |
|
288 | canvas.draw();
|
289 |
|
290 | ev.cancelBubble = true;
|
291 | ev.returnValue = false;
|
292 | };
|
293 |
|
294 | Brush.prototype._onCanvasMouseUp = function _onCanvasMouseUp() {
|
295 | var me = this;
|
296 | var canvas = me.canvas,
|
297 | type = me.type;
|
298 |
|
299 | var canvasDOM = canvas.get('canvasDOM');
|
300 |
|
301 |
|
302 |
|
303 | me.onMouseMoveListener.remove();
|
304 | me.onMouseUpListener.remove();
|
305 |
|
306 | me.isBrushing = false;
|
307 |
|
308 | var brushShape = me.brushShape;
|
309 | var polygonPath = me.polygonPath;
|
310 | var polygonPoints = me.polygonPoints;
|
311 |
|
312 | if (type === 'polygon') {
|
313 | polygonPath += 'z';
|
314 | polygonPoints.push([polygonPoints[0][0], polygonPoints[0][1]]);
|
315 |
|
316 | brushShape.attr(Util.mix({}, brushShape.__attrs, {
|
317 | path: polygonPath
|
318 | }));
|
319 | me.polygonPath = polygonPath;
|
320 | me.polygonPoints = polygonPoints;
|
321 | canvas.draw();
|
322 | } else {
|
323 | me.brushShape = null;
|
324 | }
|
325 |
|
326 |
|
327 | };
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | return Brush;
|
335 | }();
|
336 |
|
337 | module.exports = Brush;
|
338 |
|
339 | }),
|
340 |
|
341 | (function(module, exports) {
|
342 |
|
343 |
|
344 | function _mix(dist, obj) {
|
345 | for (var k in obj) {
|
346 | if (obj.hasOwnProperty(k) && k !== 'constructor' && obj[k] !== undefined) {
|
347 | dist[k] = obj[k];
|
348 | }
|
349 | }
|
350 | }
|
351 |
|
352 | var Util = {
|
353 | mix: function mix(dist, obj1, obj2, obj3) {
|
354 | if (obj1) {
|
355 | _mix(dist, obj1);
|
356 | }
|
357 |
|
358 | if (obj2) {
|
359 | _mix(dist, obj2);
|
360 | }
|
361 |
|
362 | if (obj3) {
|
363 | _mix(dist, obj3);
|
364 | }
|
365 | return dist;
|
366 | },
|
367 |
|
368 | |
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 | addEventListener: function addEventListener(target, eventType, callback) {
|
376 | if (target.addEventListener) {
|
377 | target.addEventListener(eventType, callback, false);
|
378 | return {
|
379 | remove: function remove() {
|
380 | target.removeEventListener(eventType, callback, false);
|
381 | }
|
382 | };
|
383 | } else if (target.attachEvent) {
|
384 | target.attachEvent('on' + eventType, callback);
|
385 | return {
|
386 | remove: function remove() {
|
387 | target.detachEvent('on' + eventType, callback);
|
388 | }
|
389 | };
|
390 | }
|
391 | },
|
392 |
|
393 | |
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 | wrapBehavior: function wrapBehavior(obj, action) {
|
401 | if (obj['_wrap_' + action]) {
|
402 | return obj['_wrap_' + action];
|
403 | }
|
404 | var method = function method(e) {
|
405 | obj[action](e);
|
406 | };
|
407 | obj['_wrap_' + action] = method;
|
408 | return method;
|
409 | },
|
410 |
|
411 | |
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | getWrapBehavior: function getWrapBehavior(obj, action) {
|
419 | return obj['_wrap_' + action];
|
420 | }
|
421 | };
|
422 |
|
423 | module.exports = Util;
|
424 |
|
425 | })
|
426 | ]);
|
427 | });
|
428 |
|
\ | No newline at end of file |