How to use the plywood.Range.fromJS 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
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;
  }
github allegro / turnilo / src / common / utils / plywood / range.mocha.ts View on Github external
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);
    });
github allegro / turnilo / src / common / utils / plywood / range.mocha.ts View on Github external
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 }));
    });
github allegro / turnilo / src / common / utils / plywood / range.mocha.ts View on Github external
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);
    });
github allegro / turnilo / src / common / utils / plywood / range.mocha.ts View on Github external
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 }));
    });
github allegro / turnilo / src / common / utils / plywood / range.mocha.ts View on Github external
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 }));
    });
github allegro / turnilo / src / client / visualizations / line-chart / line-chart.tsx View on Github external
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);

  }