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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | 1x 1x 1x 3300x 65x 65x 11x 6x 5x 5x 5x 5x 3x 3x 3x 2x 2x 2x 88x 5x 83x 82x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 103x 1x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 78x 102x 102x 79x 102x 102x 85x 85x 2x 83x 83x 79x 4x 102x 102x 88x 15x 15x 15x 15x 15x 4x 4x 11x 11x 5x 6x 5x 5x 1x 1x 1x 4x 1x 3x 1x 2x 2x 11x 102x 102x 22x 22x 22x 10x 12x 12x 12x 12x 12x 2x 10x 10x 12x 5x 12x 102x 102x 116x 116x 116x 103x 13x 13x 102x 102x 128x 102x 4x 4x 2x 2x 2x 102x 126x 102x 7x 7x 7x 3x 7x 102x 130x 102x 6x 6x 6x 1x 6x 102x 135x 102x 5x 102x 114x 111x 102x 30x 30x 30x 30x 30x 29x 102x 30x 30x 30x 30x 30x 29x 1x 90x 89x 1x 1x 81x 81x 81x 2x 79x 1x 6x 1x 107x 1x 106x 106x 106x 106x 3073x 3073x 3073x 3073x 106x 106x 106x 3073x 3073x 3069x 106x 106x 1x 30x 30x 3x 190x 116x 115x 126x 13x 2x 1x 1x 5x 2x 1x 1x 1x 1x | import {
addAllToArray,
binarySearch,
ClockRange,
ClockStep,
defined,
DeveloperError,
JulianDate,
} from "@cesium/engine";
import knockout from "../ThirdParty/knockout.js";
import createCommand from "../createCommand.js";
import ToggleButtonViewModel from "../ToggleButtonViewModel.js";
const monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
const realtimeShuttleRingAngle = 15;
const maxShuttleRingAngle = 105;
function numberComparator(left, right) {
return left - right;
}
function getTypicalMultiplierIndex(multiplier, shuttleRingTicks) {
const index = binarySearch(shuttleRingTicks, multiplier, numberComparator);
return index < 0 ? ~index : index;
}
function angleToMultiplier(angle, shuttleRingTicks) {
//Use a linear scale for -1 to 1 between -15 < angle < 15 degrees
if (Math.abs(angle) <= realtimeShuttleRingAngle) {
return angle / realtimeShuttleRingAngle;
}
const minp = realtimeShuttleRingAngle;
const maxp = maxShuttleRingAngle;
let maxv;
const minv = 0;
let scale;
if (angle > 0) {
maxv = Math.log(shuttleRingTicks[shuttleRingTicks.length - 1]);
scale = (maxv - minv) / (maxp - minp);
return Math.exp(minv + scale * (angle - minp));
}
maxv = Math.log(-shuttleRingTicks[0]);
scale = (maxv - minv) / (maxp - minp);
return -Math.exp(minv + scale * (Math.abs(angle) - minp));
}
function multiplierToAngle(multiplier, shuttleRingTicks, clockViewModel) {
if (clockViewModel.clockStep === ClockStep.SYSTEM_CLOCK) {
return realtimeShuttleRingAngle;
}
if (Math.abs(multiplier) <= 1) {
return multiplier * realtimeShuttleRingAngle;
}
const fastedMultipler = shuttleRingTicks[shuttleRingTicks.length - 1];
Iif (multiplier > fastedMultipler) {
multiplier = fastedMultipler;
} else Iif (multiplier < -fastedMultipler) {
multiplier = -fastedMultipler;
}
const minp = realtimeShuttleRingAngle;
const maxp = maxShuttleRingAngle;
let maxv;
const minv = 0;
let scale;
Eif (multiplier > 0) {
maxv = Math.log(fastedMultipler);
scale = (maxv - minv) / (maxp - minp);
return (Math.log(multiplier) - minv) / scale + minp;
}
maxv = Math.log(-shuttleRingTicks[0]);
scale = (maxv - minv) / (maxp - minp);
return -((Math.log(Math.abs(multiplier)) - minv) / scale + minp);
}
/**
* The view model for the {@link Animation} widget.
* @alias AnimationViewModel
* @constructor
*
* @param {ClockViewModel} clockViewModel The ClockViewModel instance to use.
*
* @see Animation
*/
function AnimationViewModel(clockViewModel) {
//>>includeStart('debug', pragmas.debug);
if (!defined(clockViewModel)) {
throw new DeveloperError("clockViewModel is required.");
}
//>>includeEnd('debug');
const that = this;
this._clockViewModel = clockViewModel;
this._allShuttleRingTicks = [];
this._dateFormatter = AnimationViewModel.defaultDateFormatter;
this._timeFormatter = AnimationViewModel.defaultTimeFormatter;
/**
* Gets or sets whether the shuttle ring is currently being dragged. This property is observable.
* @type {boolean}
* @default false
*/
this.shuttleRingDragging = false;
/**
* Gets or sets whether dragging the shuttle ring should cause the multiplier
* to snap to the defined tick values rather than interpolating between them.
* This property is observable.
* @type {boolean}
* @default false
*/
this.snapToTicks = false;
knockout.track(this, [
"_allShuttleRingTicks",
"_dateFormatter",
"_timeFormatter",
"shuttleRingDragging",
"snapToTicks",
]);
this._sortedFilteredPositiveTicks = [];
this.setShuttleRingTicks(AnimationViewModel.defaultTicks);
/**
* Gets the string representation of the current time. This property is observable.
* @type {string}
*/
this.timeLabel = undefined;
knockout.defineProperty(this, "timeLabel", function () {
return that._timeFormatter(that._clockViewModel.currentTime, that);
});
/**
* Gets the string representation of the current date. This property is observable.
* @type {string}
*/
this.dateLabel = undefined;
knockout.defineProperty(this, "dateLabel", function () {
return that._dateFormatter(that._clockViewModel.currentTime, that);
});
/**
* Gets the string representation of the current multiplier. This property is observable.
* @type {string}
*/
this.multiplierLabel = undefined;
knockout.defineProperty(this, "multiplierLabel", function () {
const clockViewModel = that._clockViewModel;
if (clockViewModel.clockStep === ClockStep.SYSTEM_CLOCK) {
return "Today";
}
const multiplier = clockViewModel.multiplier;
//If it's a whole number, just return it.
if (multiplier % 1 === 0) {
return `${multiplier.toFixed(0)}x`;
}
//Convert to decimal string and remove any trailing zeroes
return `${multiplier.toFixed(3).replace(/0{0,3}$/, "")}x`;
});
/**
* Gets or sets the current shuttle ring angle. This property is observable.
* @type {number}
*/
this.shuttleRingAngle = undefined;
knockout.defineProperty(this, "shuttleRingAngle", {
get: function () {
return multiplierToAngle(
clockViewModel.multiplier,
that._allShuttleRingTicks,
clockViewModel,
);
},
set: function (angle) {
angle = Math.max(
Math.min(angle, maxShuttleRingAngle),
-maxShuttleRingAngle,
);
const ticks = that._allShuttleRingTicks;
const clockViewModel = that._clockViewModel;
clockViewModel.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
//If we are at the max angle, simply return the max value in either direction.
if (Math.abs(angle) === maxShuttleRingAngle) {
clockViewModel.multiplier =
angle > 0 ? ticks[ticks.length - 1] : ticks[0];
return;
}
let multiplier = angleToMultiplier(angle, ticks);
if (that.snapToTicks) {
multiplier = ticks[getTypicalMultiplierIndex(multiplier, ticks)];
} else if (multiplier !== 0) {
const positiveMultiplier = Math.abs(multiplier);
if (positiveMultiplier > 100) {
const numDigits = positiveMultiplier.toFixed(0).length - 2;
const divisor = Math.pow(10, numDigits);
multiplier = (Math.round(multiplier / divisor) * divisor) | 0;
} else if (positiveMultiplier > realtimeShuttleRingAngle) {
multiplier = Math.round(multiplier);
} else if (positiveMultiplier > 1) {
multiplier = +multiplier.toFixed(1);
} else Eif (positiveMultiplier > 0) {
multiplier = +multiplier.toFixed(2);
}
}
clockViewModel.multiplier = multiplier;
},
});
this._canAnimate = undefined;
knockout.defineProperty(this, "_canAnimate", function () {
const clockViewModel = that._clockViewModel;
const clockRange = clockViewModel.clockRange;
if (that.shuttleRingDragging || clockRange === ClockRange.UNBOUNDED) {
return true;
}
const multiplier = clockViewModel.multiplier;
const currentTime = clockViewModel.currentTime;
const startTime = clockViewModel.startTime;
let result = false;
if (clockRange === ClockRange.LOOP_STOP) {
result =
JulianDate.greaterThan(currentTime, startTime) ||
(currentTime.equals(startTime) && multiplier > 0);
} else {
const stopTime = clockViewModel.stopTime;
result =
(JulianDate.greaterThan(currentTime, startTime) &&
JulianDate.lessThan(currentTime, stopTime)) || //
(currentTime.equals(startTime) && multiplier > 0) || //
(currentTime.equals(stopTime) && multiplier < 0);
}
if (!result) {
clockViewModel.shouldAnimate = false;
}
return result;
});
this._isSystemTimeAvailable = undefined;
knockout.defineProperty(this, "_isSystemTimeAvailable", function () {
const clockViewModel = that._clockViewModel;
const clockRange = clockViewModel.clockRange;
if (clockRange === ClockRange.UNBOUNDED) {
return true;
}
const systemTime = clockViewModel.systemTime;
return (
JulianDate.greaterThanOrEquals(systemTime, clockViewModel.startTime) &&
JulianDate.lessThanOrEquals(systemTime, clockViewModel.stopTime)
);
});
this._isAnimating = undefined;
knockout.defineProperty(this, "_isAnimating", function () {
return (
that._clockViewModel.shouldAnimate &&
(that._canAnimate || that.shuttleRingDragging)
);
});
const pauseCommand = createCommand(function () {
const clockViewModel = that._clockViewModel;
if (clockViewModel.shouldAnimate) {
clockViewModel.shouldAnimate = false;
} else Eif (that._canAnimate) {
clockViewModel.shouldAnimate = true;
}
});
this._pauseViewModel = new ToggleButtonViewModel(pauseCommand, {
toggled: knockout.computed(function () {
return !that._isAnimating;
}),
tooltip: "Pause",
});
const playReverseCommand = createCommand(function () {
const clockViewModel = that._clockViewModel;
const multiplier = clockViewModel.multiplier;
if (multiplier > 0) {
clockViewModel.multiplier = -multiplier;
}
clockViewModel.shouldAnimate = true;
});
this._playReverseViewModel = new ToggleButtonViewModel(playReverseCommand, {
toggled: knockout.computed(function () {
return that._isAnimating && clockViewModel.multiplier < 0;
}),
tooltip: "Play Reverse",
});
const playForwardCommand = createCommand(function () {
const clockViewModel = that._clockViewModel;
const multiplier = clockViewModel.multiplier;
if (multiplier < 0) {
clockViewModel.multiplier = -multiplier;
}
clockViewModel.shouldAnimate = true;
});
this._playForwardViewModel = new ToggleButtonViewModel(playForwardCommand, {
toggled: knockout.computed(function () {
return (
that._isAnimating &&
clockViewModel.multiplier > 0 &&
clockViewModel.clockStep !== ClockStep.SYSTEM_CLOCK
);
}),
tooltip: "Play Forward",
});
const playRealtimeCommand = createCommand(
function () {
that._clockViewModel.clockStep = ClockStep.SYSTEM_CLOCK;
},
knockout.getObservable(this, "_isSystemTimeAvailable"),
);
this._playRealtimeViewModel = new ToggleButtonViewModel(playRealtimeCommand, {
toggled: knockout.computed(function () {
return clockViewModel.clockStep === ClockStep.SYSTEM_CLOCK;
}),
tooltip: knockout.computed(function () {
return that._isSystemTimeAvailable
? "Today (real-time)"
: "Current time not in range";
}),
});
this._slower = createCommand(function () {
const clockViewModel = that._clockViewModel;
const shuttleRingTicks = that._allShuttleRingTicks;
const multiplier = clockViewModel.multiplier;
const index = getTypicalMultiplierIndex(multiplier, shuttleRingTicks) - 1;
if (index >= 0) {
clockViewModel.multiplier = shuttleRingTicks[index];
}
});
this._faster = createCommand(function () {
const clockViewModel = that._clockViewModel;
const shuttleRingTicks = that._allShuttleRingTicks;
const multiplier = clockViewModel.multiplier;
const index = getTypicalMultiplierIndex(multiplier, shuttleRingTicks) + 1;
if (index < shuttleRingTicks.length) {
clockViewModel.multiplier = shuttleRingTicks[index];
}
});
}
/**
* Gets or sets the default date formatter used by new instances.
*
* @member
* @type {AnimationViewModel.DateFormatter}
*/
AnimationViewModel.defaultDateFormatter = function (date, viewModel) {
const gregorianDate = JulianDate.toGregorianDate(date);
return `${monthNames[gregorianDate.month - 1]} ${gregorianDate.day} ${
gregorianDate.year
}`;
};
/**
* Gets or sets the default array of known clock multipliers associated with new instances of the shuttle ring.
* @type {number[]}
*/
AnimationViewModel.defaultTicks = [
//
0.001,
0.002,
0.005,
0.01,
0.02,
0.05,
0.1,
0.25,
0.5,
1.0,
2.0,
5.0,
10.0, //
15.0,
30.0,
60.0,
120.0,
300.0,
600.0,
900.0,
1800.0,
3600.0,
7200.0,
14400.0, //
21600.0,
43200.0,
86400.0,
172800.0,
345600.0,
604800.0,
];
/**
* Gets or sets the default time formatter used by new instances.
*
* @member
* @type {AnimationViewModel.TimeFormatter}
*/
AnimationViewModel.defaultTimeFormatter = function (date, viewModel) {
const gregorianDate = JulianDate.toGregorianDate(date);
const millisecond = Math.round(gregorianDate.millisecond);
if (Math.abs(viewModel._clockViewModel.multiplier) < 1) {
return `${gregorianDate.hour
.toString()
.padStart(2, "0")}:${gregorianDate.minute
.toString()
.padStart(2, "0")}:${gregorianDate.second
.toString()
.padStart(2, "0")}.${millisecond.toString().padStart(3, "0")}`;
}
return `${gregorianDate.hour
.toString()
.padStart(2, "0")}:${gregorianDate.minute
.toString()
.padStart(2, "0")}:${gregorianDate.second.toString().padStart(2, "0")} UTC`;
};
/**
* Gets a copy of the array of positive known clock multipliers to associate with the shuttle ring.
*
* @returns {number[]} The array of known clock multipliers associated with the shuttle ring.
*/
AnimationViewModel.prototype.getShuttleRingTicks = function () {
return this._sortedFilteredPositiveTicks.slice(0);
};
/**
* Sets the array of positive known clock multipliers to associate with the shuttle ring.
* These values will have negative equivalents created for them and sets both the minimum
* and maximum range of values for the shuttle ring as well as the values that are snapped
* to when a single click is made. The values need not be in order, as they will be sorted
* automatically, and duplicate values will be removed.
*
* @param {number[]} positiveTicks The list of known positive clock multipliers to associate with the shuttle ring.
*/
AnimationViewModel.prototype.setShuttleRingTicks = function (positiveTicks) {
//>>includeStart('debug', pragmas.debug);
if (!defined(positiveTicks)) {
throw new DeveloperError("positiveTicks is required.");
}
//>>includeEnd('debug');
let i;
let len;
let tick;
const hash = {};
const sortedFilteredPositiveTicks = this._sortedFilteredPositiveTicks;
sortedFilteredPositiveTicks.length = 0;
for (i = 0, len = positiveTicks.length; i < len; ++i) {
tick = positiveTicks[i];
//filter duplicates
Eif (!hash.hasOwnProperty(tick)) {
hash[tick] = true;
sortedFilteredPositiveTicks.push(tick);
}
}
sortedFilteredPositiveTicks.sort(numberComparator);
const allTicks = [];
for (len = sortedFilteredPositiveTicks.length, i = len - 1; i >= 0; --i) {
tick = sortedFilteredPositiveTicks[i];
if (tick !== 0) {
allTicks.push(-tick);
}
}
addAllToArray(allTicks, sortedFilteredPositiveTicks);
this._allShuttleRingTicks = allTicks;
};
Object.defineProperties(AnimationViewModel.prototype, {
/**
* Gets a command that decreases the speed of animation.
* @memberof AnimationViewModel.prototype
* @type {Command}
*/
slower: {
get: function () {
return this._slower;
},
},
/**
* Gets a command that increases the speed of animation.
* @memberof AnimationViewModel.prototype
* @type {Command}
*/
faster: {
get: function () {
return this._faster;
},
},
/**
* Gets the clock view model.
* @memberof AnimationViewModel.prototype
*
* @type {ClockViewModel}
*/
clockViewModel: {
get: function () {
return this._clockViewModel;
},
},
/**
* Gets the pause toggle button view model.
* @memberof AnimationViewModel.prototype
*
* @type {ToggleButtonViewModel}
*/
pauseViewModel: {
get: function () {
return this._pauseViewModel;
},
},
/**
* Gets the reverse toggle button view model.
* @memberof AnimationViewModel.prototype
*
* @type {ToggleButtonViewModel}
*/
playReverseViewModel: {
get: function () {
return this._playReverseViewModel;
},
},
/**
* Gets the play toggle button view model.
* @memberof AnimationViewModel.prototype
*
* @type {ToggleButtonViewModel}
*/
playForwardViewModel: {
get: function () {
return this._playForwardViewModel;
},
},
/**
* Gets the realtime toggle button view model.
* @memberof AnimationViewModel.prototype
*
* @type {ToggleButtonViewModel}
*/
playRealtimeViewModel: {
get: function () {
return this._playRealtimeViewModel;
},
},
/**
* Gets or sets the function which formats a date for display.
* @memberof AnimationViewModel.prototype
*
* @type {AnimationViewModel.DateFormatter}
* @default AnimationViewModel.defaultDateFormatter
*/
dateFormatter: {
//TODO:@exception {DeveloperError} dateFormatter must be a function.
get: function () {
return this._dateFormatter;
},
set: function (dateFormatter) {
//>>includeStart('debug', pragmas.debug);
if (typeof dateFormatter !== "function") {
throw new DeveloperError("dateFormatter must be a function");
}
//>>includeEnd('debug');
this._dateFormatter = dateFormatter;
},
},
/**
* Gets or sets the function which formats a time for display.
* @memberof AnimationViewModel.prototype
*
* @type {AnimationViewModel.TimeFormatter}
* @default AnimationViewModel.defaultTimeFormatter
*/
timeFormatter: {
//TODO:@exception {DeveloperError} timeFormatter must be a function.
get: function () {
return this._timeFormatter;
},
set: function (timeFormatter) {
//>>includeStart('debug', pragmas.debug);
if (typeof timeFormatter !== "function") {
throw new DeveloperError("timeFormatter must be a function");
}
//>>includeEnd('debug');
this._timeFormatter = timeFormatter;
},
},
});
//Currently exposed for tests.
AnimationViewModel._maxShuttleRingAngle = maxShuttleRingAngle;
AnimationViewModel._realtimeShuttleRingAngle = realtimeShuttleRingAngle;
/**
* A function that formats a date for display.
* @callback AnimationViewModel.DateFormatter
*
* @param {JulianDate} date The date to be formatted
* @param {AnimationViewModel} viewModel The AnimationViewModel instance requesting formatting.
* @returns {string} The string representation of the calendar date portion of the provided date.
*/
/**
* A function that formats a time for display.
* @callback AnimationViewModel.TimeFormatter
*
* @param {JulianDate} date The date to be formatted
* @param {AnimationViewModel} viewModel The AnimationViewModel instance requesting formatting.
* @returns {string} The string representation of the time portion of the provided date.
*/
export default AnimationViewModel;
|