Skip to content

Commit

Permalink
working in support for notes
Browse files Browse the repository at this point in the history
this code need to be refactor
  • Loading branch information
igorwessel committed May 2, 2024
1 parent 2116291 commit b4969b3
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 108 deletions.
57 changes: 57 additions & 0 deletions playground/testcases/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,63 @@ export const STATE_DIAGRAM_TESTCASES: TestCase[] = [
`,
type: "state",
},

{
name: "Notes",
definition: `stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
notes.
end note
State1 --> State2
note left of State2 : This is the note to the left.
`,
type: "state",
},
{
name: "Note left and right in same state",
definition: `stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
notes.
end note
note left of State1 : This is the note to the left.
`,
type: "state",
},
{
name: "Multiple notes in the same state",
definition: `stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
notes.
end note
note left of State1 : Left.
note left of State1 : Join.
note left of State1 : Out.
note right of State1 : Ok!.
`,
type: "state",
},
{
name: "Notes inside a composite state",
definition: `stateDiagram-v2
[*] --> First
state First {
[*] --> second
second --> [*]
note right of second
First is a composite state
end note
}
`,
type: "state",
},
{
name: "Sample 1",
definition: `stateDiagram-v2
Expand Down
17 changes: 14 additions & 3 deletions src/converter/types/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export const StateToExcalidrawSkeletonConvertor = new GraphConverter({
case "rectangle":
const element = transformToExcalidrawContainerSkeleton(node);

Object.assign(element, {
roundness: { type: 3 },
});
if (!element.id?.includes("note")) {
Object.assign(element, {
roundness: { type: 3 },
});
}

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

chart.edges.forEach((edge) => {
if (!edge) {
return;
}

const points = edge.reflectionPoints.map((point: Point) => [
point.x - edge.reflectionPoints[0].x,
point.y - edge.reflectionPoints[0].y,
Expand All @@ -61,6 +67,11 @@ export const StateToExcalidrawSkeletonConvertor = new GraphConverter({
return;
}

if (endVertex.id?.includes("note") || startVertex.id?.includes("note")) {
arrow.endArrowhead = null;
arrow.strokeStyle = "dashed";
}

arrow.start = {
id: startVertex.id,
type: "rectangle",
Expand Down
Loading

0 comments on commit b4969b3

Please sign in to comment.