UNPKG

wetrade-design

Version:

一款多语言支持Vue3的UI框架

132 lines 4.84 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import GraphLink from './graphLink'; import GraphNode from './graphNode'; import { mark, arrayReplace } from './index'; var Graph = /*#__PURE__*/function () { function Graph(options) { _classCallCheck(this, Graph); var relationMark = options.relationMark, startMark = options.startMark, endMark = options.endMark, _options$linkList = options.linkList, linkList = _options$linkList === void 0 ? [] : _options$linkList, _options$nodeList = options.nodeList, nodeList = _options$nodeList === void 0 ? [] : _options$nodeList, origin = options.origin, readonly = options.readonly, hiddenAppend = options.hiddenAppend; _extends(mark, { relationMark: relationMark, startMark: startMark, endMark: endMark }); this.nodeList = []; this.linkList = []; this.origin = origin; this.mouseOnLink = null; this.mouseonNode = null; this.maskBoundingClientRect = {}; this.readonly = readonly; this.hiddenAppend = hiddenAppend; this.initNode(nodeList); this.initLink(linkList); this.initButtonAndLine(linkList); } // 源数组map映射节点 _createClass(Graph, [{ key: "originPointMap", value: function originPointMap(nodeList) { var map = {}; nodeList.forEach(function (point) { map[point[mark.relationMark]] = point; }); return map; } // 节点映射 创建连线时需要用到 }, { key: "pointMap", value: function pointMap() { var map = {}; this.nodeList.forEach(function (point) { map[point[mark.relationMark]] = point; }); return map; } }, { key: "initNode", value: function initNode(nodeList) { var _this = this; arrayReplace(this.nodeList, nodeList.map(function (node) { return _this.createNode(node); })); this.nodeMap = this.originPointMap(nodeList); } }, { key: "initLink", value: function initLink(linkList) { var _this2 = this; arrayReplace(this.linkList, linkList.map(function (link) { return _this2.createLink(link); })); } }, { key: "createNode", value: function createNode(options) { return new GraphNode(options, this); } }, { key: "createLink", value: function createLink(options) { return new GraphLink(options, this); } }, { key: "clearButtonAndLine", value: function clearButtonAndLine() { this.insertNodeList = []; this.shrinkNodeList = []; this.appendNodeList = []; this.insertLineList = []; this.shrinkLineList = []; } // 初始化按钮和线段 }, { key: "initButtonAndLine", value: function initButtonAndLine(linkList) { var _this3 = this; this.clearButtonAndLine(); this.nodeList.forEach(function (node) { var _node$meta, _node$meta$extParam, _node$meta2; // 初始化【+】 if (node.meta.extParam.isOpen && node.meta.extParam.canInsert && !node.meta.extParam.isDragElement && !_this3.readonly) { _this3.insertNodeList.push(node); } //【展开收起】 var hasNextNodeAndNotEmpty = linkList.some(function (link) { var _link$meta, _link$meta2; return link.startId === node.id && (link === null || link === void 0 ? void 0 : (_link$meta = link.meta) === null || _link$meta === void 0 ? void 0 : _link$meta.activeId) === -1 && !((_link$meta2 = link.meta) !== null && _link$meta2 !== void 0 && _link$meta2.isDragElement); }); if (hasNextNodeAndNotEmpty) { _this3.shrinkNodeList.push(node); } // 初始化【添】 if (!((_node$meta = node.meta) !== null && _node$meta !== void 0 && (_node$meta$extParam = _node$meta.extParam) !== null && _node$meta$extParam !== void 0 && _node$meta$extParam.isDragElement) && !['start_node', 'empty'].includes((_node$meta2 = node.meta) === null || _node$meta2 === void 0 ? void 0 : _node$meta2.configKey) && !_this3.readonly && !_this3.hiddenAppend) { _this3.appendNodeList.push(node); } // 【+】的连线 if (node.meta.extParam.isOpen && node.meta.extParam.canInsert && !_this3.linkList.some(function (link) { return link.startId === node.id; }) && !node.meta.extParam.isDragElement) { _this3.insertLineList.push(node); } // 【展开收起】的连线 if (!node.meta.extParam.isOpen && !node.meta.extParam.isDragElement) { _this3.shrinkLineList.push(node); } }); } }]); return Graph; }(); export default Graph;