2019-02-01 00:02:34 +00:00
|
|
|
package config
|
|
|
|
|
2019-02-02 04:39:34 +00:00
|
|
|
import (
|
2019-02-24 04:49:09 +00:00
|
|
|
"github.com/sqshq/sampler/component/asciibox"
|
2019-02-02 14:45:53 +00:00
|
|
|
"github.com/sqshq/sampler/console"
|
2019-02-26 04:36:23 +00:00
|
|
|
"github.com/sqshq/sampler/data"
|
2019-02-02 04:39:34 +00:00
|
|
|
)
|
2019-02-01 00:02:34 +00:00
|
|
|
|
|
|
|
const (
|
2019-02-25 00:08:36 +00:00
|
|
|
defaultRefreshRateMs = 1000
|
2019-02-19 04:07:32 +00:00
|
|
|
defaultScale = 1
|
2019-02-02 04:39:34 +00:00
|
|
|
defaultTheme = console.ThemeDark
|
2019-02-01 00:02:34 +00:00
|
|
|
)
|
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
func (c *Config) setDefaults() {
|
|
|
|
c.setDefaultValues()
|
|
|
|
c.setDefaultColors()
|
|
|
|
c.setDefaultLayout()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) setDefaultValues() {
|
2019-02-01 00:02:34 +00:00
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
if c.Theme == nil {
|
|
|
|
t := defaultTheme
|
|
|
|
c.Theme = &t
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
for i, chart := range c.RunCharts {
|
|
|
|
if chart.RefreshRateMs == nil {
|
|
|
|
r := defaultRefreshRateMs
|
|
|
|
chart.RefreshRateMs = &r
|
|
|
|
}
|
2019-02-19 04:07:32 +00:00
|
|
|
if chart.Scale == nil {
|
|
|
|
p := defaultScale
|
|
|
|
chart.Scale = &p
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
2019-02-17 01:54:48 +00:00
|
|
|
if chart.Legend == nil {
|
|
|
|
chart.Legend = &LegendConfig{true, true}
|
|
|
|
c.RunCharts[i] = chart
|
2019-02-04 04:03:59 +00:00
|
|
|
}
|
2019-02-17 01:54:48 +00:00
|
|
|
c.RunCharts[i] = chart
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
2019-02-17 23:00:00 +00:00
|
|
|
|
2019-02-20 04:03:19 +00:00
|
|
|
for i, chart := range c.BarCharts {
|
|
|
|
if chart.RefreshRateMs == nil {
|
|
|
|
r := defaultRefreshRateMs
|
|
|
|
chart.RefreshRateMs = &r
|
|
|
|
}
|
|
|
|
if chart.Scale == nil {
|
|
|
|
p := defaultScale
|
|
|
|
chart.Scale = &p
|
|
|
|
}
|
|
|
|
c.BarCharts[i] = chart
|
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
for i, g := range c.Gauges {
|
|
|
|
if g.RefreshRateMs == nil {
|
|
|
|
r := defaultRefreshRateMs
|
|
|
|
g.RefreshRateMs = &r
|
|
|
|
}
|
|
|
|
if g.Scale == nil {
|
|
|
|
p := defaultScale
|
|
|
|
g.Scale = &p
|
|
|
|
}
|
|
|
|
var items []data.Item
|
|
|
|
for label, script := range g.Values {
|
|
|
|
l := label
|
|
|
|
items = append(items, data.Item{Label: &l, Script: script})
|
|
|
|
}
|
|
|
|
g.Items = items
|
|
|
|
c.Gauges[i] = g
|
|
|
|
}
|
|
|
|
|
2019-02-17 23:00:00 +00:00
|
|
|
for i, box := range c.AsciiBoxes {
|
|
|
|
if box.RefreshRateMs == nil {
|
|
|
|
r := defaultRefreshRateMs
|
|
|
|
box.RefreshRateMs = &r
|
|
|
|
}
|
|
|
|
if box.Label == nil {
|
|
|
|
label := string(i)
|
|
|
|
box.Label = &label
|
|
|
|
}
|
|
|
|
if box.Font == nil {
|
|
|
|
font := asciibox.AsciiFontFlat
|
|
|
|
box.Font = &font
|
|
|
|
}
|
|
|
|
if box.Color == nil {
|
|
|
|
color := console.ColorWhite
|
|
|
|
box.Color = &color
|
|
|
|
}
|
|
|
|
c.AsciiBoxes[i] = box
|
|
|
|
}
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
func (c *Config) setDefaultLayout() {
|
2019-02-17 03:18:12 +00:00
|
|
|
// TODO auto-arrange components
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
func (c *Config) setDefaultColors() {
|
2019-02-01 00:02:34 +00:00
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
palette := console.GetPalette(*c.Theme)
|
2019-02-17 03:18:12 +00:00
|
|
|
colorsCount := len(palette.Colors)
|
2019-02-01 00:02:34 +00:00
|
|
|
|
2019-02-17 03:18:12 +00:00
|
|
|
for _, chart := range c.RunCharts {
|
2019-02-01 00:02:34 +00:00
|
|
|
for j, item := range chart.Items {
|
2019-02-17 01:54:48 +00:00
|
|
|
if item.Color == nil {
|
2019-02-17 03:18:12 +00:00
|
|
|
item.Color = &palette.Colors[j%colorsCount]
|
2019-02-01 00:02:34 +00:00
|
|
|
chart.Items[j] = item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-20 04:03:19 +00:00
|
|
|
|
|
|
|
for _, chart := range c.BarCharts {
|
|
|
|
for j, item := range chart.Items {
|
|
|
|
if item.Color == nil {
|
|
|
|
item.Color = &palette.Colors[j%colorsCount]
|
|
|
|
chart.Items[j] = item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-26 04:36:23 +00:00
|
|
|
|
|
|
|
for i, g := range c.Gauges {
|
|
|
|
if g.Color == nil {
|
|
|
|
g.Color = &palette.Colors[i%colorsCount]
|
|
|
|
c.Gauges[i] = g
|
|
|
|
}
|
|
|
|
}
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|