Skip to content

Commit

Permalink
series: Fix panic from previous changes when data sizes vary
Browse files Browse the repository at this point in the history
jentfoo committed Jan 27, 2025

Verified

This commit was signed with the committer’s verified signature.
jentfoo Mike Jensen
1 parent 63f6d76 commit 36b9d8a
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion series.go
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ func (sl SeriesList) getMinMaxSumMax(yaxisIndex int, calcSum bool) (float64, flo
max := -math.MaxFloat64
var sums []float64
if calcSum {
sums = make([]float64, len(sl[0].Data)) // all data sizes assumed to be the same
sums = make([]float64, sl.getMaxDataCount(""))
}
for _, series := range sl {
if series.YAxisIndex != yaxisIndex {
6 changes: 4 additions & 2 deletions series_test.go
Original file line number Diff line number Diff line change
@@ -29,12 +29,14 @@ func TestSeriesLists(t *testing.T) {
seriesList := NewSeriesListBar([][]float64{
{1, 2},
{10},
{1, 2, 3, 4, 5, 6, 7, 8, 9},
})

assert.Len(t, seriesList.Filter(ChartTypeBar), 2)
assert.Len(t, seriesList.Filter(ChartTypeBar), 3)
assert.Empty(t, seriesList.Filter(ChartTypeLine))

min, max := seriesList.GetMinMax(0)
min, max, maxSum := seriesList.getMinMaxSumMax(0, true)
assert.InDelta(t, float64(12), maxSum, 0)
assert.InDelta(t, float64(10), max, 0)
assert.InDelta(t, float64(1), min, 0)
}

0 comments on commit 36b9d8a

Please sign in to comment.