go-chart/examples/text_rotation/main.go

52 lines
972 B
Go
Raw Normal View History

2016-09-01 01:11:52 -04:00
package main
2019-09-10 00:02:48 -04:00
//go:generate go run main.go
2016-09-01 01:11:52 -04:00
import (
2019-09-10 00:02:48 -04:00
"os"
2016-09-01 01:11:52 -04:00
2019-09-10 00:02:48 -04:00
"github.com/wcharczuk/go-chart"
2016-10-21 15:44:37 -04:00
"github.com/wcharczuk/go-chart/drawing"
2016-09-01 01:11:52 -04:00
)
2019-09-10 00:02:48 -04:00
func main() {
2016-10-21 15:44:37 -04:00
f, _ := chart.GetDefaultFont()
r, _ := chart.PNG(1024, 1024)
2016-09-01 01:11:52 -04:00
2016-10-21 15:44:37 -04:00
chart.Draw.Text(r, "Test", 64, 64, chart.Style{
FontColor: drawing.ColorBlack,
FontSize: 18,
Font: f,
})
chart.Draw.Text(r, "Test", 64, 64, chart.Style{
FontColor: drawing.ColorBlack,
FontSize: 18,
Font: f,
TextRotationDegrees: 45.0,
})
tb := chart.Draw.MeasureText(r, "Test", chart.Style{
FontColor: drawing.ColorBlack,
FontSize: 18,
Font: f,
}).Shift(64, 64)
tbc := tb.Corners().Rotate(45)
chart.Draw.BoxCorners(r, tbc, chart.Style{
StrokeColor: drawing.ColorRed,
StrokeWidth: 2,
})
tbcb := tbc.Box()
chart.Draw.Box(r, tbcb, chart.Style{
StrokeColor: drawing.ColorBlue,
StrokeWidth: 2,
})
2016-09-01 01:11:52 -04:00
2019-09-10 00:02:48 -04:00
file, _ := os.Create("output.png")
defer file.Close()
r.Save(file)
2016-09-01 01:11:52 -04:00
}