fixing svg renderer

This commit is contained in:
Will Charczuk 2016-07-10 18:09:41 -07:00
parent b4dfae683d
commit 1e62f7ce3b
4 changed files with 46 additions and 20 deletions

View file

@ -149,3 +149,35 @@ func (s Style) SVG(dpi float64) string {
} }
return strings.Join([]string{strokeWidthText, strokeText, fillText, fontSizeText}, ";") return strings.Join([]string{strokeWidthText, strokeText, fillText, fontSizeText}, ";")
} }
// SVGStroke returns the stroke components.
func (s Style) SVGStroke() Style {
return Style{
StrokeColor: s.StrokeColor,
StrokeWidth: s.StrokeWidth,
}
}
// SVGFill returns the fill components.
func (s Style) SVGFill() Style {
return Style{
FillColor: s.FillColor,
}
}
// SVGFillAndStroke returns the fill and stroke components.
func (s Style) SVGFillAndStroke() Style {
return Style{
FillColor: s.FillColor,
StrokeColor: s.StrokeColor,
StrokeWidth: s.StrokeWidth,
}
}
// SVGText returns just the text components of the style.
func (s Style) SVGText() Style {
return Style{
FontColor: s.FontColor,
FontSize: s.FontSize,
}
}

View file

@ -35,12 +35,12 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult {
Height: 400, Height: 400,
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.Style{
Show: false, Show: true,
}, },
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.Style{
Show: false, Show: true,
}, },
Range: chart.Range{ Range: chart.Range{
Min: 0.0, Min: 0.0,
@ -49,7 +49,7 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult {
}, },
YAxisSecondary: chart.YAxis{ YAxisSecondary: chart.YAxis{
Style: chart.Style{ Style: chart.Style{
Show: false, Show: true,
}, },
Range: chart.Range{ Range: chart.Range{
Min: 0.8, Min: 0.8,

View file

@ -77,28 +77,22 @@ func (vr *vectorRenderer) Close() {
// Stroke draws the path with no fill. // Stroke draws the path with no fill.
func (vr *vectorRenderer) Stroke() { func (vr *vectorRenderer) Stroke() {
vr.s.FillColor = drawing.ColorTransparent vr.drawPath(vr.s.SVGStroke())
vr.s.FontColor = drawing.ColorTransparent
vr.drawPath()
} }
// Fill draws the path with no stroke. // Fill draws the path with no stroke.
func (vr *vectorRenderer) Fill() { func (vr *vectorRenderer) Fill() {
vr.s.StrokeColor = drawing.ColorTransparent vr.drawPath(vr.s.SVGFill())
vr.s.StrokeWidth = 0
vr.s.FontColor = drawing.ColorTransparent
vr.drawPath()
} }
// FillStroke draws the path with both fill and stroke. // FillStroke draws the path with both fill and stroke.
func (vr *vectorRenderer) FillStroke() { func (vr *vectorRenderer) FillStroke() {
vr.s.FontColor = drawing.ColorTransparent vr.drawPath(vr.s.SVGFillAndStroke())
vr.drawPath()
} }
func (vr *vectorRenderer) drawPath() { func (vr *vectorRenderer) drawPath(s Style) {
vr.c.Path(strings.Join(vr.p, "\n"), vr.s.SVG(vr.dpi)) vr.c.Path(strings.Join(vr.p, "\n"), s.SVG(vr.dpi))
vr.p = []string{} vr.p = []string{} // clear the path
} }
// Circle implements the interface method. // Circle implements the interface method.
@ -134,10 +128,8 @@ func (vr *vectorRenderer) svgFontFace() string {
// Text draws a text blob. // Text draws a text blob.
func (vr *vectorRenderer) Text(body string, x, y int) { func (vr *vectorRenderer) Text(body string, x, y int) {
vr.s.FillColor = drawing.ColorTransparent s := vr.s.SVGText()
vr.s.StrokeColor = drawing.ColorTransparent vr.c.Text(x, y, body, s.SVG(vr.dpi)+";"+vr.svgFontFace())
vr.s.StrokeWidth = 0
vr.c.Text(x, y, body, vr.s.SVG(vr.dpi)+";"+vr.svgFontFace())
} }
// MeasureText uses the truetype font drawer to measure the width of text. // MeasureText uses the truetype font drawer to measure the width of text.

View file

@ -66,7 +66,9 @@ func (ya YAxis) generateTicksWithStep(ra Range, step float64, vf ValueFormatter)
func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, axisType YAxisType, ticks []Tick) { func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, axisType YAxisType, ticks []Tick) {
r.SetStrokeColor(ya.Style.GetStrokeColor(DefaultAxisColor)) r.SetStrokeColor(ya.Style.GetStrokeColor(DefaultAxisColor))
r.SetStrokeWidth(ya.Style.GetStrokeWidth(DefaultAxisLineWidth)) r.SetStrokeWidth(ya.Style.GetStrokeWidth(DefaultAxisLineWidth))
r.SetFontColor(ya.Style.GetFontColor(DefaultAxisColor))
fontColor := ya.Style.GetFontColor(DefaultAxisColor)
r.SetFontColor(fontColor)
fontSize := ya.Style.GetFontSize(DefaultFontSize) fontSize := ya.Style.GetFontSize(DefaultFontSize)
r.SetFontSize(fontSize) r.SetFontSize(fontSize)