Skip to content

Commit

Permalink
fix: [activity] strange corner whene condition is inside while (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
hikerpig authored Jun 16, 2024
1 parent 0e0747c commit f06dfd0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-readers-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pintora/diagrams': patch
---

fix: [activity] strange corner whene condition is inside while
15 changes: 15 additions & 0 deletions demo/cypress/e2e/activity/activity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,20 @@ end`),
c.get('.activity__edge-label').should('have.lengthOf', 2)
},
},
{
// issue #284
description: 'Should draw lines correctly when there is an empty else block inside a while loop',
code: stripStartEmptyLines(`
activityDiagram
partition G {
while (test while) is (next)
if (test if) then
:print error;
else (no)
endif
endwhile (done)
}
`),
},
])
})
21 changes: 19 additions & 2 deletions packages/pintora-diagrams/src/activity/artist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,27 @@ class ActivityDraw {
width: 1,
height: 1,
})

this.g.setEdge(id, dummyNode.id, { label })
this.g.setEdge(dummyNode.id, endId)
this.g.setEdge(dummyNode.id, endId, { label: '' })
if (stepModel.parentId) {
this.g.setParent(dummyNode.id, stepModel.parentId)
// set parent to the cloest group
const parentStepModel = this.model.stepModelMap.get(stepModel.parentId)
let closestGroup = null
let p = parentStepModel
while (p) {
if (p.type === 'group') {
closestGroup = p
break
}
if (p.parentId) {
p = this.model.stepModelMap.get(p.parentId)
if (!p) break
}
}
if (closestGroup) {
this.g.setParent(dummyNode.id, closestGroup.id)
}
}
}
}
Expand Down

0 comments on commit f06dfd0

Please sign in to comment.