go-chart/defaults.go

119 lines
4.4 KiB
Go
Raw Normal View History

2016-07-06 21:54:00 -04:00
package chart
import (
"image/color"
"sync"
"github.com/golang/freetype/truetype"
)
const (
// DefaultChartHeight is the default chart height.
DefaultChartHeight = 400
// DefaultChartWidth is the default chart width.
DefaultChartWidth = 200
2016-07-07 20:50:16 -04:00
// DefaultStrokeWidth is the default chart line/stroke width.
DefaultStrokeWidth = 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
// DefaultFinalLabelDeltaWidth is the width of the left triangle out of the final label.
DefaultFinalLabelDeltaWidth = 10
// DefaultFinalLabelFontSize is the font size of the final label.
DefaultFinalLabelFontSize = 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-07 23:26:07 -04:00
// DefaultXAxisMargin is the default distance from bottom of the canvas to the x axis labels.
DefaultXAxisMargin = 10
// DefaultMinimumTickHorizontalSpacing is the minimum distance between horizontal ticks.
DefaultMinimumTickHorizontalSpacing = 20
// DefaultMinimumTickVerticalSpacing is the minimum distance between vertical ticks.
DefaultMinimumTickVerticalSpacing = 20
2016-07-07 20:50:16 -04:00
// DefaultDateFormat is the default date format.
DefaultDateFormat = "2006-01-02"
2016-07-07 23:26:07 -04:00
// DefaultMaxTickCount is the maximum number of ticks to draw
DefaultMaxTickCount = 7
)
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-07 20:50:16 -04:00
DefaultBackgroundColor = color.RGBA{R: 255, G: 255, B: 255, A: 255}
// DefaultBackgroundStrokeColor is the default chart border color.
// It is equivalent to color:white.
DefaultBackgroundStrokeColor = color.RGBA{R: 255, G: 255, B: 255, A: 255}
2016-07-06 21:54:00 -04:00
// DefaultCanvasColor is the default chart canvas color.
// It is equivalent to css color:white.
DefaultCanvasColor = color.RGBA{R: 255, G: 255, B: 255, A: 255}
// DefaultCanvasStrokColor is the default chart canvas stroke color.
// It is equivalent to css color:white.
DefaultCanvasStrokColor = color.RGBA{R: 255, G: 255, B: 255, A: 255}
2016-07-06 21:54:00 -04:00
// DefaultTextColor is the default chart text color.
// It is equivalent to #333333.
DefaultTextColor = color.RGBA{R: 51, G: 51, B: 51, A: 255}
// DefaultAxisColor is the default chart axis line color.
// It is equivalent to #333333.
DefaultAxisColor = color.RGBA{R: 51, G: 51, B: 51, A: 255}
// DefaultStrokeColor is the default chart border color.
2016-07-06 21:54:00 -04:00
// It is equivalent to #efefef.
DefaultStrokeColor = color.RGBA{R: 239, G: 239, B: 239, A: 255}
2016-07-06 21:54:00 -04:00
// DefaultFillColor is the default fill color.
// It is equivalent to #0074d9.
DefaultFillColor = color.RGBA{R: 0, G: 217, B: 116, A: 255}
// DefaultFinalLabelBackgroundColor is the default final label background color.
DefaultFinalLabelBackgroundColor = color.RGBA{R: 255, G: 255, B: 255, A: 255}
2016-07-06 21:54:00 -04:00
)
2016-07-07 17:44:03 -04:00
var (
2016-07-07 20:50:16 -04:00
// DefaultSeriesStrokeColors are a couple default series colors.
DefaultSeriesStrokeColors = []color.RGBA{
color.RGBA{R: 0, G: 116, B: 217, A: 255},
color.RGBA{R: 0, G: 217, B: 116, A: 255},
color.RGBA{R: 217, G: 0, B: 116, A: 255},
}
)
// GetDefaultSeriesStrokeColor returns a color from the default list by index.
// NOTE: the index will wrap around (using a modulo).g
func GetDefaultSeriesStrokeColor(index int) color.RGBA {
finalIndex := index % len(DefaultSeriesStrokeColors)
return DefaultSeriesStrokeColors[finalIndex]
}
var (
// DefaultFinalLabelPadding is the padding around the final label.
DefaultFinalLabelPadding = Box{Top: 5, Left: 0, Right: 7, 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
}