-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.templ
155 lines (146 loc) · 3.22 KB
/
main.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import "fmt"
templ statsOverviewTempl(hits []Hit) {
<!DOCTYPE html>
<html lang="en">
<head>
@defaultHead()
<title>NanoAnalytics / Tracked Paths</title>
</head>
<body>
<header class="container">
<h1 style="margin-top: 3rem">NanoAnalytics / Tracked Paths</h1>
</header>
<main class="container">
<article>
<ul>
for _, hit := range hits {
<li><h5><a href={ templ.URL(fmt.Sprintf("/stats/%s", hit.Path)) }>{ hit.Path }</a></h5></li>
}
</ul>
</article>
</main>
@footerTempl()
</body>
</html>
}
script lineGraph(stats []stat, canvasId string) {
const ctx = document.getElementById(canvasId);
new Chart(ctx, {
type: "line",
options: {
// aspectRatio: 4,
plugins: {
legend: {
display: false,
}
}
},
data: {
labels: stats.map(stat => stat.Name),
datasets: [{
label: "Users",
data: stats.map(stat => stat.Count),
borderWidth: 2,
tension: 0.5
}],
}
})
}
script barGraph(stats []stat, canvasId string) {
const ctx = document.getElementById(canvasId);
new Chart(ctx, {
type: "bar",
options: {
indexAxis: "y",
aspectRatio: 4,
scales: {
y: {
beginAtZero: true,
}
},
plugins: {
legend: {
display: false,
}
}
},
data: {
labels: stats.map(stat => stat.Name),
datasets: [{
label: "Users",
data: stats.map(stat => stat.Count),
borderWidth: 1,
}],
}
})
}
templ statsTempl(path string, views []stat, actions []stat, countries []stat, browsers []stat, devices []stat, referrers []stat) {
<!DOCTYPE html>
<html lang="en">
<head>
@defaultHead()
<title>NanoAnalytics / { path }</title>
</head>
<body>
<header class="container">
<h1 style="margin-top: 3rem">NanoAnalytics / { path }</h1>
</header>
<main class="container">
<article>
<h2>Views</h2>
<canvas id="views"></canvas>
@lineGraph(views, "views")
</article>
<div class="grid">
<article>
<h2>Actions</h2>
<canvas id="actions"></canvas>
@barGraph(actions, "actions")
</article>
<article>
<h2>Countries</h2>
<canvas id="countries"></canvas>
@barGraph(countries, "countries")
</article>
</div>
<div class="grid">
<article>
<h2>Browsers</h2>
<canvas id="browsers"></canvas>
@barGraph(browsers, "browsers")
</article>
<article>
<h2>Devices</h2>
<canvas id="devices"></canvas>
@barGraph(devices, "devices")
</article>
</div>
<div class="grid">
<article>
<h2>Referrers</h2>
<canvas id="referrers"></canvas>
@barGraph(referrers, "referrers")
</article>
<div></div>
</div>
</main>
@footerTempl()
</body>
</html>
}
templ footerTempl() {
<footer class="container">
<small>v0.2.3 • by <a href="https://github.com/2mal3" target="_blank">2mal3</a></small>
</footer>
}
templ defaultHead() {
<meta charset="UTF-8"/>
<meta name="description" content="Analytics for your apps."/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
}