mirror of
https://github.com/Luzifer/mondash.git
synced 2024-12-23 04:21:18 +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 + ", "
|
||||
}
|
||||
s = s + "" + strconv.Itoa(int(v.Time.Unix())) + ""
|
||||
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 + "]"
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (dm *dashboardMetric) DataHistory() string {
|
||||
s := "["
|
||||
for i, v := range dm.HistoricalData {
|
||||
if i != 0 {
|
||||
s = s + ", "
|
||||
}
|
||||
s = s + strconv.FormatFloat(v.Value, 'g', 4, 64)
|
||||
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 + "]"
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
|
||||
|
||||
<!-- Chartist Library -->
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
|
||||
<script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
|
||||
<script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
|
||||
<script>
|
||||
function timeConverter(UNIX_timestamp){
|
||||
var a = new Date(UNIX_timestamp*1000);
|
||||
|
@ -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