UNPKG

wetrade-design

Version:

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

166 lines (164 loc) 6.07 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); 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 _index = require("./index"); var _types = require("./types"); /** * User: CHT * Date: 2020/5/8 * Time: 14:01 */ var GraphNode = /*#__PURE__*/function () { // 节点是否为合并节点 // 节点是否需要隐藏 // 宽度 // 高度 function GraphNode(props, graph) { (0, _classCallCheck2.default)(this, GraphNode); var _props$width = props.width, width = _props$width === void 0 ? 180 : _props$width, _props$height = props.height, height = _props$height === void 0 ? 100 : _props$height, _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, _props$merge = props.merge, merge = _props$merge === void 0 ? false : _props$merge, _props$hidden = props.hidden, hidden = _props$hidden === void 0 ? false : _props$hidden; 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.merge = merge; this.hidden = hidden; this.width = width; this.height = height; } (0, _createClass2.default)(GraphNode, [{ key: "position", get: function get() { return (0, _index.vector)(this.coordinate).add(this.graph.origin).end; }, set: function set(position) { this.coordinate = (0, _index.vector)(position).minus(this.graph.origin).end; } }, { key: "center", get: function get() { return (0, _index.vector)(this.coordinate).add([this.width / 2, this.height / 2]).end; }, set: function set(position) { this.coordinate = (0, _index.vector)(position).minus([this.width / 2, this.height / 2]).end; } }, { key: "width", get: function get() { return this._width; }, set: function set(w) { w = Math.floor(w); // this._width = w > 50 ? w : 50; this._width = w > 0 ? w : 0; // this.angle(); } }, { key: "height", get: function get() { return this._height; }, set: function set(h) { h = Math.floor(h); this._height = h > 0 ? h : 0; // this.angle(); } // angle() { // const w = this.width / 2, // h = this.height / 2, // center = [0, 0]; // const topLeft = vector(center).minus([w, h]).angle().end; // const topRight = vector(center).add([w, 0]).minus([0, h]).angle().end; // const bottomRight = vector(center).add([w, h]).angle().end; // const bottomLeft = vector(center).add([0, h]).minus([w, 0]).angle().end; // // 角度 // this.angleList = [topLeft, topRight, bottomRight, bottomLeft]; // } }, { key: "relative", value: function relative(offset) { // const angle = vector(offset) // .minus([this.width / 2, this.height / 2]) // .angle().end; // const angleList = this.angleList; // const directionList = [Direction.TOP, Direction.RIGHT, Direction.BOTTOM, Direction.LEFT]; // let dir = Direction.LEFT; // angleList.reduce((prev, current, idx) => { // if (angle >= prev && angle < current) { // dir = directionList[idx - 1]; // } // return current; // }); var x = offset[0]; var dir = x === 0 ? _types.Direction.LEFT : _types.Direction.RIGHT; return { position: this.fixOffset(offset, dir), direction: _types.DIRECTION_VECTOR[dir] }; } }, { key: "fixOffset", value: function fixOffset(offset, dir) { var _this$meta, _this$meta$extParam; var END_HEIGHT = 32; 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.isDragElement) { END_HEIGHT = 16; } switch (dir) { case _types.Direction.TOP: offset[0] = this.width / 2; offset[1] = 0; break; case _types.Direction.RIGHT: offset[0] = this.width; offset[1] = this.height ? END_HEIGHT / 2 : 0; // offset[1] = this.height / 2; break; case _types.Direction.BOTTOM: offset[0] = this.width / 2; offset[1] = this.height; break; case _types.Direction.LEFT: default: offset[0] = 0; offset[1] = this.height ? END_HEIGHT / 2 : 0; // offset[1] = this.height / 2; break; } return offset; } }, { key: "remove", value: function remove() { return this.graph.removeNode(this); } }, { key: "toJSON", value: function toJSON() { var _ref; return _ref = {}, (0, _defineProperty2.default)(_ref, _index.mark.relationMark, this[_index.mark.relationMark]), (0, _defineProperty2.default)(_ref, "width", this.width), (0, _defineProperty2.default)(_ref, "height", this.height), (0, _defineProperty2.default)(_ref, "coordinate", (0, _toConsumableArray2.default)(this.coordinate)), (0, _defineProperty2.default)(_ref, "meta", this.meta), (0, _defineProperty2.default)(_ref, "merge", this.merge), (0, _defineProperty2.default)(_ref, "hidden", this.hidden), _ref; } }]); return GraphNode; }(); exports.default = GraphNode;