ticks refactor.
This commit is contained in:
parent
78645130e4
commit
a6b6097c20
9 changed files with 131 additions and 184 deletions
57
grid_line.go
57
grid_line.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue