Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private ensureMaxTime(axisRange: PlywoodRange, maxTime: Date, continuousSplit: Split, timezone: Timezone) {
// Special treatment for realtime data, i.e. time data where the maxTime is within Duration of the filter end
const continuousBucket = continuousSplit.bucket;
if (maxTime && continuousBucket instanceof Duration) {
const axisRangeEnd = axisRange.end as Date;
const axisRangeEndFloor = continuousBucket.floor(axisRangeEnd, timezone);
const axisRangeEndCeil = continuousBucket.shift(axisRangeEndFloor, timezone);
if (maxTime && axisRangeEndFloor < maxTime && maxTime < axisRangeEndCeil) {
return Range.fromJS({ start: axisRange.start, end: axisRangeEndCeil });
}
}
return axisRange;
}
it("should handle first non range", () => {
const range = Range.fromJS({ start: 2, end: 4 });
expect(union(null, range)).to.be.deep.equal(range);
expect(union(undefined, range)).to.be.deep.equal(range);
expect(union({} as PlywoodRange, range)).to.be.deep.equal(range);
});
it("should calculate correct union for overlaps", () => {
const a = Range.fromJS({ start: 1, end: 3 });
const b = Range.fromJS({ start: 2, end: 4 });
expect(union(a, b)).to.be.deep.equal(Range.fromJS({ start: 1, end: 4 }));
});
it("should handle second non range", () => {
const range = Range.fromJS({ start: 2, end: 4 });
expect(union(range, null)).to.be.deep.equal(range);
expect(union(range, undefined)).to.be.deep.equal(range);
expect(union(range, {} as PlywoodRange)).to.be.deep.equal(range);
});
it("should calculate correct union", () => {
const a = Range.fromJS({ start: 1, end: 3 });
const b = Range.fromJS({ start: 3, end: 5 });
expect(union(a, b)).to.be.deep.equal(Range.fromJS({ start: 1, end: 5 }));
});
it("should calculate correct union", () => {
const a = Range.fromJS({ start: 1, end: 3 });
const b = Range.fromJS({ start: 3, end: 5 });
expect(union(a, b)).to.be.deep.equal(Range.fromJS({ start: 1, end: 5 }));
});
const { dragStartValue, axisRange, scaleX } = this.state;
let dragEndValue = scaleX.invert(this.getMyEventX(e));
let rangeJS: TimeRangeJS | NumberRangeJS = null;
if (dragStartValue.valueOf() === dragEndValue.valueOf()) {
dragEndValue = TimeRange.isTimeRange(axisRange) ? new Date(dragEndValue.valueOf() + 1) : dragEndValue + 1;
}
if (dragStartValue < dragEndValue) {
rangeJS = { start: dragStartValue, end: dragEndValue };
} else {
rangeJS = { start: dragEndValue, end: dragStartValue };
}
return Range.fromJS(rangeJS).intersect(axisRange);
}