mirror of
https://github.com/Luzifer/mondash.git
synced 2024-11-10 00:20:02 +00:00
Display only 60 items in graph
The decision is left to the template so template designers can easily change this behavior by removing the lastNItems filter in the template itself. Also the value can be changed easily. fixes #4
This commit is contained in:
parent
ee8770b9d8
commit
91b4e1a21c
4 changed files with 31 additions and 22 deletions
16
filters/filter.go
Normal file
16
filters/filter.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package filters
|
||||
|
||||
import "github.com/flosch/pongo2"
|
||||
|
||||
func init() {
|
||||
pongo2.RegisterFilter("lastNItems", filterLastNItems)
|
||||
}
|
||||
|
||||
func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||
if !in.CanSlice() {
|
||||
return in, nil
|
||||
}
|
||||
|
||||
from := in.Len() - param.Integer()
|
||||
return in.Slice(from, in.Len()), nil
|
||||
}
|
1
main.go
1
main.go
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/flosch/pongo2"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
_ "github.com/Luzifer/mondash/filters"
|
||||
_ "github.com/flosch/pongo2-addons"
|
||||
)
|
||||
|
||||
|
|
26
structs.go
26
structs.go
|
@ -166,27 +166,21 @@ func (dm *dashboardMetric) StatisticalStatus() string {
|
|||
return "OK"
|
||||
}
|
||||
|
||||
func (dm *dashboardMetric) LabelHistory() string {
|
||||
s := "["
|
||||
for i, v := range dm.HistoricalData {
|
||||
if i != 0 {
|
||||
s = s + ", "
|
||||
func (dm *dashboardMetric) LabelHistory() []string {
|
||||
s := []string{}
|
||||
for _, v := range dm.HistoricalData[len(dm.HistoricalData)-60:] {
|
||||
s = append(s, strconv.Itoa(int(v.Time.Unix())))
|
||||
}
|
||||
s = s + "" + strconv.Itoa(int(v.Time.Unix())) + ""
|
||||
}
|
||||
s = s + "]"
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (dm *dashboardMetric) DataHistory() string {
|
||||
s := "["
|
||||
for i, v := range dm.HistoricalData {
|
||||
if i != 0 {
|
||||
s = s + ", "
|
||||
func (dm *dashboardMetric) DataHistory() []string {
|
||||
s := []string{}
|
||||
for _, v := range dm.HistoricalData[len(dm.HistoricalData)-60:] {
|
||||
s = append(s, strconv.FormatFloat(v.Value, 'g', 4, 64))
|
||||
}
|
||||
s = s + strconv.FormatFloat(v.Value, 'g', 4, 64)
|
||||
}
|
||||
s = s + "]"
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
|
@ -110,11 +110,9 @@
|
|||
<script>
|
||||
var data = {
|
||||
// A labels array that can contain any sort of values
|
||||
labels: {{ metric.LabelHistory }},
|
||||
labels: [{{ metric.LabelHistory|lastNItems:"60"|join:"," }}],
|
||||
// Our series array that contains series objects or in this case series data arrays
|
||||
series: [
|
||||
{{ metric.DataHistory }}
|
||||
]
|
||||
series: [[{{ metric.DataHistory|lastNItems:"60"|join:"," }}]]
|
||||
};
|
||||
|
||||
for (var i = 0; i < data.labels.length; i++) {
|
||||
|
|
Loading…
Reference in a new issue