Skip to content

Commit

Permalink
Fix autogenerated self-loop saving
Browse files Browse the repository at this point in the history
  • Loading branch information
bindeali committed Dec 28, 2023
1 parent 61e637d commit b836950
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/function/FunctionGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,10 @@ export function setRepresentation(
setLinkBoundary(newLink, source, target);
newLink.addTo(g);
if (isLinkVertexArrayEmpty(linkID, diag)) {
if (source === target) {
setSelfLoopConnectionPoints(newLink, sourceBox.getBBox());
}
if (source === target)
queries.push(
setSelfLoopConnectionPoints(newLink, sourceBox.getBBox())
);
WorkspaceLinks[newLink.id].vertices[diag] = newLink.vertices();
} else {
setLinkVertices(newLink, WorkspaceLinks[linkID].vertices[diag]);
Expand Down Expand Up @@ -502,7 +503,7 @@ export function setRepresentation(
}
}

export function findLinkSelfLoop(link: joint.dia.Link) {
function findLinkSelfLoop(link: joint.dia.Link) {
const id = link.id as string;
if (
WorkspaceLinks[id].source === WorkspaceLinks[id].target &&
Expand Down
14 changes: 11 additions & 3 deletions src/function/FunctionLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ export function getOtherConnectionElementID(
export function setSelfLoopConnectionPoints(
link: joint.dia.Link,
bbox?: joint.g.Rect
) {
): string {
const sourcePoint = link.getSourcePoint();
const offsetX = bbox ? bbox.width / 2 + 50 : sourcePoint.x + 300;
const id = link.id as string;
link.vertices([
new joint.g.Point(sourcePoint.x, sourcePoint.y + 100),
new joint.g.Point(sourcePoint.x + offsetX, sourcePoint.y + 100),
new joint.g.Point(sourcePoint.x + offsetX, sourcePoint.y),
]);
WorkspaceLinks[id].vertices[AppSettings.selectedDiagram] = link.vertices();
return updateProjectLinkVertex(
id,
WorkspaceLinks[id].vertices[AppSettings.selectedDiagram].map((_, i) => i)
);
}

export function isLinkVertexArrayEmpty(
Expand Down Expand Up @@ -190,14 +196,16 @@ export function saveNewLink(
tid: string,
representation: Representation = AppSettings.representation
): string[] {
const queries: string[] = [];
const type = iri in Links ? Links[iri].type : LinkType.DEFAULT;
const link = getNewLink(type);
setLinkBoundary(link, sid, tid);
const id = link.id as string;
if (sid === tid)
setSelfLoopConnectionPoints(link, paper.findViewByModel(sid).getBBox());
queries.push(
setSelfLoopConnectionPoints(link, paper.findViewByModel(sid).getBBox())
);
setLinkBoundary(link, sid, tid);
const queries: string[] = [];
if (
representation === Representation.FULL ||
type === LinkType.GENERALIZATION
Expand Down

0 comments on commit b836950

Please sign in to comment.