2018-06-08 14:14:26 -05:00
|
|
|
<template>
|
|
|
|
<div class="mkw-posts-monitor">
|
|
|
|
<mk-widget-container :show-header="props.design == 0" :naked="props.design == 2">
|
2018-11-08 12:44:35 -06:00
|
|
|
<template slot="header"><fa icon="chart-line"/>{{ $t('title') }}</template>
|
|
|
|
<button slot="func" @click="toggle" :title="$t('toggle')"><fa icon="sort"/></button>
|
2018-06-08 14:14:26 -05:00
|
|
|
|
2018-09-28 00:26:20 -05:00
|
|
|
<div class="qpdmibaztplkylerhdbllwcokyrfxeyj" :class="{ dual: props.view == 0 }">
|
2018-06-08 21:29:50 -05:00
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`" v-show="props.view != 2">
|
2018-06-08 14:14:26 -05:00
|
|
|
<defs>
|
2018-06-08 16:27:12 -05:00
|
|
|
<linearGradient :id="localGradientId" x1="0" x2="0" y1="1" y2="0">
|
2018-06-08 14:14:26 -05:00
|
|
|
<stop offset="0%" stop-color="hsl(200, 80%, 70%)"></stop>
|
|
|
|
<stop offset="100%" stop-color="hsl(90, 80%, 70%)"></stop>
|
|
|
|
</linearGradient>
|
2018-06-08 16:27:12 -05:00
|
|
|
<mask :id="localMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
|
2018-06-08 16:21:13 -05:00
|
|
|
<polygon
|
2018-06-08 16:27:12 -05:00
|
|
|
:points="localPolygonPoints"
|
2018-06-08 16:21:13 -05:00
|
|
|
fill="#fff"
|
|
|
|
fill-opacity="0.5"/>
|
2018-06-08 14:14:26 -05:00
|
|
|
<polyline
|
2018-06-08 16:27:12 -05:00
|
|
|
:points="localPolylinePoints"
|
2018-06-08 14:14:26 -05:00
|
|
|
fill="none"
|
|
|
|
stroke="#fff"
|
|
|
|
stroke-width="1"/>
|
2018-06-08 21:29:50 -05:00
|
|
|
<circle
|
|
|
|
:cx="localHeadX"
|
|
|
|
:cy="localHeadY"
|
|
|
|
r="1.5"
|
|
|
|
fill="#fff"/>
|
2018-06-08 14:14:26 -05:00
|
|
|
</mask>
|
|
|
|
</defs>
|
|
|
|
<rect
|
2018-06-08 21:29:50 -05:00
|
|
|
x="-2" y="-2"
|
|
|
|
:width="viewBoxX + 4" :height="viewBoxY + 4"
|
2018-06-08 16:27:12 -05:00
|
|
|
:style="`stroke: none; fill: url(#${ localGradientId }); mask: url(#${ localMaskId })`"/>
|
|
|
|
<text x="1" y="5">Local</text>
|
2018-06-08 14:14:26 -05:00
|
|
|
</svg>
|
2018-06-08 21:29:50 -05:00
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`" v-show="props.view != 1">
|
2018-06-08 14:14:26 -05:00
|
|
|
<defs>
|
2018-06-08 16:27:12 -05:00
|
|
|
<linearGradient :id="fediGradientId" x1="0" x2="0" y1="1" y2="0">
|
2018-06-08 14:14:26 -05:00
|
|
|
<stop offset="0%" stop-color="hsl(200, 80%, 70%)"></stop>
|
|
|
|
<stop offset="100%" stop-color="hsl(90, 80%, 70%)"></stop>
|
|
|
|
</linearGradient>
|
2018-06-08 16:27:12 -05:00
|
|
|
<mask :id="fediMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
|
2018-06-08 16:21:13 -05:00
|
|
|
<polygon
|
2018-06-08 16:27:12 -05:00
|
|
|
:points="fediPolygonPoints"
|
2018-06-08 16:21:13 -05:00
|
|
|
fill="#fff"
|
|
|
|
fill-opacity="0.5"/>
|
2018-06-08 14:14:26 -05:00
|
|
|
<polyline
|
2018-06-08 16:27:12 -05:00
|
|
|
:points="fediPolylinePoints"
|
2018-06-08 14:14:26 -05:00
|
|
|
fill="none"
|
|
|
|
stroke="#fff"
|
|
|
|
stroke-width="1"/>
|
2018-06-08 21:29:50 -05:00
|
|
|
<circle
|
|
|
|
:cx="fediHeadX"
|
|
|
|
:cy="fediHeadY"
|
|
|
|
r="1.5"
|
|
|
|
fill="#fff"/>
|
2018-06-08 14:14:26 -05:00
|
|
|
</mask>
|
|
|
|
</defs>
|
|
|
|
<rect
|
2018-06-08 21:29:50 -05:00
|
|
|
x="-2" y="-2"
|
|
|
|
:width="viewBoxX + 4" :height="viewBoxY + 4"
|
2018-06-08 16:27:12 -05:00
|
|
|
:style="`stroke: none; fill: url(#${ fediGradientId }); mask: url(#${ fediMaskId })`"/>
|
|
|
|
<text x="1" y="5">Fedi</text>
|
2018-06-08 14:14:26 -05:00
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
</mk-widget-container>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import define from '../../../common/define-widget';
|
2018-11-08 12:44:35 -06:00
|
|
|
import i18n from '../../../i18n';
|
2018-06-08 14:14:26 -05:00
|
|
|
import * as uuid from 'uuid';
|
|
|
|
|
|
|
|
export default define({
|
2018-11-08 12:44:35 -06:00
|
|
|
name: 'posts-monitor',
|
2018-06-08 14:14:26 -05:00
|
|
|
props: () => ({
|
|
|
|
design: 0,
|
|
|
|
view: 0
|
|
|
|
})
|
|
|
|
}).extend({
|
2018-11-08 12:44:35 -06:00
|
|
|
i18n: i18n('common/views/widgets/posts-monitor.vue'),
|
|
|
|
|
2018-06-08 14:14:26 -05:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
connection: null,
|
|
|
|
viewBoxY: 30,
|
|
|
|
stats: [],
|
|
|
|
fediGradientId: uuid(),
|
|
|
|
fediMaskId: uuid(),
|
|
|
|
localGradientId: uuid(),
|
|
|
|
localMaskId: uuid(),
|
|
|
|
fediPolylinePoints: '',
|
|
|
|
localPolylinePoints: '',
|
|
|
|
fediPolygonPoints: '',
|
2018-06-08 21:29:50 -05:00
|
|
|
localPolygonPoints: '',
|
|
|
|
fediHeadX: null,
|
|
|
|
fediHeadY: null,
|
|
|
|
localHeadX: null,
|
|
|
|
localHeadY: null
|
2018-06-08 14:14:26 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
viewBoxX(): number {
|
|
|
|
return this.props.view == 0 ? 50 : 100;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
viewBoxX() {
|
|
|
|
this.draw();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-11-08 17:13:34 -06:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('notesStats');
|
2018-06-08 14:14:26 -05:00
|
|
|
|
|
|
|
this.connection.on('stats', this.onStats);
|
|
|
|
this.connection.on('statsLog', this.onStatsLog);
|
2018-10-09 01:08:31 -05:00
|
|
|
this.connection.send('requestLog',{
|
2018-10-13 05:16:47 -05:00
|
|
|
id: Math.random().toString().substr(2, 8)
|
2018-06-08 14:14:26 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2018-10-06 21:06:17 -05:00
|
|
|
this.connection.dispose();
|
2018-06-08 14:14:26 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggle() {
|
|
|
|
if (this.props.view == 2) {
|
|
|
|
this.props.view = 0;
|
|
|
|
} else {
|
|
|
|
this.props.view++;
|
|
|
|
}
|
|
|
|
this.save();
|
|
|
|
},
|
|
|
|
func() {
|
|
|
|
if (this.props.design == 2) {
|
|
|
|
this.props.design = 0;
|
|
|
|
} else {
|
|
|
|
this.props.design++;
|
|
|
|
}
|
|
|
|
this.save();
|
|
|
|
},
|
|
|
|
draw() {
|
2018-06-08 16:21:13 -05:00
|
|
|
const stats = this.props.view == 0 ? this.stats.slice(-50) : this.stats;
|
2018-06-08 16:04:41 -05:00
|
|
|
const fediPeak = Math.max.apply(null, stats.map(x => x.all)) || 1;
|
|
|
|
const localPeak = Math.max.apply(null, stats.map(x => x.local)) || 1;
|
2018-06-08 14:14:26 -05:00
|
|
|
|
2018-06-08 21:29:50 -05:00
|
|
|
const fediPolylinePoints = stats.map((s, i) => [this.viewBoxX - ((stats.length - 1) - i), (1 - (s.all / fediPeak)) * this.viewBoxY]);
|
|
|
|
const localPolylinePoints = stats.map((s, i) => [this.viewBoxX - ((stats.length - 1) - i), (1 - (s.local / localPeak)) * this.viewBoxY]);
|
|
|
|
this.fediPolylinePoints = fediPolylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
|
|
|
this.localPolylinePoints = localPolylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
2018-06-08 14:14:26 -05:00
|
|
|
|
2018-06-08 16:04:41 -05:00
|
|
|
this.fediPolygonPoints = `${this.viewBoxX - (stats.length - 1)},${ this.viewBoxY } ${ this.fediPolylinePoints } ${ this.viewBoxX },${ this.viewBoxY }`;
|
|
|
|
this.localPolygonPoints = `${this.viewBoxX - (stats.length - 1)},${ this.viewBoxY } ${ this.localPolylinePoints } ${ this.viewBoxX },${ this.viewBoxY }`;
|
2018-06-08 21:29:50 -05:00
|
|
|
|
|
|
|
this.fediHeadX = fediPolylinePoints[fediPolylinePoints.length - 1][0];
|
|
|
|
this.fediHeadY = fediPolylinePoints[fediPolylinePoints.length - 1][1];
|
|
|
|
this.localHeadX = localPolylinePoints[localPolylinePoints.length - 1][0];
|
|
|
|
this.localHeadY = localPolylinePoints[localPolylinePoints.length - 1][1];
|
2018-06-08 14:14:26 -05:00
|
|
|
},
|
|
|
|
onStats(stats) {
|
|
|
|
this.stats.push(stats);
|
|
|
|
if (this.stats.length > 100) this.stats.shift();
|
|
|
|
this.draw();
|
|
|
|
},
|
|
|
|
onStatsLog(statsLog) {
|
2018-12-11 05:36:55 -06:00
|
|
|
for (const stats of statsLog) this.onStats(stats);
|
2018-06-08 14:14:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-27 21:18:56 -05:00
|
|
|
.qpdmibaztplkylerhdbllwcokyrfxeyj
|
2018-06-08 14:14:26 -05:00
|
|
|
&.dual
|
|
|
|
> svg
|
|
|
|
width 50%
|
|
|
|
float left
|
|
|
|
|
|
|
|
&:first-child
|
|
|
|
padding-right 5px
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
padding-left 5px
|
|
|
|
|
|
|
|
> svg
|
|
|
|
display block
|
|
|
|
padding 10px
|
|
|
|
width 100%
|
|
|
|
|
|
|
|
> text
|
|
|
|
font-size 5px
|
2018-09-27 21:18:56 -05:00
|
|
|
fill var(--chartCaption)
|
2018-06-08 14:14:26 -05:00
|
|
|
|
|
|
|
> tspan
|
|
|
|
opacity 0.5
|
|
|
|
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
</style>
|