mirror of
https://github.com/tenrok/vue-ganttastic.git
synced 2026-06-24 17:40:33 +03:00
fix: prevent other bars out of range when push on overlap
This commit is contained in:
+12
-24
@@ -276,7 +276,7 @@ export default {
|
|||||||
let barWidth = this.$refs['g-gantt-bar'].getBoundingClientRect().width
|
let barWidth = this.$refs['g-gantt-bar'].getBoundingClientRect().width
|
||||||
let newXStart = e.clientX - this.barContainer.left - this.cursorOffsetX
|
let newXStart = e.clientX - this.barContainer.left - this.cursorOffsetX
|
||||||
let newXEnd = newXStart + barWidth
|
let newXEnd = newXStart + barWidth
|
||||||
if (this.isPosOutOfDragRange(e, newXStart, newXEnd)) {
|
if (this.isPosOutOfDragRange(newXStart, newXEnd)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.barStartMoment = this.mapPositionToTime(newXStart)
|
this.barStartMoment = this.mapPositionToTime(newXStart)
|
||||||
@@ -290,7 +290,7 @@ export default {
|
|||||||
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 ||
|
||||||
this.isPosOutOfDragRange(e, newXStart, null)
|
this.isPosOutOfDragRange(newXStart, null)
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ export default {
|
|||||||
let newEndMoment = this.mapPositionToTime(newXEnd)
|
let newEndMoment = this.mapPositionToTime(newXEnd)
|
||||||
if (
|
if (
|
||||||
newEndMoment.isSameOrBefore(this.barStartMoment, this.timeUnit) ||
|
newEndMoment.isSameOrBefore(this.barStartMoment, this.timeUnit) ||
|
||||||
this.isPosOutOfDragRange(e, null, newXEnd)
|
this.isPosOutOfDragRange(null, newXEnd)
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -311,8 +311,7 @@ export default {
|
|||||||
this.manageOverlapping()
|
this.manageOverlapping()
|
||||||
},
|
},
|
||||||
|
|
||||||
isPosOutOfDragRange(e, newXStart, newXEnd) {
|
isPosOutOfDragRange(newXStart, newXEnd) {
|
||||||
// console.log('isPosOutOfDragRange target', e.target.className)
|
|
||||||
if (newXStart && newXStart < 0) {
|
if (newXStart && newXStart < 0) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -343,25 +342,17 @@ export default {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
let pullToTheLeft = false,
|
const isSqueezeToLeft =
|
||||||
pullToTheRight = false
|
newXStart &&
|
||||||
let xStart = this.mapTimeToPosition(this.barStartMoment)
|
|
||||||
let xEnd = this.mapTimeToPosition(this.barEndMoment)
|
|
||||||
|
|
||||||
if (
|
|
||||||
moment(this.bar[this.barStartKey]).isBefore(this.barStartBeforeDrag)
|
moment(this.bar[this.barStartKey]).isBefore(this.barStartBeforeDrag)
|
||||||
) {
|
const isSqueezeToRight =
|
||||||
pullToTheLeft = true
|
newXEnd &&
|
||||||
} else if (
|
|
||||||
moment(this.bar[this.barEndKey]).isAfter(this.barEndBeforeDrag)
|
moment(this.bar[this.barEndKey]).isAfter(this.barEndBeforeDrag)
|
||||||
) {
|
|
||||||
pullToTheRight = true
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentIndex = this.allBarsInRow.findIndex((bar) => bar == this.bar)
|
const currentIndex = this.allBarsInRow.findIndex((bar) => bar == this.bar)
|
||||||
|
|
||||||
let otherBars = []
|
let otherBars = []
|
||||||
if (newXEnd && pullToTheRight) {
|
if (isSqueezeToRight) {
|
||||||
otherBars = this.allBarsInRow.slice(currentIndex + 1)
|
otherBars = this.allBarsInRow.slice(currentIndex + 1)
|
||||||
if (otherBars.length) {
|
if (otherBars.length) {
|
||||||
let otherBarTotalWidth = otherBars
|
let otherBarTotalWidth = otherBars
|
||||||
@@ -371,11 +362,8 @@ export default {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (newXStart && pullToTheLeft) {
|
} else if (isSqueezeToLeft) {
|
||||||
otherBars = this.allBarsInRow.slice(
|
otherBars = this.allBarsInRow.slice(0, -currentIndex)
|
||||||
0,
|
|
||||||
this.allBarsInRow.length - currentIndex
|
|
||||||
)
|
|
||||||
if (otherBars.length) {
|
if (otherBars.length) {
|
||||||
let otherBarTotalWidth = otherBars
|
let otherBarTotalWidth = otherBars
|
||||||
.map((bar) => this.getBarWidth(bar))
|
.map((bar) => this.getBarWidth(bar))
|
||||||
|
|||||||
Reference in New Issue
Block a user