added pinpoint adjustment for the legend

This commit is contained in:
sqshq 2019-02-14 23:44:25 -05:00
parent ae6e895d8a
commit 88a935d6d3
4 changed files with 28 additions and 19 deletions

View File

@ -8,7 +8,7 @@ runcharts:
script: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com/
- label: BING
script: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com/
refresh-rate-ms: 500
refresh-rate-ms: 200
decimal-places: 3
alert:
value:
@ -20,7 +20,7 @@ runcharts:
beep: true
legend:
enabled: true
details: true
details: false
position:
x: 0
y: 0

View File

@ -97,7 +97,7 @@ func (c *RunChart) renderAxes(buffer *ui.Buffer) {
func (c *RunChart) getTimeRange(linesCount int) TimeRange {
if c.mode == Pinpoint {
if c.mode == ModePinpoint {
return c.grid.timeRange
}

View File

@ -8,10 +8,11 @@ import (
)
const (
xAxisLegendIndent = 10
yAxisLegendIndent = 1
heightWithLabelOnly = 3
heightWithDetails = 7
xAxisLegendIndent = 10
yAxisLegendIndent = 1
heightOnDefault = 2
heightOnPinpoint = 4
heightOnDetails = 6
)
type Legend struct {
@ -25,9 +26,12 @@ func (c *RunChart) renderLegend(buffer *ui.Buffer, rectangle image.Rectangle) {
return
}
height := heightWithLabelOnly
if c.legend.Details {
height = heightWithDetails
height := heightOnDefault
if c.mode == ModePinpoint {
height = heightOnPinpoint
} else if c.legend.Details {
height = heightOnDetails
}
rowCount := (c.Dx() - yAxisLegendIndent) / (height + yAxisLegendIndent)
@ -44,8 +48,9 @@ func (c *RunChart) renderLegend(buffer *ui.Buffer, rectangle image.Rectangle) {
line := c.lines[row+rowCount*col]
extrema := getLineValueExtrema(line.points)
x := c.Inner.Max.X - (columnWidth+xAxisLegendIndent)*(col+1)
y := c.Inner.Min.Y + yAxisLegendIndent + row*(height)
y := c.Inner.Min.Y + yAxisLegendIndent + row*height
titleStyle := ui.NewStyle(line.color)
detailsStyle := ui.NewStyle(ui.ColorWhite)
@ -53,6 +58,10 @@ func (c *RunChart) renderLegend(buffer *ui.Buffer, rectangle image.Rectangle) {
buffer.SetString(string(ui.DOT), titleStyle, image.Pt(x-2, y))
buffer.SetString(line.label, titleStyle, image.Pt(x, y))
if c.mode == ModePinpoint {
continue
}
if !c.legend.Details {
continue
}

View File

@ -30,8 +30,8 @@ const (
type Mode int
const (
Default Mode = 0
Pinpoint Mode = 1
ModeDefault Mode = 0
ModePinpoint Mode = 1
)
type RunChart struct {
@ -79,7 +79,7 @@ func NewRunChart(title string, precision int, refreshRateMs int, legend Legend)
timescale: calculateTimescale(refreshRateMs),
mutex: &sync.Mutex{},
precision: precision,
mode: Default,
mode: ModeDefault,
legend: legend,
}
}
@ -230,7 +230,7 @@ func (c *RunChart) renderLines(buffer *ui.Buffer, drawArea image.Rectangle) {
canvas.Draw(buffer)
if c.mode == Pinpoint {
if c.mode == ModePinpoint {
for lineIndex, point := range selectionPoints {
buffer.SetCell(ui.NewCell(console.SymbolSelection, ui.NewStyle(c.lines[lineIndex].color)), point)
if c.lines[lineIndex].selection == 0 {
@ -285,8 +285,8 @@ func (c *RunChart) getMaxValueLength() int {
func (c *RunChart) MoveSelection(shift int) {
if c.mode == Default {
c.mode = Pinpoint
if c.mode == ModeDefault {
c.mode = ModePinpoint
c.selection = getMidRangeTime(c.grid.timeRange)
return
} else {
@ -304,8 +304,8 @@ func (c *RunChart) MoveSelection(shift int) {
}
func (c *RunChart) DisableSelection() {
if c.mode == Pinpoint {
c.mode = Default
if c.mode == ModePinpoint {
c.mode = ModeDefault
return
}
}