UNPKG

wetrade-design

Version:

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

135 lines (129 loc) 6.21 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _const = require("./const"); var _index = require("./index"); var d3 = _interopRequireWildcard(require("d3")); var _types = require("./types"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /** * User: CHT * Date: 2020/5/8 * Time: 14:01 */ var GraphNode = /*#__PURE__*/function () { // 计算X方法 // 计算Y方法 // 计算X的依赖集合 // 宽度 // 高度 // Y轴层级 function GraphNode(props, graph) { (0, _classCallCheck2.default)(this, GraphNode); var _props$coordinate = props.coordinate, coordinate = _props$coordinate === void 0 ? [0, 0] : _props$coordinate, _props$meta = props.meta, meta = _props$meta === void 0 ? null : _props$meta, width = props.width, height = props.height; this.$options = props; var id = props[_index.mark.relationMark] || (0, _index.uuid)('node'); this.key = (0, _index.uuid)('node'); this.graph = graph; this[_index.mark.relationMark] = id; this.coordinate = (0, _toConsumableArray2.default)(coordinate); this.meta = meta; this.width = width; this.height = height; } (0, _createClass2.default)(GraphNode, [{ key: "createPath", value: function createPath(_ref) { var type = _ref.type; var path = d3.path(); // 是否有下一个节点,并且下一个节点不是空节点 var startX = this.coordinate[0] + this.width; // 开始x var startY = this.coordinate[1] + _const.CONDITION_HEAD_NODE_HEIGHT / 2; // 开始y var endX = 0; switch (type) { case _types.NodeLineType.INSERT: endX = startX + _const.APPEND_EMPTY_X_GAP; break; case _types.NodeLineType.SHRINK: endX = startX + _const.SHRINK_CLOSE_X_GAP; break; } var endY = startY; path.moveTo(startX, startY); path.lineTo(endX, endY); path.closePath(); return path; } }, { key: "createArc", value: function createArc(type) { var startPath = d3.path(); var endPath = d3.path(); var startX = this.coordinate[0] + this.width + 3; // 开始节点x位置 var startY = this.coordinate[1] + _const.CONDITION_HEAD_NODE_HEIGHT / 2; // 开始节点y位置 var endX = 0; // 结束位置x switch (type) { case _types.NodeLineType.INSERT: endX = startX + _const.APPEND_EMPTY_X_GAP - 6.5; break; case _types.NodeLineType.SHRINK: endX = startX + _const.SHRINK_CLOSE_X_GAP - 6.5; break; } var endY = startY; // 结束位置 y startPath.arc(startX, startY, 3, 0, Math.PI * 2, true); endPath.arc(endX, endY, 3, 0, Math.PI * 2, true); return { startPath: startPath, endPath: endPath }; } // 创建端点 }, { key: "createTerminalPoint", value: function createTerminalPoint(_ref2) { var _this$meta, _this$meta$extParam, _this$meta2, _this$meta2$extParam; var g = _ref2.g, color = _ref2.color, type = _ref2.type; var _this$createArc = this.createArc(type), startPath = _this$createArc.startPath, endPath = _this$createArc.endPath; g.append('path').classed("line-end-point", true).attr('d', endPath).attr('fill', color); if ((_this$meta = this.meta) !== null && _this$meta !== void 0 && (_this$meta$extParam = _this$meta.extParam) !== null && _this$meta$extParam !== void 0 && _this$meta$extParam.isMergeNode) return; g.append('path').classed("line-start-point", true).attr('data-id', (_this$meta2 = this.meta) === null || _this$meta2 === void 0 ? void 0 : (_this$meta2$extParam = _this$meta2.extParam) === null || _this$meta2$extParam === void 0 ? void 0 : _this$meta2$extParam.activeId).attr('d', startPath).attr('fill', color); } }, { key: "createLine", value: function createLine(_ref3) { var _this$meta3, _this$meta3$extParam; var g = _ref3.g, color = _ref3.style.color, type = _ref3.type; var path = this.createPath({ type: type }); g.append('path').classed('line-path', true).attr('data-id', (_this$meta3 = this.meta) === null || _this$meta3 === void 0 ? void 0 : (_this$meta3$extParam = _this$meta3.extParam) === null || _this$meta3$extParam === void 0 ? void 0 : _this$meta3$extParam.activeId).attr('d', path).attr('stroke-width', 1).attr('fill', 'none').attr('stroke', color); this.createTerminalPoint({ g: g, color: color, type: type }); } }]); return GraphNode; }(); exports.default = GraphNode;