sampler-fork/config/default.go

61 lines
1.1 KiB
Go
Raw Normal View History

2019-02-01 00:02:34 +00:00
package config
import (
2019-02-02 14:45:53 +00:00
"github.com/sqshq/sampler/console"
)
2019-02-01 00:02:34 +00:00
const (
defaultRefreshRateMs = 300
2019-02-04 04:03:59 +00:00
defaultPrecision = 1
defaultTheme = console.ThemeDark
2019-02-01 00:02:34 +00:00
)
func (c *Config) setDefaults() {
c.setDefaultValues()
c.setDefaultColors()
c.setDefaultLayout()
}
func (c *Config) setDefaultValues() {
2019-02-01 00:02:34 +00:00
if c.Theme == nil {
t := defaultTheme
c.Theme = &t
2019-02-01 00:02:34 +00:00
}
for i, chart := range c.RunCharts {
if chart.RefreshRateMs == nil {
r := defaultRefreshRateMs
chart.RefreshRateMs = &r
}
if chart.Precision == nil {
p := defaultPrecision
chart.Precision = &p
2019-02-01 00:02:34 +00:00
}
if chart.Legend == nil {
chart.Legend = &LegendConfig{true, true}
c.RunCharts[i] = chart
2019-02-04 04:03:59 +00:00
}
c.RunCharts[i] = chart
2019-02-01 00:02:34 +00:00
}
}
func (c *Config) setDefaultLayout() {
// TODO auto-arrange components
2019-02-01 00:02:34 +00:00
}
func (c *Config) setDefaultColors() {
2019-02-01 00:02:34 +00:00
palette := console.GetPalette(*c.Theme)
colorsCount := len(palette.Colors)
2019-02-01 00:02:34 +00:00
for _, chart := range c.RunCharts {
2019-02-01 00:02:34 +00:00
for j, item := range chart.Items {
if item.Color == nil {
item.Color = &palette.Colors[j%colorsCount]
2019-02-01 00:02:34 +00:00
chart.Items[j] = item
}
}
}
}