Merge pull request #189 from lyricnz/feature/full-width

#129 Allow configurable max_chart_width (default 175, if 0 use full width)
pull/190/head
Simon Roberts 3 years ago committed by GitHub
commit cc325b9d4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -342,6 +342,10 @@ func (ct *Cointop) ShortenChart() error {
ct.State.chartHeight = candidate
ct.State.lastChartHeight = ct.State.chartHeight
if err := ct.Save(); err != nil {
return err
}
go ct.UpdateChart()
return nil
}
@ -356,6 +360,10 @@ func (ct *Cointop) EnlargeChart() error {
ct.State.chartHeight = candidate
ct.State.lastChartHeight = ct.State.chartHeight
if err := ct.Save(); err != nil {
return err
}
go ct.UpdateChart()
return nil
}
@ -453,8 +461,8 @@ func (ct *Cointop) ShowChartLoader() error {
func (ct *Cointop) ChartWidth() int {
log.Debug("ChartWidth()")
w := ct.Width()
max := 175
if w > max {
max := ct.State.maxChartWidth
if max > 0 && w > max {
return max
}

@ -46,6 +46,7 @@ type State struct {
convertMenuVisible bool
defaultView string
defaultChartRange string
maxChartWidth int
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions.
favoritesBySymbol map[string]bool
@ -179,6 +180,12 @@ var DefaultCurrency = "USD"
// DefaultChartRange ...
var DefaultChartRange = "1Y"
// DefaultMaxChartWidth ...
var DefaultMaxChartWidth int = 175
// DefaultChartHeight ...
var DefaultChartHeight int = 10
// DefaultSortBy ...
var DefaultSortBy = "rank"
@ -245,6 +252,7 @@ func NewCointop(config *Config) (*Cointop, error) {
coinsTableColumns: DefaultCoinTableHeaders,
currencyConversion: DefaultCurrency,
defaultChartRange: DefaultChartRange,
maxChartWidth: DefaultMaxChartWidth,
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions. Kept for backward compatibility.
favoritesBySymbol: make(map[string]bool),
favorites: make(map[string]bool),
@ -269,8 +277,8 @@ func NewCointop(config *Config) (*Cointop, error) {
Entries: make(map[string]*PortfolioEntry),
},
portfolioTableColumns: DefaultPortfolioTableHeaders,
chartHeight: 10,
lastChartHeight: 10,
chartHeight: DefaultChartHeight,
lastChartHeight: DefaultChartHeight,
tableOffsetX: 0,
tableColumnWidths: sync.Map{},
tableColumnAlignLeft: sync.Map{},

@ -48,6 +48,7 @@ type ConfigFileConfig struct {
RefreshRate interface{} `toml:"refresh_rate"`
CacheDir interface{} `toml:"cache_dir"`
Table map[string]interface{} `toml:"table"`
Chart map[string]interface{} `toml:"chart"`
}
// SetupConfig loads config file
@ -62,6 +63,9 @@ func (ct *Cointop) SetupConfig() error {
if err := ct.loadTableConfig(); err != nil {
return err
}
if err := ct.loadChartConfig(); err != nil {
return err
}
if err := ct.loadShortcutsFromConfig(); err != nil {
return err
}
@ -297,6 +301,10 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
var keepRowFocusOnSortIfc interface{} = ct.State.keepRowFocusOnSort
tableMapIfc["keep_row_focus_on_sort"] = keepRowFocusOnSortIfc
chartMapIfc := map[string]interface{}{}
chartMapIfc["max_width"] = ct.State.maxChartWidth
chartMapIfc["height"] = ct.State.chartHeight
var inputs = &ConfigFileConfig{
API: apiChoiceIfc,
Colorscheme: colorschemeIfc,
@ -311,6 +319,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
PriceAlerts: priceAlertsMapIfc,
CacheDir: cacheDirIfc,
Table: tableMapIfc,
Chart: chartMapIfc,
}
var b bytes.Buffer
@ -338,6 +347,22 @@ func (ct *Cointop) loadTableConfig() error {
return nil
}
// LoadChartConfig loads chart config from toml config into state struct
func (ct *Cointop) loadChartConfig() error {
log.Debugf("loadChartConfig()")
maxChartWidthIfc, ok := ct.config.Chart["max_width"]
if ok {
ct.State.maxChartWidth = int(maxChartWidthIfc.(int64))
}
chartHeightIfc, ok := ct.config.Chart["height"]
if ok {
ct.State.chartHeight = int(chartHeightIfc.(int64))
ct.State.lastChartHeight = ct.State.chartHeight
}
return nil
}
// LoadTableColumnsFromConfig loads preferred coins table columns from config file to struct
func (ct *Cointop) loadTableColumnsFromConfig() error {
log.Debug("loadTableColumnsFromConfig()")

Loading…
Cancel
Save