js2flowchart
Version:
> Why? While I've been working on [Under-the-hood-ReactJS](https://github.com/Bogdan-Lyashenko/Under-the-hood-ReactJS) I spent enormous amount of time on creating schemes. Each change in code or flowchart affects all entire scheme instantly, forcing you t
104 lines • 4.8 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { ARROW_TYPE } from 'shared/constants';
import { getShapeForNode } from './shapesDefinitionsMap';
import ConnectionArrow, { getFieldName as getConnectionArrowFieldName } from './connections/ConnectionArrow';
export var createShapeForNode = function createShapeForNode(node, position, styleTheme) {
var shape = getShapeForNode(node),
shapeStyle = styleTheme[shape.getThemeFieldName()];
return shape(node, position, shapeStyle);
};
export var createRootCircle = function createRootCircle(node, styleTheme) {
var shape = getShapeForNode(node),
shapeStyle = styleTheme[shape.getThemeFieldName()];
var _styleTheme$RootStart = _objectSpread({}, styleTheme.RootStartPoint),
center = _styleTheme$RootStart.center,
childOffset = _styleTheme$RootStart.childOffset;
var root = shape(node, center, shapeStyle);
root.setChildOffsetPoint(childOffset);
return root;
};
export var createConnectionArrow = function createConnectionArrow(config, styleTheme) {
var connectionArrowStyle = styleTheme[getConnectionArrowFieldName()],
arrowConfig = getConnectionConfig(config, connectionArrowStyle);
return ConnectionArrow(_objectSpread(_objectSpread({}, config), arrowConfig), connectionArrowStyle);
};
export var getConnectionConfig = function getConnectionConfig(_ref, theme) {
var startPoint = _ref.startPoint,
endPoint = _ref.endPoint,
boundaryPoint = _ref.boundaryPoint,
arrowType = _ref.arrowType;
var config = {
linePoints: [],
arrowPoint: {
x: endPoint.x,
y: endPoint.y
}
};
switch (arrowType) {
case ARROW_TYPE.RIGHT:
config.linePoints = [{
x: startPoint.x,
y: startPoint.y
}];
if (boundaryPoint) {
config.linePoints = config.linePoints.concat([{
x: boundaryPoint.x,
y: startPoint.y
}, {
x: boundaryPoint.x,
y: endPoint.y
}, {
x: endPoint.x,
y: endPoint.y
}]);
} else {
config.linePoints = config.linePoints.concat([{
x: startPoint.x,
y: endPoint.y
}, {
x: endPoint.x,
y: endPoint.y
}]);
}
break;
case ARROW_TYPE.LEFT:
config.linePoints = [{
x: startPoint.x,
y: startPoint.y
}, {
x: boundaryPoint.x + theme.lineTurnOffset,
y: startPoint.y
}, {
x: boundaryPoint.x + theme.lineTurnOffset,
y: endPoint.y
}, {
x: endPoint.x - theme.lineTurnOffset,
y: endPoint.y
}];
break;
case ARROW_TYPE.DOWN:
config.linePoints = [{
x: startPoint.x,
y: startPoint.y
}, {
x: boundaryPoint.x + theme.lineTurnOffset,
y: startPoint.y
}, {
x: boundaryPoint.x + theme.lineTurnOffset,
y: endPoint.y - theme.lineTurnOffset
}, {
x: endPoint.x,
y: endPoint.y - theme.lineTurnOffset
}, {
x: endPoint.x,
y: endPoint.y
}];
break;
}
return config;
};