Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
floorRange(dragRange: PlywoodRange): PlywoodRange | null {
const { essence } = this.props;
const { splits, timezone } = essence;
const continuousSplit = splits.splits.last();
if (!continuousSplit.bucket) return dragRange; // temp solution for non-bucketed reaching here
if (TimeRange.isTimeRange(dragRange)) {
const duration = continuousSplit.bucket as Duration;
return TimeRange.fromJS({
start: duration.floor(dragRange.start, timezone),
end: duration.shift(duration.floor(dragRange.end, timezone), timezone, 1)
});
}
if (NumberRange.isNumberRange(dragRange)) {
const bucketSize = continuousSplit.bucket as number;
const startFloored = roundTo((dragRange as NumberRange).start, bucketSize);
let endFloored = roundTo((dragRange as NumberRange).end, bucketSize);
if (endFloored - startFloored < bucketSize) {
endFloored += bucketSize;
}
return NumberRange.fromJS({
function datumToMySQLRow(row: Datum, timezone: Timezone) {
let newRow: any = {};
for (let k in row) {
let v = row[k];
// Kill ranges
if (v && (v as any).start) v = (v as any).start;
if (v && (v as any).toISOString) {
v = dateToSQL(v as Date, timezone);
} else if (Set.isSet(v) || TimeRange.isTimeRange(v)) {
v = v.toString(timezone); // plyql does not yet support set times though
} else if (typeof v === 'boolean') {
v = Number(v);
}
newRow[k] = v;
}
return newRow;
}
export function formatValue(value: any, timezone?: Timezone): string {
if (NumberRange.isNumberRange(value)) {
return formatNumberRange(value);
} else if (TimeRange.isTimeRange(value)) {
return formatTimeRange(new DateRange(value), timezone);
} else {
return "" + value;
}
}
export function formatSegment(value: any, timezone: Timezone): string {
if (TimeRange.isTimeRange(value)) {
return formatStartOfTimeRange(value, timezone);
} else if (NumberRange.isNumberRange(value)) {
return formatNumberRange(value);
}
return String(value);
}
getDragRange(e: MouseEvent): PlywoodRange | null {
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);
}