diff --git a/config.yml b/config.yml index 86a3ee3..f92696d 100644 --- a/config.yml +++ b/config.yml @@ -10,7 +10,6 @@ run-charts: script: curl -o /dev/null -s -w '%{time_total}' http://example.com refresh-rate-ms: 300 time-scale-sec: 1 - style: dots/lines position: x: 0 y: 0 @@ -22,8 +21,6 @@ run-charts: - label: posts script: mongo --quiet --host=localhost blog --eval "db.getCollection('post').find({}).size()" | grep 2 color: 3 - refresh-rate-ms: 200 - time-scale-sec: 1 position: x: 15 y: 0 diff --git a/config/config.go b/config/config.go index ca21b67..21c4621 100644 --- a/config/config.go +++ b/config/config.go @@ -26,8 +26,10 @@ type RunChart struct { func Load(location string) *Config { cfg := readFile(location) - validate(cfg) - setColors(cfg) + cfg.validate() + cfg.setDefaultValues() + cfg.setDefaultColors() + cfg.setDefaultLayout() return cfg } @@ -48,26 +50,3 @@ func readFile(location string) *Config { return cfg } - -/* - TODO validation - - title uniquness and mandatory within a single type of widget - - label uniqueness and mandatory (if > 1 data bullets) -*/ -func validate(config *Config) { - -} - -func setColors(config *Config) { - - palette := settings.GetPalette(config.Theme) - - for i, chart := range config.RunCharts { - for j, item := range chart.Items { - if item.Color == 0 { - item.Color = palette.Colors[i+j] - chart.Items[j] = item - } - } - } -} diff --git a/config/default.go b/config/default.go new file mode 100644 index 0000000..641e88a --- /dev/null +++ b/config/default.go @@ -0,0 +1,44 @@ +package config + +import "github.com/sqshq/vcmd/settings" + +const ( + defaultRefreshRateMs = 300 + defaultTimeScaleSec = 1 + defaultTheme = settings.ThemeDark +) + +func (self *Config) setDefaultValues() { + + if len(self.Theme) == 0 { + self.Theme = defaultTheme + } + + for i, chart := range self.RunCharts { + if chart.RefreshRateMs == 0 { + chart.RefreshRateMs = defaultRefreshRateMs + } + if chart.TimeScaleSec == 0 { + chart.TimeScaleSec = defaultTimeScaleSec + } + self.RunCharts[i] = chart + } +} + +func (config *Config) setDefaultLayout() { + +} + +func (config *Config) setDefaultColors() { + + palette := settings.GetPalette(config.Theme) + + for i, chart := range config.RunCharts { + for j, item := range chart.Items { + if item.Color == 0 { + item.Color = palette.Colors[i+j] + chart.Items[j] = item + } + } + } +} diff --git a/config/validator.go b/config/validator.go new file mode 100644 index 0000000..7f2f706 --- /dev/null +++ b/config/validator.go @@ -0,0 +1,10 @@ +package config + +/* + TODO validation + - title uniquness and mandatory within a single type of widget + - label uniqueness and mandatory (if > 1 data bullets) +*/ +func (self *Config) validate() { + +}