2016-07-06 21:54:00 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
2016-07-07 23:26:07 -04:00
|
|
|
"errors"
|
2016-07-06 21:54:00 -04:00
|
|
|
"io"
|
2016-07-07 20:14:25 -04:00
|
|
|
"math"
|
2016-07-06 21:54:00 -04:00
|
|
|
|
|
|
|
"github.com/golang/freetype/truetype"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Chart is what we're drawing.
|
|
|
|
type Chart struct {
|
2016-07-07 17:44:03 -04:00
|
|
|
Title string
|
|
|
|
TitleStyle Style
|
2016-07-06 21:54:00 -04:00
|
|
|
|
2016-07-07 20:14:25 -04:00
|
|
|
Width int
|
|
|
|
Height int
|
2016-07-06 21:54:00 -04:00
|
|
|
|
2016-07-07 17:44:03 -04:00
|
|
|
Background Style
|
|
|
|
Canvas Style
|
|
|
|
Axes Style
|
|
|
|
FinalValueLabel Style
|
2016-07-06 21:54:00 -04:00
|
|
|
|
2016-07-07 17:44:03 -04:00
|
|
|
XRange Range
|
|
|
|
YRange Range
|
2016-07-06 21:54:00 -04:00
|
|
|
|
2016-07-07 17:44:03 -04:00
|
|
|
Font *truetype.Font
|
2016-07-06 21:54:00 -04:00
|
|
|
Series []Series
|
|
|
|
}
|
|
|
|
|
2016-07-07 17:44:03 -04:00
|
|
|
// GetFont returns the text font.
|
|
|
|
func (c Chart) GetFont() (*truetype.Font, error) {
|
2016-07-06 21:54:00 -04:00
|
|
|
if c.Font != nil {
|
|
|
|
return c.Font, nil
|
|
|
|
}
|
|
|
|
return GetDefaultFont()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render renders the chart with the given renderer to the given io.Writer.
|
2016-07-07 17:44:03 -04:00
|
|
|
func (c *Chart) Render(provider RendererProvider, w io.Writer) error {
|
2016-07-07 23:26:07 -04:00
|
|
|
if len(c.Series) == 0 {
|
|
|
|
return errors.New("Please provide at least one series")
|
|
|
|
}
|
2016-07-07 22:11:30 -04:00
|
|
|
r := provider(c.Width, c.Height)
|
|
|
|
if c.hasText() {
|
|
|
|
font, err := c.GetFont()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
r.SetFont(font)
|
2016-07-07 20:14:25 -04:00
|
|
|
}
|
2016-07-07 17:44:03 -04:00
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
canvasBox := c.calculateCanvasBox(r)
|
|
|
|
xrange, yrange := c.initRanges(canvasBox)
|
|
|
|
|
2016-07-06 21:54:00 -04:00
|
|
|
c.drawBackground(r)
|
2016-07-07 22:11:30 -04:00
|
|
|
c.drawCanvas(r, canvasBox)
|
|
|
|
c.drawAxes(r, canvasBox, xrange, yrange)
|
2016-07-07 20:50:16 -04:00
|
|
|
for index, series := range c.Series {
|
2016-07-07 22:11:30 -04:00
|
|
|
c.drawSeries(r, canvasBox, index, series, xrange, yrange)
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
2016-07-07 20:14:25 -04:00
|
|
|
c.drawTitle(r)
|
2016-07-06 21:54:00 -04:00
|
|
|
return r.Save(w)
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
func (c Chart) hasText() bool {
|
2016-07-07 23:26:07 -04:00
|
|
|
return c.TitleStyle.Show || c.Axes.Show || c.FinalValueLabel.Show
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Chart) getAxisWidth() int {
|
|
|
|
asw := 0
|
|
|
|
if c.Axes.Show {
|
|
|
|
asw = int(c.Axes.GetStrokeWidth(DefaultAxisLineWidth))
|
|
|
|
}
|
|
|
|
return asw
|
2016-07-07 22:11:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Chart) calculateCanvasBox(r Renderer) Box {
|
|
|
|
dpr := DefaultBackgroundPadding.Right
|
|
|
|
finalLabelWidth := c.calculateFinalLabelWidth(r)
|
|
|
|
if finalLabelWidth > dpr {
|
|
|
|
dpr = finalLabelWidth
|
|
|
|
}
|
2016-07-07 23:26:07 -04:00
|
|
|
axisBottomHeight := c.calculateBottomLabelHeight()
|
2016-07-07 22:11:30 -04:00
|
|
|
dpb := DefaultBackgroundPadding.Bottom
|
2016-07-07 23:26:07 -04:00
|
|
|
if dpb < axisBottomHeight {
|
|
|
|
dpb = axisBottomHeight
|
|
|
|
}
|
2016-07-07 22:11:30 -04:00
|
|
|
|
|
|
|
cb := Box{
|
|
|
|
Top: c.Background.Padding.GetTop(DefaultBackgroundPadding.Top),
|
|
|
|
Left: c.Background.Padding.GetLeft(DefaultBackgroundPadding.Left),
|
|
|
|
Right: c.Width - c.Background.Padding.GetRight(dpr),
|
|
|
|
Bottom: c.Height - c.Background.Padding.GetBottom(dpb),
|
|
|
|
}
|
|
|
|
cb.Height = cb.Bottom - cb.Top
|
|
|
|
cb.Width = cb.Right - cb.Left
|
|
|
|
return cb
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Chart) calculateFinalLabelWidth(r Renderer) int {
|
|
|
|
if !c.FinalValueLabel.Show {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
var finalLabelText string
|
|
|
|
for _, s := range c.Series {
|
2016-07-07 23:26:07 -04:00
|
|
|
_, lv := s.GetValue(s.Len() - 1)
|
|
|
|
ll := s.GetYFormatter()(lv)
|
2016-07-07 22:11:30 -04:00
|
|
|
if len(finalLabelText) < len(ll) {
|
|
|
|
finalLabelText = ll
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r.SetFontSize(c.FinalValueLabel.GetFontSize(DefaultFinalLabelFontSize))
|
|
|
|
textWidth := r.MeasureText(finalLabelText)
|
2016-07-07 23:26:07 -04:00
|
|
|
asw := c.getAxisWidth()
|
2016-07-07 22:11:30 -04:00
|
|
|
|
|
|
|
pl := c.FinalValueLabel.Padding.GetLeft(DefaultFinalLabelPadding.Left)
|
|
|
|
pr := c.FinalValueLabel.Padding.GetRight(DefaultFinalLabelPadding.Right)
|
|
|
|
lsw := int(c.FinalValueLabel.GetStrokeWidth(DefaultAxisLineWidth))
|
|
|
|
|
|
|
|
return DefaultFinalLabelDeltaWidth +
|
|
|
|
pl + pr +
|
|
|
|
textWidth + asw + 2*lsw
|
|
|
|
}
|
|
|
|
|
2016-07-07 23:26:07 -04:00
|
|
|
func (c Chart) calculateBottomLabelHeight() int {
|
|
|
|
if c.Axes.Show {
|
|
|
|
return c.getAxisWidth() + int(math.Ceil(c.Axes.GetFontSize(DefaultAxisFontSize))) + DefaultXAxisMargin
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
func (c Chart) initRanges(canvasBox Box) (xrange Range, yrange Range) {
|
2016-07-07 17:44:03 -04:00
|
|
|
//iterate over each series, pull out the min/max for x,y
|
|
|
|
var didSetFirstValues bool
|
|
|
|
var globalMinY, globalMinX float64
|
|
|
|
var globalMaxY, globalMaxX float64
|
|
|
|
for _, s := range c.Series {
|
|
|
|
seriesLength := s.Len()
|
|
|
|
for index := 0; index < seriesLength; index++ {
|
|
|
|
vx, vy := s.GetValue(index)
|
|
|
|
if didSetFirstValues {
|
|
|
|
if globalMinX > vx {
|
|
|
|
globalMinX = vx
|
|
|
|
}
|
|
|
|
if globalMinY > vy {
|
|
|
|
globalMinY = vy
|
|
|
|
}
|
|
|
|
if globalMaxX < vx {
|
|
|
|
globalMaxX = vx
|
|
|
|
}
|
|
|
|
if globalMaxY < vy {
|
|
|
|
globalMaxY = vy
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
globalMinX, globalMaxX = vx, vx
|
|
|
|
globalMinY, globalMaxY = vy, vy
|
|
|
|
didSetFirstValues = true
|
|
|
|
}
|
|
|
|
}
|
2016-07-07 23:26:07 -04:00
|
|
|
xrange.Formatter = s.GetXFormatter()
|
|
|
|
yrange.Formatter = s.GetYFormatter()
|
2016-07-07 17:44:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.XRange.IsZero() {
|
|
|
|
xrange.Min = globalMinX
|
|
|
|
xrange.Max = globalMaxX
|
|
|
|
} else {
|
|
|
|
xrange.Min = c.XRange.Min
|
|
|
|
xrange.Max = c.XRange.Max
|
|
|
|
}
|
2016-07-07 22:11:30 -04:00
|
|
|
xrange.Domain = canvasBox.Width
|
2016-07-07 17:44:03 -04:00
|
|
|
|
|
|
|
if c.YRange.IsZero() {
|
|
|
|
yrange.Min = globalMinY
|
|
|
|
yrange.Max = globalMaxY
|
|
|
|
} else {
|
|
|
|
yrange.Min = c.YRange.Min
|
|
|
|
yrange.Max = c.YRange.Max
|
|
|
|
}
|
2016-07-07 22:11:30 -04:00
|
|
|
yrange.Domain = canvasBox.Height
|
2016-07-07 17:44:03 -04:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:54:00 -04:00
|
|
|
func (c Chart) drawBackground(r Renderer) {
|
2016-07-07 17:44:03 -04:00
|
|
|
r.SetFillColor(c.Background.GetFillColor(DefaultBackgroundColor))
|
2016-07-07 22:11:30 -04:00
|
|
|
r.SetStrokeColor(c.Background.GetStrokeColor(DefaultBackgroundStrokeColor))
|
|
|
|
r.SetLineWidth(c.Background.GetStrokeWidth(DefaultStrokeWidth))
|
2016-07-06 21:54:00 -04:00
|
|
|
r.MoveTo(0, 0)
|
|
|
|
r.LineTo(c.Width, 0)
|
|
|
|
r.LineTo(c.Width, c.Height)
|
|
|
|
r.LineTo(0, c.Height)
|
|
|
|
r.LineTo(0, 0)
|
|
|
|
r.Close()
|
2016-07-07 22:11:30 -04:00
|
|
|
r.FillStroke()
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
func (c Chart) drawCanvas(r Renderer, canvasBox Box) {
|
2016-07-07 17:44:03 -04:00
|
|
|
r.SetFillColor(c.Canvas.GetFillColor(DefaultCanvasColor))
|
2016-07-07 22:11:30 -04:00
|
|
|
r.SetStrokeColor(c.Canvas.GetStrokeColor(DefaultCanvasStrokColor))
|
|
|
|
r.SetLineWidth(c.Canvas.GetStrokeWidth(DefaultStrokeWidth))
|
|
|
|
r.MoveTo(canvasBox.Left, canvasBox.Top)
|
|
|
|
r.LineTo(canvasBox.Right, canvasBox.Top)
|
|
|
|
r.LineTo(canvasBox.Right, canvasBox.Bottom)
|
|
|
|
r.LineTo(canvasBox.Left, canvasBox.Bottom)
|
|
|
|
r.LineTo(canvasBox.Left, canvasBox.Top)
|
2016-07-06 21:54:00 -04:00
|
|
|
r.Close()
|
2016-07-07 22:11:30 -04:00
|
|
|
r.FillStroke()
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
func (c Chart) drawAxes(r Renderer, canvasBox Box, xrange, yrange Range) {
|
2016-07-07 17:44:03 -04:00
|
|
|
if c.Axes.Show {
|
|
|
|
r.SetStrokeColor(c.Axes.GetStrokeColor(DefaultAxisColor))
|
2016-07-07 20:50:16 -04:00
|
|
|
r.SetLineWidth(c.Axes.GetStrokeWidth(DefaultStrokeWidth))
|
2016-07-07 22:11:30 -04:00
|
|
|
r.MoveTo(canvasBox.Left, canvasBox.Bottom)
|
|
|
|
r.LineTo(canvasBox.Right, canvasBox.Bottom)
|
|
|
|
r.LineTo(canvasBox.Right, canvasBox.Top)
|
2016-07-06 21:54:00 -04:00
|
|
|
r.Stroke()
|
2016-07-07 20:14:25 -04:00
|
|
|
|
2016-07-07 23:26:07 -04:00
|
|
|
c.drawXAxisLabels(r, canvasBox, xrange)
|
|
|
|
c.drawYAxisLabels(r, canvasBox, yrange)
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 23:26:07 -04:00
|
|
|
func (c Chart) drawYAxisLabels(r Renderer, canvasBox Box, yrange Range) {
|
|
|
|
tickFontSize := c.Axes.GetFontSize(DefaultAxisFontSize)
|
|
|
|
|
|
|
|
r.SetFontColor(c.Axes.GetFontColor(DefaultAxisColor))
|
|
|
|
r.SetFontSize(tickFontSize)
|
|
|
|
|
|
|
|
minimumTickHeight := tickFontSize + DefaultMinimumTickVerticalSpacing
|
|
|
|
tickCount := int(math.Floor(float64(yrange.Domain) / float64(minimumTickHeight)))
|
|
|
|
|
|
|
|
if tickCount > DefaultMaxTickCount {
|
|
|
|
tickCount = DefaultMaxTickCount
|
|
|
|
}
|
|
|
|
|
|
|
|
rangeTicks := Slices(tickCount, yrange.Max-yrange.Min)
|
|
|
|
domainTicks := Slices(tickCount, float64(yrange.Domain))
|
|
|
|
|
|
|
|
asw := c.getAxisWidth()
|
|
|
|
tx := canvasBox.Right + DefaultFinalLabelDeltaWidth + asw
|
|
|
|
|
|
|
|
count := len(rangeTicks)
|
|
|
|
if len(domainTicks) < count {
|
|
|
|
count = len(domainTicks) //guard against mismatched array sizes.
|
|
|
|
}
|
|
|
|
|
|
|
|
for index := 0; index < count; index++ {
|
2016-07-08 00:07:47 -04:00
|
|
|
v := rangeTicks[index] + yrange.Min
|
2016-07-07 23:26:07 -04:00
|
|
|
y := domainTicks[index]
|
|
|
|
ty := canvasBox.Bottom - int(y)
|
|
|
|
r.Text(yrange.Format(v), tx, ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Chart) drawXAxisLabels(r Renderer, canvasBox Box, xrange Range) {
|
|
|
|
tickFontSize := c.Axes.GetFontSize(DefaultAxisFontSize)
|
|
|
|
|
|
|
|
r.SetFontColor(c.Axes.GetFontColor(DefaultAxisColor))
|
|
|
|
r.SetFontSize(tickFontSize)
|
|
|
|
|
|
|
|
maxLabelWidth := 60
|
|
|
|
|
|
|
|
minimumTickWidth := maxLabelWidth + DefaultMinimumTickHorizontalSpacing
|
|
|
|
tickCount := int(math.Floor(float64(xrange.Domain) / float64(minimumTickWidth)))
|
|
|
|
|
|
|
|
if tickCount > DefaultMaxTickCount {
|
|
|
|
tickCount = DefaultMaxTickCount
|
|
|
|
}
|
|
|
|
|
|
|
|
rangeTicks := Slices(tickCount, xrange.Max-xrange.Min)
|
|
|
|
domainTicks := Slices(tickCount, float64(xrange.Domain))
|
|
|
|
|
|
|
|
ty := canvasBox.Bottom + DefaultXAxisMargin + int(tickFontSize)
|
|
|
|
|
|
|
|
count := len(rangeTicks)
|
|
|
|
if len(domainTicks) < count {
|
|
|
|
count = len(domainTicks) //guard against mismatched array sizes.
|
|
|
|
}
|
|
|
|
|
|
|
|
for index := 0; index < count; index++ {
|
|
|
|
v := rangeTicks[index] + xrange.Min
|
|
|
|
x := domainTicks[index]
|
|
|
|
tx := canvasBox.Left + int(x)
|
|
|
|
r.Text(xrange.Format(v), tx, ty)
|
|
|
|
}
|
2016-07-07 20:14:25 -04:00
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
func (c Chart) drawSeries(r Renderer, canvasBox Box, index int, s Series, xrange, yrange Range) {
|
2016-07-07 20:50:16 -04:00
|
|
|
r.SetStrokeColor(s.GetStyle().GetStrokeColor(GetDefaultSeriesStrokeColor(index)))
|
|
|
|
r.SetLineWidth(s.GetStyle().GetStrokeWidth(DefaultStrokeWidth))
|
2016-07-06 22:04:21 -04:00
|
|
|
|
|
|
|
if s.Len() == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
cx := canvasBox.Left
|
|
|
|
cy := canvasBox.Top
|
|
|
|
cw := canvasBox.Width
|
2016-07-07 17:44:03 -04:00
|
|
|
|
2016-07-07 00:12:19 -04:00
|
|
|
v0x, v0y := s.GetValue(0)
|
2016-07-07 17:44:03 -04:00
|
|
|
x0 := cw - xrange.Translate(v0x)
|
2016-07-07 00:12:19 -04:00
|
|
|
y0 := yrange.Translate(v0y)
|
2016-07-07 20:50:16 -04:00
|
|
|
r.MoveTo(x0+cx, y0+cy)
|
2016-07-06 22:04:21 -04:00
|
|
|
|
2016-07-07 17:44:03 -04:00
|
|
|
var vx, vy float64
|
2016-07-06 22:04:21 -04:00
|
|
|
var x, y int
|
2016-07-07 20:50:16 -04:00
|
|
|
for i := 1; i < s.Len(); i++ {
|
|
|
|
vx, vy = s.GetValue(i)
|
2016-07-07 17:44:03 -04:00
|
|
|
x = cw - xrange.Translate(vx)
|
2016-07-07 00:12:19 -04:00
|
|
|
y = yrange.Translate(vy)
|
2016-07-07 20:50:16 -04:00
|
|
|
r.LineTo(x+cx, y+cy)
|
2016-07-06 22:04:21 -04:00
|
|
|
}
|
2016-07-07 00:12:19 -04:00
|
|
|
r.Stroke()
|
2016-07-07 20:14:25 -04:00
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
c.drawFinalValueLabel(r, canvasBox, index, s, yrange)
|
2016-07-07 20:14:25 -04:00
|
|
|
}
|
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
func (c Chart) drawFinalValueLabel(r Renderer, canvasBox Box, index int, s Series, yrange Range) {
|
2016-07-07 20:14:25 -04:00
|
|
|
if c.FinalValueLabel.Show {
|
|
|
|
_, lv := s.GetValue(s.Len() - 1)
|
2016-07-07 23:26:07 -04:00
|
|
|
ll := s.GetYFormatter()(lv)
|
2016-07-07 20:14:25 -04:00
|
|
|
|
2016-07-07 22:11:30 -04:00
|
|
|
py := canvasBox.Top
|
2016-07-07 20:14:25 -04:00
|
|
|
ly := yrange.Translate(lv) + py
|
|
|
|
|
|
|
|
r.SetFontSize(c.FinalValueLabel.GetFontSize(DefaultFinalLabelFontSize))
|
|
|
|
textWidth := r.MeasureText(ll)
|
|
|
|
textHeight := int(math.Floor(DefaultFinalLabelFontSize))
|
|
|
|
halfTextHeight := textHeight >> 1
|
|
|
|
|
2016-07-07 23:26:07 -04:00
|
|
|
asw := 0
|
|
|
|
if c.Axes.Show {
|
|
|
|
asw = int(c.Axes.GetStrokeWidth(DefaultAxisLineWidth))
|
|
|
|
}
|
|
|
|
|
|
|
|
cx := canvasBox.Right + asw
|
2016-07-07 20:14:25 -04:00
|
|
|
|
|
|
|
pt := c.FinalValueLabel.Padding.GetTop(DefaultFinalLabelPadding.Top)
|
|
|
|
pl := c.FinalValueLabel.Padding.GetLeft(DefaultFinalLabelPadding.Left)
|
|
|
|
pr := c.FinalValueLabel.Padding.GetRight(DefaultFinalLabelPadding.Right)
|
|
|
|
pb := c.FinalValueLabel.Padding.GetBottom(DefaultFinalLabelPadding.Bottom)
|
|
|
|
|
|
|
|
textX := cx + pl + DefaultFinalLabelDeltaWidth
|
|
|
|
textY := ly + halfTextHeight
|
|
|
|
|
|
|
|
ltlx := cx + pl + DefaultFinalLabelDeltaWidth
|
|
|
|
ltly := ly - (pt + halfTextHeight)
|
|
|
|
|
|
|
|
ltrx := cx + pl + pr + textWidth
|
|
|
|
ltry := ly - (pt + halfTextHeight)
|
|
|
|
|
|
|
|
lbrx := cx + pl + pr + textWidth
|
|
|
|
lbry := ly + (pb + halfTextHeight)
|
|
|
|
|
|
|
|
lblx := cx + DefaultFinalLabelDeltaWidth
|
|
|
|
lbly := ly + (pb + halfTextHeight)
|
|
|
|
|
|
|
|
//draw the shape...
|
|
|
|
r.SetFillColor(c.FinalValueLabel.GetFillColor(DefaultFinalLabelBackgroundColor))
|
2016-07-07 20:50:16 -04:00
|
|
|
r.SetStrokeColor(c.FinalValueLabel.GetStrokeColor(s.GetStyle().GetStrokeColor(GetDefaultSeriesStrokeColor(index))))
|
2016-07-07 20:14:25 -04:00
|
|
|
r.SetLineWidth(c.FinalValueLabel.GetStrokeWidth(DefaultAxisLineWidth))
|
|
|
|
r.MoveTo(cx, ly)
|
|
|
|
r.LineTo(ltlx, ltly)
|
|
|
|
r.LineTo(ltrx, ltry)
|
|
|
|
r.LineTo(lbrx, lbry)
|
|
|
|
r.LineTo(lblx, lbly)
|
|
|
|
r.LineTo(cx, ly)
|
|
|
|
r.Close()
|
|
|
|
r.FillStroke()
|
|
|
|
|
|
|
|
r.SetFontColor(c.FinalValueLabel.GetFontColor(DefaultTextColor))
|
|
|
|
r.Text(ll, textX, textY)
|
|
|
|
}
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Chart) drawTitle(r Renderer) error {
|
2016-07-07 17:44:03 -04:00
|
|
|
if len(c.Title) > 0 && c.TitleStyle.Show {
|
|
|
|
r.SetFontColor(c.Canvas.GetFontColor(DefaultTextColor))
|
|
|
|
titleFontSize := c.Canvas.GetFontSize(DefaultTitleFontSize)
|
|
|
|
r.SetFontSize(titleFontSize)
|
2016-07-06 21:54:00 -04:00
|
|
|
textWidth := r.MeasureText(c.Title)
|
|
|
|
titleX := (c.Width >> 1) - (textWidth >> 1)
|
2016-07-07 22:11:30 -04:00
|
|
|
titleY := c.TitleStyle.Padding.GetTop(DefaultTitleTop) + int(titleFontSize)
|
2016-07-06 21:54:00 -04:00
|
|
|
r.Text(c.Title, titleX, titleY)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|