diff --git a/config.yml b/config.yml index e0f20a9..76f6e05 100644 --- a/config.yml +++ b/config.yml @@ -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 diff --git a/widgets/runchart/grid.go b/widgets/runchart/grid.go index 9a9f025..5ab8cf7 100644 --- a/widgets/runchart/grid.go +++ b/widgets/runchart/grid.go @@ -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 } diff --git a/widgets/runchart/legend.go b/widgets/runchart/legend.go index bfccd41..45e2763 100644 --- a/widgets/runchart/legend.go +++ b/widgets/runchart/legend.go @@ -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 } diff --git a/widgets/runchart/runchart.go b/widgets/runchart/runchart.go index 2a44025..7ab0a19 100644 --- a/widgets/runchart/runchart.go +++ b/widgets/runchart/runchart.go @@ -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 } }