MCPcopy Index your code
hub / github.com/gonum/plot / GlyphBoxes

Method GlyphBoxes

axis.go:436–484  ·  view source on GitHub ↗

GlyphBoxes returns the GlyphBoxes for the tick labels

(p *Plot)

Source from the content-addressed store, hash-verified

434
435// GlyphBoxes returns the GlyphBoxes for the tick labels
436func (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.

Callers 2

DrawGlyphBoxesMethod · 0.95
padYFunction · 0.95

Calls 10

tickLabelWidthFunction · 0.85
NormMethod · 0.80
PointsMethod · 0.80
HeightMethod · 0.80
FontExtentsMethod · 0.80
IsMinorMethod · 0.80
TicksMethod · 0.65
WidthMethod · 0.45
AddMethod · 0.45
RectangleMethod · 0.45

Tested by

no test coverage detected