2018-09-07 13:21:25 +02:00
|
|
|
<template>
|
|
|
|
<div class="jtivnzhfwquxpsfidertopbmwmchmnmo">
|
2018-11-13 14:45:28 +01:00
|
|
|
<p class="fetching" v-if="fetching"><fa icon="spinner" pulse fixed-width/>{{ $t('@.loading') }}<mk-ellipsis/></p>
|
2018-11-08 19:44:35 +01:00
|
|
|
<p class="empty" v-else-if="tags.length == 0"><fa icon="exclamation-circle"/>{{ $t('empty') }}</p>
|
2018-09-07 13:21:25 +02:00
|
|
|
<div v-else>
|
|
|
|
<vue-word-cloud
|
2019-05-14 03:50:20 +02:00
|
|
|
:words="tags.slice(0, 20).map(x => [x.tag, x.count])"
|
2018-09-07 13:21:25 +02:00
|
|
|
:color="color"
|
2018-09-07 18:46:01 +02:00
|
|
|
:spacing="1">
|
2018-09-07 13:21:25 +02:00
|
|
|
<template slot-scope="{word, text, weight}">
|
|
|
|
<div style="cursor: pointer;" :title="weight">
|
|
|
|
{{ text }}
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</vue-word-cloud>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-08 19:44:35 +01:00
|
|
|
import i18n from '../../../i18n';
|
2018-09-07 13:21:25 +02:00
|
|
|
import * as VueWordCloud from 'vuewordcloud';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-08 19:44:35 +01:00
|
|
|
i18n: i18n('common/views/components/tag-cloud.vue'),
|
2018-09-07 13:21:25 +02:00
|
|
|
components: {
|
|
|
|
[VueWordCloud.name]: VueWordCloud
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tags: [],
|
|
|
|
fetching: true,
|
|
|
|
clock: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.fetch();
|
|
|
|
this.clock = setInterval(this.fetch, 1000 * 60);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
clearInterval(this.clock);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
2019-05-14 03:50:20 +02:00
|
|
|
this.$root.api('hashtags/trend').then(tags => {
|
2018-09-07 13:21:25 +02:00
|
|
|
this.tags = tags;
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
color([, weight]) {
|
|
|
|
const peak = Math.max.apply(null, this.tags.map(x => x.count));
|
|
|
|
const w = weight / peak;
|
|
|
|
|
2018-09-07 18:46:01 +02:00
|
|
|
if (w > 0.9) {
|
2018-09-07 13:21:25 +02:00
|
|
|
return this.$store.state.device.darkmode ? '#ff4e69' : '#ff4e69';
|
|
|
|
} else if (w > 0.5) {
|
|
|
|
return this.$store.state.device.darkmode ? '#3bc4c7' : '#3bc4c7';
|
|
|
|
} else {
|
|
|
|
return this.$store.state.device.darkmode ? '#fff' : '#555';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-28 12:59:19 +02:00
|
|
|
.jtivnzhfwquxpsfidertopbmwmchmnmo
|
2018-09-07 13:21:25 +02:00
|
|
|
height 100%
|
|
|
|
width 100%
|
|
|
|
|
|
|
|
> .fetching
|
|
|
|
> .empty
|
|
|
|
margin 0
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
2019-02-06 09:51:33 +01:00
|
|
|
color var(--text)
|
2018-09-07 13:21:25 +02:00
|
|
|
|
2018-11-05 17:40:11 +01:00
|
|
|
> [data-icon]
|
2018-09-07 13:21:25 +02:00
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
> div
|
|
|
|
height 100%
|
|
|
|
width 100%
|
|
|
|
|
|
|
|
</style>
|