mirror of
https://github.com/Luzifer/mondash.git
synced 2024-12-22 20:11:18 +00:00
Fix: Do not try to load negative slice bounds
This commit is contained in:
parent
f4164b4a86
commit
6cc4dc4572
2 changed files with 18 additions and 2 deletions
|
@ -12,5 +12,9 @@ func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *po
|
|||
}
|
||||
|
||||
from := in.Len() - param.Integer()
|
||||
if from < 0 {
|
||||
from = 0
|
||||
}
|
||||
|
||||
return in.Slice(from, in.Len()), nil
|
||||
}
|
||||
|
|
16
structs.go
16
structs.go
|
@ -168,7 +168,13 @@ func (dm *dashboardMetric) StatisticalStatus() string {
|
|||
|
||||
func (dm *dashboardMetric) LabelHistory() []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())))
|
||||
}
|
||||
|
||||
|
@ -177,7 +183,13 @@ func (dm *dashboardMetric) LabelHistory() []string {
|
|||
|
||||
func (dm *dashboardMetric) DataHistory() []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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue