2
0
mirror of https://github.com/tenrok/vue-ganttastic.git synced 2026-06-24 14:50:33 +03:00

fix: time marker movement

This commit is contained in:
2021-10-08 09:35:50 +03:00
parent 6c4ab268b5
commit 472cee8e80
3 changed files with 26 additions and 19 deletions
+8 -3
View File
@@ -273,7 +273,8 @@ export default {
}, },
drag(e) { 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 barWidth = this.$refs['g-gantt-bar'].getBoundingClientRect().width
let newXStart = let newXStart =
chart.scrollLeft + chart.scrollLeft +
@@ -291,7 +292,9 @@ export default {
}, },
dragByHandleLeft(e) { 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) let newStartMoment = this.mapPositionToTime(newXStart)
if ( if (
this.barEndMoment.diff(newStartMoment, this.timeUnit) < 1 || this.barEndMoment.diff(newStartMoment, this.timeUnit) < 1 ||
@@ -304,7 +307,9 @@ export default {
}, },
dragByHandleRight(e) { 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) let newEndMoment = this.mapPositionToTime(newXEnd)
if ( if (
newEndMoment.isSameOrBefore(this.barStartMoment, this.timeUnit) || newEndMoment.isSameOrBefore(this.barStartMoment, this.timeUnit) ||
+5 -5
View File
@@ -1,6 +1,6 @@
<template> <template>
<div <div
id="g-gantt-chart" class="g-gantt-chart"
:style="{ width: width, background: themeColors.background }" :style="{ width: width, background: themeColors.background }"
> >
<g-gantt-timeaxis <g-gantt-timeaxis
@@ -22,7 +22,7 @@
/> />
<div <div
id="g-gantt-rows-container" class="g-gantt-rows-container"
:style="{ :style="{
width: `${ width: `${
timeCount * 30 + parseInt(rowLabelWidth.replace('px', '')) timeCount * 30 + parseInt(rowLabelWidth.replace('px', ''))
@@ -480,7 +480,7 @@ export default {
</script> </script>
<style scoped> <style scoped>
#g-gantt-chart { .g-gantt-chart {
position: relative; position: relative;
/* display: flex; */ /* display: flex; */
/* flex-direction: column; */ /* flex-direction: column; */
@@ -494,11 +494,11 @@ export default {
padding-bottom: 23px; padding-bottom: 23px;
} }
#g-gantt-chart >>> * { .g-gantt-chart >>> * {
font-family: Roboto, Verdana; font-family: Roboto, Verdana;
} }
#g-gantt-rows-container { .g-gantt-rows-container {
position: relative; position: relative;
} }
</style> </style>
+13 -11
View File
@@ -1,6 +1,7 @@
<template> <template>
<div <div
id="g-timeaxis" ref="g-timeaxis"
class="g-timeaxis"
:style="{ :style="{
width: `${ width: `${
getTimeCount() * 30 + parseInt(rowLabelWidth.replace('px', '')) getTimeCount() * 30 + parseInt(rowLabelWidth.replace('px', ''))
@@ -48,7 +49,7 @@
</div> </div>
</div> </div>
</div> </div>
<div id="g-timeaxis-marker" /> <div ref="g-timeaxis-marker" class="g-timeaxis-marker" />
</div> </div>
</template> </template>
@@ -83,7 +84,7 @@ export default {
}, },
mounted() { mounted() {
this.timemarker = document.querySelector('#g-timeaxis-marker') this.timemarker = this.$refs['g-timeaxis-marker']
this.initAxis() this.initAxis()
this.onWindowResize() this.onWindowResize()
window.addEventListener('resize', this.onWindowResize) window.addEventListener('resize', this.onWindowResize)
@@ -175,7 +176,9 @@ export default {
}, },
moveTimemarker(event) { moveTimemarker(event) {
const chart = this.timemarker.closest('.g-gantt-chart')
this.timemarker.style.left = this.timemarker.style.left =
chart.scrollLeft +
event.clientX - event.clientX -
this.timemarkerOffset - this.timemarkerOffset -
this.horizontalAxisContainer.left + this.horizontalAxisContainer.left +
@@ -183,9 +186,8 @@ export default {
}, },
onWindowResize() { onWindowResize() {
this.horizontalAxisContainer = document this.horizontalAxisContainer =
.querySelector('#g-timeaxis') this.$refs['g-timeaxis'].getBoundingClientRect()
.getBoundingClientRect()
this.hourFontSize = this.hourFontSize =
Math.min( Math.min(
9.5, 9.5,
@@ -228,7 +230,7 @@ export default {
</script> </script>
<style scoped> <style scoped>
#g-timeaxis, .g-timeaxis,
.g-timeaxis-days, .g-timeaxis-days,
.g-timeaxis-day, .g-timeaxis-day,
.g-timeaxis-day > div { .g-timeaxis-day > div {
@@ -236,7 +238,7 @@ export default {
/* overflow: hidden; */ /* overflow: hidden; */
} }
#g-timeaxis { .g-timeaxis {
position: sticky; position: sticky;
top: 0; top: 0;
/* width: 100%; */ /* width: 100%; */
@@ -247,7 +249,7 @@ export default {
box-shadow: 0px 1px 3px 2px rgba(50, 50, 50, 0.5); box-shadow: 0px 1px 3px 2px rgba(50, 50, 50, 0.5);
} }
#g-timeaxis > .g-timeaxis-empty-space { .g-timeaxis > .g-timeaxis-empty-space {
/* width: 20%; this has to be as wide as .ganttRowTitle in VGanttastic.css */ /* width: 20%; this has to be as wide as .ganttRowTitle in VGanttastic.css */
min-height: 100%; min-height: 100%;
background: #f5f5f5; background: #f5f5f5;
@@ -256,7 +258,7 @@ export default {
position: sticky; position: sticky;
} }
#g-timeaxis > .g-timeaxis-days { .g-timeaxis > .g-timeaxis-days {
position: relative; position: relative;
/* width: 80%; */ /* width: 80%; */
height: 100%; height: 100%;
@@ -304,7 +306,7 @@ export default {
height: 8px; height: 8px;
} }
#g-timeaxis-marker { .g-timeaxis-marker {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;