Skip to content

Commit fc180ba

Browse files
committed
updated readme with example
1 parent ab7a300 commit fc180ba

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ and you won't find some functionalities yet such as
3636
d.Render()
3737
3838
```
39+
Result PNG file:
40+
![image description](./examples/user_starts_chatting.png)

main.go renamed to examples/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import "go-uml/sequence"
44

55
func main() {
6-
d := sequence.NewDiagram()
6+
d := sequence.NewDiagram("user_starts_chatting")
77

88
client := "Client"
99
backend := "Backend"

out.png

-14 KB
Binary file not shown.

sequence/diagram.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ type Diagram struct {
2727
renderedParticipants []*participant
2828
participantsCoordMap map[string]participantCoord
2929

30-
dc *gg.Context
31-
title string
30+
dc *gg.Context
31+
title string
32+
filename string
3233
}
3334

34-
func NewDiagram() *Diagram {
35+
func NewDiagram(filename string) *Diagram {
3536
coordMap := make(map[string]participantCoord)
3637

3738
return &Diagram{
3839
participantsCoordMap: coordMap,
40+
filename: filename,
3941
}
4042
}
4143

@@ -49,7 +51,7 @@ func (d *Diagram) Render() {
4951
d.renderParticipants()
5052
d.renderEdges()
5153

52-
d.dc.SavePNG("out.png")
54+
d.dc.SavePNG(fmt.Sprintf("%s.png", d.filename))
5355
}
5456

5557
func (d *Diagram) renderTitle() {

0 commit comments

Comments
 (0)