-
Notifications
You must be signed in to change notification settings - Fork 24
/
wiki.html
161 lines (138 loc) · 4.98 KB
/
wiki.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
<!DOCTYPE html>
<html>
<head>
<title>Decodable Tinybird.co Example</title>
<style>
.mychart {
height: 700px;
width: 700px;
}
</style>
</head>
<body>
<table>
<tr>
<td><div class="mychart"><canvas id="lineChart" width="500px" height="500px"></canvas></div></td>
<td><div class="mychart"><canvas id="barChart" width="500px" height="500px"></canvas></div></td>
</tr>
</table>
<script src="secrets/secrets.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
function colorize(opaque) {
return (ctx) => {
const v = ctx.parsed.y;
const c = v < -50 ? '#D60000'
: v < 0 ? '#F46300'
: v < 50 ? '#0358B6'
: '#44DE28';
return opaque ? c : Utils.transparentize(c, 1 - Math.abs(v / 150));
};
}
const lineCtx = document.getElementById('lineChart');
const lineChart = new Chart(lineCtx, {
type: 'line',
data: {
datasets: [{
label: 'Changes',
backgroundColor: 'green',
borderColor: 'green',
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
const barCtx = document.getElementById('barChart');
const barChart = new Chart(barCtx, {
type: 'bar',
data: {
datasets: [{
label: 'Author Update Count',
backgroundColor: 'blue',
borderColor: 'rgb(255, 99, 132)',
borderWidth: 1
}]
},
options: {
indexAxis: 'y',
scales: {
y: {
beginAtZero: true
}
},
// interaction: {
// mode: 'dataset'
// },
onClick: (e, i) => {
console.log(e)
console.log(i)
console.log()
var author = e.chart.config.data.labels[i[0].index];
window.open("author.html?author="+author);
},
elements: {
bar: {
backgroundColor: colorize(false),
borderColor: colorize(true),
borderWidth: 2
}
}
}
});
</script>
<script type="module">
const arrayColumn = (arr, n) => arr.map((x) => x[n]);
const colors = ['red', 'blue', 'green', 'purple', 'black']
async function runLine() {
let url = new URL(`https://api.us-east.tinybird.co/v0/pipes/decodable_wikipedia_pipe_activity.json`)
const result = await fetch(url, lineChartHeaders)
.then(r => r.json())
.then(r => r)
.catch(e => e.toString())
if (!result.data) {
console.error(`there is a problem running the query: ${result}`);
} else {
console.table(result.data)
console.log(arrayColumn(result.data, 'time'));
console.log("** Query columns **")
for (let column of result.meta) {
console.log(`${column.name} -> ${column.type}`)
}
lineChart.config.data.labels = arrayColumn(result.data, 'time')
lineChart.config.data.datasets[0].data = arrayColumn(result.data, 'count')
lineChart.update()
}
setTimeout(runLine, 20 * 1000);
}
runLine()
async function runBar() {
let url = new URL(`https://api.us-east.tinybird.co/v0/pipes/decodable_wikipedia_pipe_by_author.json`)
const result = await fetch(url, barChartHeaders)
.then(r => r.json())
.then(r => r)
.catch(e => e.toString())
if (!result.data) {
console.error(`there is a problem running the query: ${result}`);
} else {
console.table(result.data)
console.log(arrayColumn(result.data, 'time'));
console.log("** Query columns **")
for (let column of result.meta) {
console.log(`${column.name} -> ${column.type}`)
}
barChart.config.data.labels = arrayColumn(result.data, 'author')
barChart.config.data.datasets[0].data = arrayColumn(result.data, 'count')
barChart.update()
}
setTimeout(runBar, 20 * 1000);
}
runBar()
</script>
</body>
</html>