yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
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
76
import Color from "../../Core/Color.js";
import defined from "../../Core/defined.js";
import JulianDate from "../../Core/JulianDate.js";
 
/**
 * @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) {
  var startInterval = this.interval.start;
  var stopInterval = this.interval.stop;
 
  var spanStart = renderState.startJulian;
  var 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.
    var x;
    var start, stop;
    for (x = 0; x < renderState.timeBarWidth; ++x) {
      var 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;