-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
191 lines (188 loc) · 7.03 KB
/
index.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
181
182
183
184
185
186
187
188
189
190
191
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
</head>
<body>
<div id="app">
<v-app>
<v-content>
<v-container>
<v-row dense align="end">
<v-col>
<h1>Daily Pulls from Docker Hub</h1>
{{ start ? start.toUTCString() : '...' }} - {{ end ? end.toUTCString() : '...' }} ({{ Number(days).toFixed() }} days)
</v-col>
<v-col md="auto">
<v-btn small text v-for="b in buttons" :key="b.text" @click="zoom(b.level)">
{{ b.text }}
</v-btn>
</v-col>
</v-row>
<v-row dense>
<v-col id="bar_chart">
</v-col>
</v-row>
<v-row dense>
<v-col id="timeline_chart">
</v-col>
</v-row>
<v-row dense>
<v-spacer></v-spacer>
<v-col md="auto">
<small>Last updated: {{ lastUpdated ? lastUpdated.toUTCString() : '...' }} (loaded in: {{ loadtime }}ms)</small>
</v-col>
</v-row>
</v-container>
</v-content>
</v-app>
</div>
<script>
Vue.prototype.$http = axios;
let app = new Vue({
el: '#app',
vuetify: new Vuetify(),
components: {
},
data: () => {
return {
loadtime: 0,
db: [],
data: {},
colors: {},
table: null,
images: [],
start: null,
end: null,
stats: null,
days: 0,
timeline: null,
bar: null,
buttons: [
{text: 'day', level: 1000 * 60 * 60 * 24},
{text: 'week', level: 1000 * 60 * 60 * 24 * 7},
{text: 'month', level: 1000 * 60 * 60 * 24 * 30},
{text: 'quarter', level: 1000 * 60 * 60 * 24 * 30 * 3},
{text: 'all', level: 0},
]
};
},
mounted: function () {
const now = new Date();
this.$http.get('config/sources.json')
.then((sources) => {
sources.data.forEach(source => this.colors[`${source['user']}/${source['name']}`] = source['color']);
this.$http.get('data/db.json')
.then((db) => {
this.loadtime = new Date() - now;
this.db = db.data;
this.images = Object.keys(this.db.slice(-1)[0]).slice(1);
const cols = Object.keys(this.db.slice(-1)[0]).map((col) => {
return {
label: col,
type: (col == 'timestamp' ? 'datetime' : 'number'),
};
});
const rows = this.db.map((rowobj) => {
const c = cols.map((col) => {
let v = rowobj[col['label']]
if (col['label'] == 'timestamp') {
v = new Date(v * 1000);
}
return {v};
});
return {c};
});
this.data = {
cols,
rows,
};
// https://github.com/google/google-visualization-issues/issues/2794
google.charts.load('current', {
'packages': [
'annotatedtimeline',
'corechart',
'bar'
]
});
google.charts.setOnLoadCallback(this.drawChart);
});
});
},
computed: {
lastUpdated: function () {
const last = this.db.slice(-1)[0];
if (last && 'timestamp' in last) {
return new Date (last['timestamp'] * 1000);
} else {
return null;
}
},
},
methods: {
zoom: function (level) {
if (level) {
this.start = new Date(this.end - level);
} else {
let {min, max} = this.table.getColumnRange(0);
this.start = min;
this.end = max
}
this.timeline.setVisibleChartRange(this.start, this.end);
this.dailyStats();
},
updateRange: function (e) {
this.start = e['start'];
this.end = e['end'];
this.dailyStats();
},
dailyStats: function () {
const view = new google.visualization.DataView(this.table);
view.setRows(view.getFilteredRows([
{ column: 0, minValue: this.start, maxValue: this.end }
]));
let {min, max} = view.getColumnRange(0);
this.days = (max-min) / (1000 * 60 * 60 * 24);
const data = this.images.map((image, index) => {
let {min, max} = view.getColumnRange(index+1);
const pulls = (max - min) / this.days;
this.stats.setCell(index, 1, pulls);
this.stats.setCell(index, 3, numeral(pulls).format('0.0a'));
});
this.bar.draw(this.stats, {
height: 300,
chartArea: { left: '10%', top: 0, width: '100%', height: '90%' },
legend: { position: "none" },
});
},
drawChart: function () {
this.table = new google.visualization.DataTable(this.data);
this.timeline = new google.visualization.AnnotatedTimeLine(document.getElementById('timeline_chart'));
this.timeline.draw(this.table, {
displayAnnotations: true,
displayZoomButtons: false,
colors: this.images.map(i => this.colors[i]),
});
const r = this.timeline.getVisibleChartRange();
this.start = r['start'];
this.end = r['end'];
google.visualization.events.addListener(this.timeline, 'rangechange', this.updateRange);
let stats = [
['', 'Pulls', { role: 'style' }, { role: 'annotation' } ],
];
this.images.forEach(e => stats.push([e.split('/')[1], 0, this.colors[e], 'foobar']));
this.stats = new google.visualization.arrayToDataTable(stats);
this.bar = new google.visualization.BarChart(document.getElementById('bar_chart'));
this.zoom(1000 * 60 * 60 * 24);
},
},
});
</script>
</body>
</html>