-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
180 lines (158 loc) · 4.9 KB
/
example.html
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<script src="dist/main.js?v=10"></script>
<script src="node_modules/hawk.javascript/dist/hawk.js"></script>
<script>
new HawkCatcher({
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm9qZWN0SWQiOiI1ZDY3MGVmMzc3YzM3YTAwMTIxMTYyNjEiLCJpYXQiOjE1NjcwNDA5ODN9.NLR229AS0qhLLR8UrDKF97Kg2L2snVHAfEV-yfnCC68',
collectorEndpoint: 'ws://localhost:3000/ws',
release: 26141
});
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
body {
max-width: 640px;
margin: 0 auto;
padding: 40px 0;
font-family: Roboto, 'Helvetica Neue', -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,sans-serif;
}
body.night-mode {
background: #2b3037;
color: #fff;
}
.graph {
margin-bottom: 50px;
}
.mode-toggler {
text-align: center;
padding: 20px;
font-size: 17px;
color: #108BE3;
font-family: Roboto, 'Helvetica Neue', -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,sans-serif;
cursor: pointer;
}
#log {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 15px;
color: #eff7ff;
background: #1f3144eb;
font-size: 12px;
font-family: Roboto;
letter-spacing: 0.4px;
box-shadow: 0 0 1px rgba(0,0,0,.2);
}
</style>
<body>
<div id="graphs"></div>
</body>
<script>
const wrapper = document.getElementById('graphs');
const modeToggler = document.createElement('div');
modeToggler.classList.add('mode-toggler');
modeToggler.textContent = 'Switch to Night Mode';
/**
* Created Graphon instances will be stored here;
*/
const instances = [];
const sources = [
{
title: 'Example with zeros',
url: './data/example-zeros.csv',
colors: ['#3497ED', '#f91d72'],
labels: ['Registered', 'Articles'],
},
{
title: 'Example lines chart',
url: './data/example.csv',
urlByMonth: './data/example-month.csv',
colors: ['#3497ED', '#F5BD25', '#f91d72'],
labels: ['Registered', 'Articles', 'Comments']
},
{
title: 'Example area charts',
url: './data/example.csv',
urlByMonth: './data/example-month.csv',
colors: ['#3497ED', '#F5BD25', '#f91d72'],
labels: ['Registered', 'Articles', 'Comments'],
type: 'area'
},
{
title: 'Example 2-axis chart',
url: './data/example-2-axis.csv',
colors: ['#3497ED', '#f91d72'],
labels: ['Visitors', 'Registered'],
scaled: true
},
{
title: 'Example grouped by month',
url: './data/example-month.csv',
byMonth: true,
colors: ['#3497ED', '#F5BD25', '#f91d72'],
labels: ['Registered', 'Articles', 'Comments'],
type: 'bar'
},
{
title: 'Example grouped by month with zero values',
url: './data/example-month-zero.csv',
byMonth: true,
colors: ['#3497ED', '#f91d72'],
labels: ['Registered', 'Comments'],
type: 'bar'
},
{
title: 'Example with floats',
url: './data/example-floats.csv',
colors: ['#3497ED', '#f91d72'],
labels: ['1', '2'],
},
];
sources.forEach(async (source, idx) => {
/**
* Create a holder
*/
const holder = document.createElement('div');
const graphId = `telegraph-${idx}`;
holder.id = graphId;
holder.classList.add('graph');
wrapper.appendChild(holder);
if (idx === 0) {
wrapper.appendChild(modeToggler);
}
const data = await fetch(source.url).then((response) => response.text());
let dataByMonth = null;
if (source.urlByMonth) {
dataByMonth = await fetch(source.urlByMonth).then((response) => response.text());
}
const graph = new Graphon({
title: source.title,
holderId: graphId,
data,
dataByMonth,
type: source.type || 'line',
colors: source.colors,
titles: source.labels,
byMonth: source.byMonth,
scaled: source.scaled,
height: 250,
showLegend: source.showLegend !== undefined ? source.showLegend : true,
showTypeSwitchers: source.showTypeSwitchers !== undefined ? source.showTypeSwitchers : true,
});
instances.push(graph);
});
/**
* Handler for Toggle Night mode button
*/
modeToggler.addEventListener('click', () => {
instances.forEach( graph => {
graph.toggleNightMode();
});
document.body.classList.toggle('night-mode');
if (document.body.classList.contains('night-mode')){
modeToggler.textContent = 'Switch to Day Mode';
} else {
modeToggler.textContent = 'Switch to Night Mode';
}
});
</script>