From 472cee8e80b99b777b4a409b6d1b2d179552014e Mon Sep 17 00:00:00 2001 From: Sergey Solodyagin Date: Fri, 8 Oct 2021 09:35:50 +0300 Subject: [PATCH] fix: time marker movement --- src/GGanttBar.vue | 11 ++++++++--- src/GGanttChart.vue | 10 +++++----- src/GGanttTimeaxis.vue | 24 +++++++++++++----------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/GGanttBar.vue b/src/GGanttBar.vue index 3c7c74f..49dd4ef 100644 --- a/src/GGanttBar.vue +++ b/src/GGanttBar.vue @@ -273,7 +273,8 @@ export default { }, drag(e) { - const chart = document.querySelector('#g-gantt-chart') + const chart = e.target.closest('.g-gantt-chart') + if (!chart) return let barWidth = this.$refs['g-gantt-bar'].getBoundingClientRect().width let newXStart = chart.scrollLeft + @@ -291,7 +292,9 @@ export default { }, dragByHandleLeft(e) { - let newXStart = e.clientX - this.barContainer.left + const chart = e.target.closest('.g-gantt-chart') + if (!chart) return + let newXStart = chart.scrollLeft + e.clientX - this.barContainer.left let newStartMoment = this.mapPositionToTime(newXStart) if ( this.barEndMoment.diff(newStartMoment, this.timeUnit) < 1 || @@ -304,7 +307,9 @@ export default { }, dragByHandleRight(e) { - let newXEnd = e.clientX - this.barContainer.left + const chart = e.target.closest('.g-gantt-chart') + if (!chart) return + let newXEnd = chart.scrollLeft + e.clientX - this.barContainer.left let newEndMoment = this.mapPositionToTime(newXEnd) if ( newEndMoment.isSameOrBefore(this.barStartMoment, this.timeUnit) || diff --git a/src/GGanttChart.vue b/src/GGanttChart.vue index 7ea7d1c..de5937c 100644 --- a/src/GGanttChart.vue +++ b/src/GGanttChart.vue @@ -1,6 +1,6 @@ @@ -83,7 +84,7 @@ export default { }, mounted() { - this.timemarker = document.querySelector('#g-timeaxis-marker') + this.timemarker = this.$refs['g-timeaxis-marker'] this.initAxis() this.onWindowResize() window.addEventListener('resize', this.onWindowResize) @@ -175,7 +176,9 @@ export default { }, moveTimemarker(event) { + const chart = this.timemarker.closest('.g-gantt-chart') this.timemarker.style.left = + chart.scrollLeft + event.clientX - this.timemarkerOffset - this.horizontalAxisContainer.left + @@ -183,9 +186,8 @@ export default { }, onWindowResize() { - this.horizontalAxisContainer = document - .querySelector('#g-timeaxis') - .getBoundingClientRect() + this.horizontalAxisContainer = + this.$refs['g-timeaxis'].getBoundingClientRect() this.hourFontSize = Math.min( 9.5, @@ -228,7 +230,7 @@ export default {