Skip to content

Commit

Permalink
Fixed delta format issue on navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Aug 4, 2016
1 parent f4e1879 commit 579233a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ define(
if (this.conductor.timeSystem()) {
$scope.timeSystemModel.selected = this.conductor.timeSystem();
$scope.timeSystemModel.format = this.conductor.timeSystem().formats()[0];
$scope.timeSystemModel.deltaFormat = this.conductor.timeSystem().deltaFormat();
}

/*
Expand Down Expand Up @@ -194,6 +195,9 @@ define(
TimeConductorController.prototype.setMode = function (newModeKey, oldModeKey) {
if (newModeKey !== oldModeKey) {
var newMode = undefined;
var timeSystems = [];
var timeSystem = undefined;

this.$scope.modeModel.selectedKey = newModeKey;

if (this.conductorService.mode()) {
Expand All @@ -202,26 +206,31 @@ define(

switch (newModeKey) {
case 'fixed':
newMode = new FixedMode(this.conductor, this._timeSystems, newModeKey);
timeSystems = this._timeSystems;
timeSystem = timeSystems[0];
newMode = new FixedMode(this.conductor, timeSystem, newModeKey);
break;
case 'realtime':
// Filter time systems to only those with clock tick
// sources
newMode = new FollowMode(this.conductor, this.timeSystemsForSourceType('clock'), newModeKey);
timeSystems = this.timeSystemsForSourceType('clock');
timeSystem = timeSystems[0];
newMode = new FollowMode(this.conductor, timeSystem, newModeKey);
break;
case 'latest':
// Filter time systems to only those with data tick
// sources
newMode = new FollowMode(this.conductor, this.timeSystemsForSourceType('data'), newModeKey);
timeSystems = this.timeSystemsForSourceType('data');
timeSystem = timeSystems[0];
newMode = new FollowMode(this.conductor, timeSystem, newModeKey);
break;
}
newMode.initialize();
this.conductorService.mode(newMode);
var timeSystem = newMode.selectedTimeSystem();

//Synchronize scope with time system on mode
this.$scope.timeSystemModel.options = newMode.timeSystems().map(function (timeSystem) {
return timeSystem.metadata;
this.$scope.timeSystemModel.options = timeSystems.map(function (t) {
return t.metadata;
});

this.setTimeSystem(timeSystem);
Expand Down Expand Up @@ -272,7 +281,7 @@ define(
this.$scope.timeSystemModel.format = newTimeSystem.formats()[0];
this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat();
var mode = this.conductorService.mode();
mode.selectedTimeSystem(newTimeSystem);
mode.timeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ define(
* @param timeSystems
* @constructor
*/
function FixedMode(conductor, timeSystems, key) {
TimeConductorMode.call(this, conductor, timeSystems, key);
function FixedMode(conductor, timeSystem, key) {
TimeConductorMode.call(this, conductor, timeSystem, key);
}

FixedMode.prototype = Object.create(TimeConductorMode.prototype);
Expand All @@ -49,8 +49,8 @@ define(
* @param timeSystem
* @returns {*}
*/
FixedMode.prototype.selectedTimeSystem = function (timeSystem){
TimeConductorMode.prototype.selectedTimeSystem.apply(this, arguments);
FixedMode.prototype.timeSystem = function (timeSystem){
TimeConductorMode.prototype.timeSystem.apply(this, arguments);

if (timeSystem) {
var defaults = timeSystem.defaults()[0];
Expand All @@ -62,7 +62,7 @@ define(

this.conductor.timeSystem(timeSystem, bounds);
}
return this._selectedTimeSystem;
return this._timeSystem;
};

return FixedMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ define(
* the mode relevant, with both offsets defined relative to it.
* @constructor
*/
function FollowMode(conductor, timeSystems, key) {
TimeConductorMode.call(this, conductor, timeSystems, key);
function FollowMode(conductor, timeSystem, key) {
TimeConductorMode.call(this, conductor, timeSystem, key);

this._deltas = undefined;
}
Expand Down Expand Up @@ -63,10 +63,8 @@ define(
* @param tickSource
*/
FollowMode.prototype.listenToTickSource = function () {
if (this._selectedTimeSystem &&
this._timeSystems[0]) {

var tickSource = this._timeSystems[0].tickSources()[0];
if (this._timeSystem) {
var tickSource = this._timeSystem.tickSources()[0];
if (tickSource) {
this.tickSourceUnlisten = tickSource.listen(this.tick.bind(this));
}
Expand All @@ -79,8 +77,8 @@ define(
* @param timeSystem
* @returns {TimeSystem}
*/
FollowMode.prototype.selectedTimeSystem = function (timeSystem) {
TimeConductorMode.prototype.selectedTimeSystem.apply(this, arguments);
FollowMode.prototype.timeSystem = function (timeSystem) {
TimeConductorMode.prototype.timeSystem.apply(this, arguments);

if (timeSystem) {
if (this.tickSourceUnlisten) {
Expand All @@ -106,7 +104,7 @@ define(
this.listenToTickSource();
}
}
return this._selectedTimeSystem;
return this._timeSystem;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,29 @@ define(
* @constructor
* @param {TimeConductorMetadata} metadata
*/
function TimeConductorMode(conductor, timeSystems, key) {
function TimeConductorMode(conductor, timeSystem, key) {
this.conductor = conductor;
this._timeSystems = timeSystems;
this._timeSystem = timeSystem;
this._key = key;
}

/**
* Function is called when mode becomes active (ie. is selected)
*/
TimeConductorMode.prototype.initialize = function () {
this.selectedTimeSystem(this._timeSystems[0]);
};

/**
* Return the time systems supported by this mode. Modes are
* expected to determine which time systems they will support by
* filtering a provided list of all time systems.
*
* @returns {TimeSystem[]} The time systems supported by this mode
*/
TimeConductorMode.prototype.timeSystems = function () {
return this._timeSystems;
this.timeSystem(this._timeSystem);
};

/**
* Get or set the currently selected time system
* @param timeSystem
* @returns {TimeSystem} the currently selected time system
*/
TimeConductorMode.prototype.selectedTimeSystem = function (timeSystem) {
TimeConductorMode.prototype.timeSystem = function (timeSystem) {
if (arguments.length > 0) {
if (this._timeSystems.indexOf(timeSystem) === -1){
throw new Error("Unsupported time system");
} else {
this._selectedTimeSystem = timeSystem;
}
this._timeSystem = timeSystem;
}
return this._selectedTimeSystem;
return this._timeSystem;
};

TimeConductorMode.prototype.key = function () {
Expand Down

0 comments on commit 579233a

Please sign in to comment.