Skip to content

Commit aed4e3a

Browse files
committed
optional improving node positioning for nodes that have thumbs centered in the middle
1 parent e504315 commit aed4e3a

File tree

7 files changed

+55
-31
lines changed

7 files changed

+55
-31
lines changed

apps/vps-web/src/app/custom-nodes/mermaid.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export const getMermaidNode =
5252
const computeAsync = (input: string, loopIndex?: number, payload?: any) => {
5353
return mermaidNode.compute(input, loopIndex, payload).then((result) => {
5454
if (rect && rect.resize) {
55-
rect.resize(undefined, true, '.child-node-wrapper > *:first-child');
55+
rect.resize(
56+
undefined,
57+
true,
58+
'.child-node-wrapper > *:first-child',
59+
true
60+
);
5661
}
5762
return result;
5863
});
@@ -96,7 +101,8 @@ export const getMermaidNode =
96101
rect.resize(
97102
undefined,
98103
true,
99-
'.child-node-wrapper > *:first-child'
104+
'.child-node-wrapper > *:first-child',
105+
true
100106
);
101107
}
102108
});
@@ -110,16 +116,17 @@ export const getMermaidNode =
110116
};
111117
}
112118
}
113-
if (rect && rect.resize) {
114-
rect.resize();
115-
}
119+
// if (rect && rect.resize) {
120+
// rect.resize(undefined, undefined, undefined, true);
121+
// }
116122
},
117123
{
118124
category: 'Diagrams',
119125
hasStaticWidthHeight: true,
120126
hasCustomStyling: true,
121127
customClassName: 'mermaid-node',
122128
childNodeWrapperClass: 'child-node-wrapper',
129+
centerToYPositionThumb: true,
123130
},
124131
<div class="child-instance"></div>,
125132
true

examples-test-flows/mermaid-diagram-node.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"nodes": [
99
{
1010
"id": "2e7ca45f-a13e-4deb-8e8f-cae85b46b091",
11-
"x": 3205.4072698505697,
12-
"y": 1721.4742245852408,
13-
"width": 199.96093174395054,
14-
"height": 180.9296625777389,
11+
"x": 3188.56323756902,
12+
"y": 1720.6335735902078,
13+
"width": 199.98447027747773,
14+
"height": 180.94521385214784,
1515
"nodeType": "Shape",
1616
"nodeInfo": {
1717
"type": "mermaid-node",
@@ -44,8 +44,8 @@
4444
"id": "75229244-ebd1-411d-8c6d-aca0df473c9e",
4545
"x": 3072.38946876743,
4646
"y": 1810.9796798117168,
47-
"endX": 3205.4072698505697,
48-
"endY": 1811.9390558741102,
47+
"endX": 3188.56323756902,
48+
"endY": 1811.1061805162817,
4949
"startNodeId": "a1af55a9-cd5b-4675-a577-cfc8c57e1cf7",
5050
"endNodeId": "2e7ca45f-a13e-4deb-8e8f-cae85b46b091",
5151
"startThumbName": "output",

libs/visual-programming-system/src/canvas-app/base-flow.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ export interface IBaseFlow<T extends BaseNodeInfo> {
118118
text?: string,
119119
thumbs?: IThumb[],
120120
markup?: string | INodeComponent<T> | undefined,
121-
layoutProperties?: {
122-
classNames?: string;
123-
autoSizeToContentIfNodeHasNoThumbs?: boolean;
124-
hasCustomStyling?: boolean;
125-
customClassName?: string;
126-
},
121+
layoutProperties?: LayoutProperties,
127122
hasStaticWidthHeight?: boolean,
128123
disableInteraction?: boolean,
129124
disableManualResize?: boolean,

libs/visual-programming-system/src/components/rect-thumb.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
IThumbNodeComponent,
1414
ThumbConnectionType,
1515
} from '../interfaces';
16+
import { LayoutProperties } from '../interfaces/layout-properties';
1617
import { Theme } from '../interfaces/theme';
1718
import { getSelectedNode } from '../reactivity';
1819
import { ConnectionControllerType, NodeType } from '../types';
@@ -45,10 +46,7 @@ export class RectThumb<T extends BaseNodeInfo> extends Rect<T> {
4546
text?: string,
4647
thumbs?: IThumb[],
4748
markup?: string | INodeComponent<T>,
48-
layoutProperties?: {
49-
classNames?: string;
50-
hasCustomStyling?: boolean;
51-
},
49+
layoutProperties?: LayoutProperties,
5250
hasStaticWidthHeight?: boolean,
5351
disableInteraction?: boolean,
5452
disableManualResize?: boolean,

libs/visual-programming-system/src/components/rect.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { FlowChangeType } from '../interfaces';
3333
import { BaseNodeInfo } from '../types/base-node-info';
3434
import { getRectNodeCssClasses } from './css-classes/rect-css-classes';
3535
import { Theme } from '../interfaces/theme';
36+
import { LayoutProperties } from '../interfaces/layout-properties';
3637

3738
export class Rect<T extends BaseNodeInfo> {
3839
public nodeComponent?: IRectNodeComponent<T>;
@@ -89,11 +90,7 @@ export class Rect<T extends BaseNodeInfo> {
8990
text?: string,
9091
thumbs?: IThumb[],
9192
markup?: string | INodeComponent<T> | HTMLElement,
92-
layoutProperties?: {
93-
classNames?: string;
94-
autoSizeToContentIfNodeHasNoThumbs?: boolean;
95-
hasCustomStyling?: boolean;
96-
},
93+
layoutProperties?: LayoutProperties,
9794
hasStaticWidthHeight?: boolean,
9895
disableInteraction?: boolean,
9996
disableManualResize?: boolean,
@@ -121,6 +118,7 @@ export class Rect<T extends BaseNodeInfo> {
121118
this.rootElement = rootElement;
122119
this.theme = theme;
123120

121+
const oldHeight = height ?? 0;
124122
this.interactionStateMachine = interactionStateMachine;
125123
this.hasStaticWidthHeight = hasStaticWidthHeight;
126124

@@ -305,15 +303,27 @@ export class Rect<T extends BaseNodeInfo> {
305303
hasStaticWidthHeight ?? false
306304
);
307305

306+
if (layoutProperties?.centerToYPositionThumb) {
307+
this.nodeComponent.y =
308+
this.nodeComponent.y +
309+
(oldHeight ?? 0) / 2 -
310+
(this.nodeComponent.height ?? 0) / 2;
311+
} //paddingRect -
312+
313+
// if (centerToYPositionThumb) {
314+
// this.nodeComponent.y =
315+
// this.nodeComponent.y + (oldHeight ?? 0) / 2 - this.points.height / 2;
316+
// }
317+
308318
// WARNING! .. if this is not done, then thumb positioning is incoraddUpdateEventListenerafter loading flow
309319
// for thumb-types EndConnecterCenter and StartConnectorCenter
310320
this.cachedWidth = -1;
311321
this.cachedHeight = -1;
312322

313323
this.nodeComponent.update(
314324
this.nodeComponent,
315-
startX,
316-
startY,
325+
this.nodeComponent.x,
326+
this.nodeComponent.y,
317327
this.nodeComponent
318328
);
319329

@@ -424,14 +434,16 @@ export class Rect<T extends BaseNodeInfo> {
424434
public resize(
425435
width?: number,
426436
overrideStaticWidthHeight?: boolean,
427-
selectChildElemenSelectorAsReference?: string
437+
selectChildElemenSelectorAsReference?: string,
438+
centerToYPositionThumb?: boolean
428439
) {
429440
if (
430441
(this.hasStaticWidthHeight && !overrideStaticWidthHeight) ||
431442
!this.nodeComponent
432443
) {
433444
return;
434445
}
446+
const oldHeight = this.nodeComponent.height;
435447
const { scale } = getCamera();
436448
if (this.nodeComponent.thumbConnectors) {
437449
let minHeightAdd = 0;
@@ -518,6 +530,11 @@ export class Rect<T extends BaseNodeInfo> {
518530
rectContainerDOMElement.style.width = `${this.nodeComponent.width}px`;
519531
rectContainerDOMElement.style.height = `${this.nodeComponent.height}px`;
520532
}
533+
534+
if (centerToYPositionThumb) {
535+
this.nodeComponent.y =
536+
this.nodeComponent.y + (oldHeight ?? 0) / 2 - this.points.height / 2;
537+
}
521538
if (this.nodeComponent.update) {
522539
this.nodeComponent.update(
523540
this.nodeComponent,

libs/visual-programming-system/src/interfaces/layout-properties.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface LayoutProperties {
33
autoSizeToContentIfNodeHasNoThumbs?: boolean;
44
hasCustomStyling?: boolean;
55
customClassName?: string;
6+
centerToYPositionThumb?: boolean;
67
}

libs/visual-programming-system/src/utils/create-rect-node.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface NodeSettings {
7070
hasCustomStyling?: boolean;
7171
customClassName?: string;
7272
noFlexAutoInNodeContentWrapper?: boolean;
73+
centerToYPositionThumb?: boolean;
7374
}
7475

7576
export const createRectNode = <T extends BaseNodeInfo>(
@@ -394,6 +395,7 @@ export const createRectNode = <T extends BaseNodeInfo>(
394395
classNames: '',
395396
hasCustomStyling: settings?.hasCustomStyling ?? false,
396397
customClassName: settings?.customClassName,
398+
centerToYPositionThumb: settings?.centerToYPositionThumb,
397399
},
398400
settings?.adjustToFormContent
399401
? false
@@ -600,8 +602,12 @@ export const visualNodeFactory = <T extends BaseNodeInfo>(
600602
settings?.hasSettingsPopup ? [] : formElements,
601603
x,
602604
y,
603-
width,
604-
height,
605+
settings?.hasStaticWidthHeight && settings?.centerToYPositionThumb
606+
? _width ?? width
607+
: width,
608+
settings?.hasStaticWidthHeight && settings?.centerToYPositionThumb
609+
? _height ?? height
610+
: height,
605611
compute,
606612
initializeCompute,
607613
thumbs,

0 commit comments

Comments
 (0)