Skip to content

Commit

Permalink
add XYLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Oct 8, 2015
1 parent ca0e8e5 commit 95350d6
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions plotter/labels.go
Expand Up @@ -48,10 +48,7 @@ type Labels struct {

// NewLabels returns a new Labels using the DefaultFont and
// the DefaultFontSize.
func NewLabels(d interface {
XYer
Labeller
}) (*Labels, error) {
func NewLabels(d XYLabeller) (*Labels, error) {
xys, err := CopyXYs(d)
if err != nil {
return nil, err
Expand Down Expand Up @@ -84,7 +81,7 @@ func (l *Labels) Plot(c draw.Canvas, p *plot.Plot) {
for i, label := range l.Labels {
x := trX(l.XYs[i].X)
y := trY(l.XYs[i].Y)
if !c.Contains(draw.Point{x, y}) {
if !c.Contains(draw.Point{X: x, Y: y}) {
continue
}
x += l.XOffset
Expand Down Expand Up @@ -115,3 +112,21 @@ func (l *Labels) GlyphBoxes(p *plot.Plot) []plot.GlyphBox {
}
return bs
}

// XYLabeller combines the XYer and Labeller types.
type XYLabeller interface {
XYer
Labeller
}

// XYLabels holds XY data with labels.
// The ith label corresponds to the ith XY.
type XYLabels struct {
XYs
Labels []string
}

// Label returns the label for point index i.
func (l XYLabels) Label(i int) string {
return l.Labels[i]
}

0 comments on commit 95350d6

Please sign in to comment.