GlyphBoxes returns the GlyphBoxes for the tick labels.
(p *Plot)
| 307 | |
| 308 | // GlyphBoxes returns the GlyphBoxes for the tick labels. |
| 309 | func (a horizontalAxis) GlyphBoxes(p *Plot) []GlyphBox { |
| 310 | var ( |
| 311 | boxes []GlyphBox |
| 312 | yoff font.Length |
| 313 | ) |
| 314 | |
| 315 | if a.Label.Text != "" { |
| 316 | x := a.Norm(p.X.Max) |
| 317 | switch a.Label.Position { |
| 318 | case draw.PosCenter: |
| 319 | x = a.Norm(0.5 * (p.X.Max + p.X.Min)) |
| 320 | case draw.PosRight: |
| 321 | x -= a.Norm(0.5 * a.Label.TextStyle.Width(a.Label.Text).Points()) // FIXME(sbinet): want data coordinates |
| 322 | } |
| 323 | descent := a.Label.TextStyle.FontExtents().Descent |
| 324 | boxes = append(boxes, GlyphBox{ |
| 325 | X: x, |
| 326 | Rectangle: a.Label.TextStyle.Rectangle(a.Label.Text).Add(vg.Point{Y: yoff + descent}), |
| 327 | }) |
| 328 | yoff += a.Label.TextStyle.Height(a.Label.Text) |
| 329 | yoff += a.Label.Padding |
| 330 | } |
| 331 | |
| 332 | var ( |
| 333 | marks = a.Tick.Marker.Ticks(a.Min, a.Max) |
| 334 | height = tickLabelHeight(a.Tick.Label, marks) |
| 335 | descent = a.Tick.Label.FontExtents().Descent |
| 336 | ) |
| 337 | for _, t := range marks { |
| 338 | if t.IsMinor() { |
| 339 | continue |
| 340 | } |
| 341 | box := GlyphBox{ |
| 342 | X: a.Norm(t.Value), |
| 343 | Rectangle: a.Tick.Label.Rectangle(t.Label).Add(vg.Point{Y: yoff + height + descent}), |
| 344 | } |
| 345 | boxes = append(boxes, box) |
| 346 | } |
| 347 | return boxes |
| 348 | } |
| 349 | |
| 350 | // A verticalAxis is drawn vertically up the left side of a plot. |
| 351 | type verticalAxis struct { |
no test coverage detected