NewLabels returns a new Labels using the DefaultFont and the DefaultFontSize.
(d XYLabeller)
| 42 | // NewLabels returns a new Labels using the DefaultFont and |
| 43 | // the DefaultFontSize. |
| 44 | func 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. |
| 75 | func (l *Labels) Plot(c draw.Canvas, p *plot.Plot) { |