Spaces:
Running
Running
Music Pie chart
Browse files- index.html +72 -27
index.html
CHANGED
|
@@ -448,32 +448,25 @@
|
|
| 448 |
// Music Genre Pie Chart
|
| 449 |
const genreCtx = document.getElementById('genreChart').querySelector('div').getContext('2d');
|
| 450 |
const genreChart = new Chart(genreCtx, {
|
| 451 |
-
type: '
|
| 452 |
data: {
|
| 453 |
labels: ['EDM', 'Hip Hop', 'Rock', 'R&B', 'Jazz', 'Alternative', 'Pop', 'Other'],
|
| 454 |
datasets: [{
|
| 455 |
-
data: [
|
| 456 |
backgroundColor: [
|
| 457 |
-
'rgba(219, 39, 119, 0.
|
| 458 |
-
'rgba(16, 185, 129, 0.
|
| 459 |
-
'rgba(234, 179, 8, 0.
|
| 460 |
-
'rgba(239, 68, 68, 0.
|
| 461 |
-
'rgba(59, 130, 246, 0.
|
| 462 |
-
'rgba(139, 92, 246, 0.
|
| 463 |
-
'rgba(20, 184, 166, 0.
|
| 464 |
-
'rgba(156, 163, 175, 0.
|
| 465 |
-
],
|
| 466 |
-
borderColor: [
|
| 467 |
-
'rgba(219, 39, 119, 1)',
|
| 468 |
-
'rgba(16, 185, 129, 1)',
|
| 469 |
-
'rgba(234, 179, 8, 1)',
|
| 470 |
-
'rgba(239, 68, 68, 1)',
|
| 471 |
-
'rgba(59, 130, 246, 1)',
|
| 472 |
-
'rgba(139, 92, 246, 1)',
|
| 473 |
-
'rgba(20, 184, 166, 1)',
|
| 474 |
-
'rgba(156, 163, 175, 1)'
|
| 475 |
],
|
| 476 |
-
|
|
|
|
|
|
|
|
|
|
| 477 |
}]
|
| 478 |
},
|
| 479 |
options: {
|
|
@@ -482,14 +475,50 @@
|
|
| 482 |
plugins: {
|
| 483 |
legend: {
|
| 484 |
position: 'right',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
},
|
| 486 |
title: {
|
| 487 |
display: true,
|
| 488 |
-
text: 'Music Genre
|
|
|
|
| 489 |
font: {
|
| 490 |
-
size:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
}
|
| 492 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
}
|
| 494 |
}
|
| 495 |
});
|
|
@@ -534,20 +563,36 @@
|
|
| 534 |
|
| 535 |
// Initialize first button as active
|
| 536 |
document.getElementById('age-all').classList.add('active', 'bg-pink-600');
|
| 537 |
-
|
|
|
|
| 538 |
btn.addEventListener('click', function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
const filter = this.id.split('-').pop();
|
|
|
|
| 540 |
if (filter === 'all') {
|
| 541 |
-
genreChart.data.datasets[0].data = [
|
| 542 |
} else {
|
| 543 |
genreChart.data.datasets[0].data = [0, 0, 0, 0, 0, 0, 0, 0];
|
| 544 |
const index = ['edm', 'hiphop', 'rock', 'r&b', 'jazz', 'alternative', 'pop', 'other'].indexOf(filter);
|
| 545 |
-
if (index !== -1) genreChart.data.datasets[0].data[index] = [
|
| 546 |
}
|
|
|
|
| 547 |
genreChart.update();
|
| 548 |
});
|
| 549 |
});
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
| 551 |
VANTA.NET({
|
| 552 |
el: "#vanta-bg",
|
| 553 |
mouseControls: true,
|
|
|
|
| 448 |
// Music Genre Pie Chart
|
| 449 |
const genreCtx = document.getElementById('genreChart').querySelector('div').getContext('2d');
|
| 450 |
const genreChart = new Chart(genreCtx, {
|
| 451 |
+
type: 'doughnut',
|
| 452 |
data: {
|
| 453 |
labels: ['EDM', 'Hip Hop', 'Rock', 'R&B', 'Jazz', 'Alternative', 'Pop', 'Other'],
|
| 454 |
datasets: [{
|
| 455 |
+
data: [28, 22, 19, 16, 8, 5, 1, 1],
|
| 456 |
backgroundColor: [
|
| 457 |
+
'rgba(219, 39, 119, 0.8)',
|
| 458 |
+
'rgba(16, 185, 129, 0.8)',
|
| 459 |
+
'rgba(234, 179, 8, 0.8)',
|
| 460 |
+
'rgba(239, 68, 68, 0.8)',
|
| 461 |
+
'rgba(59, 130, 246, 0.8)',
|
| 462 |
+
'rgba(139, 92, 246, 0.8)',
|
| 463 |
+
'rgba(20, 184, 166, 0.8)',
|
| 464 |
+
'rgba(156, 163, 175, 0.8)'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
],
|
| 466 |
+
borderColor: 'rgba(31, 41, 55, 0.8)',
|
| 467 |
+
borderWidth: 2,
|
| 468 |
+
hoverOffset: 15,
|
| 469 |
+
cutout: '70%'
|
| 470 |
}]
|
| 471 |
},
|
| 472 |
options: {
|
|
|
|
| 475 |
plugins: {
|
| 476 |
legend: {
|
| 477 |
position: 'right',
|
| 478 |
+
labels: {
|
| 479 |
+
color: 'rgba(255, 255, 255, 0.8)',
|
| 480 |
+
padding: 20,
|
| 481 |
+
font: {
|
| 482 |
+
size: 12
|
| 483 |
+
},
|
| 484 |
+
usePointStyle: true,
|
| 485 |
+
pointStyle: 'circle'
|
| 486 |
+
}
|
| 487 |
},
|
| 488 |
title: {
|
| 489 |
display: true,
|
| 490 |
+
text: 'Music Genre Distribution',
|
| 491 |
+
color: 'rgba(255, 255, 255, 0.9)',
|
| 492 |
font: {
|
| 493 |
+
size: 18,
|
| 494 |
+
weight: 'bold'
|
| 495 |
+
},
|
| 496 |
+
padding: {
|
| 497 |
+
top: 20,
|
| 498 |
+
bottom: 20
|
| 499 |
+
}
|
| 500 |
+
},
|
| 501 |
+
tooltip: {
|
| 502 |
+
backgroundColor: 'rgba(17, 24, 39, 0.95)',
|
| 503 |
+
titleColor: '#ec4899',
|
| 504 |
+
bodyColor: 'white',
|
| 505 |
+
borderColor: 'rgba(255, 255, 255, 0.1)',
|
| 506 |
+
borderWidth: 1,
|
| 507 |
+
padding: 12,
|
| 508 |
+
callbacks: {
|
| 509 |
+
label: function(context) {
|
| 510 |
+
const label = context.label || '';
|
| 511 |
+
const value = context.raw || 0;
|
| 512 |
+
const total = context.dataset.data.reduce((a, b) => a + b, 0);
|
| 513 |
+
const percentage = Math.round((value / total) * 100);
|
| 514 |
+
return `${label}: ${percentage}% (${value})`;
|
| 515 |
+
}
|
| 516 |
}
|
| 517 |
}
|
| 518 |
+
},
|
| 519 |
+
animation: {
|
| 520 |
+
animateScale: true,
|
| 521 |
+
animateRotate: true
|
| 522 |
}
|
| 523 |
}
|
| 524 |
});
|
|
|
|
| 563 |
|
| 564 |
// Initialize first button as active
|
| 565 |
document.getElementById('age-all').classList.add('active', 'bg-pink-600');
|
| 566 |
+
// Filter buttons for genre chart
|
| 567 |
+
document.querySelectorAll('#genre-all, #genre-edm, #genre-rock, #genre-hiphop').forEach(btn => {
|
| 568 |
btn.addEventListener('click', function() {
|
| 569 |
+
// Remove active class from all buttons
|
| 570 |
+
document.querySelectorAll('#genre-all, #genre-edm, #genre-rock, #genre-hiphop').forEach(b => {
|
| 571 |
+
b.classList.remove('bg-gray-700');
|
| 572 |
+
b.classList.add('bg-opacity-70');
|
| 573 |
+
});
|
| 574 |
+
|
| 575 |
+
// Add active class to clicked button
|
| 576 |
+
this.classList.add('bg-gray-700');
|
| 577 |
+
this.classList.remove('bg-opacity-70');
|
| 578 |
+
|
| 579 |
const filter = this.id.split('-').pop();
|
| 580 |
+
|
| 581 |
if (filter === 'all') {
|
| 582 |
+
genreChart.data.datasets[0].data = [28, 22, 19, 16, 8, 5, 1, 1];
|
| 583 |
} else {
|
| 584 |
genreChart.data.datasets[0].data = [0, 0, 0, 0, 0, 0, 0, 0];
|
| 585 |
const index = ['edm', 'hiphop', 'rock', 'r&b', 'jazz', 'alternative', 'pop', 'other'].indexOf(filter);
|
| 586 |
+
if (index !== -1) genreChart.data.datasets[0].data[index] = [28, 22, 19, 16, 8, 5, 1, 1][index];
|
| 587 |
}
|
| 588 |
+
|
| 589 |
genreChart.update();
|
| 590 |
});
|
| 591 |
});
|
| 592 |
+
|
| 593 |
+
// Initialize first button as active
|
| 594 |
+
document.getElementById('genre-all').classList.add('bg-gray-700');
|
| 595 |
+
});
|
| 596 |
VANTA.NET({
|
| 597 |
el: "#vanta-bg",
|
| 598 |
mouseControls: true,
|