refactoring how we handle styles in create legend.

This commit is contained in:
Will Charczuk 2016-07-14 19:36:40 -07:00
parent 0cef99b524
commit eda016a7f9

View File

@ -168,8 +168,17 @@ func DrawTextCentered(r Renderer, text string, x, y int, s Style) {
r.Text(text, tx, ty) r.Text(text, tx, ty)
} }
func CreateLegend(c *Chart) Renderable { // CreateLegend returns a legend renderable function.
func CreateLegend(c *Chart, style Style) Renderable {
return func(r Renderer, cb Box, defaults Style) { return func(r Renderer, cb Box, defaults Style) {
workingStyle := style.WithDefaultsFrom(defaults.WithDefaultsFrom(Style{
FillColor: drawing.ColorWhite,
FontColor: DefaultTextColor,
FontSize: 8.0,
StrokeColor: DefaultAxisColor,
StrokeWidth: DefaultAxisLineWidth,
}))
// DEFAULTS // DEFAULTS
legendPadding := 5 legendPadding := 5
lineTextGap := 5 lineTextGap := 5
@ -196,8 +205,8 @@ func CreateLegend(c *Chart) Renderable {
Left: legend.Left + legendPadding, Left: legend.Left + legendPadding,
} }
r.SetFontColor(DefaultTextColor) r.SetFontColor(workingStyle.GetFontColor())
r.SetFontSize(8.0) r.SetFontSize(workingStyle.GetFontSize())
// measure // measure
for x := 0; x < len(labels); x++ { for x := 0; x < len(labels); x++ {
@ -210,11 +219,7 @@ func CreateLegend(c *Chart) Renderable {
} }
legend = legend.Grow(legendContent) legend = legend.Grow(legendContent)
DrawBox(r, legend, Style{ DrawBox(r, legend, workingStyle)
FillColor: drawing.ColorWhite,
StrokeColor: DefaultAxisColor,
StrokeWidth: 1.0,
})
legendContent.Right = legend.Right - legendPadding legendContent.Right = legend.Right - legendPadding
legendContent.Bottom = legend.Bottom - legendPadding legendContent.Bottom = legend.Bottom - legendPadding