Make chart height adjustable

pull/45/head
Rigas Papathanasopoulos 5 years ago
parent 53a5d728c5
commit b46cea5801
No known key found for this signature in database
GPG Key ID: 76DC37F8CDF0891B

@ -307,6 +307,8 @@ Key|Action
<kbd>Ctrl</kbd>+<kbd>r</kbd>|Force refresh data
<kbd>Ctrl</kbd>+<kbd>s</kbd>|Save config
<kbd>Ctrl</kbd>+<kbd>u</kbd>|Jump page up (vim inspired)
<kbd>Ctrl</kbd>+<kbd>j</kbd>|Increase chart height
<kbd>Ctrl</kbd>+<kbd>k</kbd>|Decrease chart height
<kbd>Alt</kbd>+<kbd></kbd>|Sort current column in ascending order
<kbd>Alt</kbd>+<kbd></kbd>|Sort current column in descending order
<kbd>Alt</kbd>+<kbd></kbd>|Sort column to the left

@ -51,6 +51,8 @@ func actionsMap() map[string]bool {
"hide_currency_convert_menu": true,
"toggle_portfolio": true,
"toggle_show_portfolio": true,
"enlarge_chart": true,
"shorten_chart": true,
}
}

@ -117,7 +117,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
go ct.updateMarketbar()
chart := termui.NewLineChart()
chart.Height = 10
chart.Height = ct.State.chartHeight
chart.Border = false
// NOTE: empty list means don't show x-axis labels
@ -157,7 +157,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
}
for i := range graphData.MarketCapByAvailableSupply {
price := graphData.MarketCapByAvailableSupply[i][1]
data = append(data, price/1E9)
data = append(data, price/1e9)
}
} else {
graphData, err := ct.api.GetCoinGraphData(symbol, name, start, end)
@ -192,7 +192,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
// calculate layout
termui.Body.Align()
w := termui.Body.Width
h := 10
h := chart.Height
row := termui.Body.Rows[0]
b := row.Buffer()
for i := 0; i < h; i = i + 1 {
@ -220,7 +220,7 @@ func (ct *Cointop) PortfolioChart() error {
go ct.updateMarketbar()
chart := termui.NewLineChart()
chart.Height = 10
chart.Height = ct.State.chartHeight
chart.Border = false
// NOTE: empty list means don't show x-axis labels
@ -303,7 +303,7 @@ func (ct *Cointop) PortfolioChart() error {
// calculate layout
termui.Body.Align()
w := termui.Body.Width
h := 10
h := chart.Height
row := termui.Body.Rows[0]
b := row.Buffer()
for i := 0; i < h; i = i + 1 {
@ -320,6 +320,32 @@ func (ct *Cointop) PortfolioChart() error {
return nil
}
// ShortenChart decreases the chart height by one row
func (ct *Cointop) ShortenChart() error {
ct.debuglog("ShortenChart()")
candidate := ct.State.chartHeight - 1
if candidate < 5 {
return nil
}
ct.State.chartHeight = candidate
go ct.UpdateChart()
return nil
}
// EnlargeChart increases the chart height by one row
func (ct *Cointop) EnlargeChart() error {
ct.debuglog("EnlargeChart()")
candidate := ct.State.chartHeight + 1
if candidate > 30 {
return nil
}
ct.State.chartHeight = candidate
go ct.UpdateChart()
return nil
}
// NextChartRange sets the chart to the next range option
func (ct *Cointop) NextChartRange() error {
ct.debuglog("nextChartRange()")

@ -71,6 +71,7 @@ type State struct {
sortDesc bool
sortBy string
onlyTable bool
chartHeight int
}
// Cointop cointop
@ -184,6 +185,7 @@ func NewCointop(config *Config) (*Cointop, error) {
portfolio: &Portfolio{
Entries: make(map[string]*PortfolioEntry, 0),
},
chartHeight: 10,
},
tableColumnOrder: tableColumnOrder(),
Views: &Views{

@ -333,6 +333,10 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
case "toggle_table_fullscreen":
fn = ct.keyfn(ct.ToggleTableFullscreen)
view = ""
case "enlarge_chart":
fn = ct.keyfn(ct.EnlargeChart)
case "shorten_chart":
fn = ct.keyfn(ct.ShortenChart)
default:
fn = ct.keyfn(ct.noop)
}

@ -21,7 +21,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
headerHeight := 1
marketbarHeight := 1
chartHeight := 10
chartHeight := ct.State.chartHeight
statusbarHeight := 1
if ct.State.onlyTable {

@ -23,6 +23,8 @@ func defaultShortcuts() map[string]string {
"ctrl+s": "save",
"ctrl+S": "save",
"ctrl+u": "page_up",
"ctrl+j": "enlarge_chart",
"ctrl+k": "shorten_chart",
"alt+up": "sort_column_asc",
"alt+down": "sort_column_desc",
"alt+left": "sort_left_column",

Loading…
Cancel
Save