mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 21:53:08 +00:00
Select appropriate tick source based on mode
This commit is contained in:
parent
579233ade9
commit
f96f78ff79
56
example/localTimeSystem/src/LADTickSource.js
Normal file
56
example/localTimeSystem/src/LADTickSource.js
Normal file
@ -0,0 +1,56 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(['../../../platform/features/conductor-v2/conductor/src/timeSystems/LocalClock'], function (LocalClock) {
|
||||
/**
|
||||
* @implements TickSource
|
||||
* @constructor
|
||||
*/
|
||||
function LADTickSource ($timeout, period) {
|
||||
LocalClock.call(this, $timeout, period);
|
||||
|
||||
this.metadata = {
|
||||
key: 'test-lad',
|
||||
cssclass: 'icon-clock',
|
||||
label: 'Latest Available Data',
|
||||
name: 'Latest available data',
|
||||
description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.'
|
||||
};
|
||||
}
|
||||
LADTickSource.prototype = Object.create(LocalClock.prototype);
|
||||
|
||||
LADTickSource.prototype.tick = function () {
|
||||
console.log('data tick');
|
||||
var now = Date.now();
|
||||
this.listeners.forEach(function (listener){
|
||||
listener(now);
|
||||
});
|
||||
this.timeoutHandle = this.$timeout(this.tick.bind(this), this.period);
|
||||
};
|
||||
|
||||
|
||||
LADTickSource.prototype.type = function () {
|
||||
return 'data';
|
||||
};
|
||||
|
||||
return LADTickSource;
|
||||
});
|
@ -22,8 +22,9 @@
|
||||
|
||||
define([
|
||||
'../../../platform/features/conductor-v2/conductor/src/timeSystems/TimeSystem',
|
||||
'../../../platform/features/conductor-v2/conductor/src/timeSystems/LocalClock'
|
||||
], function (TimeSystem, LocalClock) {
|
||||
'../../../platform/features/conductor-v2/conductor/src/timeSystems/LocalClock',
|
||||
'./LADTickSource'
|
||||
], function (TimeSystem, LocalClock, LADTickSource) {
|
||||
var FIFTEEN_MINUTES = 15 * 60 * 1000,
|
||||
DEFAULT_PERIOD = 1000;
|
||||
|
||||
@ -47,7 +48,7 @@ define([
|
||||
};
|
||||
|
||||
this._formats = ['local-format'];
|
||||
this._tickSources = [new LocalClock($timeout, DEFAULT_PERIOD)];
|
||||
this._tickSources = [new LocalClock($timeout, DEFAULT_PERIOD), new LADTickSource($timeout, DEFAULT_PERIOD)];
|
||||
}
|
||||
|
||||
LocalTimeSystem.prototype = Object.create(TimeSystem.prototype);
|
||||
|
@ -54,6 +54,7 @@ define(['./TickSource'], function (TickSource) {
|
||||
};
|
||||
|
||||
LocalClock.prototype.tick = function () {
|
||||
console.log('clock tick');
|
||||
var now = Date.now();
|
||||
this.listeners.forEach(function (listener){
|
||||
listener(now);
|
||||
|
@ -67,6 +67,7 @@ define(
|
||||
cssclass: 'icon-clock',
|
||||
label: 'Real-time',
|
||||
name: 'Real-time Mode',
|
||||
tickSourceType: 'clock',
|
||||
description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.'
|
||||
};
|
||||
}
|
||||
@ -77,6 +78,7 @@ define(
|
||||
cssclass: 'icon-database',
|
||||
label: 'LAD',
|
||||
name: 'LAD Mode',
|
||||
tickSourceType: 'data',
|
||||
description: 'Latest Available Data mode monitors real-time streaming data as it comes in. The Time Conductor and displays will only advance when data becomes available.'
|
||||
};
|
||||
}
|
||||
@ -185,6 +187,12 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
TimeConductorController.prototype.selectTickSource = function (timeSystem, sourceType) {
|
||||
return timeSystem.tickSources().filter(function (source){
|
||||
return source.type() === sourceType;
|
||||
})[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the selected Time Conductor mode. This will call destroy
|
||||
* and initialization functions on the relevant modes, setting
|
||||
@ -197,6 +205,7 @@ define(
|
||||
var newMode = undefined;
|
||||
var timeSystems = [];
|
||||
var timeSystem = undefined;
|
||||
var tickSourceType = this.modes[newModeKey].tickSourceType;
|
||||
|
||||
this.$scope.modeModel.selectedKey = newModeKey;
|
||||
|
||||
@ -210,19 +219,23 @@ define(
|
||||
timeSystem = timeSystems[0];
|
||||
newMode = new FixedMode(this.conductor, timeSystem, newModeKey);
|
||||
break;
|
||||
|
||||
case 'realtime':
|
||||
// Filter time systems to only those with clock tick
|
||||
// sources
|
||||
timeSystems = this.timeSystemsForSourceType('clock');
|
||||
timeSystems = this.timeSystemsForSourceType(tickSourceType);
|
||||
timeSystem = timeSystems[0];
|
||||
newMode = new FollowMode(this.conductor, timeSystem, newModeKey);
|
||||
newMode.tickSource(this.selectTickSource(timeSystem, tickSourceType));
|
||||
break;
|
||||
|
||||
case 'latest':
|
||||
// Filter time systems to only those with data tick
|
||||
// sources
|
||||
timeSystems = this.timeSystemsForSourceType('data');
|
||||
timeSystems = this.timeSystemsForSourceType(tickSourceType);
|
||||
timeSystem = timeSystems[0];
|
||||
newMode = new FollowMode(this.conductor, timeSystem, newModeKey);
|
||||
newMode.tickSource(this.selectTickSource(timeSystem, tickSourceType));
|
||||
break;
|
||||
}
|
||||
newMode.initialize();
|
||||
@ -283,6 +296,13 @@ define(
|
||||
var mode = this.conductorService.mode();
|
||||
mode.timeSystem(newTimeSystem);
|
||||
this.setDeltasFromTimeSystem(newTimeSystem);
|
||||
|
||||
// If current mode supports ticking, set an appropriate tick
|
||||
// source from the new time system
|
||||
if (mode.tickSource) {
|
||||
var tickSourceType = this.modes[mode.key()].tickSourceType;
|
||||
mode.tickSource(this.selectTickSource(newTimeSystem, tickSourceType));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -37,6 +37,8 @@ define(
|
||||
TimeConductorMode.call(this, conductor, timeSystem, key);
|
||||
|
||||
this._deltas = undefined;
|
||||
this._tickSource = undefined;
|
||||
this._tickSourceUnlisten = undefined;
|
||||
}
|
||||
|
||||
FollowMode.prototype = Object.create(TimeConductorMode.prototype);
|
||||
@ -59,16 +61,20 @@ define(
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Get or set tick source. Setting tick source will also start
|
||||
* listening to it and unlisten from any existing tick source
|
||||
* @param tickSource
|
||||
* @returns {undefined|*}
|
||||
*/
|
||||
FollowMode.prototype.listenToTickSource = function () {
|
||||
if (this._timeSystem) {
|
||||
var tickSource = this._timeSystem.tickSources()[0];
|
||||
if (tickSource) {
|
||||
this.tickSourceUnlisten = tickSource.listen(this.tick.bind(this));
|
||||
FollowMode.prototype.tickSource = function (tickSource) {
|
||||
if (tickSource) {
|
||||
if (this._tickSourceUnlisten) {
|
||||
this._tickSourceUnlisten();
|
||||
}
|
||||
this._tickSource = tickSource;
|
||||
this._tickSourceUnlisten = tickSource.listen(this.tick.bind(this));
|
||||
}
|
||||
return this._tickSource;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -81,10 +87,6 @@ define(
|
||||
TimeConductorMode.prototype.timeSystem.apply(this, arguments);
|
||||
|
||||
if (timeSystem) {
|
||||
if (this.tickSourceUnlisten) {
|
||||
this.tickSourceUnlisten();
|
||||
}
|
||||
|
||||
var defaults = timeSystem.defaults()[0];
|
||||
|
||||
if (arguments.length > 0) {
|
||||
@ -100,8 +102,6 @@ define(
|
||||
}
|
||||
|
||||
this.conductor.timeSystem(timeSystem, bounds);
|
||||
|
||||
this.listenToTickSource();
|
||||
}
|
||||
}
|
||||
return this._timeSystem;
|
||||
@ -139,8 +139,8 @@ define(
|
||||
* Stop listening to tick sources
|
||||
*/
|
||||
FollowMode.prototype.destroy = function () {
|
||||
if (this.tickSourceUnlisten) {
|
||||
this.tickSourceUnlisten();
|
||||
if (this._tickSourceUnlisten) {
|
||||
this._tickSourceUnlisten();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user