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

Function NewLabels

plotter/labels.go:44–72  ·  view source on GitHub ↗

NewLabels returns a new Labels using the DefaultFont and the DefaultFontSize.

(d XYLabeller)

Source from the content-addressed store, hash-verified

42// NewLabels returns a new Labels using the DefaultFont and
43// the DefaultFontSize.
44func NewLabels(d XYLabeller) (*Labels, error) {
45 xys, err := CopyXYs(d)
46 if err != nil {
47 return nil, err
48 }
49
50 if d.Len() != len(xys) {
51 return nil, errors.New("plotter: number of points does not match the number of labels")
52 }
53
54 strs := make([]string, d.Len())
55 for i := range strs {
56 strs[i] = d.Label(i)
57 }
58
59 styles := make([]text.Style, d.Len())
60 for i := range styles {
61 styles[i] = text.Style{
62 Font: font.From(DefaultFont, DefaultFontSize),
63 Handler: plot.DefaultTextHandler,
64 }
65 }
66
67 return &Labels{
68 XYs: xys,
69 Labels: strs,
70 TextStyle: styles,
71 }, nil
72}
73
74// Plot implements the Plotter interface, drawing labels.
75func (l *Labels) Plot(c draw.Canvas, p *plot.Plot) {

Callers 11

TestDrawGlyphBoxesFunction · 0.92
ExampleLabelsFunction · 0.92
Example_rotationFunction · 0.92
TestLabelsWithGlyphBoxesFunction · 0.92
Example_addFontFunction · 0.92
ExampleLatexFunction · 0.92
OutsideLabelsMethod · 0.85
OutsideLabelsMethod · 0.85
OutsideLabelsMethod · 0.85
OutsideLabelsMethod · 0.85

Calls 4

FromFunction · 0.92
CopyXYsFunction · 0.85
LenMethod · 0.65
LabelMethod · 0.65

Tested by 7

TestDrawGlyphBoxesFunction · 0.74
ExampleLabelsFunction · 0.74
Example_rotationFunction · 0.74
TestLabelsWithGlyphBoxesFunction · 0.74
Example_addFontFunction · 0.74
ExampleLatexFunction · 0.74