func (c *Canvas) relationsGroup(canvas *svg.SVG) { canvas.Gid("relations") defer canvas.Gend() for _, relation := range c.relations { relation.usage(canvas) } }
func (c *Canvas) servicesGroup(canvas *svg.SVG) { canvas.Gid("services") defer canvas.Gend() for _, service := range c.services { service.usage(canvas, c.iconIds) } }
func DrawLabel(s *svg.SVG, bs string) *BrailleCanvas { var c BrailleCanvas // TODO: they hard coded c.dotSize = 12 c.pageMarginTop = 3 c.pageMarginBottom = 3 c.pageMarginLeft = 3 c.pageMarginRight = 3 c.gapCell = 3 c.canvasW = c.pageMarginLeft + c.pageMarginRight c.canvasW += c.dotSize * 2 * utf8.RuneCountInString(bs) c.canvasW += c.gapCell*utf8.RuneCountInString(bs) - 1 c.canvasH = c.pageMarginTop + c.pageMarginBottom c.canvasH += c.dotSize * 3 s.Start(c.canvasW, c.canvasH) x := c.pageMarginLeft y := c.pageMarginTop for _, b := range bs { if b&0x2800 != 0x2800 { log.Printf("0x%x is not a braille character!\n", b) continue } Draw(s, b, x, y, c.dotSize) x += (c.dotSize * 2) + c.gapCell } return &c }
func DrawPage30(s *svg.SVG, bs string) *BrailleCanvas { var c BrailleCanvas // TODO: they hard coded c.dotSize = 12 c.pageMarginTop = 10 c.pageMarginBottom = 10 c.pageMarginLeft = 10 c.pageMarginRight = 10 c.gapCell = 3 c.gapLine = 16 c.lineCellsCnt = 30 c.canvasW = c.pageMarginLeft + c.pageMarginRight c.canvasW += c.dotSize * 2 * 30 c.canvasW += c.gapCell*30 - 1 lineCnt := calcLines(bs, 30) c.canvasH = c.pageMarginTop + c.pageMarginBottom c.canvasH += c.dotSize * 3 * lineCnt c.canvasH += c.gapLine*lineCnt - 1 s.Start(c.canvasW, c.canvasH) x := c.pageMarginLeft y := c.pageMarginTop lines := strings.Split(bs, "\n") ri := 0 for _, line := range lines { for _, b := range line { if ri == 30 { x = c.pageMarginLeft y += (c.dotSize * 3) + c.gapLine ri = 0 } if b&0x2800 != 0x2800 { log.Printf("0x%x is not a braille character!\n", b) continue } Draw(s, b, x, y, c.dotSize) ri += 1 x += (c.dotSize * 2) + c.gapCell } x = c.pageMarginLeft y += (c.dotSize * 3) + c.gapLine ri = 0 } return &c }
// usage creates any necessary tags for actually using the service in the SVG. func (s *service) usage(canvas *svg.SVG, iconIds map[string]string) { canvas.Use( s.point.X, s.point.Y, "#serviceBlock", fmt.Sprintf(`id=%q`, s.name)) if len(s.iconSrc) > 0 { canvas.Use( s.point.X+serviceBlockSize/2-iconSize/2, s.point.Y+serviceBlockSize/2-iconSize/2, "#"+iconIds[s.charmPath], fmt.Sprintf(`width="%d" height="%d"`, iconSize, iconSize), ) } else { canvas.Image( s.point.X+serviceBlockSize/2-iconSize/2, s.point.Y+serviceBlockSize/2-iconSize/2, iconSize, iconSize, s.iconUrl, ) } canvas.Textlines( s.point.X+serviceBlockSize/2, s.point.Y+serviceBlockSize/6, []string{s.name}, serviceBlockSize/10, 0, "#505050", "middle") }
// usage creates any necessary tags for actually using the relation in the SVG. func (r *serviceRelation) usage(canvas *svg.SVG) { l := r.shortestRelation() canvas.Line( l.p0.X, l.p0.Y, l.p1.X, l.p1.Y, fmt.Sprintf(`stroke=%q`, relationColor), fmt.Sprintf(`stroke-width="%dpx"`, relationLineWidth), fmt.Sprintf(`stroke-dasharray=%q`, strokeDashArray(l)), ) mid := l.p0.Add(l.p1).Div(2).Sub(point(healthCircleRadius, healthCircleRadius)) canvas.Use(mid.X, mid.Y, "#healthCircle") }
func (c *Canvas) definition(canvas *svg.SVG) { canvas.Def() defer canvas.DefEnd() // Service block. canvas.Group(`id="serviceBlock"`, `transform="scale(0.8)"`) io.WriteString(canvas.Writer, assets.ServiceModule) canvas.Gend() // Gid // Relation health circle. canvas.Gid("healthCircle") canvas.Circle( healthCircleRadius, healthCircleRadius, healthCircleRadius, fmt.Sprintf("stroke:%s;fill:none;stroke-width:%dpx", relationColor, relationLineWidth), ) canvas.Circle( healthCircleRadius, healthCircleRadius, healthCircleRadius/2, fmt.Sprintf("fill:%s", relationColor), ) canvas.Gend() // Service and relation specific defs. for _, relation := range c.relations { relation.definition(canvas) } for _, service := range c.services { service.definition(canvas, c.iconsRendered, c.iconIds) } }
func drawDot(c *svg.SVG, x, y, s int) { //c.Rect(x, y, s, s, "fill:none; stroke:yellow") c.Circle(x+s/2, y+s/2, s/3) }