web/sparkline: guard days[i] against shorter days slice in RenderChart
This commit is contained in:
@@ -141,7 +141,8 @@ type ChartOpts struct {
|
|||||||
// RenderChart returns an inline SVG <svg> with up to two y-axes,
|
// RenderChart returns an inline SVG <svg> with up to two y-axes,
|
||||||
// one polyline per series, hover-dot per data point, and X-axis
|
// one polyline per series, hover-dot per data point, and X-axis
|
||||||
// labels at start / midpoint / end. With no series or empty
|
// labels at start / midpoint / end. With no series or empty
|
||||||
// series, renders a faint baseline + EmptyLabel centred.
|
// series, renders a faint baseline + EmptyLabel centred. Points
|
||||||
|
// beyond len(days) are ignored.
|
||||||
func RenderChart(series []Series, days []time.Time, opts ChartOpts) template.HTML {
|
func RenderChart(series []Series, days []time.Time, opts ChartOpts) template.HTML {
|
||||||
if opts.Width <= 0 {
|
if opts.Width <= 0 {
|
||||||
opts.Width = 600
|
opts.Width = 600
|
||||||
@@ -246,6 +247,9 @@ func RenderChart(series []Series, days []time.Time, opts ChartOpts) template.HTM
|
|||||||
seg.Reset()
|
seg.Reset()
|
||||||
}
|
}
|
||||||
for i, v := range s.Points {
|
for i, v := range s.Points {
|
||||||
|
if i >= len(days) {
|
||||||
|
break
|
||||||
|
}
|
||||||
if math.IsNaN(v) {
|
if math.IsNaN(v) {
|
||||||
flush()
|
flush()
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user