-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
260 lines (242 loc) · 10.7 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
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
<html>
<head>
<meta charset="utf-8">
<title>数据可视化</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-lazyload/vue-lazyload.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/antd.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/antd.min.js"></script>
<style>
body {
text-align: center;
background-color: white;
}
</style>
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
/* height: 80%; */
/* height: calc(100vh - 130px); */
height: calc(100vh - 15px);
/* padding-top: 20%; */
/* margin-bottom: 25px; */
position: relative;
}
.slogn {
position: fixed;
bottom: 5px;
right: 5px;
font-size: 12px;
z-index: 2000;
color: #aaa
}
* {
padding: 0;
margin: 0;
}
</style>
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/plugins/wordCloud.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PEPQ7KZ023"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-PEPQ7KZ023');
</script>
</head>
<body>
<a class="slogn" target="_blank" href="https://github.com/xiami2021/backup">github.com/xiami2021/backup</a>
<div id="app">
<div style="padding-top: 10%" v-show="switchBox">
<p>可视化类型:</p>
<p>
<a-button style="margin-right: 15px" icon="cloud" @click="show('tag')">
风格标签云
</a-button>
<a-button icon="table" style="margin-right: 15px" @click="show('cover')">
专辑墙
</a-button>
<a-button icon="cloud" style="margin-right: 15px" @click="show('artist_tag')">
艺术家标签云
</a-button>
<a-button icon="table" @click="show('artist_cover')">
艺术家墙
</a-button>
</p>
</div>
<div v-if="!switchBox">
<div v-if="loading">loading...</div>
<div id="chartdiv" v-show="showTag"></div>
<img src="qrcode.png" style="position: absolute; left: 0; bottom: 0;" height="100" />
<!-- <div style="text-align: left; margin-top: 10px; padding: 10px 20px; background: #f4f4f4;">
<img src="qrcode.png" style="vertical-align: middle; margin-right: 15px;" height="100" />
生成虾米音乐收藏歌曲Tag云
</div> -->
<div v-if="allAlbumsItems.length">
<img v-lazy="item.cover" v-for="item in allAlbumsItems" height="80" width="80" />
</div>
</div>
</div>
<script>
Vue.use(VueLazyload);
var app = new Vue({
el: '#app',
data: {
switchBox: true,
showTag: false,
loading: true,
songs: null,
type: 'tag',
topStyles: [],
allAlbumsItems: []
},
mounted() {
// var data = 'http://localhost:8765/downloader/analytics?all=1'
},
methods: {
show(type) {
this.switchBox = false;
this.loadData(type);
},
draw() {
var self = this;
// this.$refs.main.width = window.innerWidth
// this.$refs.main.height = window.innerHeight
am4core.ready(function () {
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("chartdiv", am4plugins_wordCloud.WordCloud);
var series = chart.series.push(new am4plugins_wordCloud.WordCloudSeries());
series.accuracy = 4;
series.step = 30;
series.rotationThreshold = 0.4;
series.maxCount = 400;
series.minWordLength = 2;
series.labels.template.tooltipText = "{word}: {value}";
series.fontFamily = "Courier New";
series.maxFontSize = am4core.percent(22);
series.data = self.topStyles.map(_ => {
return {
// tag: _.name,
tag: _.name_cn,
weight: _.count
}
});
series.dataFields.word = "tag";
series.dataFields.value = "weight";
series.colors = new am4core.ColorSet();
console.log('series', series)
}); // end am4core.ready()
// WordCloud(document.getElementById('my_canvas'), {
// gridSize: Math.round(16 * window.innerWidth / 1024),
// weightFactor: function (size) {
// return Math.pow(size, 2.3) * window.innerWidth / 1024;
// },
// fontFamily: 'Times, serif',
// color: function (word, weight) {
// return (weight === 12) ? '#f02222' : '#c09292';
// },
// rotateRatio: 0.5,
// rotationSteps: 2,
// backgroundColor: '#ffe0e0',
// list: this.topStyles.map(_ => {
// return [_.name, _.count]
// })
// });
// chart.marginBottom = 10
},
async loadData(type) {
const { data } = await axios.get('http://localhost:8765/downloader/analytics?all=1')
if (data.length === 0) {
alert('请备份虾米数据后,【备份所有收藏歌曲】后再打开本页面, 数据是基于已完成的歌曲标签来的!')
return
}
this.songs = data.filter(_ => _.raw).map(_ => {
return JSON.parse(_.raw)
})
var byStyles = {};
const topStyles = {};
const styleMeta = {};
const allAlbums = {};
console.log('data sample', this.songs[0])
var logoKey = type === 'cover' ? 'albumLogo' : 'artistLogo';
var tagKey = type === 'tag' ? 'styleName' : 'artistName';
var isStyle = type === 'tag';
for (let index = 0; index < this.songs.length; index++) {
const rawData = this.songs[index];
if (!rawData.styles) continue;
allAlbums[rawData[logoKey]] = allAlbums[rawData[logoKey]] || 0;
allAlbums[rawData[logoKey]]++;
if(isStyle) {
rawData.styles.forEach((_) => {
styleMeta[_.styleName] = _;
topStyles[_.styleName] = topStyles[_.styleName] || 0;
topStyles[_.styleName]++;
});
} else {
topStyles[rawData[tagKey]] = topStyles[rawData[tagKey]] || 0;
topStyles[rawData[tagKey]]++;
}
}
function getTop() {
return Object.keys(topStyles).sort(function (a, b) {
return topStyles[b] - topStyles[a]
}).map(_ => {
if(isStyle) {
var pairs = _.split(" ");
var cnName = pairs.shift();
return {
rawName: _,
name: pairs.join(" "),
name_cn: cnName,
meta: styleMeta[_],
count: topStyles[_]
}
} else {
var pairs = _.split(" ");
var cnName = pairs.shift();
return {
name_cn: _,
count: topStyles[_]
}
}
})
}
var topStylesRaw = getTop();
console.log('topStylesRaw', topStylesRaw)
if (!isStyle) {
topStylesRaw = topStylesRaw.slice(0, 200)
}
this.topStyles = topStylesRaw;
// let params = (new URL(document.location)).searchParams;
// let type = params.get("type") || 'tag';
if(type.indexOf('tag') > -1) {
this.showTag = true;
this.draw();
}
if(type == 'cover' || type == 'artist_cover') {
var allAlbumsItems = Object.keys(allAlbums).sort(function (a, b) {
return allAlbums[b] - allAlbums[a]
}).map(_ => {
return {
cover: _,
count: allAlbums[_]
}
})
this.allAlbumsItems = allAlbumsItems
console.log('allAlbumsItems', allAlbumsItems)
}
this.loading = false;
}
},
})
</script>
</body>
</html>