UNPKG

wetrade-design

Version:

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

159 lines (158 loc) 5.51 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; /** * User: CHT * Date: 2020/5/8 * Time: 14:01 */ import { uuid, vector, mark } from './index'; import { Direction, DIRECTION_VECTOR } from './types'; var GraphNode = /*#__PURE__*/function () { // 节点是否为合并节点 // 节点是否需要隐藏 // 宽度 // 高度 function GraphNode(props, graph) { _classCallCheck(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[mark.relationMark] || uuid('node'); this.key = uuid('node'); this.graph = graph; this[mark.relationMark] = id; this.coordinate = _toConsumableArray(coordinate); this.meta = meta; this.merge = merge; this.hidden = hidden; this.width = width; this.height = height; } _createClass(GraphNode, [{ key: "position", get: function get() { return vector(this.coordinate).add(this.graph.origin).end; }, set: function set(position) { this.coordinate = vector(position).minus(this.graph.origin).end; } }, { key: "center", get: function get() { return vector(this.coordinate).add([this.width / 2, this.height / 2]).end; }, set: function set(position) { this.coordinate = 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 ? Direction.LEFT : Direction.RIGHT; return { position: this.fixOffset(offset, dir), direction: 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 Direction.TOP: offset[0] = this.width / 2; offset[1] = 0; break; case Direction.RIGHT: offset[0] = this.width; offset[1] = this.height ? END_HEIGHT / 2 : 0; // offset[1] = this.height / 2; break; case Direction.BOTTOM: offset[0] = this.width / 2; offset[1] = this.height; break; case 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 = {}, _defineProperty(_ref, mark.relationMark, this[mark.relationMark]), _defineProperty(_ref, "width", this.width), _defineProperty(_ref, "height", this.height), _defineProperty(_ref, "coordinate", _toConsumableArray(this.coordinate)), _defineProperty(_ref, "meta", this.meta), _defineProperty(_ref, "merge", this.merge), _defineProperty(_ref, "hidden", this.hidden), _ref; } }]); return GraphNode; }(); export { GraphNode as default };