|
@@ -37,9 +37,11 @@ Graph.registerConnector(
|
|
|
// 直线
|
|
|
Graph.registerConnector(
|
|
|
"straight-branch-connector",
|
|
|
- function(sourcePoint, targetPoint, routerPoints, options){
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
const halfWidth = this.sourceBBox.width / 2;
|
|
|
- const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? halfWidth + 10 : -halfWidth-10 );
|
|
|
+ const midX =
|
|
|
+ sourcePoint.x +
|
|
|
+ (sourcePoint.x < targetPoint.x ? halfWidth + 10 : -halfWidth - 10);
|
|
|
const midY = sourcePoint.y;
|
|
|
const pathData = `
|
|
|
M ${sourcePoint.x} ${sourcePoint.y}
|
|
@@ -52,8 +54,8 @@ Graph.registerConnector(
|
|
|
);
|
|
|
Graph.registerConnector(
|
|
|
"straight-sub-connector",
|
|
|
- function(sourcePoint, targetPoint, routerPoints, options) {
|
|
|
- const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? 10 : -10 );
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
+ const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? 10 : -10);
|
|
|
const midY = sourcePoint.y;
|
|
|
const pathData = `
|
|
|
M ${sourcePoint.x} ${sourcePoint.y}
|
|
@@ -67,9 +69,11 @@ Graph.registerConnector(
|
|
|
// 圆角折线
|
|
|
Graph.registerConnector(
|
|
|
"rounded-branch-connector",
|
|
|
- function(sourcePoint, targetPoint, routerPoints, options) {
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
const halfWidth = this.sourceBBox.width / 2;
|
|
|
- const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? halfWidth + 10 : -halfWidth-10 );
|
|
|
+ const midX =
|
|
|
+ sourcePoint.x +
|
|
|
+ (sourcePoint.x < targetPoint.x ? halfWidth + 10 : -halfWidth - 10);
|
|
|
const midY = sourcePoint.y;
|
|
|
const pathData = `
|
|
|
M ${sourcePoint.x} ${sourcePoint.y}
|
|
@@ -85,12 +89,15 @@ Graph.registerConnector(
|
|
|
Graph.registerConnector(
|
|
|
"rounded-sub-connector",
|
|
|
(sourcePoint, targetPoint, routerPoints, options) => {
|
|
|
- const midX = sourcePoint.x < targetPoint.x ? sourcePoint.x + 10 : sourcePoint.x - 10;
|
|
|
+ const midX =
|
|
|
+ sourcePoint.x < targetPoint.x ? sourcePoint.x + 10 : sourcePoint.x - 10;
|
|
|
const midY = sourcePoint.y;
|
|
|
+ // 可能存在误差
|
|
|
+ const deviationY = Math.abs(targetPoint.y - sourcePoint.y);
|
|
|
const pathData = `
|
|
|
M ${sourcePoint.x} ${sourcePoint.y}
|
|
|
L ${midX} ${midY}
|
|
|
- L ${midX} ${targetPoint.y + (targetPoint.y < sourcePoint.y ? 5 : targetPoint.y === sourcePoint.y ? 0 : -5)}
|
|
|
+ L ${midX} ${targetPoint.y + (deviationY < 10 ? 0 : targetPoint.y < sourcePoint.y ? 5 : -5)}
|
|
|
Q ${midX} ${targetPoint.y} ${midX + (targetPoint.x < sourcePoint.x ? -5 : 5)} ${targetPoint.y}
|
|
|
L ${targetPoint.x} ${targetPoint.y}
|
|
|
`;
|
|
@@ -101,9 +108,11 @@ Graph.registerConnector(
|
|
|
// 折线
|
|
|
Graph.registerConnector(
|
|
|
"poly-branch-connector",
|
|
|
- function(sourcePoint, targetPoint, routerPoints, options) {
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
const halfWidth = this.sourceBBox.width / 2;
|
|
|
- const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? halfWidth + 10 : -halfWidth-10 );
|
|
|
+ const midX =
|
|
|
+ sourcePoint.x +
|
|
|
+ (sourcePoint.x < targetPoint.x ? halfWidth + 10 : -halfWidth - 10);
|
|
|
const midY = sourcePoint.y;
|
|
|
const pathData = `
|
|
|
M ${sourcePoint.x} ${sourcePoint.y}
|
|
@@ -117,8 +126,8 @@ Graph.registerConnector(
|
|
|
);
|
|
|
Graph.registerConnector(
|
|
|
"poly-sub-connector",
|
|
|
- function(sourcePoint, targetPoint, routerPoints, options) {
|
|
|
- const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? 10 : -10 );
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
+ const midX = sourcePoint.x + (sourcePoint.x < targetPoint.x ? 10 : -10);
|
|
|
const midY = sourcePoint.y;
|
|
|
const pathData = `
|
|
|
M ${sourcePoint.x} ${sourcePoint.y}
|
|
@@ -131,12 +140,42 @@ Graph.registerConnector(
|
|
|
true
|
|
|
);
|
|
|
|
|
|
+// 树形
|
|
|
+Graph.registerConnector(
|
|
|
+ "tree-branch-connector",
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
+ const pathData = `
|
|
|
+ M ${sourcePoint.x} ${sourcePoint.y}
|
|
|
+ L ${sourcePoint.x} ${sourcePoint.y + 10}
|
|
|
+ L ${targetPoint.x} ${sourcePoint.y + 10}
|
|
|
+ L ${targetPoint.x} ${targetPoint.y}
|
|
|
+ `;
|
|
|
+ return options.raw ? Path.parse(pathData) : pathData;
|
|
|
+ },
|
|
|
+ true
|
|
|
+);
|
|
|
+Graph.registerConnector(
|
|
|
+ "tree-sub-connector",
|
|
|
+ function (sourcePoint, targetPoint, routerPoints, options) {
|
|
|
+ const pathData = `
|
|
|
+ M ${sourcePoint.x} ${sourcePoint.y}
|
|
|
+ L ${sourcePoint.x} ${targetPoint.y}
|
|
|
+ L ${targetPoint.x} ${targetPoint.y}
|
|
|
+ `;
|
|
|
+ return options.raw ? Path.parse(pathData) : pathData;
|
|
|
+ },
|
|
|
+ true
|
|
|
+);
|
|
|
+
|
|
|
const getConnector = (
|
|
|
structure: StructureType,
|
|
|
theme: string,
|
|
|
type: TopicType
|
|
|
) => {
|
|
|
// TODO根据结构处理连接线
|
|
|
+ if(structure === StructureType.tree) {
|
|
|
+ return `tree-${type}-connector`
|
|
|
+ }
|
|
|
const themeObj = getTheme(theme);
|
|
|
if (type === TopicType.branch) {
|
|
|
return `${themeObj.branchConnector}-${type}-connector`;
|
|
@@ -165,6 +204,23 @@ const getSourceAnchor = (type: TopicType, structure: StructureType) => {
|
|
|
name: "right",
|
|
|
};
|
|
|
}
|
|
|
+ case StructureType.leftRight: {
|
|
|
+ }
|
|
|
+ case StructureType.tree: {
|
|
|
+ return type === TopicType.branch
|
|
|
+ ? {
|
|
|
+ name: "bottom",
|
|
|
+ args: {
|
|
|
+ dy: -5
|
|
|
+ }
|
|
|
+ }
|
|
|
+ : {
|
|
|
+ name: "bottomLeft",
|
|
|
+ args: {
|
|
|
+ dx: 10,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
case StructureType.leftBracket:
|
|
|
case StructureType.leftFishbone:
|
|
|
case StructureType.leftTreeShape:
|
|
@@ -185,11 +241,20 @@ const getTargetAnchor = (type: TopicType, structure: StructureType) => {
|
|
|
switch (structure) {
|
|
|
case StructureType.left: {
|
|
|
return {
|
|
|
- name: "right",
|
|
|
- };
|
|
|
+ name: "right",
|
|
|
+ };
|
|
|
}
|
|
|
case StructureType.right: {
|
|
|
return {
|
|
|
+ name: "left",
|
|
|
+ };
|
|
|
+ }
|
|
|
+ case StructureType.tree: {
|
|
|
+ return type === TopicType.branch
|
|
|
+ ? {
|
|
|
+ name: "top",
|
|
|
+ }
|
|
|
+ : {
|
|
|
name: "left",
|
|
|
};
|
|
|
}
|