diff options
Diffstat (limited to 'packages/frontend/src/widgets/WidgetActivity.chart.vue')
| -rw-r--r-- | packages/frontend/src/widgets/WidgetActivity.chart.vue | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/packages/frontend/src/widgets/WidgetActivity.chart.vue b/packages/frontend/src/widgets/WidgetActivity.chart.vue index e708343b3a..bab688f851 100644 --- a/packages/frontend/src/widgets/WidgetActivity.chart.vue +++ b/packages/frontend/src/widgets/WidgetActivity.chart.vue @@ -53,19 +53,27 @@ const pointsReply = ref<string>(); const pointsRenote = ref<string>(); const pointsTotal = ref<string>(); -function dragListen(fn) { +function dragListen(fn: (ev: MouseEvent | TouchEvent) => void) { window.addEventListener('mousemove', fn); window.addEventListener('mouseleave', dragClear.bind(null, fn)); window.addEventListener('mouseup', dragClear.bind(null, fn)); } -function dragClear(fn) { +function dragClear(fn: (ev: MouseEvent | TouchEvent) => void) { window.removeEventListener('mousemove', fn); - window.removeEventListener('mouseleave', dragClear); - window.removeEventListener('mouseup', dragClear); + window.removeEventListener('mouseleave', dragClear as any); + window.removeEventListener('mouseup', dragClear as any); } -function onMousedown(ev) { +function getPositionX(event: MouseEvent | TouchEvent) { + return 'touches' in event && event.touches.length > 0 ? event.touches[0].clientX : 'clientX' in event ? event.clientX : 0; +} + +function getPositionY(event: MouseEvent | TouchEvent) { + return 'touches' in event && event.touches.length > 0 ? event.touches[0].clientY : 'clientY' in event ? event.clientY : 0; +} + +function onMousedown(ev: MouseEvent) { const clickX = ev.clientX; const clickY = ev.clientY; const baseZoom = zoom.value; @@ -73,8 +81,11 @@ function onMousedown(ev) { // 動かした時 dragListen(me => { - let moveLeft = me.clientX - clickX; - let moveTop = me.clientY - clickY; + const x = getPositionX(me); + const y = getPositionY(me); + + let moveLeft = x - clickX; + let moveTop = y - clickY; zoom.value = Math.max(1, baseZoom + (-moveTop / 20)); pos.value = Math.min(0, basePos + moveLeft); |