1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-23 04:21:18 +00:00

Fix: Do not try to load negative slice bounds

This commit is contained in:
Knut Ahlers 2016-01-23 12:53:04 +01:00
parent f4164b4a86
commit 6cc4dc4572
2 changed files with 18 additions and 2 deletions

View file

@ -12,5 +12,9 @@ func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *po
} }
from := in.Len() - param.Integer() from := in.Len() - param.Integer()
if from < 0 {
from = 0
}
return in.Slice(from, in.Len()), nil return in.Slice(from, in.Len()), nil
} }

View file

@ -168,7 +168,13 @@ func (dm *dashboardMetric) StatisticalStatus() string {
func (dm *dashboardMetric) LabelHistory() []string { func (dm *dashboardMetric) LabelHistory() []string {
s := []string{} s := []string{}
for _, v := range dm.HistoricalData[len(dm.HistoricalData)-60:] {
labelStart := len(dm.HistoricalData) - 60
if labelStart < 0 {
labelStart = 0
}
for _, v := range dm.HistoricalData[labelStart:] {
s = append(s, strconv.Itoa(int(v.Time.Unix()))) s = append(s, strconv.Itoa(int(v.Time.Unix())))
} }
@ -177,7 +183,13 @@ func (dm *dashboardMetric) LabelHistory() []string {
func (dm *dashboardMetric) DataHistory() []string { func (dm *dashboardMetric) DataHistory() []string {
s := []string{} s := []string{}
for _, v := range dm.HistoricalData[len(dm.HistoricalData)-60:] {
dataStart := len(dm.HistoricalData) - 60
if dataStart < 0 {
dataStart = 0
}
for _, v := range dm.HistoricalData[dataStart:] {
s = append(s, strconv.FormatFloat(v.Value, 'g', 4, 64)) s = append(s, strconv.FormatFloat(v.Value, 'g', 4, 64))
} }