added trim for out of range values

This commit is contained in:
sqshq 2019-02-11 22:49:57 -05:00
parent f9a73817c3
commit df5cee1d39
2 changed files with 21 additions and 3 deletions

View File

@ -15,7 +15,7 @@ const (
const ( const (
ColorOlive ui.Color = 178 ColorOlive ui.Color = 178
ColorDeepSkyBlue ui.Color = 39 ColorDeepSkyBlue ui.Color = 39
ColorDeepPink ui.Color = 162 ColorDeepPink ui.Color = 198
ColorDarkGrey ui.Color = 240 ColorDarkGrey ui.Color = 240
ColorWhite ui.Color = 7 ColorWhite ui.Color = 7
ColorBlack ui.Color = 0 ColorBlack ui.Color = 0

View File

@ -22,6 +22,8 @@ const (
xAxisGridWidth = xAxisLabelsGap + xAxisLabelsWidth xAxisGridWidth = xAxisLabelsGap + xAxisLabelsWidth
yAxisLabelsHeight = 1 yAxisLabelsHeight = 1
yAxisLabelsGap = 1 yAxisLabelsGap = 1
historyReserveHrs = 1
) )
type ScrollMode int type ScrollMode int
@ -180,7 +182,7 @@ func (self *RunChart) renderLines(buffer *ui.Buffer, drawArea image.Rectangle) {
probe := self.lines[0].points[0] probe := self.lines[0].points[0]
delta := ui.AbsInt(self.calculateTimeCoordinate(probe.time) - probe.coordinate) delta := ui.AbsInt(self.calculateTimeCoordinate(probe.time) - probe.coordinate)
for i, line := range self.lines { // TODO start from right side, break on out of range for i, line := range self.lines {
xPoint := make(map[int]image.Point) xPoint := make(map[int]image.Point)
xOrder := make([]int, 0) xOrder := make([]int, 0)
@ -356,7 +358,23 @@ func (self *RunChart) renderLegend(buffer *ui.Buffer, rectangle image.Rectangle)
} }
func (self *RunChart) trimOutOfRangeValues() { func (self *RunChart) trimOutOfRangeValues() {
// TODO use hard limit
minRangeTime := self.grid.timeRange.min.Add(-time.Hour * time.Duration(historyReserveHrs))
for i, item := range self.lines {
lastOutOfRangeValueIndex := -1
for j, point := range item.points {
if point.time.Before(minRangeTime) {
lastOutOfRangeValueIndex = j
}
}
if lastOutOfRangeValueIndex > 0 {
item.points = append(item.points[:0], item.points[lastOutOfRangeValueIndex+1:]...)
self.lines[i] = item
}
}
} }
func (self *RunChart) calculateTimeCoordinate(t time.Time) int { func (self *RunChart) calculateTimeCoordinate(t time.Time) int {