GlyphBoxes returns the GlyphBoxes for the tick labels
(p *Plot)
| 434 | |
| 435 | // GlyphBoxes returns the GlyphBoxes for the tick labels |
| 436 | func (a verticalAxis) GlyphBoxes(p *Plot) []GlyphBox { |
| 437 | var ( |
| 438 | boxes []GlyphBox |
| 439 | xoff font.Length |
| 440 | ) |
| 441 | |
| 442 | if a.Label.Text != "" { |
| 443 | yoff := a.Norm(p.Y.Max) |
| 444 | switch a.Label.Position { |
| 445 | case draw.PosCenter: |
| 446 | yoff = a.Norm(0.5 * (p.Y.Max + p.Y.Min)) |
| 447 | case draw.PosTop: |
| 448 | yoff -= a.Norm(0.5 * a.Label.TextStyle.Width(a.Label.Text).Points()) // FIXME(sbinet): want data coordinates |
| 449 | } |
| 450 | |
| 451 | sty := a.Label.TextStyle |
| 452 | sty.Rotation += math.Pi / 2 |
| 453 | |
| 454 | xoff += a.Label.TextStyle.Height(a.Label.Text) |
| 455 | descent := a.Label.TextStyle.FontExtents().Descent |
| 456 | boxes = append(boxes, GlyphBox{ |
| 457 | Y: yoff, |
| 458 | Rectangle: sty.Rectangle(a.Label.Text).Add(vg.Point{X: xoff - descent}), |
| 459 | }) |
| 460 | xoff += descent |
| 461 | xoff += a.Label.Padding |
| 462 | } |
| 463 | |
| 464 | marks := a.Tick.Marker.Ticks(a.Min, a.Max) |
| 465 | if w := tickLabelWidth(a.Tick.Label, marks); len(marks) != 0 && w > 0 { |
| 466 | xoff += w |
| 467 | } |
| 468 | |
| 469 | var ( |
| 470 | ext = a.Tick.Label.FontExtents() |
| 471 | desc = ext.Height - ext.Ascent // descent + linegap |
| 472 | ) |
| 473 | for _, t := range marks { |
| 474 | if t.IsMinor() { |
| 475 | continue |
| 476 | } |
| 477 | box := GlyphBox{ |
| 478 | Y: a.Norm(t.Value), |
| 479 | Rectangle: a.Tick.Label.Rectangle(t.Label).Add(vg.Point{X: xoff, Y: desc}), |
| 480 | } |
| 481 | boxes = append(boxes, box) |
| 482 | } |
| 483 | return boxes |
| 484 | } |
| 485 | |
| 486 | // DefaultTicks is suitable for the Tick.Marker field of an Axis, |
| 487 | // it returns a reasonable default set of tick marks. |
no test coverage detected