Skip to content

Commit e2462d2

Browse files
Merge pull request #18 from hydecnc/diagram-node
feat: add DiagramNode component for CA Learning graph
2 parents 49b694f + c95232d commit e2462d2

4 files changed

Lines changed: 79 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Feature
66

7+
- Added component `DiagramNode` for CA Learning graph
78

89
### Bug Fix
910

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.node {
2+
cursor: pointer;
3+
fill: none;
4+
}
5+
.nodeLabel {
6+
fill: white;
7+
font-weight: 700;
8+
}

components/diagram/DiagramNode.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import styles from "./DiagramNode.module.css";
2+
3+
interface DiagramNodeProps {
4+
label: string;
5+
onClick: () => void;
6+
}
7+
8+
enum NodeCategory {
9+
InterfaceAdapters = "Interface Adapters",
10+
ApplicationBusinessRules = "Application Business Rules",
11+
EnterpriseBusinessRules = "Enterprise Business Rules",
12+
FrameworksAndDrivers = "Frameworks & Drivers",
13+
}
14+
15+
const titleToCategory: Record<string, NodeCategory> = {
16+
controller: NodeCategory.InterfaceAdapters,
17+
presenter: NodeCategory.InterfaceAdapters,
18+
"view model": NodeCategory.InterfaceAdapters,
19+
"input data": NodeCategory.ApplicationBusinessRules,
20+
"input boundary": NodeCategory.ApplicationBusinessRules,
21+
"use case interactor": NodeCategory.ApplicationBusinessRules,
22+
"output data": NodeCategory.ApplicationBusinessRules,
23+
"output boundary": NodeCategory.ApplicationBusinessRules,
24+
"data access interface": NodeCategory.ApplicationBusinessRules,
25+
entities: NodeCategory.EnterpriseBusinessRules,
26+
view: NodeCategory.FrameworksAndDrivers,
27+
"data access": NodeCategory.FrameworksAndDrivers,
28+
database: NodeCategory.FrameworksAndDrivers,
29+
};
30+
31+
const categoryToColor: Record<NodeCategory, string> = {
32+
[NodeCategory.InterfaceAdapters]: "var(--color-brand-green)",
33+
[NodeCategory.ApplicationBusinessRules]: "var(--color-brand-pink)",
34+
[NodeCategory.EnterpriseBusinessRules]: "var(--color-brand-yellow)",
35+
[NodeCategory.FrameworksAndDrivers]: "var(--color-brand-blue)",
36+
};
37+
38+
export const DiagramNode = ({ label, onClick }: DiagramNodeProps) => {
39+
const category = titleToCategory[label.toLowerCase()];
40+
if (!category) throw new Error(`DiagramNode: unknown label: "${label}"`);
41+
42+
return (
43+
<svg
44+
width="160"
45+
height="40"
46+
viewBox="0 0 150 36"
47+
onClick={onClick}
48+
className={styles.node}
49+
>
50+
<rect
51+
width="100%"
52+
height="100%"
53+
rx="5"
54+
ry="5"
55+
fill={categoryToColor[category]}
56+
/>
57+
<text
58+
x="50%"
59+
y="50%"
60+
textAnchor="middle"
61+
dominantBaseline="middle"
62+
className={`text-mono ${styles.nodeLabel}`}
63+
>
64+
{label}
65+
</text>
66+
</svg>
67+
);
68+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"contributors": [
3636
"Masa Abu Arja",
37-
"Matthew Dahlgren"
37+
"Matthew Dahlgren",
38+
"Seokjin Yoo"
3839
]
3940
}

0 commit comments

Comments
 (0)