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

Method Draw

text/plain.go:55–86  ·  view source on GitHub ↗

Draw renders the given text with the provided style and position on the canvas.

(c vg.Canvas, txt string, sty Style, pt vg.Point)

Source from the content-addressed store, hash-verified

53// Draw renders the given text with the provided style and position
54// on the canvas.
55func (hdlr Plain) Draw(c vg.Canvas, txt string, sty Style, pt vg.Point) {
56 txt = strings.TrimRight(txt, "\n")
57 if len(txt) == 0 {
58 return
59 }
60
61 fnt := hdlr.Fonts.Lookup(sty.Font, sty.Font.Size)
62 c.SetColor(sty.Color)
63
64 if sty.Rotation != 0 {
65 c.Push()
66 c.Rotate(sty.Rotation)
67 }
68
69 sin64, cos64 := math.Sincos(sty.Rotation)
70 cos := vg.Length(cos64)
71 sin := vg.Length(sin64)
72 pt.X, pt.Y = pt.Y*sin+pt.X*cos, pt.Y*cos-pt.X*sin
73
74 lines := hdlr.Lines(txt)
75 ht := sty.Height(txt)
76 pt.Y += ht*vg.Length(sty.YAlign) - fnt.Extents().Ascent
77 for i, line := range lines {
78 xoffs := vg.Length(sty.XAlign) * fnt.Width(line)
79 n := vg.Length(len(lines) - i)
80 c.FillString(fnt, pt.Add(vg.Point{X: xoffs, Y: n * sty.Font.Size}), line)
81 }
82
83 if sty.Rotation != 0 {
84 c.Pop()
85 }
86}

Callers

nothing calls this directly

Calls 11

LinesMethod · 0.95
LookupMethod · 0.80
HeightMethod · 0.80
SetColorMethod · 0.65
PushMethod · 0.65
RotateMethod · 0.65
ExtentsMethod · 0.65
FillStringMethod · 0.65
PopMethod · 0.65
WidthMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected