Skip to content

Commit

Permalink
Added the "cloud" participant icon
Browse files Browse the repository at this point in the history
  • Loading branch information
lmika committed Jul 27, 2021
1 parent 9ece611 commit 09b59a5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions seqdiagram/actoricon.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ func (bai *builtinActorIcon) graphboxIcon() graphbox.Icon {
var builtinIcons = map[string]ActorIcon{
"human": &builtinActorIcon{graphbox.StickPersonIcon(1)},
"cylinder": &builtinActorIcon{graphbox.CylinderIcon(1)},
"cloud": &builtinActorIcon{graphbox.PathIcon{graphbox.CloudPathData}},
}
51 changes: 51 additions & 0 deletions seqdiagram/graphbox/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,54 @@ func (ci CylinderIcon) drawCurve(ctx DrawContext, fx, fy, tx, ty, mag int, style

ctx.Canvas.Path(pathCmds.String(), style)
}

// A cloud
//

type PathIcon struct {
Data PathIconData
}

func (pi PathIcon) Size() (width int, height int) {
width = int(pi.Data.TargetIconSize * pi.Data.Width / pi.Data.Height)
height = int(pi.Data.TargetIconSize)
return
}

func (pi PathIcon) Draw(ctx DrawContext, x int, y int, lineStyle *SvgStyle) {
scaleFactor := (pi.Data.TargetIconSize - pi.Data.IconPadding*2) / pi.Data.Width

style := lineStyle.ToStyle()

tx, ty := float64(x)/scaleFactor-pi.Data.Width/2.0, float64(y)/scaleFactor-pi.Data.Height/2.0
transformations := fmt.Sprintf("scale(%f) translate(%f %f)", scaleFactor, tx, ty)

ctx.Canvas.Group(style)
ctx.Canvas.Path(pi.Data.Path, "transform=\""+transformations+"\"", "style=\"stroke-width:10px\"")
ctx.Canvas.Gend()
}

type PathIconData struct {
Width float64
Height float64
TargetIconSize float64
IconPadding float64
Path string
}


// CloudPathData represents the path data for the cloud icon.
// The image was adapted from the one at https://freesvg.org/simple-white-cloud-icon-vector-graphics
var CloudPathData = PathIconData{
Width: 365.0,
Height: 185.0,
TargetIconSize: 44.0,
IconPadding: -18.0,
Path: `
m299.75 60.587c-4.108 0-8.123 0.411-12.001 1.188-11.95-35.875-46.03-61.775-86.23-61.775-33.761
0-63.196 18.27-78.847 45.363-0.919-0.036-1.84-0.07-2.769-0.07-23.494 0-44.202 11.816-56.409
29.777-3.263-0.617-6.627-0.953-10.071-0.953-29.503 0-53.42 23.702-53.42 52.943 0 29.24 23.917
52.94 53.421 52.94h66.435 0.045 0.045 81.525 0.045 0.047 98.145 0.046c33.28 0 60.25-26.73
60.25-59.71 0-32.972-26.97-59.703-60.25-59.703z
`,
}

0 comments on commit 09b59a5

Please sign in to comment.