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

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

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

Loading…
Cancel
Save