Fixed delta format issue on navigation

This commit is contained in:
Henry 2016-08-03 18:30:01 -07:00
parent f4e1879a2d
commit 579233ade9
4 changed files with 34 additions and 42 deletions

View File

@ -99,6 +99,7 @@ define(
if (this.conductor.timeSystem()) { if (this.conductor.timeSystem()) {
$scope.timeSystemModel.selected = this.conductor.timeSystem(); $scope.timeSystemModel.selected = this.conductor.timeSystem();
$scope.timeSystemModel.format = this.conductor.timeSystem().formats()[0]; $scope.timeSystemModel.format = this.conductor.timeSystem().formats()[0];
$scope.timeSystemModel.deltaFormat = this.conductor.timeSystem().deltaFormat();
} }
/* /*
@ -194,6 +195,9 @@ define(
TimeConductorController.prototype.setMode = function (newModeKey, oldModeKey) { TimeConductorController.prototype.setMode = function (newModeKey, oldModeKey) {
if (newModeKey !== oldModeKey) { if (newModeKey !== oldModeKey) {
var newMode = undefined; var newMode = undefined;
var timeSystems = [];
var timeSystem = undefined;
this.$scope.modeModel.selectedKey = newModeKey; this.$scope.modeModel.selectedKey = newModeKey;
if (this.conductorService.mode()) { if (this.conductorService.mode()) {
@ -202,26 +206,31 @@ define(
switch (newModeKey) { switch (newModeKey) {
case 'fixed': case 'fixed':
newMode = new FixedMode(this.conductor, this._timeSystems, newModeKey); timeSystems = this._timeSystems;
timeSystem = timeSystems[0];
newMode = new FixedMode(this.conductor, timeSystem, newModeKey);
break; break;
case 'realtime': case 'realtime':
// Filter time systems to only those with clock tick // Filter time systems to only those with clock tick
// sources // 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; break;
case 'latest': case 'latest':
// Filter time systems to only those with data tick // Filter time systems to only those with data tick
// sources // 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; break;
} }
newMode.initialize(); newMode.initialize();
this.conductorService.mode(newMode); this.conductorService.mode(newMode);
var timeSystem = newMode.selectedTimeSystem();
//Synchronize scope with time system on mode //Synchronize scope with time system on mode
this.$scope.timeSystemModel.options = newMode.timeSystems().map(function (timeSystem) { this.$scope.timeSystemModel.options = timeSystems.map(function (t) {
return timeSystem.metadata; return t.metadata;
}); });
this.setTimeSystem(timeSystem); this.setTimeSystem(timeSystem);
@ -272,7 +281,7 @@ define(
this.$scope.timeSystemModel.format = newTimeSystem.formats()[0]; this.$scope.timeSystemModel.format = newTimeSystem.formats()[0];
this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat(); this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat();
var mode = this.conductorService.mode(); var mode = this.conductorService.mode();
mode.selectedTimeSystem(newTimeSystem); mode.timeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem); this.setDeltasFromTimeSystem(newTimeSystem);
} }
}; };

View File

@ -32,8 +32,8 @@ define(
* @param timeSystems * @param timeSystems
* @constructor * @constructor
*/ */
function FixedMode(conductor, timeSystems, key) { function FixedMode(conductor, timeSystem, key) {
TimeConductorMode.call(this, conductor, timeSystems, key); TimeConductorMode.call(this, conductor, timeSystem, key);
} }
FixedMode.prototype = Object.create(TimeConductorMode.prototype); FixedMode.prototype = Object.create(TimeConductorMode.prototype);
@ -49,8 +49,8 @@ define(
* @param timeSystem * @param timeSystem
* @returns {*} * @returns {*}
*/ */
FixedMode.prototype.selectedTimeSystem = function (timeSystem){ FixedMode.prototype.timeSystem = function (timeSystem){
TimeConductorMode.prototype.selectedTimeSystem.apply(this, arguments); TimeConductorMode.prototype.timeSystem.apply(this, arguments);
if (timeSystem) { if (timeSystem) {
var defaults = timeSystem.defaults()[0]; var defaults = timeSystem.defaults()[0];
@ -62,7 +62,7 @@ define(
this.conductor.timeSystem(timeSystem, bounds); this.conductor.timeSystem(timeSystem, bounds);
} }
return this._selectedTimeSystem; return this._timeSystem;
}; };
return FixedMode; return FixedMode;

View File

@ -33,8 +33,8 @@ define(
* the mode relevant, with both offsets defined relative to it. * the mode relevant, with both offsets defined relative to it.
* @constructor * @constructor
*/ */
function FollowMode(conductor, timeSystems, key) { function FollowMode(conductor, timeSystem, key) {
TimeConductorMode.call(this, conductor, timeSystems, key); TimeConductorMode.call(this, conductor, timeSystem, key);
this._deltas = undefined; this._deltas = undefined;
} }
@ -63,10 +63,8 @@ define(
* @param tickSource * @param tickSource
*/ */
FollowMode.prototype.listenToTickSource = function () { FollowMode.prototype.listenToTickSource = function () {
if (this._selectedTimeSystem && if (this._timeSystem) {
this._timeSystems[0]) { var tickSource = this._timeSystem.tickSources()[0];
var tickSource = this._timeSystems[0].tickSources()[0];
if (tickSource) { if (tickSource) {
this.tickSourceUnlisten = tickSource.listen(this.tick.bind(this)); this.tickSourceUnlisten = tickSource.listen(this.tick.bind(this));
} }
@ -79,8 +77,8 @@ define(
* @param timeSystem * @param timeSystem
* @returns {TimeSystem} * @returns {TimeSystem}
*/ */
FollowMode.prototype.selectedTimeSystem = function (timeSystem) { FollowMode.prototype.timeSystem = function (timeSystem) {
TimeConductorMode.prototype.selectedTimeSystem.apply(this, arguments); TimeConductorMode.prototype.timeSystem.apply(this, arguments);
if (timeSystem) { if (timeSystem) {
if (this.tickSourceUnlisten) { if (this.tickSourceUnlisten) {
@ -106,7 +104,7 @@ define(
this.listenToTickSource(); this.listenToTickSource();
} }
} }
return this._selectedTimeSystem; return this._timeSystem;
}; };
/** /**

View File

@ -33,9 +33,9 @@ define(
* @constructor * @constructor
* @param {TimeConductorMetadata} metadata * @param {TimeConductorMetadata} metadata
*/ */
function TimeConductorMode(conductor, timeSystems, key) { function TimeConductorMode(conductor, timeSystem, key) {
this.conductor = conductor; this.conductor = conductor;
this._timeSystems = timeSystems; this._timeSystem = timeSystem;
this._key = key; this._key = key;
} }
@ -43,18 +43,7 @@ define(
* Function is called when mode becomes active (ie. is selected) * Function is called when mode becomes active (ie. is selected)
*/ */
TimeConductorMode.prototype.initialize = function () { TimeConductorMode.prototype.initialize = function () {
this.selectedTimeSystem(this._timeSystems[0]); this.timeSystem(this._timeSystem);
};
/**
* 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;
}; };
/** /**
@ -62,15 +51,11 @@ define(
* @param timeSystem * @param timeSystem
* @returns {TimeSystem} the currently selected time system * @returns {TimeSystem} the currently selected time system
*/ */
TimeConductorMode.prototype.selectedTimeSystem = function (timeSystem) { TimeConductorMode.prototype.timeSystem = function (timeSystem) {
if (arguments.length > 0) { if (arguments.length > 0) {
if (this._timeSystems.indexOf(timeSystem) === -1){ this._timeSystem = timeSystem;
throw new Error("Unsupported time system");
} else {
this._selectedTimeSystem = timeSystem;
} }
} return this._timeSystem;
return this._selectedTimeSystem;
}; };
TimeConductorMode.prototype.key = function () { TimeConductorMode.prototype.key = function () {