pulling generate grid lines into its own function

This commit is contained in:
Will Charczuk 2016-07-12 19:22:02 -07:00
parent 249e9956d0
commit 1c3473f674
3 changed files with 35 additions and 35 deletions

View file

@ -1,5 +1,33 @@
package chart 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
}
// 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

View file

@ -46,12 +46,6 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult {
Style: chart.Style{ Style: chart.Style{
Show: true, Show: true,
}, },
GridMajorStyle: chart.Style{
Show: true,
},
GridMinorStyle: chart.Style{
Show: true,
},
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.Style{
@ -64,7 +58,7 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult {
}, },
}, },
GridMajorStyle: chart.Style{ GridMajorStyle: chart.Style{
Show: true, Show: false,
}, },
GridMinorStyle: chart.Style{ GridMinorStyle: chart.Style{
Show: true, Show: true,
@ -75,12 +69,16 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult {
Name: "a", Name: "a",
XValues: s1x, XValues: s1x,
YValues: s1y, YValues: s1y,
Style: chart.Style{
Show: true,
FillColor: chart.GetDefaultSeriesStrokeColor(0).WithAlpha(64),
},
}, },
chart.AnnotationSeries{ chart.AnnotationSeries{
Name: fmt.Sprintf("%s - Last Value", "Test"), Name: fmt.Sprintf("%s - Last Value", "Test"),
Style: chart.Style{ Style: chart.Style{
Show: true, Show: true,
StrokeColor: chart.DefaultSeriesStrokeColors[0], StrokeColor: chart.GetDefaultSeriesStrokeColor(0),
}, },
Annotations: []chart.Annotation{ Annotations: []chart.Annotation{
chart.Annotation{ chart.Annotation{

View file

@ -71,33 +71,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 ya.generateGridLines(ticks) return GenerateGridLines(ticks, false)
}
func (ya YAxis) generateGridLines(ticks []Tick) []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,
Value: t.Value,
})
isMinor = !isMinor
}
return gl
} }
// Measure returns the bounds of the axis. // Measure returns the bounds of the axis.