Skip to content

Commit 536a475

Browse files
committed
improving positioning a little bit for compositions and thumb-input/output when creating a composition
1 parent 449827e commit 536a475

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

libs/app-canvas/src/app/app.element.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,25 +1020,46 @@ export class AppElement<T extends BaseNodeInfo> {
10201020
let minY = -1;
10211021
let maxX = -1;
10221022
let maxY = -1;
1023+
let nodeCounter = 0;
1024+
let lastNode: FlowNode<T> | undefined = undefined;
10231025
composition.nodes.forEach((node) => {
1026+
if (
1027+
node.nodeInfo?.type === 'thumb-input' ||
1028+
node.nodeInfo?.type === 'thumb-output'
1029+
) {
1030+
return;
1031+
} else if (node.nodeType === NodeType.Connection) {
1032+
return;
1033+
}
10241034
if (node.x < minX || minX === -1) {
10251035
minX = node.x;
10261036
}
10271037
if (node.y < minY || minY === -1) {
10281038
minY = node.y;
10291039
}
10301040
if (node.x + (node.width ?? 0) > maxX || maxX === -1) {
1031-
maxX = node.x;
1041+
maxX = node.x + (node.width ?? 0);
10321042
}
10331043
if (node.y + (node.height ?? 0) > maxY || maxY === -1) {
1034-
maxY = node.y;
1044+
maxY = node.y + (node.height ?? 0);
10351045
}
1046+
lastNode = node;
1047+
nodeCounter++;
10361048
});
10371049
minX = minX === -1 ? minX : composition.nodes[0]?.x ?? 0;
10381050
minY = minY === -1 ? minY : composition.nodes[0]?.y ?? 0;
10391051
let x = (minX + maxX) / 2 - 100;
10401052
let y = (minY + maxY) / 2 - 100;
10411053

1054+
function isFlowNode(node: FlowNode<T> | undefined): node is FlowNode<T> {
1055+
return node !== undefined;
1056+
}
1057+
if (nodeCounter === 1 && isFlowNode(lastNode)) {
1058+
const node: FlowNode<T> = lastNode;
1059+
x = node.x;
1060+
y = node.y;
1061+
}
1062+
10421063
if (minX === -1) {
10431064
let halfWidth = 0;
10441065
let halfHeight = 0;

libs/visual-programming-system/src/components/node-selector.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,42 @@ export class NodeSelector<T extends BaseNodeInfo> {
532532
return;
533533
}
534534

535+
let minX = -1;
536+
let minY = -1;
537+
let maxX = -1;
538+
let maxY = -1;
539+
this.elements.forEach((element) => {
540+
const nodeComponent = element as unknown as IRectNodeComponent<T>;
541+
if (nodeComponent.nodeType === NodeType.Shape) {
542+
const isNodeSelected = this.selectedNodes.find(
543+
(n) => n.id === nodeComponent.id
544+
);
545+
if (isNodeSelected) {
546+
if (nodeComponent.x < minX || minX === -1) {
547+
minX = nodeComponent.x;
548+
}
549+
if (nodeComponent.y < minY || minY === -1) {
550+
minY = nodeComponent.y;
551+
}
552+
if (
553+
nodeComponent.x + (nodeComponent.width ?? 0) > maxX ||
554+
maxX === -1
555+
) {
556+
maxX = nodeComponent.x + (nodeComponent.width ?? 0);
557+
}
558+
if (
559+
nodeComponent.y + (nodeComponent.height ?? 0) > maxY ||
560+
maxY === -1
561+
) {
562+
maxY = nodeComponent.y + (nodeComponent.height ?? 0);
563+
}
564+
}
565+
}
566+
});
567+
568+
minX -= 300;
569+
maxX += 300;
570+
535571
this.elements.forEach((element) => {
536572
const nodeComponent = element as unknown as IRectNodeComponent<T>;
537573
if (nodeComponent.nodeType === NodeType.Shape) {
@@ -584,8 +620,8 @@ export class NodeSelector<T extends BaseNodeInfo> {
584620
nodeTask.setTitle?.(thumb.name);
585621
const thumbOutput = nodeTask.createVisualNode(
586622
this.canvasApp,
587-
0 + 100,
588-
0 + 100 + outputThumbIndex * 200,
623+
maxX + 100,
624+
minY - 100 + outputThumbIndex * 200,
589625
undefined,
590626
{
591627
valueType: thumb.thumbConstraint,
@@ -735,8 +771,8 @@ export class NodeSelector<T extends BaseNodeInfo> {
735771
nodeTask.setTitle?.(thumb.name);
736772
const thumbInput = nodeTask.createVisualNode(
737773
this.canvasApp,
738-
0 - 100,
739-
0 - 100 + inputThumbIndex * 200,
774+
minX - 100,
775+
minY - 100 + inputThumbIndex * 200,
740776
undefined,
741777
{
742778
valueType: thumb.thumbConstraint,

0 commit comments

Comments
 (0)