ticks refactor.

This commit is contained in:
Will Charczuk 2016-07-23 15:35:49 -07:00
parent 78645130e4
commit a6b6097c20
9 changed files with 131 additions and 184 deletions

View file

@ -1,31 +1,8 @@
package chart
// GenerateGridLines generates grid lines.
func GenerateGridLines(ticks []Tick, isVertical bool) []GridLine {
var gl []GridLine
isMinor := false
minorStyle := Style{
StrokeColor: DefaultGridLineColor.WithAlpha(100),
StrokeWidth: 1.0,
}
majorStyle := Style{
StrokeColor: DefaultGridLineColor,
StrokeWidth: 1.0,
}
for _, t := range ticks {
s := majorStyle
if isMinor {
s = minorStyle
}
gl = append(gl, GridLine{
Style: s,
IsMinor: isMinor,
IsVertical: isVertical,
Value: t.Value,
})
isMinor = !isMinor
}
return gl
// GridLineProvider is a type that provides grid lines.
type GridLineProvider interface {
GetGridLines(ticks []Tick, isVertical bool) []GridLine
}
// GridLine is a line on a graph canvas.
@ -82,3 +59,31 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) {
r.Stroke()
}
}
// GenerateGridLines generates grid lines.
func GenerateGridLines(ticks []Tick, isVertical bool) []GridLine {
var gl []GridLine
isMinor := false
minorStyle := Style{
StrokeColor: DefaultGridLineColor.WithAlpha(100),
StrokeWidth: 1.0,
}
majorStyle := Style{
StrokeColor: DefaultGridLineColor,
StrokeWidth: 1.0,
}
for _, t := range ticks {
s := majorStyle
if isMinor {
s = minorStyle
}
gl = append(gl, GridLine{
Style: s,
IsMinor: isMinor,
IsVertical: isVertical,
Value: t.Value,
})
isMinor = !isMinor
}
return gl
}