smon/views/pages/datapoint_values.gotmpl

53 lines
1.5 KiB
Go Template
Raw Normal View History

2024-05-05 20:16:28 +02:00
{{ define "page" }}
{{ $version := .VERSION }}
2024-06-27 08:59:34 +02:00
{{ $graph := and (eq .Data.Display "graph") (eq .Data.Datapoint.Datatype "INT") }}
2024-06-25 08:59:07 +02:00
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/{{ .CONFIG.THEME }}/datapoints.css">
2024-06-26 11:58:54 +02:00
<script src="/js/{{ .VERSION }}/lib/plotly-2.32.0.min.js" charset="utf-8"></script>
2024-05-05 20:16:28 +02:00
{{ block "page_label" . }}{{end}}
2024-06-27 08:59:34 +02:00
<form action="/datapoint/values/{{ .Data.Datapoint.ID }}" method="get">
{{ if eq .Data.Datapoint.Datatype "INT" }}
<div>
<input name="display" value="graph" type="radio" id="display-graph" {{ if $graph }} checked {{ end}}> <label for="display-graph">Graph</label>
<input name="display" value="list" type="radio" id="display-list" {{ if not $graph }} checked {{ end }}> <label for="display-list">List</label>
</div>
{{ end }}
<input name="f" type="datetime-local" value="{{ .Data.TimeFrom }}">
<input name="t" type="datetime-local" value="{{ .Data.TimeTo }}">
<button>OK</button>
</form>
<br><br>
{{ if $graph }}
2024-06-27 09:14:02 +02:00
<div class="graph">
<div id="graph-values"></div>
</div>
2024-06-26 11:58:54 +02:00
<script type="text/javascript">
2024-06-27 09:14:02 +02:00
const graphValues = document.getElementById('graph-values');
2024-06-26 11:58:54 +02:00
let data = {{ .Data }}
let x = data.Values.map(d => d.Ts)
let y = data.Values.map(d => d.ValueInt.Int64)
Plotly.newPlot(
2024-06-27 09:14:02 +02:00
graphValues,
2024-06-26 11:58:54 +02:00
[
{
x,
y,
},
], {
margin: { t: 0 },
}
);
</script>
2024-06-26 12:01:47 +02:00
{{ else }}
<div id="values">
{{ range .Data.Values }}
<div class="value">{{ format_time .Ts }}</div>
<div class="value">{{ .Value }}</div>
{{ end }}
</div>
2024-06-26 11:58:54 +02:00
{{ end }}
2024-05-05 20:16:28 +02:00
{{ end }}