go-chart/defaults.go

232 lines
8.3 KiB
Go
Raw Normal View History

2016-07-06 21:54:00 -04:00
package chart
import (
"sync"
"github.com/golang/freetype/truetype"
2016-07-09 14:23:35 -04:00
"github.com/wcharczuk/go-chart/drawing"
2016-07-06 21:54:00 -04:00
)
const (
// DefaultChartHeight is the default chart height.
DefaultChartHeight = 400
// DefaultChartWidth is the default chart width.
2016-07-16 23:53:46 -04:00
DefaultChartWidth = 1024
2017-02-22 20:47:08 -05:00
// DefaultStrokeWidth is the default chart stroke width.
DefaultStrokeWidth = 0.0
2017-03-04 20:42:10 -05:00
// DefaultDotWidth is the default chart dot width.
DefaultDotWidth = 0.0
2017-02-22 20:47:08 -05:00
// DefaultSeriesLineWidth is the default line width.
DefaultSeriesLineWidth = 1.0
2016-07-06 22:04:21 -04:00
// DefaultAxisLineWidth is the line width of the axis lines.
DefaultAxisLineWidth = 1.0
2016-07-06 21:54:00 -04:00
//DefaultDPI is the default dots per inch for the chart.
2016-07-08 20:57:14 -04:00
DefaultDPI = 92.0
2016-07-06 21:54:00 -04:00
// DefaultMinimumFontSize is the default minimum font size.
DefaultMinimumFontSize = 8.0
2016-07-07 17:44:03 -04:00
// DefaultFontSize is the default font size.
DefaultFontSize = 10.0
// DefaultTitleFontSize is the default title font size.
DefaultTitleFontSize = 18.0
2016-07-09 23:14:11 -04:00
// DefaultAnnotationDeltaWidth is the width of the left triangle out of annotations.
DefaultAnnotationDeltaWidth = 10
// DefaultAnnotationFontSize is the font size of annotations.
DefaultAnnotationFontSize = 10.0
2016-07-07 23:26:07 -04:00
// DefaultAxisFontSize is the font size of the axis labels.
DefaultAxisFontSize = 10.0
// DefaultTitleTop is the default distance from the top of the chart to put the title.
DefaultTitleTop = 10
2016-07-10 13:43:04 -04:00
2017-02-22 20:44:44 -05:00
// DefaultBackgroundStrokeWidth is the default stroke on the chart background.
DefaultBackgroundStrokeWidth = 0.0
// DefaultCanvasStrokeWidth is the default stroke on the chart canvas.
DefaultCanvasStrokeWidth = 0.0
2016-07-29 21:24:25 -04:00
// DefaultLineSpacing is the default vertical distance between lines of text.
DefaultLineSpacing = 5
2016-07-09 23:14:11 -04:00
// DefaultYAxisMargin is the default distance from the right of the canvas to the y axis labels.
2016-07-10 13:43:04 -04:00
DefaultYAxisMargin = 10
2016-07-07 23:26:07 -04:00
// DefaultXAxisMargin is the default distance from bottom of the canvas to the x axis labels.
DefaultXAxisMargin = 10
2016-07-10 13:43:04 -04:00
2016-07-11 21:48:51 -04:00
//DefaultVerticalTickHeight is half the margin.
DefaultVerticalTickHeight = DefaultXAxisMargin >> 1
2016-07-10 13:43:04 -04:00
//DefaultHorizontalTickWidth is half the margin.
2016-07-11 21:48:51 -04:00
DefaultHorizontalTickWidth = DefaultYAxisMargin >> 1
2016-07-13 14:50:22 -04:00
// DefaultTickCount is the default number of ticks to show
2016-07-11 21:48:51 -04:00
DefaultTickCount = 10
2016-07-13 14:50:22 -04:00
// DefaultTickCountSanityCheck is a hard limit on number of ticks to prevent infinite loops.
DefaultTickCountSanityCheck = 1 << 10 //1024
2016-07-10 13:43:04 -04:00
2016-07-07 23:26:07 -04:00
// DefaultMinimumTickHorizontalSpacing is the minimum distance between horizontal ticks.
DefaultMinimumTickHorizontalSpacing = 20
// DefaultMinimumTickVerticalSpacing is the minimum distance between vertical ticks.
DefaultMinimumTickVerticalSpacing = 20
2016-07-10 13:43:04 -04:00
2016-07-07 20:50:16 -04:00
// DefaultDateFormat is the default date format.
DefaultDateFormat = "2006-01-02"
2016-07-14 14:17:57 -04:00
// DefaultDateHourFormat is the date format for hour timestamp formats.
2016-07-14 14:36:47 -04:00
DefaultDateHourFormat = "01-02 3PM"
// DefaultDateMinuteFormat is the date format for minute range timestamp formats.
2016-07-27 03:34:10 -04:00
DefaultDateMinuteFormat = "01-02 3:04PM"
2016-07-14 14:17:57 -04:00
// DefaultFloatFormat is the default float format.
DefaultFloatFormat = "%.2f"
2016-07-14 14:21:41 -04:00
// DefaultPercentValueFormat is the default percent format.
DefaultPercentValueFormat = "%0.2f%%"
2016-08-05 23:08:24 -04:00
// DefaultBarSpacing is the default pixel spacing between bars.
DefaultBarSpacing = 100
// DefaultBarWidth is the default pixel width of bars in a bar chart.
DefaultBarWidth = 50
)
2016-07-28 05:34:44 -04:00
var (
// ColorWhite is white.
ColorWhite = drawing.Color{R: 255, G: 255, B: 255, A: 255}
// ColorBlue is the basic theme blue color.
ColorBlue = drawing.Color{R: 0, G: 116, B: 217, A: 255}
// ColorCyan is the basic theme cyan color.
ColorCyan = drawing.Color{R: 0, G: 217, B: 210, A: 255}
// ColorGreen is the basic theme green color.
ColorGreen = drawing.Color{R: 0, G: 217, B: 101, A: 255}
// ColorRed is the basic theme red color.
ColorRed = drawing.Color{R: 217, G: 0, B: 116, A: 255}
// ColorOrange is the basic theme orange color.
ColorOrange = drawing.Color{R: 217, G: 101, B: 0, A: 255}
// ColorYellow is the basic theme yellow color.
ColorYellow = drawing.Color{R: 217, G: 210, B: 0, A: 255}
// ColorBlack is the basic theme black color.
ColorBlack = drawing.Color{R: 51, G: 51, B: 51, A: 255}
// ColorLightGray is the basic theme light gray color.
ColorLightGray = drawing.Color{R: 239, G: 239, B: 239, A: 255}
// ColorAlternateBlue is a alternate theme color.
ColorAlternateBlue = drawing.Color{R: 106, G: 195, B: 203, A: 255}
// ColorAlternateGreen is a alternate theme color.
ColorAlternateGreen = drawing.Color{R: 42, G: 190, B: 137, A: 255}
// ColorAlternateGray is a alternate theme color.
ColorAlternateGray = drawing.Color{R: 110, G: 128, B: 139, A: 255}
// ColorAlternateYellow is a alternate theme color.
ColorAlternateYellow = drawing.Color{R: 240, G: 174, B: 90, A: 255}
// ColorAlternateLightGray is a alternate theme color.
ColorAlternateLightGray = drawing.Color{R: 187, G: 190, B: 191, A: 255}
2017-02-22 20:34:23 -05:00
// ColorTransparent is a transparent (alpha zero) color.
ColorTransparent = drawing.Color{R: 1, G: 1, B: 1, A: 0}
2016-07-28 05:34:44 -04:00
)
2016-07-06 21:54:00 -04:00
var (
// DefaultBackgroundColor is the default chart background color.
// It is equivalent to css color:white.
2016-07-28 05:34:44 -04:00
DefaultBackgroundColor = ColorWhite
// DefaultBackgroundStrokeColor is the default chart border color.
// It is equivalent to color:white.
2016-07-28 05:34:44 -04:00
DefaultBackgroundStrokeColor = ColorWhite
2016-07-06 21:54:00 -04:00
// DefaultCanvasColor is the default chart canvas color.
// It is equivalent to css color:white.
2016-07-28 05:34:44 -04:00
DefaultCanvasColor = ColorWhite
2016-07-14 14:17:57 -04:00
// DefaultCanvasStrokeColor is the default chart canvas stroke color.
// It is equivalent to css color:white.
2016-07-28 05:34:44 -04:00
DefaultCanvasStrokeColor = ColorWhite
2016-07-06 21:54:00 -04:00
// DefaultTextColor is the default chart text color.
// It is equivalent to #333333.
2016-07-28 05:34:44 -04:00
DefaultTextColor = ColorBlack
2016-07-06 21:54:00 -04:00
// DefaultAxisColor is the default chart axis line color.
// It is equivalent to #333333.
2016-07-28 05:34:44 -04:00
DefaultAxisColor = ColorBlack
// DefaultStrokeColor is the default chart border color.
2016-07-06 21:54:00 -04:00
// It is equivalent to #efefef.
2016-07-28 05:34:44 -04:00
DefaultStrokeColor = ColorLightGray
2016-07-06 21:54:00 -04:00
// DefaultFillColor is the default fill color.
// It is equivalent to #0074d9.
2016-07-28 05:34:44 -04:00
DefaultFillColor = ColorBlue
2016-07-09 23:14:11 -04:00
// DefaultAnnotationFillColor is the default annotation background color.
2016-07-28 05:34:44 -04:00
DefaultAnnotationFillColor = ColorWhite
2016-07-12 22:14:14 -04:00
// DefaultGridLineColor is the default grid line color.
2016-07-28 05:34:44 -04:00
DefaultGridLineColor = ColorLightGray
2016-07-06 21:54:00 -04:00
)
2016-07-07 17:44:03 -04:00
var (
2016-07-28 05:34:44 -04:00
// DefaultColors are a couple default series colors.
DefaultColors = []drawing.Color{
ColorBlue,
ColorGreen,
ColorRed,
ColorCyan,
ColorOrange,
}
// DefaultAlternateColors are a couple alternate colors.
DefaultAlternateColors = []drawing.Color{
ColorAlternateBlue,
ColorAlternateGreen,
ColorAlternateGray,
ColorAlternateYellow,
2016-07-30 02:31:49 -04:00
ColorBlue,
ColorGreen,
ColorRed,
ColorCyan,
ColorOrange,
2016-07-07 20:50:16 -04:00
}
)
2016-07-11 21:48:51 -04:00
var (
// DashArrayDots is a dash array that represents '....' style stroke dashes.
DashArrayDots = []int{1, 1}
// DashArrayDashesSmall is a dash array that represents '- - -' style stroke dashes.
DashArrayDashesSmall = []int{3, 3}
// DashArrayDashesMedium is a dash array that represents '-- -- --' style stroke dashes.
DashArrayDashesMedium = []int{5, 5}
// DashArrayDashesLarge is a dash array that represents '----- ----- -----' style stroke dashes.
DashArrayDashesLarge = []int{10, 10}
)
2017-02-22 20:34:23 -05:00
// NewColor returns a new color.
func NewColor(r, g, b, a uint8) drawing.Color {
return drawing.Color{R: r, G: g, B: b, A: a}
}
2016-07-28 21:51:55 -04:00
// GetDefaultColor returns a color from the default list by index.
2016-07-28 05:34:44 -04:00
// NOTE: the index will wrap around (using a modulo).
2016-07-28 21:51:55 -04:00
func GetDefaultColor(index int) drawing.Color {
2016-07-28 05:34:44 -04:00
finalIndex := index % len(DefaultColors)
return DefaultColors[finalIndex]
}
2016-07-28 21:51:55 -04:00
// GetAlternateColor returns a color from the default list by index.
2016-07-28 05:34:44 -04:00
// NOTE: the index will wrap around (using a modulo).
2016-07-28 21:51:55 -04:00
func GetAlternateColor(index int) drawing.Color {
2016-07-28 05:34:44 -04:00
finalIndex := index % len(DefaultAlternateColors)
return DefaultAlternateColors[finalIndex]
2016-07-07 20:50:16 -04:00
}
var (
2016-07-09 23:14:11 -04:00
// DefaultAnnotationPadding is the padding around an annotation.
2016-07-15 00:14:46 -04:00
DefaultAnnotationPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
2016-07-07 20:50:16 -04:00
// DefaultBackgroundPadding is the default canvas padding config.
DefaultBackgroundPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
2016-07-07 17:44:03 -04:00
)
2016-07-06 21:54:00 -04:00
var (
_defaultFontLock sync.Mutex
_defaultFont *truetype.Font
)
// GetDefaultFont returns the default font (Roboto-Medium).
func GetDefaultFont() (*truetype.Font, error) {
if _defaultFont == nil {
_defaultFontLock.Lock()
defer _defaultFontLock.Unlock()
if _defaultFont == nil {
font, err := truetype.Parse(roboto)
if err != nil {
return nil, err
}
_defaultFont = font
}
}
return _defaultFont, nil
}