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

Method draw

axis.go:380–433  ·  view source on GitHub ↗

draw draws the axis along the left side of a draw.Canvas.

(c draw.Canvas)

Source from the content-addressed store, hash-verified

378
379// draw draws the axis along the left side of a draw.Canvas.
380func (a verticalAxis) draw(c draw.Canvas) {
381 var (
382 x = c.Min.X
383 y vg.Length
384 )
385 if a.Label.Text != "" {
386 sty := a.Label.TextStyle
387 sty.Rotation += math.Pi / 2
388 x += a.Label.TextStyle.Height(a.Label.Text)
389 switch a.Label.Position {
390 case draw.PosCenter:
391 y = c.Center().Y
392 case draw.PosTop:
393 y = c.Max.Y
394 y -= a.Label.TextStyle.Width(a.Label.Text) / 2
395 }
396 descent := a.Label.TextStyle.FontExtents().Descent
397 c.FillText(sty, vg.Point{X: x - descent, Y: y}, a.Label.Text)
398 x += descent
399 x += a.Label.Padding
400 }
401 marks := a.Tick.Marker.Ticks(a.Min, a.Max)
402 if w := tickLabelWidth(a.Tick.Label, marks); len(marks) > 0 && w > 0 {
403 x += w
404 }
405
406 major := false
407 descent := a.Tick.Label.FontExtents().Descent
408 for _, t := range marks {
409 y := c.Y(a.Norm(t.Value))
410 if !c.ContainsY(y) || t.IsMinor() {
411 continue
412 }
413 c.FillText(a.Tick.Label, vg.Point{X: x, Y: y + descent}, t.Label)
414 major = true
415 }
416 if major {
417 x += a.Tick.Label.Width(" ")
418 }
419 if a.drawTicks() && len(marks) > 0 {
420 len := a.Tick.Length
421 for _, t := range marks {
422 y := c.Y(a.Norm(t.Value))
423 if !c.ContainsY(y) {
424 continue
425 }
426 start := t.lengthOffset(len)
427 c.StrokeLine2(a.Tick.LineStyle, x+start, y, x+len, y)
428 }
429 x += len
430 }
431
432 c.StrokeLine2(a.LineStyle, x, c.Min.Y, x, c.Max.Y)
433}
434
435// GlyphBoxes returns the GlyphBoxes for the tick labels
436func (a verticalAxis) GlyphBoxes(p *Plot) []GlyphBox {

Callers 1

DrawMethod · 0.95

Calls 14

tickLabelWidthFunction · 0.85
HeightMethod · 0.80
CenterMethod · 0.80
FontExtentsMethod · 0.80
FillTextMethod · 0.80
NormMethod · 0.80
ContainsYMethod · 0.80
IsMinorMethod · 0.80
drawTicksMethod · 0.80
lengthOffsetMethod · 0.80
StrokeLine2Method · 0.80
TicksMethod · 0.65

Tested by

no test coverage detected