2018-02-19 16:37:09 +02:00
|
|
|
<template>
|
2018-06-09 05:40:42 +03:00
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`" @mousedown.prevent="onMousedown">
|
2018-11-08 20:44:35 +02:00
|
|
|
<title>{{ $t('total') }}<br/>{{ $t('notes') }}<br/>{{ $t('replies') }}<br/>{{ $t('renotes') }}</title>
|
2018-02-19 16:37:09 +02:00
|
|
|
<polyline
|
2018-04-07 20:30:37 +03:00
|
|
|
:points="pointsNote"
|
2018-02-19 16:37:09 +02:00
|
|
|
fill="none"
|
|
|
|
stroke-width="1"
|
|
|
|
stroke="#41ddde"/>
|
|
|
|
<polyline
|
|
|
|
:points="pointsReply"
|
|
|
|
fill="none"
|
|
|
|
stroke-width="1"
|
|
|
|
stroke="#f7796c"/>
|
|
|
|
<polyline
|
2018-04-07 20:30:37 +03:00
|
|
|
:points="pointsRenote"
|
2018-02-19 16:37:09 +02:00
|
|
|
fill="none"
|
|
|
|
stroke-width="1"
|
|
|
|
stroke="#a1de41"/>
|
|
|
|
<polyline
|
|
|
|
:points="pointsTotal"
|
|
|
|
fill="none"
|
|
|
|
stroke-width="1"
|
|
|
|
stroke="#555"
|
|
|
|
stroke-dasharray="2 2"/>
|
|
|
|
</svg>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-08 20:44:35 +02:00
|
|
|
import i18n from '../../../i18n';
|
2018-02-19 16:37:09 +02:00
|
|
|
|
|
|
|
function dragListen(fn) {
|
|
|
|
window.addEventListener('mousemove', fn);
|
|
|
|
window.addEventListener('mouseleave', dragClear.bind(null, fn));
|
|
|
|
window.addEventListener('mouseup', dragClear.bind(null, fn));
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragClear(fn) {
|
|
|
|
window.removeEventListener('mousemove', fn);
|
|
|
|
window.removeEventListener('mouseleave', dragClear);
|
|
|
|
window.removeEventListener('mouseup', dragClear);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-08 20:44:35 +02:00
|
|
|
i18n: i18n('desktop/views/components/activity.chart.vue'),
|
2018-02-19 16:37:09 +02:00
|
|
|
props: ['data'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
viewBoxX: 140,
|
|
|
|
viewBoxY: 60,
|
|
|
|
zoom: 1,
|
|
|
|
pos: 0,
|
2018-04-07 20:30:37 +03:00
|
|
|
pointsNote: null,
|
2018-02-19 16:37:09 +02:00
|
|
|
pointsReply: null,
|
2018-04-07 20:30:37 +03:00
|
|
|
pointsRenote: null,
|
2018-02-19 16:37:09 +02:00
|
|
|
pointsTotal: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
2018-12-11 13:36:55 +02:00
|
|
|
for (const d of this.data) {
|
|
|
|
d.total = d.notes + d.replies + d.renotes;
|
|
|
|
}
|
|
|
|
|
2018-02-19 16:37:09 +02:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
render() {
|
|
|
|
const peak = Math.max.apply(null, this.data.map(d => d.total));
|
2018-02-22 13:52:39 +02:00
|
|
|
if (peak != 0) {
|
2018-06-09 05:40:42 +03:00
|
|
|
const data = this.data.slice().reverse();
|
|
|
|
this.pointsNote = data.map((d, i) => `${(i * this.zoom) + this.pos},${(1 - (d.notes / peak)) * this.viewBoxY}`).join(' ');
|
|
|
|
this.pointsReply = data.map((d, i) => `${(i * this.zoom) + this.pos},${(1 - (d.replies / peak)) * this.viewBoxY}`).join(' ');
|
|
|
|
this.pointsRenote = data.map((d, i) => `${(i * this.zoom) + this.pos},${(1 - (d.renotes / peak)) * this.viewBoxY}`).join(' ');
|
|
|
|
this.pointsTotal = data.map((d, i) => `${(i * this.zoom) + this.pos},${(1 - (d.total / peak)) * this.viewBoxY}`).join(' ');
|
2018-02-22 13:52:39 +02:00
|
|
|
}
|
2018-02-19 16:37:09 +02:00
|
|
|
},
|
|
|
|
onMousedown(e) {
|
|
|
|
const clickX = e.clientX;
|
|
|
|
const clickY = e.clientY;
|
|
|
|
const baseZoom = this.zoom;
|
|
|
|
const basePos = this.pos;
|
|
|
|
|
|
|
|
// 動かした時
|
|
|
|
dragListen(me => {
|
|
|
|
let moveLeft = me.clientX - clickX;
|
|
|
|
let moveTop = me.clientY - clickY;
|
|
|
|
|
|
|
|
this.zoom = baseZoom + (-moveTop / 20);
|
|
|
|
this.pos = basePos + moveLeft;
|
|
|
|
if (this.zoom < 1) this.zoom = 1;
|
|
|
|
if (this.pos > 0) this.pos = 0;
|
|
|
|
if (this.pos < -(((this.data.length - 1) * this.zoom) - this.viewBoxX)) this.pos = -(((this.data.length - 1) * this.zoom) - this.viewBoxX);
|
|
|
|
|
|
|
|
this.render();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
svg
|
|
|
|
display block
|
|
|
|
padding 10px
|
|
|
|
width 100%
|
|
|
|
cursor all-scroll
|
|
|
|
|
|
|
|
</style>
|