style handling on gridlines.

This commit is contained in:
Will Charczuk 2016-07-24 20:27:19 -07:00
parent 2f7cd11039
commit 50a798f67f
3 changed files with 21 additions and 25 deletions

View File

@ -34,15 +34,16 @@ func (gl GridLine) Horizontal() bool {
} }
// Render renders the gridline // Render renders the gridline
func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) { func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, defaults Style) {
r.SetStrokeColor(gl.Style.GetStrokeColor(defaults.GetStrokeColor()))
r.SetStrokeWidth(gl.Style.GetStrokeWidth(defaults.GetStrokeWidth()))
r.SetStrokeDashArray(gl.Style.GetStrokeDashArray(defaults.GetStrokeDashArray()))
if gl.IsVertical { if gl.IsVertical {
lineLeft := canvasBox.Left + ra.Translate(gl.Value) lineLeft := canvasBox.Left + ra.Translate(gl.Value)
lineBottom := canvasBox.Bottom lineBottom := canvasBox.Bottom
lineTop := canvasBox.Top lineTop := canvasBox.Top
r.SetStrokeColor(gl.Style.GetStrokeColor(DefaultAxisColor))
r.SetStrokeWidth(gl.Style.GetStrokeWidth(DefaultAxisLineWidth))
r.MoveTo(lineLeft, lineBottom) r.MoveTo(lineLeft, lineBottom)
r.LineTo(lineLeft, lineTop) r.LineTo(lineLeft, lineTop)
r.Stroke() r.Stroke()
@ -51,9 +52,6 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) {
lineRight := canvasBox.Right lineRight := canvasBox.Right
lineHeight := canvasBox.Bottom - ra.Translate(gl.Value) lineHeight := canvasBox.Bottom - ra.Translate(gl.Value)
r.SetStrokeColor(gl.Style.GetStrokeColor(DefaultAxisColor))
r.SetStrokeWidth(gl.Style.GetStrokeWidth(DefaultAxisLineWidth))
r.MoveTo(lineLeft, lineHeight) r.MoveTo(lineLeft, lineHeight)
r.LineTo(lineRight, lineHeight) r.LineTo(lineRight, lineHeight)
r.Stroke() r.Stroke()
@ -61,17 +59,9 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) {
} }
// GenerateGridLines generates grid lines. // GenerateGridLines generates grid lines.
func GenerateGridLines(ticks []Tick, isVertical bool) []GridLine { func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, isVertical bool) []GridLine {
var gl []GridLine var gl []GridLine
isMinor := false isMinor := false
minorStyle := Style{
StrokeColor: DefaultGridLineColor.WithAlpha(100),
StrokeWidth: 1.0,
}
majorStyle := Style{
StrokeColor: DefaultGridLineColor,
StrokeWidth: 1.0,
}
for _, t := range ticks { for _, t := range ticks {
s := majorStyle s := majorStyle
if isMinor { if isMinor {

View File

@ -46,7 +46,7 @@ func (xa XAxis) GetGridLines(ticks []Tick) []GridLine {
if len(xa.GridLines) > 0 { if len(xa.GridLines) > 0 {
return xa.GridLines return xa.GridLines
} }
return GenerateGridLines(ticks, true) return GenerateGridLines(ticks, xa.GridMajorStyle, xa.GridMinorStyle, true)
} }
// Measure returns the bounds of the axis. // Measure returns the bounds of the axis.
@ -102,9 +102,12 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
if xa.GridMajorStyle.Show || xa.GridMinorStyle.Show { if xa.GridMajorStyle.Show || xa.GridMinorStyle.Show {
for _, gl := range xa.GetGridLines(ticks) { for _, gl := range xa.GetGridLines(ticks) {
if (gl.IsMinor && xa.GridMinorStyle.Show) || if (gl.IsMinor && xa.GridMinorStyle.Show) || (!gl.IsMinor && xa.GridMajorStyle.Show) {
(!gl.IsMinor && xa.GridMajorStyle.Show) { defaults := xa.GridMajorStyle
gl.Render(r, canvasBox, ra) if gl.IsMinor {
defaults = xa.GridMinorStyle
}
gl.Render(r, canvasBox, ra, defaults)
} }
} }
} }

View File

@ -53,7 +53,7 @@ func (ya YAxis) GetGridLines(ticks []Tick) []GridLine {
if len(ya.GridLines) > 0 { if len(ya.GridLines) > 0 {
return ya.GridLines return ya.GridLines
} }
return GenerateGridLines(ticks, false) return GenerateGridLines(ticks, ya.GridMajorStyle, ya.GridMinorStyle, false)
} }
// Measure returns the bounds of the axis. // Measure returns the bounds of the axis.
@ -145,14 +145,17 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
} }
if ya.Zero.Style.Show { if ya.Zero.Style.Show {
ya.Zero.Render(r, canvasBox, ra) ya.Zero.Render(r, canvasBox, ra, Style{})
} }
if ya.GridMajorStyle.Show || ya.GridMinorStyle.Show { if ya.GridMajorStyle.Show || ya.GridMinorStyle.Show {
for _, gl := range ya.GetGridLines(ticks) { for _, gl := range ya.GetGridLines(ticks) {
if (gl.IsMinor && ya.GridMinorStyle.Show) || if (gl.IsMinor && ya.GridMinorStyle.Show) || (!gl.IsMinor && ya.GridMajorStyle.Show) {
(!gl.IsMinor && ya.GridMajorStyle.Show) { defaults := ya.GridMajorStyle
gl.Render(r, canvasBox, ra) if gl.IsMinor {
defaults = ya.GridMinorStyle
}
gl.Render(r, canvasBox, ra, defaults)
} }
} }
} }