fixing svg circles
This commit is contained in:
parent
10de6fa9bf
commit
66b99eb8e3
4 changed files with 33 additions and 19 deletions
|
@ -125,8 +125,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
|
||||
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
graph.Render(chart.PNG, res)
|
||||
res.Header().Set("Content-Type", chart.ContentTypeSVG)
|
||||
graph.Render(chart.SVG, res)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -24,8 +24,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
err := graph.Render(chart.PNG, res)
|
||||
res.Header().Set("Content-Type", chart.ContentTypeSVG)
|
||||
err := graph.Render(chart.SVG, res)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ func unit(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
err := graph.Render(chart.PNG, res)
|
||||
res.Header().Set("Content-Type", chart.ContentTypeSVG)
|
||||
err := graph.Render(chart.SVG, res)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
|
|
|
@ -225,3 +225,11 @@ func GetDefaultFont() (*truetype.Font, error) {
|
|||
}
|
||||
return _defaultFont, nil
|
||||
}
|
||||
|
||||
const (
|
||||
// ContentTypePNG is the png mime type.
|
||||
ContentTypePNG = "image/png"
|
||||
|
||||
// ContentTypeSVG is the svg mime type.
|
||||
ContentTypeSVG = "image/svg+xml"
|
||||
)
|
||||
|
|
|
@ -222,7 +222,7 @@ func (c *canvas) Path(d string, style Style) {
|
|||
if len(style.StrokeDashArray) > 0 {
|
||||
strokeDashArrayProperty = c.getStrokeDashArray(style)
|
||||
}
|
||||
c.w.Write([]byte(fmt.Sprintf(`<path %s d="%s" style="%s"/>\n`, strokeDashArrayProperty, d, c.styleAsSVG(style))))
|
||||
c.w.Write([]byte(fmt.Sprintf(`<path %s d="%s" style="%s"/>`, strokeDashArrayProperty, d, c.styleAsSVG(style))))
|
||||
}
|
||||
|
||||
func (c *canvas) Text(x, y int, body string, style Style) {
|
||||
|
@ -235,7 +235,7 @@ func (c *canvas) Text(x, y int, body string, style Style) {
|
|||
}
|
||||
|
||||
func (c *canvas) Circle(x, y, r int, style Style) {
|
||||
c.w.Write([]byte(fmt.Sprintf(`<circle cx="%d" cy="%d" r="%d" style="%s">`, x, y, r, c.styleAsSVG(style))))
|
||||
c.w.Write([]byte(fmt.Sprintf(`<circle cx="%d" cy="%d" r="%d" style="%s"/>`, x, y, r, c.styleAsSVG(style))))
|
||||
}
|
||||
|
||||
func (c *canvas) End() {
|
||||
|
@ -274,30 +274,36 @@ func (c *canvas) styleAsSVG(s Style) string {
|
|||
fs := s.FontSize
|
||||
fnc := s.FontColor
|
||||
|
||||
strokeWidthText := "stroke-width:0"
|
||||
var pieces []string
|
||||
|
||||
if sw != 0 {
|
||||
strokeWidthText = "stroke-width:" + fmt.Sprintf("%d", int(sw))
|
||||
pieces = append(pieces, "stroke-width:"+fmt.Sprintf("%d", int(sw)))
|
||||
} else {
|
||||
pieces = append(pieces, "stroke-width:0")
|
||||
}
|
||||
|
||||
strokeText := "stroke:none"
|
||||
if !sc.IsZero() {
|
||||
strokeText = "stroke:" + sc.String()
|
||||
pieces = append(pieces, "stroke:"+sc.String())
|
||||
} else {
|
||||
pieces = append(pieces, "stroke:none")
|
||||
}
|
||||
|
||||
fillText := "fill:none"
|
||||
if !fc.IsZero() {
|
||||
fillText = "fill:" + fc.String()
|
||||
pieces = append(pieces, "fill:"+fc.String())
|
||||
} else {
|
||||
pieces = append(pieces, "fill:none")
|
||||
}
|
||||
|
||||
fontSizeText := ""
|
||||
if fs != 0 {
|
||||
fontSizeText = "font-size:" + fmt.Sprintf("%.1fpx", drawing.PointsToPixels(c.dpi, fs))
|
||||
pieces = append(pieces, "font-size:"+fmt.Sprintf("%.1fpx", drawing.PointsToPixels(c.dpi, fs)))
|
||||
}
|
||||
|
||||
if !fnc.IsZero() {
|
||||
fillText = "fill:" + fnc.String()
|
||||
pieces = append(pieces, "fill:"+fnc.String())
|
||||
}
|
||||
|
||||
fontText := c.getFontFace(s)
|
||||
return strings.Join([]string{strokeWidthText, strokeText, fillText, fontSizeText, fontText}, ";")
|
||||
if s.Font != nil {
|
||||
pieces = append(pieces, c.getFontFace(s))
|
||||
}
|
||||
return strings.Join(pieces, ";")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue