Selector/Selector.Web/scripts/Now/Spotify.ts

128 lines
3.5 KiB
TypeScript
Raw Normal View History

import * as Vue from "vue";
2021-11-11 19:54:28 +00:00
import { KeyString, ModeString } from "../Helper";
import { Chart, RadarController, RadialLinearScale, PointElement, LineElement } from "chart.js";
Chart.register(RadarController, RadialLinearScale, PointElement, LineElement);
export let PopularityCard: Vue.Component = {
props: ['track'],
template:
`
<div class="card info-card">
<h3>Popularity</h3>
<h1>{{ track.popularity }}%</h1>
<spotify-logo :link="track.externalUrls.spotify" />
</div>
`
}
export let SpotifyLogoLink: Vue.Component = {
props: ['link'],
template:
`
2021-11-10 01:49:20 +00:00
<a :href="link" target="_blank" class="spotify-logo" v-if="link != null && link != undefined">
2021-11-11 19:54:28 +00:00
<img src="/Spotify_Icon_RGB_White.png" >
</a>
2021-11-11 19:54:28 +00:00
<img src="/Spotify_Icon_RGB_White.png" class="spotify-logo" v-else>
`
}
export let AudioFeatureCard: Vue.Component = {
props: ['feature'],
computed: {
Key(): string
{
return KeyString(this.feature.key);
},
Mode(): string
{
return ModeString(this.feature.mode);
}
},
template:
`
<div class="card info-card">
<h3>Info</h3>
2021-11-21 09:21:08 +00:00
<h5>{{ Key }} {{ Mode }}</h5>
<h5>{{ feature.tempo }} BPM</h5>
<h5>{{ feature.timeSignature }}/4</h5>
<h5>{{ feature.loudness }} dB</h5>
2021-11-11 19:54:28 +00:00
<spotify-logo />
</div>
`
}
export let AudioFeatureChartCard: Vue.Component = {
props: ['feature'],
data() {
return {
chartData: {
labels: [
'Energy',
'Dance',
'Speech',
'Live',
'Instrumental',
'Acoustic',
'Valence'
],
datasets: [{
// label: '# of Votes',
data: [
this.feature.energy,
this.feature.danceability,
this.feature.speechiness,
this.feature.liveness,
this.feature.instrumentalness,
this.feature.acousticness,
this.feature.valence
],
}]
}
}
},
template:
`
2021-11-11 19:54:28 +00:00
<div class="card info-card">
<canvas id="feature-chart"></canvas>
<spotify-logo />
</div>
`,
mounted() {
new Chart("feature-chart", {
type: "radar",
data: this.chartData,
options: {
// plugins: {
// legend: {
// labels: {
// color: "white"
// }
// }
// },
elements: {
line: {
borderWidth: 4
},
point: {
radius: 4
}
},
scales: {
r: {
angleLines: {
display: false
},
beginAtZero: true,
suggestedMin: 0,
suggestedMax: 1,
ticks: {
display: false
}
}
}
}
})
}
}