How to use the plywood.Range.isRange 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
function findClosest(data: Datum[], dragDate: Date, scaleX: (v: continuousValueType) => number, continuousDimension: Dimension) {
  let closestDatum: Datum = null;
  let minDist = Infinity;
  for (const datum of data) {
    const continuousSegmentValue = datum[continuousDimension.name] as (TimeRange | NumberRange);
    if (!continuousSegmentValue || !Range.isRange(continuousSegmentValue)) continue; // !Range.isRange => temp solution for non-bucketed reaching here
    const mid = continuousSegmentValue.midpoint();
    const dist = Math.abs(mid.valueOf() - dragDate.valueOf());
    const distPx = Math.abs(scaleX(mid) - scaleX(dragDate));
    if ((!closestDatum || dist < minDist) && distPx < MAX_HOVER_DIST) { // Make sure it is not too far way
      closestDatum = datum;
      minDist = dist;
    }
  }
  return closestDatum;
}
github allegro / turnilo / src / client / components / chart-line / chart-line.tsx View on Github external
export const ChartLine: React.SFC = ({ stage, dataset, getY, getX, scaleX, scaleY, color, showArea, hoverRange, dashed }) => {
  if (!dataset || !color) return null;

  let dataPoints: DataPoint[] = [];
  let hoverDataPoint: DataPoint = null;

  const ds = dataset.data;
  for (let i = 0; i < ds.length; i++) {
    const datum = ds[i];
    const range = getX(datum) as PlywoodRange;

    const incorrectData = !range; // !range => Incorrect data loaded, !Range.isRange => temp solution for non-bucketed reaching here
    if (incorrectData || !Range.isRange(range)) return null;

    const rangeMidpoint = (range as NumberRange | TimeRange).midpoint();
    const measureValue = getY(datum);

    // Add potential pre zero point
    const prevDatum = ds[i - 1];
    if (prevDatum) {
      const prevRange = getX(prevDatum) as PlywoodRange;
      if (prevRange.end.valueOf() !== range.start.valueOf()) {
        dataPoints.push([
          scaleX(rangeMidpoint.valueOf() - ((range.end.valueOf() as any) - (range.start.valueOf() as any))),
          scaleY(0)
        ]);
      }
    }
github allegro / turnilo / src / common / utils / plywood / range.ts View on Github external
export function union(first: PlywoodRange, second: PlywoodRange): PlywoodRange | null {
  if (!Range.isRange(first) && !Range.isRange(second)) {
    return null;
  }
  if (!Range.isRange(first)) {
    return second;
  }
  if (!Range.isRange(second)) {
    return first;
  }
  return first.union(second);
}
github allegro / turnilo / src / common / utils / plywood / range.ts View on Github external
export function union(first: PlywoodRange, second: PlywoodRange): PlywoodRange | null {
  if (!Range.isRange(first) && !Range.isRange(second)) {
    return null;
  }
  if (!Range.isRange(first)) {
    return second;
  }
  if (!Range.isRange(second)) {
    return first;
  }
  return first.union(second);
}
github allegro / turnilo / src / client / visualizations / bar-chart / bar-chart.tsx View on Github external
data.forEach((d, i) => {
        let segmentValue = d[dimension.name];
        let segmentValueStr = String(Range.isRange(segmentValue) ? (segmentValue as any)[leftThing] : "");
        let coordinate = coordinates[i];

        labels.push(<div style="{{">{segmentValueStr}</div>);

        if (i === lastIndex) {
          segmentValueStr = String(Range.isRange(segmentValue) ? (segmentValue as any)[rightThing] : "");
          labels.push(<div style="{{">{segmentValueStr}</div>);
        }
github geo-opensource / pivot / src / client / components / time-filter-menu / time-filter-menu.tsx View on Github external
componentWillMount() {
    const { essence, timekeeper, dimension } = this.props;
    const { filter } = essence;
    const { timezone } = essence;

    var dimensionExpression = dimension.expression;
    var timeSelection = filter.getSelection(dimensionExpression) as Expression;
    var selectedTimeRangeSet = essence.getEffectiveFilter(timekeeper).getLiteralSet(dimensionExpression);
    var selectedTimeRange = (selectedTimeRangeSet && selectedTimeRangeSet.size() === 1) ? selectedTimeRangeSet.elements[0] : null;
    if (selectedTimeRange && !Range.isRange(selectedTimeRange)) selectedTimeRange = makeDateIntoTimeRange(selectedTimeRange, timezone);
    var clause = filter.clauseForExpression(dimensionExpression);

    this.setState({
      timeSelection,
      tab: (!clause || clause.relative || clause.isLessThanFullDay()) ? 'relative' : 'specific',
      startTime: selectedTimeRange ? day.floor(selectedTimeRange.start, timezone) : null,
      endTime: selectedTimeRange ? day.ceil(selectedTimeRange.end, timezone) : null
    });
  }