File size: 5,146 Bytes
ecd3201 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FürElise Dataset Visualizer</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome for Icons -->
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: 'Source Sans Pro', sans-serif;
margin: 20px;
}
th {
cursor: pointer;
}
tr:hover {
background-color: #f1f1f1;
}
th i {
margin-left: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1 class="my-4 text-center">FürElise Dataset Visualizer</h1>
Click any piece to start.
<!-- Search Input -->
<div class="row">
<div class="col-md-6 mx-auto">
<input type="text" class="form-control" id="searchInput" placeholder="Search by piece ID, name, or composer" onkeyup="searchTable()">
</div>
</div>
<!-- Table -->
<table class="table table-hover mt-4">
<thead class="table-dark">
<tr>
<th scope="col" onclick="sortTable(0)">Piece ID <i class="fas fa-sort"></i></th>
<th scope="col" onclick="sortTable(1)">Piece Name <i class="fas fa-sort"></i></th>
<th scope="col" onclick="sortTable(2)">Composer <i class="fas fa-sort"></i></th>
</tr>
</thead>
<tbody id="piecesTable"></tbody>
</table>
</div>
<!-- Bootstrap JS (for responsive elements) -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
let sortDirections = [true, true, true]; // True for ascending, false for descending for each column
// Load the JSON data from a local file
async function loadJSON() {
const response = await fetch('/pieces_metadata'); // Ensure 'pieces_metadata.json' is in the same directory
const pieces = await response.json();
return pieces;
}
// Generate the table rows from the fetched JSON data
function loadTable(pieces) {
const table = document.getElementById('piecesTable');
pieces.forEach(piece => {
let row = document.createElement('tr');
row.innerHTML = `
<td>${piece.piece_id}</td>
<td><a href="/vis?id=${piece.piece_id}" class="text-decoration-none">${piece.name}</a></td>
<td>${piece.composer}</td>
`;
table.appendChild(row);
});
}
// Sort table based on columns
function sortTable(columnIndex) {
const table = document.getElementById('piecesTable');
let rows = Array.from(table.getElementsByTagName('tr'));
const ascending = sortDirections[columnIndex];
rows.sort((a, b) => {
const aText = a.cells[columnIndex].textContent.trim();
const bText = b.cells[columnIndex].textContent.trim();
// Sort piece_id as numbers
if (columnIndex === 0) {
return ascending ? aText - bText : bText - aText;
}
// Sort by text for other columns
return ascending ? aText.localeCompare(bText) : bText.localeCompare(aText);
});
// Toggle the sort direction for next click
sortDirections[columnIndex] = !ascending;
// Clear the table and re-append the sorted rows
table.innerHTML = '';
rows.forEach(row => table.appendChild(row));
// Update sort icons
updateSortIcons(columnIndex, ascending);
}
// Update the sort icons
function updateSortIcons(columnIndex, ascending) {
const ths = document.querySelectorAll('th');
ths.forEach((th, i) => {
const icon = th.querySelector('i');
if (i === columnIndex) {
icon.className = ascending ? 'fas fa-sort-up' : 'fas fa-sort-down'; // Show up or down arrow
} else {
icon.className = 'fas fa-sort'; // Reset other columns to neutral
}
});
}
// Search function for filtering rows
function searchTable() {
const input = document.getElementById('searchInput').value.toLowerCase();
const rows = document.querySelectorAll('#piecesTable tr');
rows.forEach(row => {
const pieceID = row.cells[0].textContent.toLowerCase();
const name = row.cells[1].textContent.toLowerCase();
const composer = row.cells[2].textContent.toLowerCase();
row.style.display = pieceID.includes(input) || name.includes(input) || composer.includes(input) ? '' : 'none';
});
}
// Initialize the table on page load
loadJSON().then(pieces => {
loadTable(pieces);
});
</script>
</body>
</html>
|