diff --git a/widgets/linechart/linechart.go b/widgets/linechart/linechart.go index f1f00b5..8edf635 100644 --- a/widgets/linechart/linechart.go +++ b/widgets/linechart/linechart.go @@ -376,7 +376,7 @@ func (lc *LineChart) drawSeries(cvs *canvas.Canvas, xd *axes.XDetails, yd *axes. // Skip over series that don't have at least two points since we can't // draw a line for just one point. // Skip over series that fall under the minimum value on the X axis. - if got := len(sv.values); got <= 1 || got < int(xdForCap.Scale.Min.Value) { + if got := len(sv.values); got <= 1 { continue } diff --git a/widgets/linechart/linechart_test.go b/widgets/linechart/linechart_test.go index 4451b8f..6d3e278 100644 --- a/widgets/linechart/linechart_test.go +++ b/widgets/linechart/linechart_test.go @@ -133,6 +133,33 @@ func TestLineChartDraws(t *testing.T) { return ft }, }, + { + desc: "empty with just one point", + canvas: image.Rect(0, 0, 3, 4), + writes: func(lc *LineChart) error { + return lc.Series("first", []float64{1}) + }, + wantCapacity: 2, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + + // Y and X axis. + lines := []draw.HVLine{ + {Start: image.Point{1, 0}, End: image.Point{1, 2}}, + {Start: image.Point{1, 2}, End: image.Point{2, 2}}, + } + testdraw.MustHVLines(c, lines) + + // Value labels. + testdraw.MustText(c, "…", image.Point{0, 0}) + testdraw.MustText(c, "0", image.Point{0, 1}) + testdraw.MustText(c, "0", image.Point{2, 3}) + + testcanvas.MustApply(c, ft) + return ft + }, + }, { desc: "sets axes cell options", canvas: image.Rect(0, 0, 3, 4), diff --git a/widgets/linechart/options.go b/widgets/linechart/options.go index 39f3a62..7f23c06 100644 --- a/widgets/linechart/options.go +++ b/widgets/linechart/options.go @@ -151,10 +151,11 @@ func YAxisCustomScale(min, max float64) Option { // XAxisUnscaled when provided, stops the LineChart from rescaling the X axis // when it can't fit all the values in the series, instead the LineCharts only -// displays the last n values that fit into its width. This results in hiding -// some values from the beginning of the series that didn't fit completely and -// might hide some shorter series as this effectively maked the X axis start at -// a non-zero value. +// displays the last n values that fit into its width. This is useful to create +// an impression of values rolling through the linechart right to left. Note +// that this results in hiding of values from the beginning of the series +// that didn't fit completely and might hide some shorter series as this +// effectively makes the X axis start at a non-zero value. // // The default behavior is to rescale the X axis to display all the values. // This option takes no effect if all the values on the series fit into the