draw draws the axis along the lower edge of a draw.Canvas.
(c draw.Canvas)
| 254 | |
| 255 | // draw draws the axis along the lower edge of a draw.Canvas. |
| 256 | func (a horizontalAxis) draw(c draw.Canvas) { |
| 257 | var ( |
| 258 | x vg.Length |
| 259 | y = c.Min.Y |
| 260 | ) |
| 261 | switch a.Label.Position { |
| 262 | case draw.PosCenter: |
| 263 | x = c.Center().X |
| 264 | case draw.PosRight: |
| 265 | x = c.Max.X |
| 266 | x -= a.Label.TextStyle.Width(a.Label.Text) / 2 |
| 267 | } |
| 268 | if a.Label.Text != "" { |
| 269 | descent := a.Label.TextStyle.FontExtents().Descent |
| 270 | c.FillText(a.Label.TextStyle, vg.Point{X: x, Y: y + descent}, a.Label.Text) |
| 271 | y += a.Label.TextStyle.Height(a.Label.Text) |
| 272 | y += a.Label.Padding |
| 273 | } |
| 274 | |
| 275 | marks := a.Tick.Marker.Ticks(a.Min, a.Max) |
| 276 | ticklabelheight := tickLabelHeight(a.Tick.Label, marks) |
| 277 | descent := a.Tick.Label.FontExtents().Descent |
| 278 | for _, t := range marks { |
| 279 | x := c.X(a.Norm(t.Value)) |
| 280 | if !c.ContainsX(x) || t.IsMinor() { |
| 281 | continue |
| 282 | } |
| 283 | c.FillText(a.Tick.Label, vg.Point{X: x, Y: y + ticklabelheight + descent}, t.Label) |
| 284 | } |
| 285 | |
| 286 | if len(marks) > 0 { |
| 287 | y += ticklabelheight |
| 288 | } else { |
| 289 | y += a.Width / 2 |
| 290 | } |
| 291 | |
| 292 | if len(marks) > 0 && a.drawTicks() { |
| 293 | len := a.Tick.Length |
| 294 | for _, t := range marks { |
| 295 | x := c.X(a.Norm(t.Value)) |
| 296 | if !c.ContainsX(x) { |
| 297 | continue |
| 298 | } |
| 299 | start := t.lengthOffset(len) |
| 300 | c.StrokeLine2(a.Tick.LineStyle, x, y+start, x, y+len) |
| 301 | } |
| 302 | y += len |
| 303 | } |
| 304 | |
| 305 | c.StrokeLine2(a.LineStyle, c.Min.X, y, c.Max.X, y) |
| 306 | } |
| 307 | |
| 308 | // GlyphBoxes returns the GlyphBoxes for the tick labels. |
| 309 | func (a horizontalAxis) GlyphBoxes(p *Plot) []GlyphBox { |
no test coverage detected