Improving option comment and test coverage.

This commit is contained in:
Jakub Sobon 2019-02-16 01:01:04 -05:00
parent 587185eb73
commit 52ae7d1807
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
3 changed files with 33 additions and 5 deletions

View File

@ -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
}

View File

@ -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),

View File

@ -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