ajstarks / svgo

Go Language Library for SVG generation
Other
2.14k stars 169 forks source link

Add <title> to individual element? #48

Closed nathanleclaire closed 5 years ago

nathanleclaire commented 5 years ago

Title seems like it will work fine for the whole canvas but for individual elements - seems it won't work based on reading the source. Is there any approach to take here?

ajstarks commented 5 years ago

you can place a title with a group, or alternatively add a title attribute to an element.

package main

import (
    "os"

    svg "github.com/ajstarks/svgo"
)

func main() {

    canvas := svg.New(os.Stdout)

    canvas.Start(500, 500)
    canvas.Group()
    canvas.Title("this is the title")
    canvas.Circle(100, 100, 10)
    canvas.Gend()
    canvas.Rect(200, 200, 50, 40, `title="box"`)
    canvas.End()
}
nathanleclaire commented 5 years ago

Creating a group worked perfectly. STOKED!