-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard.js
More file actions
444 lines (395 loc) · 13.9 KB
/
dashboard.js
File metadata and controls
444 lines (395 loc) · 13.9 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/**
* WDProp Dashboard
* Real-time data from Wikidata with animations
*/
const dashboardEndpoint = 'https://query.wikidata.org/sparql';
// Counter animation for stat cards
function animateCounter(element, target) {
const duration = 2000; // 2 seconds
const start = 0;
const increment = target / (duration / 16); // 60fps
let current = start;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
element.textContent = target.toLocaleString();
clearInterval(timer);
} else {
element.textContent = Math.floor(current).toLocaleString();
}
}, 16);
}
// Fetch data from Wikidata
function queryDashboardData(sparqlQuery) {
const fullUrl = dashboardEndpoint + '?query=' + encodeURIComponent(sparqlQuery) + "&format=json";
const headers = { 'Accept': 'application/sparql-results+json' };
return fetch(fullUrl, { headers })
.then(response => response.json())
.catch(error => {
console.error('Dashboard query error:', error);
return null;
});
}
// Get total count of properties
function getTotalPropertiesCount() {
const query = `PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT (COUNT(DISTINCT ?property) as ?count)
WHERE {
?property rdf:type wikibase:Property.
}`;
return queryDashboardData(query).then(json => {
if (json && json.results && json.results.bindings.length > 0) {
return parseInt(json.results.bindings[0].count.value);
}
return 0;
});
}
// Get total count of languages
function getLanguagesCount() {
const query = `SELECT (COUNT(DISTINCT ?language) as ?count)
WHERE {
[] wdt:P31 wd:Q10876391;
wdt:P407 [wdt:P424 ?language]
}`;
return queryDashboardData(query).then(json => {
if (json && json.results && json.results.bindings.length > 0) {
return parseInt(json.results.bindings[0].count.value);
}
return 0;
});
}
// Get total count of datatypes
function getDatatypesCount() {
const query = `PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT (COUNT(DISTINCT ?datatype) as ?count)
WHERE {
[] wikibase:propertyType ?datatype.
}`;
return queryDashboardData(query).then(json => {
if (json && json.results && json.results.bindings.length > 0) {
return parseInt(json.results.bindings[0].count.value);
}
return 0;
});
}
// Get total count of property classes (mirrors allClassesQuery in wdprop.js)
function getPropertyClassesCount() {
const query = `PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT (COUNT(DISTINCT ?item) as ?count)
WHERE {
{
?item wdt:P1963 [].
}
UNION
{
?property a wikibase:Property;
(wdt:P31|wdt:P279) ?item.
}
}`;
return queryDashboardData(query).then(json => {
if (json && json.results && json.results.bindings.length > 0) {
return parseInt(json.results.bindings[0].count.value);
}
return 0;
});
}
// Get translation statistics for top languages
function getTranslationStats() {
const languages = [
{ code: 'en', name: 'English' },
{ code: 'de', name: 'German' },
{ code: 'fr', name: 'French' },
{ code: 'es', name: 'Spanish' },
{ code: 'ja', name: 'Japanese' }
];
const promises = languages.map(lang => {
const query = `PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT
(COUNT(DISTINCT ?property) as ?total)
(COUNT(DISTINCT ?label) as ?translated)
WHERE {
?property rdf:type wikibase:Property.
OPTIONAL {
?property rdfs:label ?label.
FILTER(lang(?label)="${lang.code}")
}
}`;
return queryDashboardData(query).then(json => {
if (json && json.results && json.results.bindings.length > 0) {
const binding = json.results.bindings[0];
const total = parseInt(binding.total.value);
const translated = parseInt(binding.translated.value);
const percentage = total > 0 ? Math.round((translated / total) * 100) : 0;
return {
code: lang.code,
name: lang.name,
percentage: percentage,
translated: translated,
total: total
};
}
return { code: lang.code, name: lang.name, percentage: 0, translated: 0, total: 0 };
});
});
return Promise.all(promises);
}
// Update hero stats with real data
function updateHeroStats() {
const stats = document.querySelectorAll('.stat-value[data-target]');
// Update Total Properties
getTotalPropertiesCount().then(count => {
if (count > 0 && stats[0]) {
stats[0].setAttribute('data-target', count);
animateCounter(stats[0], count);
}
});
// Update Languages
getLanguagesCount().then(count => {
if (count > 0 && stats[1]) {
stats[1].setAttribute('data-target', count);
animateCounter(stats[1], count);
}
});
// Update Data Types
getDatatypesCount().then(count => {
if (count > 0 && stats[2]) {
stats[2].setAttribute('data-target', count);
animateCounter(stats[2], count);
}
});
// Update Property Classes
getPropertyClassesCount().then(count => {
if (count > 0 && stats[3]) {
stats[3].setAttribute('data-target', count);
animateCounter(stats[3], count);
}
});
}
// Update translation progress bars with real data
function updateTranslationProgress() {
getTranslationStats().then(stats => {
stats.forEach((lang, index) => {
const progressItems = document.querySelectorAll('.progress-item');
if (progressItems[index]) {
const labelEl = progressItems[index].querySelector('.progress-label');
const valueEl = progressItems[index].querySelector('.progress-value');
const barEl = progressItems[index].querySelector('.progress-bar');
if (labelEl) labelEl.textContent = `${lang.name} (${lang.code})`;
if (valueEl) valueEl.textContent = `${lang.percentage}%`;
if (barEl) {
barEl.style.width = `${lang.percentage}%`;
// Update color class based on percentage
barEl.classList.remove('high', 'medium', 'low');
if (lang.percentage >= 90) {
barEl.classList.add('high');
} else if (lang.percentage >= 50) {
barEl.classList.add('medium');
} else {
barEl.classList.add('low');
}
}
}
});
});
}
// Animate all stat values on page load
function initDashboard() {
// Show loading state
const statValues = document.querySelectorAll('.stat-value[data-target]');
statValues.forEach(stat => {
stat.textContent = '...';
});
// Fetch and update real data
updateHeroStats();
updateTranslationProgress();
// Animate progress bars
setTimeout(() => {
const progressBars = document.querySelectorAll('.progress-bar');
progressBars.forEach((bar, index) => {
const width = bar.style.width;
bar.style.width = '0%';
setTimeout(() => {
bar.style.width = width;
}, 500 + (index * 100));
});
}, 1000);
// Add entrance animations to cards
const cards = document.querySelectorAll('.stat-card, .dashboard-widget, .project-card');
cards.forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
setTimeout(() => {
card.style.transition = 'all 0.6s cubic-bezier(0.4, 0, 0.2, 1)';
card.style.opacity = '1';
card.style.transform = 'translateY(0)';
}, 100 + (index * 50));
});
}
// Update last updated time
function updateLastUpdatedTime() {
const statusItems = document.querySelectorAll('.status-item');
statusItems.forEach(item => {
const label = item.querySelector('.status-label');
if (label && label.textContent === 'Last Updated') {
const valueElement = item.querySelector('.status-value');
if (valueElement) {
const now = new Date();
valueElement.textContent = 'Just now';
}
}
});
}
// Search input enhancements
function initSearchInput() {
const searchInput = document.querySelector('.search-input');
if (searchInput) {
searchInput.addEventListener('focus', () => {
const container = searchInput.closest('.search-widget');
if (container) {
container.style.transform = 'translateY(-4px)';
container.style.boxShadow = '0 12px 40px var(--shadow-color)';
}
});
searchInput.addEventListener('blur', () => {
const container = searchInput.closest('.search-widget');
if (container) {
container.style.transform = '';
container.style.boxShadow = '';
}
});
}
}
// Add ripple effect to action buttons
function addRippleEffect(button, event) {
const ripple = document.createElement('span');
const rect = button.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = event.clientX - rect.left - size / 2;
const y = event.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
const rippleContainer = button.querySelector('.ripple');
if (rippleContainer) {
rippleContainer.remove();
}
button.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
}
// Initialize ripple effects on action buttons
function initRippleEffects() {
const actionButtons = document.querySelectorAll('.action-btn');
actionButtons.forEach(button => {
button.addEventListener('click', (e) => {
addRippleEffect(button, e);
});
});
}
// Add CSS for ripple effect dynamically
function addRippleStyles() {
const style = document.createElement('style');
style.textContent = `
.action-btn {
position: relative;
overflow: hidden;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.4);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(2);
opacity: 0;
}
}
`;
document.head.appendChild(style);
}
// Get Top Properties from MediaWiki
function getTopPropertiesFromMediaWiki() {
const url = 'https://www.wikidata.org/w/api.php?action=query&prop=links&pllimit=500&origin=*&titles=Wikidata:Database_reports/List_of_properties/Top100&format=json';
return fetch(url)
.then(response => response.json())
.then(json => {
const properties = [];
for (const page of Object.keys(json.query.pages)) {
for (const link of json.query.pages[page].links || []) {
if (link.title.indexOf("Property:") !== -1 && link.title !== "Property:P") {
const propertyId = link.title.replace("Property:", "");
properties.push(propertyId);
}
}
}
return properties.slice(0, 5); // Return top 5
})
.catch(error => {
console.error('Error fetching top properties:', error);
return [];
});
}
// Get property label for a given property ID
function getPropertyLabel(propertyId) {
const query = `
SELECT ?label WHERE {
wd:${propertyId} rdfs:label ?label.
FILTER(lang(?label)="en")
}
`;
return queryDashboardData(query).then(json => {
if (json && json.results && json.results.bindings.length > 0) {
return json.results.bindings[0].label.value;
}
return propertyId;
});
}
// Update Top Properties table with real data
function updateTopProperties() {
getTopPropertiesFromMediaWiki().then(propertyIds => {
if (propertyIds.length === 0) return;
const table = document.querySelector('.top-properties-table');
if (!table) return;
// Clear existing rows
table.innerHTML = '';
// Add new rows with real data
propertyIds.forEach((propId, index) => {
getPropertyLabel(propId).then(label => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td class="rank">#${index + 1}</td>
<td>
<div class="property-name">${label}</div>
<div class="property-id">${propId}</div>
</td>
<td class="usage-count">Top ${index + 1}</td>
`;
table.appendChild(tr);
});
});
});
}
// Initialize everything when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
initDashboard();
initSearchInput();
initRippleEffects();
addRippleStyles();
updateLastUpdatedTime();
updateTopProperties();
});
} else {
initDashboard();
initSearchInput();
initRippleEffects();
addRippleStyles();
updateLastUpdatedTime();
updateTopProperties();
}