All files / widgets/Source/Timeline TimelineTrack.js

3.84% Statements 1/26
0% Branches 0/24
0% Functions 0/2
3.84% Lines 1/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                        1x                                                                                                                            
import { Color, defined, JulianDate } from "@cesium/engine";
 
/**
 * @private
 */
function TimelineTrack(interval, pixelHeight, color, backgroundColor) {
  this.interval = interval;
  this.height = pixelHeight;
  this.color = color || new Color(0.5, 0.5, 0.5, 1.0);
  this.backgroundColor = backgroundColor || new Color(0.0, 0.0, 0.0, 0.0);
}
 
TimelineTrack.prototype.render = function (context, renderState) {
  const startInterval = this.interval.start;
  const stopInterval = this.interval.stop;
 
  const spanStart = renderState.startJulian;
  const spanStop = JulianDate.addSeconds(
    renderState.startJulian,
    renderState.duration,
    new JulianDate(),
  );
 
  if (
    JulianDate.lessThan(startInterval, spanStart) &&
    JulianDate.greaterThan(stopInterval, spanStop)
  ) {
    //The track takes up the entire visible span.
    context.fillStyle = this.color.toCssColorString();
    context.fillRect(0, renderState.y, renderState.timeBarWidth, this.height);
  } else if (
    JulianDate.lessThanOrEquals(startInterval, spanStop) &&
    JulianDate.greaterThanOrEquals(stopInterval, spanStart)
  ) {
    //The track only takes up some of the visible span, compute that span.
    let x;
    let start, stop;
    for (x = 0; x < renderState.timeBarWidth; ++x) {
      const currentTime = JulianDate.addSeconds(
        renderState.startJulian,
        (x / renderState.timeBarWidth) * renderState.duration,
        new JulianDate(),
      );
      if (
        !defined(start) &&
        JulianDate.greaterThanOrEquals(currentTime, startInterval)
      ) {
        start = x;
      } else if (
        !defined(stop) &&
        JulianDate.greaterThanOrEquals(currentTime, stopInterval)
      ) {
        stop = x;
      }
    }
 
    context.fillStyle = this.backgroundColor.toCssColorString();
    context.fillRect(0, renderState.y, renderState.timeBarWidth, this.height);
 
    if (defined(start)) {
      if (!defined(stop)) {
        stop = renderState.timeBarWidth;
      }
      context.fillStyle = this.color.toCssColorString();
      context.fillRect(
        start,
        renderState.y,
        Math.max(stop - start, 1),
        this.height,
      );
    }
  }
};
export default TimelineTrack;