Skip to content

Commit

Permalink
plotter: refactor Labels.{X,Y}Offset into a vg.Point
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Jul 1, 2021
1 parent 2a53c6f commit eacbd7b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions plotter/boxplot.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ func (b *BoxPlot) OutsideLabels(labels Labeller) (*Labels, error) {
if err != nil {
return nil, err
}
ls.XOffset += b.GlyphStyle.Radius / 2
ls.YOffset += b.GlyphStyle.Radius / 2
off := 0.5 * b.GlyphStyle.Radius
ls.Offset = ls.Offset.Add(vg.Point{X: off, Y: off})
return ls, nil
}

Expand Down Expand Up @@ -421,8 +421,8 @@ func (b *horizBoxPlot) OutsideLabels(labels Labeller) (*Labels, error) {
if err != nil {
return nil, err
}
ls.XOffset += b.GlyphStyle.Radius / 2
ls.YOffset += b.GlyphStyle.Radius / 2
off := 0.5 * b.GlyphStyle.Radius
ls.Offset = ls.Offset.Add(vg.Point{X: off, Y: off})
return ls, nil
}

Expand Down
8 changes: 3 additions & 5 deletions plotter/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ type Labels struct {
// can have a different text style.
TextStyle []text.Style

// XOffset and YOffset are added directly to the final
// label X and Y location respectively.
XOffset, YOffset vg.Length
// Offset is added directly to the final label location.
Offset vg.Point
}

// NewLabels returns a new Labels using the DefaultFont and
Expand Down Expand Up @@ -80,8 +79,7 @@ func (l *Labels) Plot(c draw.Canvas, p *plot.Plot) {
if !c.Contains(pt) {
continue
}
pt.X += l.XOffset
pt.Y += l.YOffset
pt = pt.Add(l.Offset)
c.FillText(l.TextStyle[i], pt, label)
}
}
Expand Down
8 changes: 4 additions & 4 deletions plotter/quartile.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func (b *QuartPlot) OutsideLabels(labels Labeller) (*Labels, error) {
if err != nil {
return nil, err
}
ls.XOffset += b.MedianStyle.Radius / 2
ls.YOffset += b.MedianStyle.Radius / 2
off := 0.5 * b.MedianStyle.Radius
ls.Offset = ls.Offset.Add(vg.Point{X: off, Y: off})
return ls, nil
}

Expand Down Expand Up @@ -269,8 +269,8 @@ func (b *horizQuartPlot) OutsideLabels(labels Labeller) (*Labels, error) {
if err != nil {
return nil, err
}
ls.XOffset += b.MedianStyle.Radius / 2
ls.YOffset += b.MedianStyle.Radius / 2
off := 0.5 * b.MedianStyle.Radius
ls.Offset = ls.Offset.Add(vg.Point{X: off, Y: off})
return ls, nil
}

Expand Down

0 comments on commit eacbd7b

Please sign in to comment.