This commit is contained in:
syuilo 2018-06-11 11:24:29 +09:00
parent 2ec25a7729
commit 7d7193cb63
4 changed files with 119 additions and 31 deletions

View file

@ -254,6 +254,9 @@ common/views/widgets/posts-monitor.vue:
title: "投稿チャート" title: "投稿チャート"
toggle: "表示を切り替え" toggle: "表示を切り替え"
common/views/widgets/hashtags.vue:
title: "ハッシュタグ"
common/views/widgets/server.vue: common/views/widgets/server.vue:
title: "サーバー情報" title: "サーバー情報"
toggle: "表示を切り替え" toggle: "表示を切り替え"

View file

@ -0,0 +1,78 @@
<template>
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
<defs>
<linearGradient :id="gradientId" x1="0" x2="0" y1="1" y2="0">
<stop offset="0%" stop-color="hsl(200, 80%, 70%)"></stop>
<stop offset="100%" stop-color="hsl(90, 80%, 70%)"></stop>
</linearGradient>
<mask :id="maskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
<polygon
:points="polygonPoints"
fill="#fff"
fill-opacity="0.5"/>
<polyline
:points="polylinePoints"
fill="none"
stroke="#fff"
stroke-width="0.7"/>
<circle
:cx="headX"
:cy="headY"
r="1.2"
fill="#fff"/>
</mask>
</defs>
<rect
x="-2" y="-2"
:width="viewBoxX + 4" :height="viewBoxY + 4"
:style="`stroke: none; fill: url(#${ gradientId }); mask: url(#${ maskId })`"/>
</svg>
</template>
<script lang="ts">
import Vue from 'vue';
import * as uuid from 'uuid';
export default Vue.extend({
props: {
src: {
type: Array,
required: true
}
},
data() {
return {
viewBoxX: 50,
viewBoxY: 30,
gradientId: uuid(),
maskId: uuid(),
polylinePoints: '',
polygonPoints: '',
headX: null,
headY: null
};
},
watch: {
src() {
this.draw();
}
},
created() {
this.draw();
},
methods: {
draw() {
const stats = this.src.slice().reverse();
const peak = Math.max.apply(null, stats) || 1;
const polylinePoints = stats.map((x, i) => [this.viewBoxX - ((stats.length - 1) - i), (1 - (x / peak)) * this.viewBoxY]);
this.polylinePoints = polylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' ');
this.polygonPoints = `${this.viewBoxX - (stats.length - 1)},${ this.viewBoxY } ${ this.polylinePoints } ${ this.viewBoxX },${ this.viewBoxY }`;
this.headX = polylinePoints[polylinePoints.length - 1][0];
this.headY = polylinePoints[polylinePoints.length - 1][1];
}
}
});
</script>

View file

@ -6,7 +6,12 @@
<div class="mkw-hashtags--body" :data-mobile="platform == 'mobile'"> <div class="mkw-hashtags--body" :data-mobile="platform == 'mobile'">
<p class="fetching" v-if="fetching">%fa:spinner .pulse .fw%%i18n:common.loading%<mk-ellipsis/></p> <p class="fetching" v-if="fetching">%fa:spinner .pulse .fw%%i18n:common.loading%<mk-ellipsis/></p>
<div v-else> <div v-else>
<router-link v-for="stat in stats" :key="stat.tag" :to="`/tags/${ stat.tag }`">{{ stat.tag }}</router-link> <div v-for="stat in stats" :key="stat.tag">
<div class="tag">
<router-link :to="`/tags/${ stat.tag }`">#{{ stat.tag }}</router-link>
</div>
<x-chart class="chart" :src="stat.chart"/>
</div>
</div> </div>
</div> </div>
</mk-widget-container> </mk-widget-container>
@ -15,12 +20,17 @@
<script lang="ts"> <script lang="ts">
import define from '../../../common/define-widget'; import define from '../../../common/define-widget';
import XChart from './hashtags.chart.vue';
export default define({ export default define({
name: 'hashtags', name: 'hashtags',
props: () => ({ props: () => ({
compact: false compact: false
}) })
}).extend({ }).extend({
components: {
XChart
},
data() { data() {
return { return {
stats: [], stats: [],
@ -52,21 +62,8 @@ export default define({
<style lang="stylus" scoped> <style lang="stylus" scoped>
root(isDark) root(isDark)
.mkw-rss--body .mkw-hashtags--body
.feed > .fetching
padding 12px 16px
font-size 0.9em
> a
display block
padding 4px 0
color isDark ? #9aa4b3 : #666
border-bottom dashed 1px isDark ? #1c2023 : #eee
&:last-child
border-bottom none
.fetching
margin 0 margin 0
padding 16px padding 16px
text-align center text-align center
@ -75,23 +72,29 @@ root(isDark)
> [data-fa] > [data-fa]
margin-right 4px margin-right 4px
&[data-mobile] > div
background isDark ? #21242f : #f3f3f3 > div
display flex
align-items center
padding 16px
.feed &:not(:last-child)
padding 0 border-bottom solid 1px #393f4f
> a > .tag
padding 8px 16px flex 1
border-bottom none
&:nth-child(even) > a
background isDark ? rgba(#000, 0.05) : rgba(#fff, 0.7) color #9baec8
.mkw-rss[data-darkmode] > .chart
width 50px
height 30px
.mkw-hashtags[data-darkmode]
root(true) root(true)
.mkw-rss:not([data-darkmode]) .mkw-hashtags:not([data-darkmode])
root(false) root(false)
</style> </style>

View file

@ -4,13 +4,10 @@ import Note from '../../../../models/note';
* Get trends of hashtags * Get trends of hashtags
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// 10分
const interval = 1000 * 60 * 10;
const data = await Note.aggregate([{ const data = await Note.aggregate([{
$match: { $match: {
createdAt: { createdAt: {
$gt: new Date(Date.now() - interval) $gt: new Date(Date.now() - 1000 * 60 * 60)
}, },
tags: { tags: {
$exists: true, $exists: true,
@ -48,6 +45,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}> }>
}>; }>;
if (data.length == 0) {
return res([]);
}
const hots = data[0].tags const hots = data[0].tags
.sort((a, b) => a.count - b.count) .sort((a, b) => a.count - b.count)
.map(tag => tag.tag) .map(tag => tag.tag)
@ -56,6 +57,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const countPromises: Array<Promise<number[]>> = []; const countPromises: Array<Promise<number[]>> = [];
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
// 10分
const interval = 1000 * 60 * 10;
countPromises.push(Promise.all(hots.map(tag => Note.count({ countPromises.push(Promise.all(hots.map(tag => Note.count({
tags: tag, tags: tag,
createdAt: { createdAt: {