diff --git a/grid_line.go b/grid_line.go index c906314..d7d7781 100644 --- a/grid_line.go +++ b/grid_line.go @@ -34,15 +34,16 @@ func (gl GridLine) Horizontal() bool { } // Render renders the gridline -func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) { +func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, 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 { lineLeft := canvasBox.Left + ra.Translate(gl.Value) lineBottom := canvasBox.Bottom lineTop := canvasBox.Top - r.SetStrokeColor(gl.Style.GetStrokeColor(DefaultAxisColor)) - r.SetStrokeWidth(gl.Style.GetStrokeWidth(DefaultAxisLineWidth)) - r.MoveTo(lineLeft, lineBottom) r.LineTo(lineLeft, lineTop) r.Stroke() @@ -51,9 +52,6 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) { lineRight := canvasBox.Right lineHeight := canvasBox.Bottom - ra.Translate(gl.Value) - r.SetStrokeColor(gl.Style.GetStrokeColor(DefaultAxisColor)) - r.SetStrokeWidth(gl.Style.GetStrokeWidth(DefaultAxisLineWidth)) - r.MoveTo(lineLeft, lineHeight) r.LineTo(lineRight, lineHeight) r.Stroke() @@ -61,17 +59,9 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range) { } // GenerateGridLines generates grid lines. -func GenerateGridLines(ticks []Tick, isVertical bool) []GridLine { +func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, 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 { diff --git a/xaxis.go b/xaxis.go index a14a42f..bf8522c 100644 --- a/xaxis.go +++ b/xaxis.go @@ -46,7 +46,7 @@ func (xa XAxis) GetGridLines(ticks []Tick) []GridLine { if len(xa.GridLines) > 0 { return xa.GridLines } - return GenerateGridLines(ticks, true) + return GenerateGridLines(ticks, xa.GridMajorStyle, xa.GridMinorStyle, true) } // Measure returns the bounds of the axis. @@ -102,9 +102,12 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick if xa.GridMajorStyle.Show || xa.GridMinorStyle.Show { for _, gl := range xa.GetGridLines(ticks) { - if (gl.IsMinor && xa.GridMinorStyle.Show) || - (!gl.IsMinor && xa.GridMajorStyle.Show) { - gl.Render(r, canvasBox, ra) + if (gl.IsMinor && xa.GridMinorStyle.Show) || (!gl.IsMinor && xa.GridMajorStyle.Show) { + defaults := xa.GridMajorStyle + if gl.IsMinor { + defaults = xa.GridMinorStyle + } + gl.Render(r, canvasBox, ra, defaults) } } } diff --git a/yaxis.go b/yaxis.go index cb84147..afad3ce 100644 --- a/yaxis.go +++ b/yaxis.go @@ -53,7 +53,7 @@ func (ya YAxis) GetGridLines(ticks []Tick) []GridLine { if len(ya.GridLines) > 0 { return ya.GridLines } - return GenerateGridLines(ticks, false) + return GenerateGridLines(ticks, ya.GridMajorStyle, ya.GridMinorStyle, false) } // Measure returns the bounds of the axis. @@ -145,14 +145,17 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick } if ya.Zero.Style.Show { - ya.Zero.Render(r, canvasBox, ra) + ya.Zero.Render(r, canvasBox, ra, Style{}) } if ya.GridMajorStyle.Show || ya.GridMinorStyle.Show { for _, gl := range ya.GetGridLines(ticks) { - if (gl.IsMinor && ya.GridMinorStyle.Show) || - (!gl.IsMinor && ya.GridMajorStyle.Show) { - gl.Render(r, canvasBox, ra) + if (gl.IsMinor && ya.GridMinorStyle.Show) || (!gl.IsMinor && ya.GridMajorStyle.Show) { + defaults := ya.GridMajorStyle + if gl.IsMinor { + defaults = ya.GridMinorStyle + } + gl.Render(r, canvasBox, ra, defaults) } } }