diff --git a/grid_line.go b/grid_line.go index 6fce265..fe49cba 100644 --- a/grid_line.go +++ b/grid_line.go @@ -1,5 +1,33 @@ 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. type GridLine struct { IsMinor bool diff --git a/testserver/main.go b/testserver/main.go index 269d596..3918733 100644 --- a/testserver/main.go +++ b/testserver/main.go @@ -46,12 +46,6 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult { Style: chart.Style{ Show: true, }, - GridMajorStyle: chart.Style{ - Show: true, - }, - GridMinorStyle: chart.Style{ - Show: true, - }, }, YAxis: chart.YAxis{ Style: chart.Style{ @@ -64,7 +58,7 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult { }, }, GridMajorStyle: chart.Style{ - Show: true, + Show: false, }, GridMinorStyle: chart.Style{ Show: true, @@ -75,12 +69,16 @@ func chartHandler(rc *web.RequestContext) web.ControllerResult { Name: "a", XValues: s1x, YValues: s1y, + Style: chart.Style{ + Show: true, + FillColor: chart.GetDefaultSeriesStrokeColor(0).WithAlpha(64), + }, }, chart.AnnotationSeries{ Name: fmt.Sprintf("%s - Last Value", "Test"), Style: chart.Style{ Show: true, - StrokeColor: chart.DefaultSeriesStrokeColors[0], + StrokeColor: chart.GetDefaultSeriesStrokeColor(0), }, Annotations: []chart.Annotation{ chart.Annotation{ diff --git a/yaxis.go b/yaxis.go index 2dc9439..4213875 100644 --- a/yaxis.go +++ b/yaxis.go @@ -71,33 +71,7 @@ func (ya YAxis) GetGridLines(ticks []Tick) []GridLine { if len(ya.GridLines) > 0 { return ya.GridLines } - return ya.generateGridLines(ticks) -} - -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 + return GenerateGridLines(ticks, false) } // Measure returns the bounds of the axis.