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

View File

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

View File

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

View File

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