Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing how to paint in 1:1 relationships #169

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/core/providers/canvas-schema/canvas.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const TABLE_WIDTH = 320; // Width of the table rectangle
const HEADER_HEIGHT = FONT_SIZE + ROW_PADDING; // Height of the table header
const DEFAULT_TABLE_WIDTH = TABLE_WIDTH;
const ROW_HEIGHT = FONT_SIZE + ROW_PADDING; // Height of the table line
const HORIZONTAL_LEFT_EXTENSION = 15; // Horizontal extension for the relation line 1:1

export const TABLE_CONST = {
FONT_SIZE,
Expand All @@ -20,4 +21,5 @@ export const TABLE_CONST = {
HEADER_HEIGHT,
DEFAULT_TABLE_WIDTH,
ROW_HEIGHT,
HORIZONTAL_LEFT_EXTENSION,
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ClickableLineComponent: React.FC<Props> = props => {
y1={startCoords.y}
x2={endCoords.x}
y2={endCoords.y}
strokeWidth={25}
strokeWidth={40}
stroke="transparent"
onClick={handleClick}
onDoubleClick={() => onDoubleClick(id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
.non-selected-relation {
stroke: #ffae42;
stroke-width: 2px;
fill: none;
}

.selected-relation {
stroke: #00ee00;
stroke-width: 4px;
fill: none;
}
43 changes: 31 additions & 12 deletions src/pods/canvas/components/relation/database-relation.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { RelationType } from '@/core/providers/canvas-schema';
import { RelationType, TABLE_CONST } from '@/core/providers/canvas-schema';
import { Coords, GUID } from '@/core/model';
import { ClickableLineComponent, ForkComponent } from './components';
import {
Expand Down Expand Up @@ -46,6 +46,13 @@ const DatabaseRelationshipComponent: React.FC<DatabaseRelationshipProps> = ({
isDrawLeftToRight
);

const oneToOneRelationPath = `
M ${originXMinusFork} ${startCoords.y}
H ${originXMinusFork - TABLE_CONST.HORIZONTAL_LEFT_EXTENSION}
V ${endCoords.y}
H ${originXMinusFork}
`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, one to on relationships can be between two different tables, see screenshot:

image

Please implement it in the way we mentioned, two separate components.

detect if is a recursive relations (fromTableId === toTableId)

Later one this nested relation will support one to many and many to one and one to one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


return (
<svg>
{/* Glow filter if selected */}
Expand All @@ -59,17 +66,29 @@ const DatabaseRelationshipComponent: React.FC<DatabaseRelationshipProps> = ({
</filter>
</defs>

{/* Base line of the relationship */}
<line
x1={originXMinusFork}
y1={startCoords.y}
x2={destinationXMinusFork}
y2={endCoords.y}
className={
isSelected ? classes.selectedRelation : classes.nonSelectedRelation
}
filter={isSelected ? `url(#table_glow)` : ''}
/>
{/* Render a path for 1:1 relationships */}
{relationType === '1:1' && (
<path
d={oneToOneRelationPath}
className={
isSelected ? classes.selectedRelation : classes.nonSelectedRelation
}
filter={isSelected ? `url(#table_glow)` : ''}
/>
)}

{relationType !== '1:1' && (
<line
x1={originXMinusFork}
y1={startCoords.y}
x2={destinationXMinusFork}
y2={endCoords.y}
className={
isSelected ? classes.selectedRelation : classes.nonSelectedRelation
}
filter={isSelected ? `url(#table_glow)` : ''}
/>
)}

{/* Draw the fork */}
{relationType === '1:M' && (
Expand Down
Loading