Rename ScaleNumbers to CompactNotation. Use the new scaling function.

pull/200/head
Simon Roberts 3 years ago
parent 31bb4b005c
commit 648a8e772d
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -136,9 +136,8 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "24h_volume":
text := humanize.Monetaryf(coin.Volume24H, 0)
if ct.State.scaleNumbers {
numScale, numSuffix := humanize.Scale(coin.Volume24H)
text = humanize.Numericf(numScale, 1) + numSuffix
if ct.State.compactNotation {
text = humanize.ScaleNumericf(coin.Volume24H, 3)
}
ct.SetTableColumnWidthFromString(header, text)
ct.SetTableColumnAlignLeft(header, false)
@ -247,9 +246,8 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "market_cap":
text := humanize.Monetaryf(coin.MarketCap, 0)
if ct.State.scaleNumbers {
numScale, numSuffix := humanize.Scale(coin.MarketCap)
text = humanize.Numericf(numScale, 1) + numSuffix
if ct.State.compactNotation {
text = humanize.ScaleNumericf(coin.MarketCap, 3)
}
ct.SetTableColumnWidthFromString(header, text)
ct.SetTableColumnAlignLeft(header, false)
@ -263,9 +261,8 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "total_supply":
text := humanize.Numericf(coin.TotalSupply, 0)
if ct.State.scaleNumbers {
numScale, numSuffix := humanize.Scale(coin.TotalSupply)
text = humanize.Numericf(numScale, 1) + numSuffix
if ct.State.compactNotation {
text = humanize.ScaleNumericf(coin.TotalSupply, 3)
}
ct.SetTableColumnWidthFromString(header, text)
ct.SetTableColumnAlignLeft(header, false)
@ -279,9 +276,8 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "available_supply":
text := humanize.Numericf(coin.AvailableSupply, 0)
if ct.State.scaleNumbers {
numScale, numSuffix := humanize.Scale(coin.AvailableSupply)
text = humanize.Numericf(numScale, 1) + numSuffix
if ct.State.compactNotation {
text = humanize.ScaleNumericf(coin.AvailableSupply, 3)
}
ct.SetTableColumnWidthFromString(header, text)
ct.SetTableColumnAlignLeft(header, false)

@ -39,7 +39,7 @@ type State struct {
allCoins []*Coin
allCoinsSlugMap sync.Map
cacheDir string
scaleNumbers bool
compactNotation bool
coins []*Coin
chartPoints [][]rune
currencyConversion string
@ -182,8 +182,8 @@ var DefaultCurrency = "USD"
// DefaultChartRange ...
var DefaultChartRange = "1Y"
// DefaultScaleNumbers ...
var DefaultScaleNumbers = false
// DefaultCompactNotation ...
var DefaultCompactNotation = false
// DefaultMaxChartWidth ...
var DefaultMaxChartWidth int = 175
@ -257,7 +257,7 @@ func NewCointop(config *Config) (*Cointop, error) {
State: &State{
allCoins: []*Coin{},
cacheDir: DefaultCacheDir,
scaleNumbers: DefaultScaleNumbers,
compactNotation: DefaultCompactNotation,
coinsTableColumns: DefaultCoinTableHeaders,
currencyConversion: DefaultCurrency,
defaultChartRange: DefaultChartRange,

@ -48,7 +48,7 @@ type ConfigFileConfig struct {
Colorscheme interface{} `toml:"colorscheme"`
RefreshRate interface{} `toml:"refresh_rate"`
CacheDir interface{} `toml:"cache_dir"`
ScaleNumbers interface{} `toml:"scale_numbers"`
CompactNotation interface{} `toml:"compact_notation"`
Table map[string]interface{} `toml:"table"`
Chart map[string]interface{} `toml:"chart"`
}
@ -71,7 +71,7 @@ func (ct *Cointop) SetupConfig() error {
ct.loadColorschemeFromConfig,
ct.loadRefreshRateFromConfig,
ct.loadCacheDirFromConfig,
ct.loadScaleNumbersFromConfig,
ct.loadCompactNotationFromConfig,
ct.loadPriceAlertsFromConfig,
ct.loadPortfolioFromConfig,
}
@ -286,7 +286,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
Portfolio: portfolioIfc,
PriceAlerts: priceAlertsMapIfc,
CacheDir: ct.State.cacheDir,
ScaleNumbers: ct.State.scaleNumbers,
CompactNotation: ct.State.compactNotation,
Table: tableMapIfc,
Chart: chartMapIfc,
}
@ -461,11 +461,11 @@ func (ct *Cointop) loadCacheDirFromConfig() error {
return nil
}
// LoadScaleNumbersFromConfig loads scale-numbers setting from config file to struct
func (ct *Cointop) loadScaleNumbersFromConfig() error {
log.Debug("loadScaleNumbersFromConfig()")
if scaleNumbers, ok := ct.config.ScaleNumbers.(bool); ok {
ct.State.scaleNumbers = scaleNumbers
// loadCompactNotationFromConfig loads compact-notation setting from config file to struct
func (ct *Cointop) loadCompactNotationFromConfig() error {
log.Debug("loadCompactNotationFromConfig()")
if compactNotation, ok := ct.config.CompactNotation.(bool); ok {
ct.State.compactNotation = compactNotation
}
return nil

@ -131,7 +131,7 @@ var HeaderColumns = map[string]*HeaderColumn{
// GetLabel fetch the label to use for the heading (depends on configuration)
func (ct *Cointop) GetLabel(h *HeaderColumn) string {
// TODO: technically this should support nosort
if ct.State.scaleNumbers && h.ShortLabel != "" {
if ct.State.compactNotation && h.ShortLabel != "" {
return h.ShortLabel
}
return h.Label

Loading…
Cancel
Save