Ask the chart how many data points it needs

pull/180/head
Simon Roberts 3 years ago
parent 065f23eba2
commit 49ac2fbc0f
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -173,14 +173,10 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
}
// Resample cachedata
maxPoints := len(cacheData)
if maxPoints > 2*maxX {
maxPoints = 2 * maxX
}
timeQuantum := timedata.CalculateTimeQuantum(cacheData)
newStart := time.Unix(start, 0).Add(timeQuantum)
newEnd := time.Unix(end, 0).Add(-timeQuantum)
timeData := timedata.ResampleTimeSeriesData(cacheData, float64(newStart.UnixMilli()), float64(newEnd.UnixMilli()), maxPoints)
timeData := timedata.ResampleTimeSeriesData(cacheData, float64(newStart.UnixMilli()), float64(newEnd.UnixMilli()), chart.GetChartDataSize(maxX))
// Extract just the values from the data
var data []float64
@ -276,17 +272,6 @@ func (ct *Cointop) PortfolioChart() error {
allCacheData = append(allCacheData, PriceData{p, cacheData})
}
// Calculate how many data points to provide to the chart. Limit maxPoints to 2*maxX
maxPoints := 0
for _, cacheData := range allCacheData {
if len(cacheData.data) > maxPoints {
maxPoints = len(cacheData.data)
}
}
if maxPoints > 2*maxX {
maxPoints = 2 * maxX
}
// Use the gap between price samples to adjust start/end in by one interval
var timeQuantum time.Duration
for _, cacheData := range allCacheData {
@ -301,7 +286,7 @@ func (ct *Cointop) PortfolioChart() error {
// Resample and sum data
var data []float64
for _, cacheData := range allCacheData {
coinData := timedata.ResampleTimeSeriesData(cacheData.data, float64(newStart.UnixMilli()), float64(newEnd.UnixMilli()), maxPoints)
coinData := timedata.ResampleTimeSeriesData(cacheData.data, float64(newStart.UnixMilli()), float64(newEnd.UnixMilli()), chart.GetChartDataSize(maxX))
// sum (excluding NaN)
for i := range coinData {
price := coinData[i][1]

@ -56,10 +56,18 @@ func (c *ChartPlot) SetData(data []float64) {
c.t.Data = data
}
func (c *ChartPlot) GetChartDataSize(width int) int {
axisYWidth := 30
return (width * 2) - axisYWidth
}
// GetChartPoints ...
func (c *ChartPlot) GetChartPoints(width int) [][]rune {
axisYWidth := 30
c.t.Data = interpolateData(c.t.Data, (width*2)-axisYWidth)
targetWidth := c.GetChartDataSize(width)
if len(c.t.Data) != targetWidth {
// Don't resample data if it's already the right size
c.t.Data = interpolateData(c.t.Data, targetWidth)
}
termui.Body = termui.NewGrid()
termui.Body.Width = width
termui.Body.AddRows(

Loading…
Cancel
Save