2019-02-01 00:02:34 +00:00
|
|
|
package config
|
|
|
|
|
2019-02-02 04:39:34 +00:00
|
|
|
import (
|
2019-02-02 14:45:53 +00:00
|
|
|
"github.com/sqshq/sampler/console"
|
2019-02-02 04:39:34 +00:00
|
|
|
)
|
2019-02-01 00:02:34 +00:00
|
|
|
|
|
|
|
const (
|
2019-04-07 15:17:28 +00:00
|
|
|
defaultRateMs = 1000
|
|
|
|
defaultScale = 1
|
|
|
|
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()
|
2019-04-26 05:11:40 +00:00
|
|
|
c.setDefaultArrangement()
|
2019-02-17 01:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2019-03-03 23:35:32 +00:00
|
|
|
|
|
|
|
setDefaultTriggersValues(chart.Triggers)
|
2019-03-17 23:55:24 +00:00
|
|
|
chart.ComponentConfig.Type = TypeRunChart
|
2019-03-03 23:35:32 +00:00
|
|
|
|
2019-04-07 15:17:28 +00:00
|
|
|
if chart.RateMs == nil {
|
|
|
|
r := defaultRateMs
|
|
|
|
chart.RateMs = &r
|
2019-02-17 01:54:48 +00:00
|
|
|
}
|
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-03-24 22:46:39 +00:00
|
|
|
for i, line := range c.SparkLines {
|
|
|
|
|
|
|
|
setDefaultTriggersValues(line.Triggers)
|
|
|
|
line.ComponentConfig.Type = TypeSparkLine
|
|
|
|
line.Item.Label = &line.Title
|
|
|
|
|
2019-04-07 15:17:28 +00:00
|
|
|
if line.RateMs == nil {
|
|
|
|
r := defaultRateMs
|
|
|
|
line.RateMs = &r
|
2019-03-24 22:46:39 +00:00
|
|
|
}
|
|
|
|
if line.Scale == nil {
|
|
|
|
p := defaultScale
|
|
|
|
line.Scale = &p
|
|
|
|
}
|
|
|
|
c.SparkLines[i] = line
|
|
|
|
}
|
|
|
|
|
2019-02-20 04:03:19 +00:00
|
|
|
for i, chart := range c.BarCharts {
|
2019-03-03 23:35:32 +00:00
|
|
|
|
|
|
|
setDefaultTriggersValues(chart.Triggers)
|
2019-03-17 23:55:24 +00:00
|
|
|
chart.ComponentConfig.Type = TypeBarChart
|
2019-03-03 23:35:32 +00:00
|
|
|
|
2019-04-07 15:17:28 +00:00
|
|
|
if chart.RateMs == nil {
|
|
|
|
r := defaultRateMs
|
|
|
|
chart.RateMs = &r
|
2019-02-20 04:03:19 +00:00
|
|
|
}
|
|
|
|
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 {
|
2019-03-03 23:35:32 +00:00
|
|
|
|
|
|
|
setDefaultTriggersValues(g.Triggers)
|
2019-03-17 23:55:24 +00:00
|
|
|
g.ComponentConfig.Type = TypeGauge
|
2019-03-03 23:35:32 +00:00
|
|
|
|
2019-04-07 15:17:28 +00:00
|
|
|
if g.RateMs == nil {
|
|
|
|
r := defaultRateMs
|
|
|
|
g.RateMs = &r
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
if g.Scale == nil {
|
|
|
|
p := defaultScale
|
|
|
|
g.Scale = &p
|
|
|
|
}
|
2019-04-06 02:11:52 +00:00
|
|
|
|
|
|
|
cur := "cur"
|
|
|
|
max := "max"
|
|
|
|
min := "min"
|
|
|
|
|
|
|
|
g.Cur.Label = &cur
|
|
|
|
g.Max.Label = &max
|
|
|
|
g.Min.Label = &min
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
c.Gauges[i] = g
|
|
|
|
}
|
|
|
|
|
2019-02-17 23:00:00 +00:00
|
|
|
for i, box := range c.AsciiBoxes {
|
2019-03-03 23:35:32 +00:00
|
|
|
|
|
|
|
setDefaultTriggersValues(box.Triggers)
|
2019-03-17 23:55:24 +00:00
|
|
|
box.ComponentConfig.Type = TypeAsciiBox
|
2019-03-03 23:35:32 +00:00
|
|
|
|
2019-04-07 15:17:28 +00:00
|
|
|
if box.RateMs == nil {
|
|
|
|
r := defaultRateMs
|
|
|
|
box.RateMs = &r
|
2019-02-17 23:00:00 +00:00
|
|
|
}
|
|
|
|
if box.Label == nil {
|
|
|
|
label := string(i)
|
|
|
|
box.Label = &label
|
|
|
|
}
|
|
|
|
if box.Font == nil {
|
2019-04-25 00:48:16 +00:00
|
|
|
font := console.AsciiFont2D
|
2019-02-17 23:00:00 +00:00
|
|
|
box.Font = &font
|
|
|
|
}
|
2019-04-10 02:34:45 +00:00
|
|
|
if box.Border == nil {
|
|
|
|
border := true
|
|
|
|
box.Border = &border
|
|
|
|
}
|
2019-02-17 23:00:00 +00:00
|
|
|
c.AsciiBoxes[i] = box
|
|
|
|
}
|
2019-04-10 02:30:21 +00:00
|
|
|
|
|
|
|
for i, box := range c.TextBoxes {
|
|
|
|
|
|
|
|
setDefaultTriggersValues(box.Triggers)
|
|
|
|
box.ComponentConfig.Type = TypeTextBox
|
|
|
|
|
|
|
|
if box.RateMs == nil {
|
|
|
|
r := defaultRateMs
|
|
|
|
box.RateMs = &r
|
|
|
|
}
|
|
|
|
if box.Label == nil {
|
|
|
|
label := string(i)
|
|
|
|
box.Label = &label
|
|
|
|
}
|
|
|
|
if box.Border == nil {
|
|
|
|
border := true
|
|
|
|
box.Border = &border
|
|
|
|
}
|
|
|
|
|
|
|
|
c.TextBoxes[i] = box
|
|
|
|
}
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:35:32 +00:00
|
|
|
func setDefaultTriggersValues(triggers []TriggerConfig) {
|
|
|
|
|
2019-03-10 04:41:23 +00:00
|
|
|
defaultTerminalBell := false
|
2019-03-03 23:35:32 +00:00
|
|
|
defaultSound := false
|
2019-03-10 04:41:23 +00:00
|
|
|
defaultVisual := false
|
2019-03-03 23:35:32 +00:00
|
|
|
|
|
|
|
for i, trigger := range triggers {
|
|
|
|
|
|
|
|
if trigger.Actions == nil {
|
|
|
|
trigger.Actions = &ActionsConfig{TerminalBell: &defaultTerminalBell, Sound: &defaultSound, Visual: &defaultVisual, Script: nil}
|
|
|
|
} else {
|
|
|
|
if trigger.Actions.TerminalBell == nil {
|
|
|
|
trigger.Actions.TerminalBell = &defaultTerminalBell
|
|
|
|
}
|
|
|
|
if trigger.Actions.Sound == nil {
|
|
|
|
trigger.Actions.Sound = &defaultSound
|
|
|
|
}
|
|
|
|
if trigger.Actions.Visual == nil {
|
|
|
|
trigger.Actions.Visual = &defaultVisual
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
triggers[i] = trigger
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-03-24 00:16:59 +00:00
|
|
|
colorsCount := len(palette.ContentColors)
|
2019-02-01 00:02:34 +00:00
|
|
|
|
2019-03-10 04:41:23 +00:00
|
|
|
for _, ch := range c.RunCharts {
|
|
|
|
for j, item := range ch.Items {
|
2019-02-17 01:54:48 +00:00
|
|
|
if item.Color == nil {
|
2019-03-24 00:16:59 +00:00
|
|
|
item.Color = &palette.ContentColors[j%colorsCount]
|
2019-03-10 04:41:23 +00:00
|
|
|
ch.Items[j] = item
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-20 04:03:19 +00:00
|
|
|
|
2019-03-10 04:41:23 +00:00
|
|
|
for _, b := range c.BarCharts {
|
|
|
|
for j, item := range b.Items {
|
2019-02-20 04:03:19 +00:00
|
|
|
if item.Color == nil {
|
2019-03-24 00:16:59 +00:00
|
|
|
item.Color = &palette.ContentColors[j%colorsCount]
|
2019-03-10 04:41:23 +00:00
|
|
|
b.Items[j] = item
|
2019-02-20 04:03:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-26 04:36:23 +00:00
|
|
|
|
2019-03-26 03:29:23 +00:00
|
|
|
for i, s := range c.SparkLines {
|
2019-04-01 04:35:55 +00:00
|
|
|
s.Gradient = &palette.GradientColors[i%(len(palette.GradientColors))]
|
|
|
|
c.SparkLines[i] = s
|
2019-03-26 03:29:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
for i, g := range c.Gauges {
|
|
|
|
if g.Color == nil {
|
2019-03-24 00:16:59 +00:00
|
|
|
g.Color = &palette.ContentColors[i%colorsCount]
|
2019-02-26 04:36:23 +00:00
|
|
|
c.Gauges[i] = g
|
|
|
|
}
|
|
|
|
}
|
2019-02-01 00:02:34 +00:00
|
|
|
}
|