private setRectangleBounds(left: number, right: number, top: number, bottom: number): boolean {
const bounds = normalizeBounds(left, right, top, bottom, this.container);
const snapshot = this.dragStateSnapshot;
const dragTarget = this.activeDragTarget;
if (this.mode === 'dragging' && snapshot && dragTarget && dragTarget !== 'body') {
if (
snapshot.startTime === null ||
snapshot.endTime === null ||
snapshot.startPrice === null ||
snapshot.endPrice === null
) {
return false;
}
let nextStartTime = snapshot.startTime;
let nextEndTime = snapshot.endTime;
let nextStartPrice = snapshot.startPrice;
let nextEndPrice = snapshot.endPrice;
const startIsLeft = this.isStartTimeOnLeft(snapshot);
const startIsTop = this.isStartPriceOnTop(snapshot);
if (dragTarget.includes('w')) {
const nextTime = getTimeFromXCoordinate(this.chart, bounds.left);
if (nextTime === null) {
return false;
}
if (startIsLeft) {
nextStartTime = nextTime;
} else {
nextEndTime = nextTime;
}
}
if (dragTarget.includes('e')) {
const nextTime = getTimeFromXCoordinate(this.chart, bounds.right);
if (nextTime === null) {
return false;
}
if (startIsLeft) {
nextEndTime = nextTime;
} else {
nextStartTime = nextTime;
}
}
if (dragTarget.includes('n')) {
const nextPrice = getPriceFromYCoordinate(this.series, bounds.top);
if (nextPrice === null) {
return false;
}
if (startIsTop) {
nextStartPrice = nextPrice;
} else {
nextEndPrice = nextPrice;
}
}
if (dragTarget.includes('s')) {
const nextPrice = getPriceFromYCoordinate(this.series, bounds.bottom);
if (nextPrice === null) {
return false;
}
if (startIsTop) {
nextEndPrice = nextPrice;
} else {
nextStartPrice = nextPrice;
}
}
this.startTime = nextStartTime;
this.endTime = nextEndTime;
this.startPrice = nextStartPrice;
this.endPrice = nextEndPrice;
return true;
}
const startTime = getTimeFromXCoordinate(this.chart, bounds.left);
const endTime = getTimeFromXCoordinate(this.chart, bounds.right);
const startPrice = getPriceFromYCoordinate(this.series, bounds.top);
const endPrice = getPriceFromYCoordinate(this.series, bounds.bottom);
if (startTime === null || endTime === null || startPrice === null || endPrice === null) {
return false;
}
this.startTime = startTime;
this.endTime = endTime;
this.startPrice = startPrice;
this.endPrice = endPrice;
return true;
}