-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterface.html
More file actions
298 lines (268 loc) · 10.2 KB
/
Copy pathinterface.html
File metadata and controls
298 lines (268 loc) · 10.2 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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>喜好歌單分析</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<style>
#songTable {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
font-family: Arial, sans-serif;
font-size: 14px;
color: #333;
}
#songTable th, #songTable td {
padding: 10px;
border: 1px solid #ddd;
text-align: left;
}
#songTable th {
background-color: #f4f4f4;
font-weight: bold;
}
#songTable tr:nth-child(even) {
background-color: #f9f9f9;
}
#songTable tr:hover {
background-color: #f1f1f1;
}
.container {
display: flex;
width: 100%;
}
.sidebar {
padding: 10px;
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
overflow-y: auto;
border-right: 2px solid #ccc;
}
.content {
flex: 1;
padding: 20px;
}
.buttons {
margin-bottom: 20px;
}
.buttons button {
margin-right: 10px;
padding: 8px 16px;
}
.chart-container {
display: flex;
flex-direction: column;
align-items: center;
}
canvas {
display: none;
}
.filters {
margin-bottom: 20px;
}
.filters label {
margin-right: 20px;
}
.filters button {
margin-top: 10px;
padding: 8px 16px;
}
</style>
</head>
<body>
<div class="sidebar">
<table id="songTable">
<thead>
<tr>
<th>Song Name</th>
<th>Singer Name</th>
<th>Language</th>
<th>Genre</th>
<th>Emotion</th>
<th>Album Name</th>
<th>Singer Gender</th>
</tr>
</thead>
<tbody>
{% for row in playlist %}
<tr>
<td>{{ row.song_name }}</td>
<td>{{ row.singer_name }}</td>
<td>{{ row.song_language }}</td>
<td>{{ row.song_genre }}</td>
<td>{{ row.song_timing }}</td>
<td>{{ row.album_name }}</td>
<td>{{ row.singer_gender }}</td>
</tr>
{% else %}
<tr>
<td colspan="7">No data available</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="content">
<div class="buttons">
<button onclick="showAnalysis('language')">語言</button>
<button onclick="showAnalysis('genre')">風格</button>
<button onclick="showAnalysis('emotion')">Emo指數</button>
<button onclick="showAnalysis('artist')">歌手</button>
</div>
<div class="chart-container">
<canvas id="languageChart"></canvas>
<canvas id="genreChart"></canvas>
<canvas id="timingChart"></canvas>
<canvas id="singerChart"></canvas>
</div>
</div>
<div class="filters"></div>
<h3>選擇過濾條件</h3>
<div id="filterContainer"></div>
<button onclick="filterSongs()">篩選</button>
</div>
<div class="song-list">
<h3>篩選後的歌曲</h3>
<ul id="filteredSongs"></ul>
<button id="createPlaylistButton" style="display:none;" onclick="createPlaylist()">建立歌單</button>
</div>
<script>
const timingData = {{ timing_count | tojson }};
const genreData = {{ genre_count | tojson }};
const languageData = {{ language_count | tojson }};
const singerData = {{ singer_count | tojson }};
let currentChart = null; // Track the current chart instance
// Function to create a pie chart
function createPieChart(ctx, data, label) {
// Destroy any existing chart before creating a new one
if (currentChart) {
currentChart.destroy();
}
// Create the chart
currentChart = new Chart(ctx, {
type: 'pie',
data: {
labels: Object.keys(data),
datasets: [{
data: Object.values(data),
backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56', '#FF5733', '#FF8C00'],
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(tooltipItem) {
return tooltipItem.label + ': ' + tooltipItem.raw + ' songs';
}
}
}
}
}
});
}
// Display analysis chart
function showAnalysis(type) {
// Hide all canvases
document.querySelectorAll('canvas').forEach(canvas => {
canvas.style.display = 'none';
});
let ctx, data;
if (type === 'language') {
ctx = document.getElementById('languageChart');
data = languageData;
} else if (type === 'genre') {
ctx = document.getElementById('genreChart');
data = genreData;
} else if (type === 'emotion') {
ctx = document.getElementById('timingChart');
data = timingData;
} else if (type === 'artist') {
ctx = document.getElementById('singerChart');
data = singerData;
}
if (ctx && data) {
ctx.style.display = 'block';
createPieChart(ctx, data, type);
} else {
alert('No data available for this category.');
}
}
function getUniqueValues(columnIndex) {
const rows = document.querySelectorAll("#songTable tbody tr");
const values = new Set();
rows.forEach(row => {
const cell = row.cells[columnIndex];
if (cell) values.add(cell.textContent.trim());
});
return Array.from(values);
}
function populateFilters() {
const filterContainer = document.getElementById("filterContainer");
const columns = ["Singer","Language", "Genre", "Timing"];
columns.forEach((col, index) => {
const uniqueValues = getUniqueValues(index + 1); // Skip first two columns (Song Name, Singer Name)
const filterGroup = document.createElement("div");
filterGroup.innerHTML = `<strong>${col}:</strong>`;
uniqueValues.forEach(value => {
const label = document.createElement("label");
label.innerHTML = `<input type="checkbox" class="filter" data-type="${col.toLowerCase()}" value="${value}"> ${value}`;
filterGroup.appendChild(label);
});
filterContainer.appendChild(filterGroup);
});
}
function filterSongs() {
const selectedFilters = { language: [], singer: [], genre: [], timing: [] };
document.querySelectorAll(".filter:checked").forEach(checkbox => {
const type = checkbox.getAttribute("data-type");
const value = checkbox.value;
selectedFilters[type].push(value);
});
const rows = document.querySelectorAll("#songTable tbody tr");
const filteredSongs = [];
rows.forEach(row => {
const cells = row.cells;
const song = {
song_name: cells[0].textContent.trim(),
singer_name: cells[1].textContent.trim(),
language: cells[2].textContent.trim(),
genre: cells[3].textContent.trim(),
timing: cells[4].textContent.trim()
};
const matchesFilter = (!selectedFilters.language.length || selectedFilters.language.includes(song.language)) &&
(!selectedFilters.singer.length || selectedFilters.singer.includes(song.singer_name)) &&
(!selectedFilters.genre.length || selectedFilters.genre.includes(song.genre)) &&
(!selectedFilters.timing.length || selectedFilters.timing.includes(song.timing));
if (matchesFilter) filteredSongs.push(song.song_name);
});
const filteredSongsList = document.getElementById("filteredSongs");
filteredSongsList.innerHTML = "";
filteredSongs.forEach(song => {
const li = document.createElement("li");
li.textContent = song;
filteredSongsList.appendChild(li);
});
const createPlaylistButton = document.getElementById("createPlaylistButton");
createPlaylistButton.style.display = filteredSongs.length ? "block" : "none";
}
function createPlaylist() {
const selectedSongs = [];
document.querySelectorAll("#filteredSongs li").forEach(item => {
selectedSongs.push(item.textContent);
});
localStorage.setItem("playlist", JSON.stringify(selectedSongs));
window.location.href = "newplaylist.html";
}
// Initialize filters
document.addEventListener("DOMContentLoaded", populateFilters);
</script>
</body>
</html>