Skip to content

Commit ecd5c17

Browse files
committed
all: use text.TextStyle in lieu of draw.TextStyle
1 parent b87959d commit ecd5c17

9 files changed

Lines changed: 27 additions & 23 deletions

File tree

axis.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strconv"
1111
"time"
1212

13+
"gonum.org/v1/plot/text"
1314
"gonum.org/v1/plot/vg"
1415
"gonum.org/v1/plot/vg/draw"
1516
)
@@ -46,7 +47,7 @@ type Axis struct {
4647
// For the vertical axis, one quarter turn
4748
// counterclockwise will be added to the label
4849
// text before drawing.
49-
draw.TextStyle
50+
text.TextStyle
5051

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

6768
Tick struct {
6869
// Label is the TextStyle on the tick labels.
69-
Label draw.TextStyle
70+
Label text.TextStyle
7071

7172
// LineStyle is the LineStyle of the tick lines.
7273
draw.LineStyle
@@ -113,7 +114,7 @@ func makeAxis(o orientation) (Axis, error) {
113114
Padding: vg.Points(5),
114115
Scale: LinearScale{},
115116
}
116-
a.Label.TextStyle = draw.TextStyle{
117+
a.Label.TextStyle = text.TextStyle{
117118
Color: color.Black,
118119
Font: labelFont,
119120
XAlign: draw.XCenter,
@@ -135,7 +136,7 @@ func makeAxis(o orientation) (Axis, error) {
135136
yalign = draw.YTop
136137
}
137138

138-
a.Tick.Label = draw.TextStyle{
139+
a.Tick.Label = text.TextStyle{
139140
Color: color.Black,
140141
Font: tickFont,
141142
XAlign: xalign,
@@ -632,7 +633,7 @@ func (t Tick) lengthOffset(len vg.Length) vg.Length {
632633
}
633634

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

650651
// tickLabelWidth returns the width of the widest tick mark label.
651-
func tickLabelWidth(sty draw.TextStyle, ticks []Tick) vg.Length {
652+
func tickLabelWidth(sty text.TextStyle, ticks []Tick) vg.Length {
652653
maxWidth := vg.Length(0)
653654
for _, t := range ticks {
654655
if t.IsMinor() {

legend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package plot
77
import (
88
"math"
99

10+
"gonum.org/v1/plot/text"
1011
"gonum.org/v1/plot/vg"
1112
"gonum.org/v1/plot/vg/draw"
1213
)
@@ -18,7 +19,7 @@ import (
1819
type Legend struct {
1920
// TextStyle is the style given to the legend
2021
// entry texts.
21-
draw.TextStyle
22+
text.TextStyle
2223

2324
// Padding is the amount of padding to add
2425
// between each entry in the legend. If Padding
@@ -84,7 +85,7 @@ func NewLegend() (Legend, error) {
8485
return Legend{
8586
YPosition: draw.PosBottom,
8687
ThumbnailWidth: vg.Points(20),
87-
TextStyle: draw.TextStyle{
88+
TextStyle: text.TextStyle{
8889
Font: font,
8990
Handler: DefaultTextHandler,
9091
},

plot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Plot struct {
3838
// the top of the plot.
3939
Padding vg.Length
4040

41-
draw.TextStyle
41+
text.TextStyle
4242
}
4343

4444
// BackgroundColor is the background color of the plot.
@@ -106,7 +106,7 @@ func New() (*Plot, error) {
106106
Y: y,
107107
Legend: legend,
108108
}
109-
p.Title.TextStyle = draw.TextStyle{
109+
p.Title.TextStyle = text.TextStyle{
110110
Color: color.Black,
111111
Font: titleFont,
112112
XAlign: draw.XCenter,

plot_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"gonum.org/v1/plot"
1717
"gonum.org/v1/plot/cmpimg"
1818
"gonum.org/v1/plot/plotter"
19+
"gonum.org/v1/plot/text"
1920
"gonum.org/v1/plot/vg"
2021
"gonum.org/v1/plot/vg/draw"
2122
"gonum.org/v1/plot/vg/recorder"
@@ -29,7 +30,7 @@ func TestLegendAlignment(t *testing.T) {
2930
}
3031
l := plot.Legend{
3132
ThumbnailWidth: vg.Points(20),
32-
TextStyle: draw.TextStyle{
33+
TextStyle: text.TextStyle{
3334
Font: font,
3435
Handler: plot.DefaultTextHandler,
3536
},

plotter/labels.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99

1010
"gonum.org/v1/plot"
11+
"gonum.org/v1/plot/text"
1112
"gonum.org/v1/plot/vg"
1213
"gonum.org/v1/plot/vg/draw"
1314
)
@@ -31,7 +32,7 @@ type Labels struct {
3132

3233
// TextStyle is the style of the label text. Each label
3334
// can have a different text style.
34-
TextStyle []draw.TextStyle
35+
TextStyle []text.TextStyle
3536

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

63-
styles := make([]draw.TextStyle, d.Len())
64+
styles := make([]text.TextStyle, d.Len())
6465
for i := range styles {
65-
styles[i] = draw.TextStyle{
66+
styles[i] = text.TextStyle{
6667
Font: fnt,
6768
Handler: plot.DefaultTextHandler,
6869
}

plotter/sankey.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212

1313
"gonum.org/v1/plot"
14+
"gonum.org/v1/plot/text"
1415
"gonum.org/v1/plot/tools/bezier"
1516
"gonum.org/v1/plot/vg"
1617
"gonum.org/v1/plot/vg/draw"
@@ -40,7 +41,7 @@ type Sankey struct {
4041
// TextStyle specifies the default stock label
4142
// text style. Styles can be modified for
4243
// individual stocks.
43-
TextStyle draw.TextStyle
44+
TextStyle text.TextStyle
4445

4546
flows []Flow
4647

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

6566
// stocks arranges the stocks by category.
6667
// The first key is the category and the seond
@@ -178,7 +179,7 @@ func NewSankey(flows ...Flow) (*Sankey, error) {
178179
if err != nil {
179180
return nil, err
180181
}
181-
s.TextStyle = draw.TextStyle{
182+
s.TextStyle = text.TextStyle{
182183
Font: fnt,
183184
Rotation: math.Pi / 2,
184185
XAlign: draw.XCenter,
@@ -191,7 +192,7 @@ func NewSankey(flows ...Flow) (*Sankey, error) {
191192
return s.Color, s.LineStyle
192193
}
193194

194-
s.StockStyle = func(label string, category int) (string, draw.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
195+
s.StockStyle = func(label string, category int) (string, text.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
195196
return label, s.TextStyle, 0, 0, s.Color, s.LineStyle
196197
}
197198

plotter/sankey_example_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"gonum.org/v1/plot"
1414
"gonum.org/v1/plot/plotter"
15+
"gonum.org/v1/plot/text"
1516
"gonum.org/v1/plot/vg"
1617
"gonum.org/v1/plot/vg/draw"
1718
"gonum.org/v1/plot/vg/vgimg"
@@ -351,7 +352,7 @@ func ExampleSankey_grouped() {
351352

352353
// Here we set the StockStyle function to give an example of
353354
// setting a custom style for one of the stocks.
354-
sankey.StockStyle = func(label string, category int) (string, draw.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
355+
sankey.StockStyle = func(label string, category int) (string, text.TextStyle, vg.Length, vg.Length, color.Color, draw.LineStyle) {
355356
if label == "Small" && category == treeType {
356357
// Here we demonstrate how to rotate the label text
357358
// and change the style of the stock bar.

text/latex_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"gonum.org/v1/plot/text"
1111
"gonum.org/v1/plot/vg"
12-
"gonum.org/v1/plot/vg/draw"
1312
)
1413

1514
func TestLatexText(t *testing.T) {
@@ -111,7 +110,7 @@ func TestLatexText(t *testing.T) {
111110
fnt = tr12
112111
}
113112

114-
sty := draw.TextStyle{
113+
sty := text.TextStyle{
115114
Font: fnt,
116115
Handler: text.Latex{},
117116
}

text/plain_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"gonum.org/v1/plot/text"
1111
"gonum.org/v1/plot/vg"
12-
"gonum.org/v1/plot/vg/draw"
1312
)
1413

1514
func TestPlainText(t *testing.T) {
@@ -148,7 +147,7 @@ func TestPlainText(t *testing.T) {
148147
fnt = tr12
149148
}
150149

151-
sty := draw.TextStyle{
150+
sty := text.TextStyle{
152151
Font: fnt,
153152
Handler: text.Plain{},
154153
}

0 commit comments

Comments
 (0)