Skip to content

Commit 0a877f5

Browse files
committed
working in support for notes
this code need to be refactor
1 parent 5cc0490 commit 0a877f5

File tree

4 files changed

+250
-107
lines changed

4 files changed

+250
-107
lines changed

playground/testcases/state.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,59 @@ export const STATE_DIAGRAM_TESTCASES = [
174174
}
175175
`,
176176
},
177+
178+
{
179+
name: "Notes",
180+
definition: `stateDiagram-v2
181+
State1: The state with a note
182+
note right of State1
183+
Important information! You can write
184+
notes.
185+
end note
186+
State1 --> State2
187+
note left of State2 : This is the note to the left.
188+
`,
189+
},
190+
{
191+
name: "Note left and right in same state",
192+
definition: `stateDiagram-v2
193+
State1: The state with a note
194+
note right of State1
195+
Important information! You can write
196+
notes.
197+
end note
198+
note left of State1 : This is the note to the left.
199+
`,
200+
},
201+
{
202+
name: "Multiple notes in the same state",
203+
definition: `stateDiagram-v2
204+
State1: The state with a note
205+
note right of State1
206+
Important information! You can write
207+
notes.
208+
end note
209+
note left of State1 : Left.
210+
note left of State1 : Join.
211+
note left of State1 : Out.
212+
note right of State1 : Ok!.
213+
`,
214+
},
215+
{
216+
name: "Notes inside a composite state",
217+
definition: `stateDiagram-v2
218+
[*] --> First
219+
state First {
220+
[*] --> second
221+
second --> [*]
222+
223+
note right of second
224+
First is a composite state
225+
end note
226+
227+
}
228+
`,
229+
},
177230
{
178231
name: "Sample 1",
179232
definition: `stateDiagram-v2

src/converter/types/state.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ export const StateToExcalidrawSkeletonConvertor = new GraphConverter({
2323
case "rectangle":
2424
const element = transformToExcalidrawContainerSkeleton(node);
2525

26-
Object.assign(element, {
27-
roundness: { type: 3 },
28-
});
26+
if (!element.id?.includes("note")) {
27+
Object.assign(element, {
28+
roundness: { type: 3 },
29+
});
30+
}
2931

3032
elements.push(element);
3133
break;
@@ -43,6 +45,10 @@ export const StateToExcalidrawSkeletonConvertor = new GraphConverter({
4345
});
4446

4547
chart.edges.forEach((edge) => {
48+
if (!edge) {
49+
return;
50+
}
51+
4652
const points = edge.reflectionPoints.map((point: Point) => [
4753
point.x - edge.reflectionPoints[0].x,
4854
point.y - edge.reflectionPoints[0].y,
@@ -61,6 +67,11 @@ export const StateToExcalidrawSkeletonConvertor = new GraphConverter({
6167
return;
6268
}
6369

70+
if (endVertex.id?.includes("note") || startVertex.id?.includes("note")) {
71+
arrow.endArrowhead = null;
72+
arrow.strokeStyle = "dashed";
73+
}
74+
6475
arrow.start = {
6576
id: startVertex.id,
6677
type: "rectangle",

0 commit comments

Comments
 (0)