Skip to content

Commit

Permalink
Improving option comment and test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Feb 16, 2019
1 parent 587185e commit 52ae7d1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion widgets/linechart/linechart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
27 changes: 27 additions & 0 deletions widgets/linechart/linechart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions widgets/linechart/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52ae7d1

Please sign in to comment.