Skip to content

Commit

Permalink
Merge pull request ngageoint#740 in WV/opensphere from ~BRELSFORDT/op…
Browse files Browse the repository at this point in the history
…ensphere:feature_linx-timeline to master

* commit '8b0e5a2507092cd28aa4f74f2604a4a3fcfab748':
  docs(timelinecontroller): fix spelling errors THIN-13290
  docs(timelinecontroller): Fix spelling mistake THIN-13290
  feat(timelinecontroller): seperate restore and reset THIN-13290
  feat(timelinecontroller): Add test for setting ranges, fix restoring states THIN-13290
  • Loading branch information
brelsftm committed May 21, 2019
2 parents 7f7ef46 + 8b0e5a2 commit d5e1d11
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/os/time/timelinecontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,6 @@ os.time.TimelineController.prototype.restore = function(config) {
this.setLoadRanges(config['loadRanges']);
this.setAnimateRanges(config['animateRanges']);
this.setHoldRanges(config['holdRanges']);
this.updateOffetsAndCurrent_();

if (config['playing']) {
this.play();
Expand All @@ -968,15 +967,25 @@ os.time.TimelineController.prototype.restore = function(config) {


/**
* Updates the current position to the beginning of the anmation sequence, and
* re-computes the step size and offests based on the current animation range.
* Updates the current position to the beginning of the animation sequence, and
* re-computes the step size and offsets based on the current animation range.
* @private
*/
os.time.TimelineController.prototype.updateOffetsAndCurrent_ = function() {
os.time.timeline.setDefaultOffsetForRange(this, this.getSmallestAnimateRangeLength());
};


/**
* Reset the timeline to config state
* @param {Object} config The state
*/
os.time.TimelineController.prototype.reset = function(config) {
this.restore(config);
this.updateOffetsAndCurrent_();
};


/**
* Repositions the current playback position to the start of the
* timeline animation.
Expand Down Expand Up @@ -1119,7 +1128,7 @@ os.time.TimelineController.prototype.removeSliceRange = function(timerange) {
* @param {?goog.math.RangeSet} ranges
*/
os.time.TimelineController.prototype.setSliceRanges = function(ranges) {
if (ranges) {
if (ranges && ranges instanceof goog.math.RangeSet) {
var tr = this.sliceRanges_.clone();
this.sliceRanges_ = ranges.clone();
this.calcRangeCache_.clear();
Expand Down Expand Up @@ -1336,7 +1345,7 @@ os.time.TimelineController.prototype.removeLoadRange = function(timerange) {
* @param {?goog.math.RangeSet} ranges
*/
os.time.TimelineController.prototype.setLoadRanges = function(ranges) {
if (ranges) {
if (ranges && ranges instanceof goog.math.RangeSet) {
var numPrev = this.getLoadRanges().length;
var numNow = goog.iter.toArray(ranges).length;
if ((numPrev === 1 && numNow != 1) || (numPrev > 1 && numNow === 1)) {
Expand Down Expand Up @@ -1435,7 +1444,7 @@ os.time.TimelineController.prototype.removeAnimateRange = function(timerange) {
* @param {?goog.math.RangeSet} ranges
*/
os.time.TimelineController.prototype.setAnimateRanges = function(ranges) {
if (ranges) {
if (ranges && ranges instanceof goog.math.RangeSet) {
this.animateRanges_ = ranges.clone();
this.dispatchEvent(os.time.TimelineEventType.ANIMATE_RANGE_CHANGED);
this.dispatchShowEvent_();
Expand Down Expand Up @@ -1482,7 +1491,7 @@ os.time.TimelineController.prototype.getHoldRanges = function() {
* @param {?goog.math.RangeSet} ranges
*/
os.time.TimelineController.prototype.setHoldRanges = function(ranges) {
if (ranges) {
if (ranges && ranges instanceof goog.math.RangeSet) {
this.holdRanges_ = ranges.clone();
this.dispatchEvent(os.time.TimelineEventType.HOLD_RANGE_CHANGED);
this.dispatchShowEvent_();
Expand Down
2 changes: 1 addition & 1 deletion src/os/ui/timeline/abstracttimelinectrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ os.ui.timeline.AbstractTimelineCtrl.prototype.previousFrame = function() {
*/
os.ui.timeline.AbstractTimelineCtrl.prototype.reset = function() {
if (this.tlcState_) {
this.tlc.restore(this.tlcState_);
this.tlc.reset(this.tlcState_);
this.updateTimeline(true);
os.metrics.Metrics.getInstance().updateMetric(os.metrics.keys.Timeline.RESET, 1);
var refreshTimer = new goog.async.Delay(this.refreshLoadBrushes_, 10, this);
Expand Down
28 changes: 28 additions & 0 deletions test/os/time/timelinecontroller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ describe('os.time.TimelineController', function() {
expect(getDispatchEventCallCount(os.time.TimelineEventType.SHOW)).toBeGreaterThan((fps * runtime / 1000) - 2);
});

it('setting ranges must be a range set', function() {
controller.clearLoadRanges();
controller.setHoldRanges({'g': []});

// we should have zero range
target = controller.getLoadRanges();
expect(target.length).toBe(0);

controller.clearSliceRanges();
controller.setSliceRanges({'g': []});

// we should have zero range
target = controller.getSliceRanges();
expect(target.length).toBe(0);

controller.clearHoldRanges();
controller.setHoldRanges({'g': []});

target = controller.getHoldRanges();
expect(target.length).toBe(0);

controller.clearAnimateRanges();
controller.setAnimateRanges({'g': []});

target = controller.getAnimationRanges();
expect(target.length).toBe(0);
});

it('adding range should fire range changed event', function() {
var fullRange = controller.getRange();
controller.addAnimateRange(fullRange);
Expand Down

0 comments on commit d5e1d11

Please sign in to comment.