Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 45 additions & 37 deletions src/utils/calcPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,62 @@ export function calcPath(r, tableWidth = 200, zoom = 1) {
}

const width = tableWidth * zoom;
const tableWidthSafetyMargin = 70 * zoom;
const tableWidthPadding = 30 * zoom;

let x1 = r.startTable.x;
const fieldHeight = tableFieldHeight * zoom;
const headerHeight = tableHeaderHeight * zoom;
let y1 =
r.startTable.y +
r.startFieldIndex * tableFieldHeight +
tableHeaderHeight +
tableFieldHeight / 2;
r.startFieldIndex * fieldHeight +
headerHeight +
fieldHeight / 2;
let x2 = r.endTable.x;
let y2 =
r.endTable.y +
r.endFieldIndex * tableFieldHeight +
tableHeaderHeight +
tableFieldHeight / 2;
r.endFieldIndex * fieldHeight +
headerHeight +
fieldHeight / 2;

let radius = 10 * zoom;
const curveRadius = 18 * zoom;
const midX = (x2 + x1 + width) / 2;
const endX = x2 + width < x1 ? x2 + width : x2;

if (Math.abs(y1 - y2) <= 36 * zoom) {
radius = Math.abs(y2 - y1) / 3;
if (radius <= 2) {
if (x1 + width <= x2) return `M ${x1 + width} ${y1} L ${x2} ${y2 + 0.1}`;
radius = Math.max(Math.abs(y2 - y1) / 3, curveRadius);
if (radius <= curveRadius) {
if (x1 + width <= x2) return `M ${x1 + width} ${y1} L ${x2} ${y2}`;
else if (x2 + width < x1)
return `M ${x1} ${y1} L ${x2 + width} ${y2 + 0.1}`;
return `M ${x1} ${y1} L ${x2 + width} ${y2}`;
}
} else {
radius = Math.max(radius, curveRadius);
}

if (y1 <= y2) {
if (x1 + width <= x2) {
if (x1 + width + tableWidthSafetyMargin <= x2) {
return `M ${x1 + width} ${y1} L ${
midX - radius
} ${y1} A ${radius} ${radius} 0 0 1 ${midX} ${y1 + radius} L ${midX} ${
y2 - radius
} A ${radius} ${radius} 0 0 0 ${midX + radius} ${y2} L ${endX} ${y2}`;
} else if (x2 <= x1 + width && x1 <= x2) {
} else if (x2 <= x1 + width + tableWidthSafetyMargin && x1 <= x2) {
return `M ${x1 + width} ${y1} L ${
x2 + width
} ${y1} A ${radius} ${radius} 0 0 1 ${x2 + width + radius} ${
x2 + width + tableWidthPadding
} ${y1} A ${radius} ${radius} 0 0 1 ${x2 + width + tableWidthPadding + radius} ${
y1 + radius
} L ${x2 + width + radius} ${y2 - radius} A ${radius} ${radius} 0 0 1 ${
x2 + width
} L ${x2 + width + tableWidthPadding + radius} ${y2 - radius} A ${radius} ${radius} 0 0 1 ${
x2 + width + tableWidthPadding
} ${y2} L ${x2 + width} ${y2}`;
} else if (x2 + width >= x1 && x2 + width <= x1 + width) {
} else if (x2 + width >= x1 - tableWidthSafetyMargin && x2 + width <= x1 + width) {
return `M ${x1} ${y1} L ${
x2 - radius
} ${y1} A ${radius} ${radius} 0 0 0 ${x2 - radius - radius} ${
x2 - tableWidthPadding
} ${y1} A ${radius} ${radius} 0 0 0 ${x2 - tableWidthPadding - radius} ${
y1 + radius
} L ${x2 - radius - radius} ${y2 - radius} A ${radius} ${radius} 0 0 0 ${
x2 - radius
} L ${x2 - tableWidthPadding - radius} ${y2 - radius} A ${radius} ${radius} 0 0 0 ${
x2 - tableWidthPadding
} ${y2} L ${x2} ${y2}`;
} else {
return `M ${x1} ${y1} L ${
Expand All @@ -76,32 +84,32 @@ export function calcPath(r, tableWidth = 200, zoom = 1) {
} A ${radius} ${radius} 0 0 1 ${midX - radius} ${y2} L ${endX} ${y2}`;
}
} else {
if (x1 + width <= x2) {
if (x1 + width + tableWidthSafetyMargin <= x2) {
return `M ${x1 + width} ${y1} L ${
midX - radius
} ${y1} A ${radius} ${radius} 0 0 0 ${midX} ${y1 - radius} L ${midX} ${
y2 + radius
} A ${radius} ${radius} 0 0 1 ${midX + radius} ${y2} L ${endX} ${y2}`;
} else if (x1 + width >= x2 && x1 + width <= x2 + width) {
return `M ${x1} ${y1} L ${
x1 - radius - radius
} ${y1} A ${radius} ${radius} 0 0 1 ${x1 - radius - radius - radius} ${
y1 - radius
} L ${x1 - radius - radius - radius} ${
y2 + radius
} A ${radius} ${radius} 0 0 1 ${
x1 - radius - radius
} ${y2} L ${endX} ${y2}`;
} else if (x1 >= x2 && x1 <= x2 + width) {
} else if (x1 + width >= x2 - tableWidthSafetyMargin && x1 + width <= x2 + width) {
return `M ${x1 + width} ${y1} L ${
x1 + width + radius
} ${y1} A ${radius} ${radius} 0 0 0 ${x1 + width + radius + radius} ${
x2 + width + tableWidthPadding
} ${y1} A ${radius} ${radius} 0 0 0 ${x2 + width + tableWidthPadding + radius} ${
y1 - radius
} L ${x1 + width + radius + radius} ${
} L ${x2 + width + tableWidthPadding + radius} ${
y2 + radius
} A ${radius} ${radius} 0 0 0 ${x1 + width + radius} ${y2} L ${
} A ${radius} ${radius} 0 0 0 ${x2 + width + tableWidthPadding} ${y2} L ${
x2 + width
} ${y2}`;
} else if (x2 + width >= x1 - tableWidthSafetyMargin && x2 + width <= x1 + width) {
return `M ${x1} ${y1} L ${
x2 - tableWidthPadding
} ${y1} A ${radius} ${radius} 0 0 1 ${x2 - tableWidthPadding - radius} ${
y1 - radius
} L ${x2 - tableWidthPadding - radius} ${
y2 + radius
} A ${radius} ${radius} 0 0 1 ${
x2 - tableWidthPadding
} ${y2} L ${x2} ${y2}`;
} else {
return `M ${x1} ${y1} L ${
midX + radius
Expand Down