Skip to content

Commit

Permalink
all: use text.TextStyle in lieu of draw.TextStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Jan 29, 2021
1 parent b87959d commit ecd5c17
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
13 changes: 7 additions & 6 deletions axis.go
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"time"

"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ type Axis struct {
// For the vertical axis, one quarter turn
// counterclockwise will be added to the label
// text before drawing.
draw.TextStyle
text.TextStyle

// Position is where the axis label string should be drawn.
// The default value is draw.PosCenter, displaying the label
Expand All @@ -66,7 +67,7 @@ type Axis struct {

Tick struct {
// Label is the TextStyle on the tick labels.
Label draw.TextStyle
Label text.TextStyle

// LineStyle is the LineStyle of the tick lines.
draw.LineStyle
Expand Down Expand Up @@ -113,7 +114,7 @@ func makeAxis(o orientation) (Axis, error) {
Padding: vg.Points(5),
Scale: LinearScale{},
}
a.Label.TextStyle = draw.TextStyle{
a.Label.TextStyle = text.TextStyle{
Color: color.Black,
Font: labelFont,
XAlign: draw.XCenter,
Expand All @@ -135,7 +136,7 @@ func makeAxis(o orientation) (Axis, error) {
yalign = draw.YTop
}

a.Tick.Label = draw.TextStyle{
a.Tick.Label = text.TextStyle{
Color: color.Black,
Font: tickFont,
XAlign: xalign,
Expand Down Expand Up @@ -632,7 +633,7 @@ func (t Tick) lengthOffset(len vg.Length) vg.Length {
}

// tickLabelHeight returns height of the tick mark labels.
func tickLabelHeight(sty draw.TextStyle, ticks []Tick) vg.Length {
func tickLabelHeight(sty text.TextStyle, ticks []Tick) vg.Length {
maxHeight := vg.Length(0)
for _, t := range ticks {
if t.IsMinor() {
Expand All @@ -648,7 +649,7 @@ func tickLabelHeight(sty draw.TextStyle, ticks []Tick) vg.Length {
}

// tickLabelWidth returns the width of the widest tick mark label.
func tickLabelWidth(sty draw.TextStyle, ticks []Tick) vg.Length {
func tickLabelWidth(sty text.TextStyle, ticks []Tick) vg.Length {
maxWidth := vg.Length(0)
for _, t := range ticks {
if t.IsMinor() {
Expand Down
5 changes: 3 additions & 2 deletions legend.go
Expand Up @@ -7,6 +7,7 @@ package plot
import (
"math"

"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)
Expand All @@ -18,7 +19,7 @@ import (
type Legend struct {
// TextStyle is the style given to the legend
// entry texts.
draw.TextStyle
text.TextStyle

// Padding is the amount of padding to add
// between each entry in the legend. If Padding
Expand Down Expand Up @@ -84,7 +85,7 @@ func NewLegend() (Legend, error) {
return Legend{
YPosition: draw.PosBottom,
ThumbnailWidth: vg.Points(20),
TextStyle: draw.TextStyle{
TextStyle: text.TextStyle{
Font: font,
Handler: DefaultTextHandler,
},
Expand Down
4 changes: 2 additions & 2 deletions plot.go
Expand Up @@ -38,7 +38,7 @@ type Plot struct {
// the top of the plot.
Padding vg.Length

draw.TextStyle
text.TextStyle
}

// BackgroundColor is the background color of the plot.
Expand Down Expand Up @@ -106,7 +106,7 @@ func New() (*Plot, error) {
Y: y,
Legend: legend,
}
p.Title.TextStyle = draw.TextStyle{
p.Title.TextStyle = text.TextStyle{
Color: color.Black,
Font: titleFont,
XAlign: draw.XCenter,
Expand Down
3 changes: 2 additions & 1 deletion plot_test.go
Expand Up @@ -16,6 +16,7 @@ import (
"gonum.org/v1/plot"
"gonum.org/v1/plot/cmpimg"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
"gonum.org/v1/plot/vg/recorder"
Expand All @@ -29,7 +30,7 @@ func TestLegendAlignment(t *testing.T) {
}
l := plot.Legend{
ThumbnailWidth: vg.Points(20),
TextStyle: draw.TextStyle{
TextStyle: text.TextStyle{
Font: font,
Handler: plot.DefaultTextHandler,
},
Expand Down
7 changes: 4 additions & 3 deletions plotter/labels.go
Expand Up @@ -8,6 +8,7 @@ import (
"errors"

"gonum.org/v1/plot"
"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)
Expand All @@ -31,7 +32,7 @@ type Labels struct {

// TextStyle is the style of the label text. Each label
// can have a different text style.
TextStyle []draw.TextStyle
TextStyle []text.TextStyle

// XOffset and YOffset are added directly to the final
// label X and Y location respectively.
Expand Down Expand Up @@ -60,9 +61,9 @@ func NewLabels(d XYLabeller) (*Labels, error) {
return nil, err
}

styles := make([]draw.TextStyle, d.Len())
styles := make([]text.TextStyle, d.Len())
for i := range styles {
styles[i] = draw.TextStyle{
styles[i] = text.TextStyle{
Font: fnt,
Handler: plot.DefaultTextHandler,
}
Expand Down
9 changes: 5 additions & 4 deletions plotter/sankey.go
Expand Up @@ -11,6 +11,7 @@ import (
"sort"

"gonum.org/v1/plot"
"gonum.org/v1/plot/text"
"gonum.org/v1/plot/tools/bezier"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
Expand Down Expand Up @@ -40,7 +41,7 @@ type Sankey struct {
// TextStyle specifies the default stock label
// text style. Styles can be modified for
// individual stocks.
TextStyle draw.TextStyle
TextStyle text.TextStyle

flows []Flow

Expand All @@ -60,7 +61,7 @@ type Sankey struct {
// The default function uses the default TextStyle, color and LineStyle
// specified above for all stocks; zero horizontal and vertical offsets;
// and the stock label as the text to be printed on the plot.
StockStyle func(label string, category int) (lbl string, ts draw.TextStyle, xOff, yOff vg.Length, c color.Color, ls draw.LineStyle)
StockStyle func(label string, category int) (lbl string, ts text.TextStyle, xOff, yOff vg.Length, c color.Color, ls draw.LineStyle)

// stocks arranges the stocks by category.
// The first key is the category and the seond
Expand Down Expand Up @@ -178,7 +179,7 @@ func NewSankey(flows ...Flow) (*Sankey, error) {
if err != nil {
return nil, err
}
s.TextStyle = draw.TextStyle{
s.TextStyle = text.TextStyle{
Font: fnt,
Rotation: math.Pi / 2,
XAlign: draw.XCenter,
Expand All @@ -191,7 +192,7 @@ func NewSankey(flows ...Flow) (*Sankey, error) {
return s.Color, s.LineStyle
}

s.StockStyle = func(label string, category int) (string, draw.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
s.StockStyle = func(label string, category int) (string, text.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
return label, s.TextStyle, 0, 0, s.Color, s.LineStyle
}

Expand Down
3 changes: 2 additions & 1 deletion plotter/sankey_example_test.go
Expand Up @@ -12,6 +12,7 @@ import (

"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
"gonum.org/v1/plot/vg/vgimg"
Expand Down Expand Up @@ -351,7 +352,7 @@ func ExampleSankey_grouped() {

// Here we set the StockStyle function to give an example of
// setting a custom style for one of the stocks.
sankey.StockStyle = func(label string, category int) (string, draw.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
sankey.StockStyle = func(label string, category int) (string, text.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
if label == "Small" && category == treeType {
// Here we demonstrate how to rotate the label text
// and change the style of the stock bar.
Expand Down
3 changes: 1 addition & 2 deletions text/latex_test.go
Expand Up @@ -9,7 +9,6 @@ import (

"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)

func TestLatexText(t *testing.T) {
Expand Down Expand Up @@ -111,7 +110,7 @@ func TestLatexText(t *testing.T) {
fnt = tr12
}

sty := draw.TextStyle{
sty := text.TextStyle{
Font: fnt,
Handler: text.Latex{},
}
Expand Down
3 changes: 1 addition & 2 deletions text/plain_test.go
Expand Up @@ -9,7 +9,6 @@ import (

"gonum.org/v1/plot/text"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)

func TestPlainText(t *testing.T) {
Expand Down Expand Up @@ -148,7 +147,7 @@ func TestPlainText(t *testing.T) {
fnt = tr12
}

sty := draw.TextStyle{
sty := text.TextStyle{
Font: fnt,
Handler: text.Plain{},
}
Expand Down

0 comments on commit ecd5c17

Please sign in to comment.