changing gridline behavior.
This commit is contained in:
parent
3735edb5be
commit
2e41dfd5db
30
grid_line.go
30
grid_line.go
|
@ -7,10 +7,9 @@ type GridLineProvider interface {
|
|||
|
||||
// GridLine is a line on a graph canvas.
|
||||
type GridLine struct {
|
||||
IsMinor bool
|
||||
IsVertical bool
|
||||
Style Style
|
||||
Value float64
|
||||
IsMinor bool
|
||||
Style Style
|
||||
Value float64
|
||||
}
|
||||
|
||||
// Major returns if the gridline is a `major` line.
|
||||
|
@ -23,23 +22,13 @@ func (gl GridLine) Minor() bool {
|
|||
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
|
||||
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.SetStrokeWidth(gl.Style.GetStrokeWidth(defaults.GetStrokeWidth()))
|
||||
r.SetStrokeDashArray(gl.Style.GetStrokeDashArray(defaults.GetStrokeDashArray()))
|
||||
|
||||
if gl.IsVertical {
|
||||
if isVertical {
|
||||
lineLeft := canvasBox.Left + ra.Translate(gl.Value)
|
||||
lineBottom := canvasBox.Bottom
|
||||
lineTop := canvasBox.Top
|
||||
|
@ -59,7 +48,7 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, defaults Style) {
|
|||
}
|
||||
|
||||
// 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
|
||||
isMinor := false
|
||||
|
||||
|
@ -73,10 +62,9 @@ func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, isVertical bo
|
|||
s = minorStyle
|
||||
}
|
||||
gl = append(gl, GridLine{
|
||||
Style: s,
|
||||
IsMinor: isMinor,
|
||||
IsVertical: isVertical,
|
||||
Value: t.Value,
|
||||
Style: s,
|
||||
IsMinor: isMinor,
|
||||
Value: t.Value,
|
||||
})
|
||||
isMinor = !isMinor
|
||||
}
|
||||
|
|
4
xaxis.go
4
xaxis.go
|
@ -63,7 +63,7 @@ func (xa XAxis) GetGridLines(ticks []Tick) []GridLine {
|
|||
if len(xa.GridLines) > 0 {
|
||||
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.
|
||||
|
@ -183,7 +183,7 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
|
|||
if gl.IsMinor {
|
||||
defaults = xa.GridMinorStyle
|
||||
}
|
||||
gl.Render(r, canvasBox, ra, gl.Style.InheritFrom(defaults))
|
||||
gl.Render(r, canvasBox, ra, true, gl.Style.InheritFrom(defaults))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
yaxis.go
6
yaxis.go
|
@ -63,7 +63,7 @@ func (ya YAxis) GetGridLines(ticks []Tick) []GridLine {
|
|||
if len(ya.GridLines) > 0 {
|
||||
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.
|
||||
|
@ -190,7 +190,7 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
|
|||
}
|
||||
|
||||
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 {
|
||||
|
@ -200,7 +200,7 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
|
|||
if gl.IsMinor {
|
||||
defaults = ya.GridMinorStyle
|
||||
}
|
||||
gl.Render(r, canvasBox, ra, gl.Style.InheritFrom(defaults))
|
||||
gl.Render(r, canvasBox, ra, false, gl.Style.InheritFrom(defaults))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user