How to use the plywood.TimeRange.isTimeRange function in plywood

To help you get started, we’ve selected a few plywood examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github allegro / turnilo / src / client / visualizations / line-chart / line-chart.tsx View on Github external
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({
github implydata / plyql / src / plyql-mysql-gateway.ts View on Github external
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;
}
github allegro / turnilo / src / common / utils / formatter / formatter.ts View on Github external
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;
  }
}
github allegro / turnilo / src / common / utils / formatter / formatter.ts View on Github external
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);
}
github allegro / turnilo / src / client / visualizations / line-chart / line-chart.tsx View on Github external
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);

  }