UNPKG

14.4 kBSource Map (JSON)View Raw
1{"version":3,"file":"g2-plugin-brush.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 9ace5933f725c00cc374","webpack:///./index.js","webpack:///./src/index.js","webpack:///./src/util.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Brush\"] = factory();\n\telse\n\t\troot[\"Brush\"] = factory();\n})(typeof self !== 'undefined' ? self : this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 9ace5933f725c00cc374","/**\n * [exports description]\n * @type {Object}\n */\nvar Brush = require('./src/index');\nmodule.exports = Brush;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./index.js\n// module id = 0\n// module chunks = 0","function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n/**\n * [exports description]\n * @type {Object}\n */\nvar Util = require('./util');\n\nvar Brush = function () {\n function Brush(chart, type) {\n _classCallCheck(this, Brush);\n\n this.startPoint = null;\n this.isBrushing = false;\n this.brushShape = null;\n this.container = null;\n this.polygonPath = null;\n this.polygonPoints = null;\n\n this.type = type || 'XY';\n this.chart = chart;\n // TODO\n this.canvas = chart.get('canvas');\n this.plotRange = chart.get('plotRange');\n this.frontPlot = chart.get('frontPlot');\n\n this.bindEvent();\n }\n\n Brush.prototype.bindEvent = function bindEvent() {\n var me = this;\n var chart = me.chart,\n frontPlot = me.frontPlot,\n type = me.type;\n\n\n chart.on('mousedown', function (ev) {\n var x = ev.x,\n y = ev.y;\n\n var container = me.container;\n me.startPoint = {\n x: x,\n y: y\n };\n me.isBrushing = true; // 开始框选\n if (!container) {\n container = frontPlot.addGroup();\n container.initTransform();\n } else {\n container.clear();\n }\n me.container = container;\n\n if (type === 'polygon') {\n // 不规则筛选\n me.polygonPoints = [];\n me.polygonPath = 'M ' + x + ' ' + y;\n me.polygonPoints.push([x, y]);\n }\n // 这里抛出 brush start 事件\n\n // const originEvent = ev.event;\n // originEvent.stopPropagation();\n // originEvent.preventDefault();\n me._bindCanvasEvent();\n });\n };\n\n Brush.prototype._bindCanvasEvent = function _bindCanvasEvent() {\n var canvas = this.canvas;\n\n var canvasDOM = canvas.get('canvasDOM');\n // canvasDOM.addEventListener('mousemove', Util.wrapBehavior(this, '_onCanvasMouseMove'), false);\n // canvasDOM.addEventListener('mouseup', Util.wrapBehavior(this, '_onCanvasMouseUp'), false);\n this.onMouseMoveListener = Util.addEventListener(canvasDOM, 'mousemove', Util.wrapBehavior(this, '_onCanvasMouseMove'));\n this.onMouseUpListener = Util.addEventListener(canvasDOM, 'mouseup', Util.wrapBehavior(this, '_onCanvasMouseUp'));\n };\n\n Brush.prototype._limitCoordScope = function _limitCoordScope(point) {\n var plotRange = this.plotRange;\n var tl = plotRange.tl,\n br = plotRange.br;\n\n\n if (point.x < tl.x) {\n point.x = tl.x;\n }\n if (point.x > br.x) {\n point.x = br.x;\n }\n if (point.y < tl.y) {\n point.y = tl.y;\n }\n if (point.y > br.y) {\n point.y = br.y;\n }\n return point;\n };\n\n Brush.prototype._onCanvasMouseMove = function _onCanvasMouseMove(ev) {\n var me = this;\n var isBrushing = me.isBrushing,\n type = me.type,\n plotRange = me.plotRange,\n startPoint = me.startPoint;\n\n if (!isBrushing) {\n return;\n }\n var canvas = me.canvas;\n var tl = plotRange.tl,\n tr = plotRange.tr,\n bl = plotRange.bl;\n\n var polygonPath = me.polygonPath;\n var polygonPoints = me.polygonPoints;\n var brushShape = me.brushShape;\n var container = me.container;\n var pointX = ev.offsetX;\n var pointY = ev.offsetY;\n var currentPoint = me._limitCoordScope({\n x: pointX,\n y: pointY\n });\n var rectStartX = void 0;\n var rectStartY = void 0;\n var rectWidth = void 0;\n var rectHeight = void 0;\n\n if (type === 'Y') {\n rectStartX = tl.x;\n rectStartY = currentPoint.y >= startPoint.y ? startPoint.y : currentPoint.y;\n rectWidth = Math.abs(tl.x - tr.x);\n rectHeight = Math.abs(startPoint.y - currentPoint.y);\n } else if (type === 'X') {\n rectStartX = currentPoint.x >= startPoint.x ? startPoint.x : currentPoint.x;\n rectStartY = tl.y;\n rectWidth = Math.abs(startPoint.x - currentPoint.x);\n rectHeight = Math.abs(tl.y - bl.y);\n } else if (type === 'XY') {\n if (currentPoint.x >= startPoint.x) {\n rectStartX = startPoint.x;\n rectStartY = pointY >= startPoint.y ? startPoint.y : currentPoint.y;\n } else {\n rectStartX = currentPoint.x;\n rectStartY = currentPoint.y >= startPoint.y ? startPoint.y : currentPoint.y;\n }\n rectWidth = Math.abs(startPoint.x - currentPoint.x);\n rectHeight = Math.abs(startPoint.y - currentPoint.y);\n } else if (type === 'polygon') {\n // 不规则框选\n polygonPath += 'L ' + pointX + ' ' + pointY;\n polygonPoints.push([pointX, pointY]);\n me.polygonPath = polygonPath;\n me.polygonPoints = polygonPoints;\n if (!brushShape) {\n brushShape = container.addShape('path', {\n attrs: {\n path: polygonPath,\n stroke: '#979797',\n lineWidth: 2,\n fill: '#D8D8D8',\n fillOpacity: 0.5,\n lineDash: [5, 5]\n }\n });\n } else {\n brushShape.attr(Util.mix({}, brushShape.__attrs, {\n path: polygonPath\n }));\n }\n }\n if (type !== 'polygon') {\n if (!brushShape) {\n brushShape = container.addShape('rect', {\n attrs: {\n x: rectStartX,\n y: rectStartY,\n width: rectWidth,\n height: rectHeight,\n fill: '#CCD7EB',\n opacity: 0.4\n }\n });\n } else {\n brushShape.attr(Util.mix({}, brushShape.__attrs, {\n x: rectStartX,\n y: rectStartY,\n width: rectWidth,\n height: rectHeight\n }));\n }\n }\n\n me.brushShape = brushShape;\n\n canvas.draw();\n\n ev.cancelBubble = true;\n ev.returnValue = false;\n };\n\n Brush.prototype._onCanvasMouseUp = function _onCanvasMouseUp() {\n var me = this;\n var canvas = me.canvas,\n type = me.type;\n\n var canvasDOM = canvas.get('canvasDOM');\n\n // canvasDOM.removeEventListener('mousemove', Util.getWrapBehavior(me, '_onCanvasMouseMove'), false);\n // canvasDOM.removeEventListener('mouseup', Util.getWrapBehavior(me, '_onCanvasMouseUp'), false);\n me.onMouseMoveListener.remove();\n me.onMouseUpListener.remove();\n // selectionPlot.clear(); // 一期先默认清楚\n me.isBrushing = false;\n // this.brushShape = null;\n var brushShape = me.brushShape;\n var polygonPath = me.polygonPath;\n var polygonPoints = me.polygonPoints;\n\n if (type === 'polygon') {\n polygonPath += 'z';\n polygonPoints.push([polygonPoints[0][0], polygonPoints[0][1]]);\n\n brushShape.attr(Util.mix({}, brushShape.__attrs, {\n path: polygonPath\n }));\n me.polygonPath = polygonPath;\n me.polygonPoints = polygonPoints;\n canvas.draw();\n } else {\n me.brushShape = null;\n }\n\n // 抛出 brush end 事件\n };\n\n // setMode(type) {\n // // TODO: 框选模式转变\n // }\n\n\n return Brush;\n}();\n\nmodule.exports = Brush;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/index.js\n// module id = 1\n// module chunks = 0","\nfunction _mix(dist, obj) {\n for (var k in obj) {\n if (obj.hasOwnProperty(k) && k !== 'constructor' && obj[k] !== undefined) {\n dist[k] = obj[k];\n }\n }\n}\n\nvar Util = {\n mix: function mix(dist, obj1, obj2, obj3) {\n if (obj1) {\n _mix(dist, obj1);\n }\n\n if (obj2) {\n _mix(dist, obj2);\n }\n\n if (obj3) {\n _mix(dist, obj3);\n }\n return dist;\n },\n\n /**\n * 添加事件监听器\n * @param {Object} target DOM对象\n * @param {String} eventType 事件名\n * @param {Funtion} callback 回调函数\n * @return {Object} 返回对象\n */\n addEventListener: function addEventListener(target, eventType, callback) {\n if (target.addEventListener) {\n target.addEventListener(eventType, callback, false);\n return {\n remove: function remove() {\n target.removeEventListener(eventType, callback, false);\n }\n };\n } else if (target.attachEvent) {\n target.attachEvent('on' + eventType, callback);\n return {\n remove: function remove() {\n target.detachEvent('on' + eventType, callback);\n }\n };\n }\n },\n\n /**\n * 封装事件,便于使用上下文this,和便于解除事件时使用\n * @protected\n * @param {Object} obj 对象\n * @param {String} action 事件名称\n * @return {Function} 返回事件处理函数\n */\n wrapBehavior: function wrapBehavior(obj, action) {\n if (obj['_wrap_' + action]) {\n return obj['_wrap_' + action];\n }\n var method = function method(e) {\n obj[action](e);\n };\n obj['_wrap_' + action] = method;\n return method;\n },\n\n /**\n * 获取封装的事件\n * @protected\n * @param {Object} obj 对象\n * @param {String} action 事件名称\n * @return {Function} 返回事件处理函数\n */\n getWrapBehavior: function getWrapBehavior(obj, action) {\n return obj['_wrap_' + action];\n }\n};\n\nmodule.exports = Util;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/util.js\n// module id = 2\n// module chunks = 0"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;AC7DA;AACA;AACA;AACA;AACA;AACA;;;;;;ACLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;ACtPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""}
\No newline at end of file