changing gridline behavior.

This commit is contained in:
Will Charczuk 2016-08-11 20:42:25 -07:00
parent 3735edb5be
commit 2e41dfd5db
3 changed files with 14 additions and 26 deletions

View File

@ -8,7 +8,6 @@ type GridLineProvider interface {
// GridLine is a line on a graph canvas. // GridLine is a line on a graph canvas.
type GridLine struct { type GridLine struct {
IsMinor bool IsMinor bool
IsVertical bool
Style Style Style Style
Value float64 Value float64
} }
@ -23,23 +22,13 @@ func (gl GridLine) Minor() bool {
return gl.IsMinor return gl.IsMinor
} }
// Vertical returns if the line is vertical line or not.
func (gl GridLine) Vertical() bool {
return gl.IsVertical
}
// Horizontal returns if the line is horizontal line or not.
func (gl GridLine) Horizontal() bool {
return !gl.IsVertical
}
// Render renders the gridline // Render renders the gridline
func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, defaults Style) { func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, isVertical bool, defaults Style) {
r.SetStrokeColor(gl.Style.GetStrokeColor(defaults.GetStrokeColor())) r.SetStrokeColor(gl.Style.GetStrokeColor(defaults.GetStrokeColor()))
r.SetStrokeWidth(gl.Style.GetStrokeWidth(defaults.GetStrokeWidth())) r.SetStrokeWidth(gl.Style.GetStrokeWidth(defaults.GetStrokeWidth()))
r.SetStrokeDashArray(gl.Style.GetStrokeDashArray(defaults.GetStrokeDashArray())) r.SetStrokeDashArray(gl.Style.GetStrokeDashArray(defaults.GetStrokeDashArray()))
if gl.IsVertical { if 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
@ -59,7 +48,7 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, defaults Style) {
} }
// GenerateGridLines generates grid lines. // GenerateGridLines generates grid lines.
func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, isVertical bool) []GridLine { func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style) []GridLine {
var gl []GridLine var gl []GridLine
isMinor := false isMinor := false
@ -75,7 +64,6 @@ func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, isVertical bo
gl = append(gl, GridLine{ gl = append(gl, GridLine{
Style: s, Style: s,
IsMinor: isMinor, IsMinor: isMinor,
IsVertical: isVertical,
Value: t.Value, Value: t.Value,
}) })
isMinor = !isMinor isMinor = !isMinor

View File

@ -63,7 +63,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, xa.GridMajorStyle, xa.GridMinorStyle, true) return GenerateGridLines(ticks, xa.GridMajorStyle, xa.GridMinorStyle)
} }
// Measure returns the bounds of the axis. // Measure returns the bounds of the axis.
@ -183,7 +183,7 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
if gl.IsMinor { if gl.IsMinor {
defaults = xa.GridMinorStyle defaults = xa.GridMinorStyle
} }
gl.Render(r, canvasBox, ra, gl.Style.InheritFrom(defaults)) gl.Render(r, canvasBox, ra, true, gl.Style.InheritFrom(defaults))
} }
} }
} }

View File

@ -63,7 +63,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, ya.GridMajorStyle, ya.GridMinorStyle, false) return GenerateGridLines(ticks, ya.GridMajorStyle, ya.GridMinorStyle)
} }
// Measure returns the bounds of the axis. // Measure returns the bounds of the axis.
@ -190,7 +190,7 @@ 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, Style{}) ya.Zero.Render(r, canvasBox, ra, false, Style{})
} }
if ya.GridMajorStyle.Show || ya.GridMinorStyle.Show { if ya.GridMajorStyle.Show || ya.GridMinorStyle.Show {
@ -200,7 +200,7 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
if gl.IsMinor { if gl.IsMinor {
defaults = ya.GridMinorStyle defaults = ya.GridMinorStyle
} }
gl.Render(r, canvasBox, ra, gl.Style.InheritFrom(defaults)) gl.Render(r, canvasBox, ra, false, gl.Style.InheritFrom(defaults))
} }
} }
} }