Skip to content

Commit

Permalink
Fix rendering when input and output port has same name
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenneke committed Oct 17, 2023
1 parent 69e3cb2 commit bbc7a88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/app/src/components/Port.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Port: FC<{
}}
onMouseUp={(e) => onMouseUp?.(e, id)}
data-portid={id}
data-porttype={input ? 'input' : 'output'}
data-nodeid={nodeId}
>
{canDragTo && <div className={clsx('port-hover-area')} />}
Expand Down
9 changes: 5 additions & 4 deletions packages/app/src/components/Wire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const ConditionallyRenderWire: FC<WireProps> = ({
return null;
}

const start = getNodePortPosition(outputNode, connection.outputId, portPositions);
const end = getNodePortPosition(inputNode, connection.inputId, portPositions);
const start = getNodePortPosition(outputNode, connection.outputId, false, portPositions);
const end = getNodePortPosition(inputNode, connection.inputId, true, portPositions);

// Optimization might not be needed
// if (!lineCrossesViewport(canvasToClientPosition(start.x, start.y), canvasToClientPosition(end.x, end.y))) {
Expand All @@ -60,7 +60,7 @@ export const PartialWire: FC<{ connection: PartialConnection; portPositions: Por
return null;
}

const start = getNodePortPosition(node, connection.portId, portPositions);
const start = getNodePortPosition(node, connection.portId, false, portPositions);
const end = { x: connection.toX, y: connection.toY };

return (
Expand Down Expand Up @@ -102,14 +102,15 @@ export const Wire: FC<{
export function getNodePortPosition(
node: ChartNode,
portId: PortId,
portIsInput: boolean,
portPositions: PortPositions,
): { x: number; y: number } {
if (!node) {
return { x: 0, y: 0 };
}

if (portId) {
const key = `${node.id}-${portId}`;
const key = `${node.id}-${portIsInput ? 'input' : 'output'}-${portId}`;
const portPosition = portPositions[key];
if (portPosition) {
return { x: portPosition.x, y: portPosition.y };
Expand Down
6 changes: 4 additions & 2 deletions packages/app/src/hooks/useNodePortPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function useNodePortPositions() {
for (const elem of normalPortElements) {
const portId = elem.dataset.portid! as PortId;
const nodeId = elem.dataset.nodeid! as NodeId;
const key = `${nodeId}-${portId}`;
const portType = elem.dataset.porttype! as 'input' | 'output';
const key = `${nodeId}-${portType}-${portId}`;

if (seen.has(key)) {
return;
Expand Down Expand Up @@ -72,7 +73,8 @@ export function useNodePortPositions() {

const portId = elem.dataset.portid! as PortId;
const nodeId = elem.dataset.nodeid! as NodeId;
const key = `${nodeId}-${portId}`;
const portType = elem.dataset.porttype! as 'input' | 'output';
const key = `${nodeId}-${portType}-${portId}`;

if (seen.has(key)) {
return;
Expand Down

0 comments on commit bbc7a88

Please sign in to comment.