2016-07-06 21:54:00 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import "image/color"
|
|
|
|
|
|
|
|
// Style is a simple style set.
|
|
|
|
type Style struct {
|
2016-07-07 17:44:03 -04:00
|
|
|
Show bool
|
2016-07-06 21:54:00 -04:00
|
|
|
StrokeColor color.RGBA
|
|
|
|
FillColor color.RGBA
|
2016-07-07 17:44:03 -04:00
|
|
|
StrokeWidth float64
|
|
|
|
FontSize float64
|
|
|
|
FontColor color.RGBA
|
2016-07-07 20:14:25 -04:00
|
|
|
Padding Box
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsZero returns if the object is set or not.
|
|
|
|
func (s Style) IsZero() bool {
|
2016-07-07 17:44:03 -04:00
|
|
|
return ColorIsZero(s.StrokeColor) && ColorIsZero(s.FillColor) && s.StrokeWidth == 0 && s.FontSize == 0
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetStrokeColor returns the stroke color.
|
2016-07-07 17:44:03 -04:00
|
|
|
func (s Style) GetStrokeColor(defaults ...color.RGBA) color.RGBA {
|
2016-07-06 21:54:00 -04:00
|
|
|
if ColorIsZero(s.StrokeColor) {
|
2016-07-07 17:44:03 -04:00
|
|
|
if len(defaults) > 0 {
|
|
|
|
return defaults[0]
|
|
|
|
}
|
2016-07-07 20:50:16 -04:00
|
|
|
return DefaultStrokeColor
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
return s.StrokeColor
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFillColor returns the fill color.
|
2016-07-07 17:44:03 -04:00
|
|
|
func (s Style) GetFillColor(defaults ...color.RGBA) color.RGBA {
|
2016-07-06 21:54:00 -04:00
|
|
|
if ColorIsZero(s.FillColor) {
|
2016-07-07 17:44:03 -04:00
|
|
|
if len(defaults) > 0 {
|
|
|
|
return defaults[0]
|
|
|
|
}
|
2016-07-06 21:54:00 -04:00
|
|
|
return DefaultFillColor
|
|
|
|
}
|
|
|
|
return s.FillColor
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStrokeWidth returns the stroke width.
|
2016-07-07 17:44:03 -04:00
|
|
|
func (s Style) GetStrokeWidth(defaults ...float64) float64 {
|
2016-07-06 21:54:00 -04:00
|
|
|
if s.StrokeWidth == 0 {
|
2016-07-07 17:44:03 -04:00
|
|
|
if len(defaults) > 0 {
|
|
|
|
return defaults[0]
|
|
|
|
}
|
2016-07-07 20:50:16 -04:00
|
|
|
return DefaultStrokeWidth
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|
|
|
|
return s.StrokeWidth
|
|
|
|
}
|
2016-07-07 17:44:03 -04:00
|
|
|
|
|
|
|
// GetFontSize gets the font size.
|
|
|
|
func (s Style) GetFontSize(defaults ...float64) float64 {
|
|
|
|
if s.FontSize == 0 {
|
|
|
|
if len(defaults) > 0 {
|
|
|
|
return defaults[0]
|
|
|
|
}
|
|
|
|
return DefaultFontSize
|
|
|
|
}
|
|
|
|
return s.FontSize
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFontColor gets the font size.
|
|
|
|
func (s Style) GetFontColor(defaults ...color.RGBA) color.RGBA {
|
|
|
|
if ColorIsZero(s.FontColor) {
|
|
|
|
if len(defaults) > 0 {
|
|
|
|
return defaults[0]
|
|
|
|
}
|
|
|
|
return DefaultTextColor
|
|
|
|
}
|
|
|
|
return s.FontColor
|
|
|
|
}
|