[Time Conductor] Fixed code style errors

This commit is contained in:
Henry 2016-09-06 10:04:29 -07:00
parent c6eaa3d528
commit 7af5875dd5
21 changed files with 124 additions and 113 deletions

View File

@ -56,7 +56,7 @@ define([
* the threshold required.
* @private
*/
function getScaledFormat (d) {
function getScaledFormat(d) {
var momentified = moment.utc(d);
/**
* Uses logic from d3 Time-Scales, v3 of the API. See
@ -65,20 +65,32 @@ define([
* Licensed
*/
return [
[".SSS", function(m) { return m.milliseconds(); }],
[":ss", function(m) { return m.seconds(); }],
["HH:mm", function(m) { return m.minutes(); }],
["HH", function(m) { return m.hours(); }],
["ddd DD", function(m) {
[".SSS", function (m) {
return m.milliseconds();
}],
[":ss", function (m) {
return m.seconds();
}],
["HH:mm", function (m) {
return m.minutes();
}],
["HH", function (m) {
return m.hours();
}],
["ddd DD", function (m) {
return m.days() &&
m.date() !== 1;
}],
["MMM DD", function(m) { return m.date() !== 1; }],
["MMMM", function(m) {
["MMM DD", function (m) {
return m.date() !== 1;
}],
["MMMM", function (m) {
return m.month();
}],
["YYYY", function() { return true; }]
].filter(function (row){
["YYYY", function () {
return true;
}]
].filter(function (row) {
return row[1](momentified);
})[0][0];
}
@ -91,7 +103,7 @@ define([
* @returns {string} the formatted date
*/
UTCTimeFormat.prototype.format = function (value, scale) {
if (scale !== undefined){
if (scale !== undefined) {
var scaledFormat = getScaledFormat(value, scale);
if (scaledFormat) {
return moment.utc(value).format(scaledFormat);

View File

@ -76,7 +76,7 @@ define(
}
conductor.on('bounds', amendRequests);
return function() {
return function () {
unsubscribeFunc();
conductor.off('bounds', amendRequests);
};

View File

@ -112,7 +112,7 @@ define(['EventEmitter'], function (EventEmitter) {
TimeConductor.prototype.bounds = function (newBounds) {
if (arguments.length > 0) {
var validationResult = this.validateBounds(newBounds);
if (validationResult !== true){
if (validationResult !== true) {
throw new Error(validationResult);
}
//Create a copy to avoid direct mutation of conductor bounds

View File

@ -25,7 +25,7 @@ define(['./TickSource'], function (TickSource) {
* @implements TickSource
* @constructor
*/
function LocalClock ($timeout, period) {
function LocalClock($timeout, period) {
TickSource.call(this);
this.metadata = {
@ -56,7 +56,7 @@ define(['./TickSource'], function (TickSource) {
LocalClock.prototype.tick = function () {
var now = Date.now();
this.listeners.forEach(function (listener){
this.listeners.forEach(function (listener) {
listener(now);
});
this.timeoutHandle = this.$timeout(this.tick.bind(this), this.period);
@ -73,7 +73,7 @@ define(['./TickSource'], function (TickSource) {
var listeners = this.listeners;
listeners.push(listener);
if (listeners.length === 1){
if (listeners.length === 1) {
this.start();
}

View File

@ -30,7 +30,7 @@ define([], function () {
* @interface
* @constructor
*/
function TickSource () {
function TickSource() {
this.listeners = [];
}

View File

@ -25,7 +25,7 @@ define([], function () {
* @interface
* @constructor
*/
function TimeSystem () {
function TimeSystem() {
/**
* @typedef TimeSystemMetadata
* @property {string} key
@ -35,7 +35,6 @@ define([], function () {
* @type {TimeSystemMetadata}
*/
this.metadata = undefined;
this._tickSources = [];
}
/**

View File

@ -87,7 +87,7 @@ define(
//Define a custom format function
this.xAxis.tickFormat(function (tickValue) {
// Normalize date representations to numbers
if (tickValue instanceof Date){
if (tickValue instanceof Date) {
tickValue = tickValue.getTime();
}
return format.format(tickValue, {
@ -127,7 +127,7 @@ define(
}
};
return function(conductor, formatService) {
return function (conductor, formatService) {
return new MCTConductorAxis(conductor, formatService);
};
}

View File

@ -71,7 +71,7 @@ define(['./MctConductorAxis'], function (MctConductorAxis) {
"range"
];
d3 = jasmine.createSpyObj("d3", d3Functions);
d3Functions.forEach(function(func) {
d3Functions.forEach(function (func) {
d3[func].andReturn(d3);
});
@ -89,7 +89,7 @@ define(['./MctConductorAxis'], function (MctConductorAxis) {
var mockTimeSystem;
var mockFormat;
beforeEach(function() {
beforeEach(function () {
mockTimeSystem = jasmine.createSpyObj("timeSystem", [
"formats",
"isUTCBased"

View File

@ -34,7 +34,7 @@ define([], function () {
}
NumberFormat.prototype.format = function (value) {
if (isNaN(value)){
if (isNaN(value)) {
return '';
} else {
return '' + value;

View File

@ -30,13 +30,13 @@ define(['./NumberFormat'], function (NumberFormat) {
it("The format function takes a string and produces a number", function () {
var text = format.format(1);
expect(text).toBe("1");
expect(typeof(text)).toBe("string");
expect(typeof text).toBe("string");
});
it("The parse function takes a string and produces a number", function () {
var number = format.parse("1");
expect(number).toBe(1);
expect(typeof(number)).toBe("number");
expect(typeof number).toBe("number");
});
it("validates that the input is a number", function () {

View File

@ -45,7 +45,7 @@ define(
this.validation = new TimeConductorValidation(this.conductor);
// Construct the provided time system definitions
this.timeSystems = timeSystems.map(function (timeSystemConstructor){
this.timeSystems = timeSystems.map(function (timeSystemConstructor) {
return timeSystemConstructor();
});
@ -53,7 +53,7 @@ define(
this.initializeScope();
this.conductor.on('bounds', this.setFormFromBounds);
this.conductor.on('follow', function (follow){
this.conductor.on('follow', function (follow) {
$scope.followMode = follow;
});
this.conductor.on('timeSystem', this.changeTimeSystem);
@ -67,7 +67,7 @@ define(
/**
* @private
*/
TimeConductorController.prototype.initializeScope = function() {
TimeConductorController.prototype.initializeScope = function () {
//Set time Conductor bounds in the form
this.$scope.boundsModel = this.conductor.bounds();
@ -126,10 +126,11 @@ define(
TimeConductorController.prototype.setFormFromMode = function (mode) {
this.$scope.modeModel.selectedKey = mode;
//Synchronize scope with time system on mode
this.$scope.timeSystemModel.options = this.conductorViewService.availableTimeSystems()
this.$scope.timeSystemModel.options =
this.conductorViewService.availableTimeSystems()
.map(function (t) {
return t.metadata;
});
});
};
/**
@ -204,13 +205,13 @@ define(
* @param key
* @see TimeConductorController#setTimeSystem
*/
TimeConductorController.prototype.selectTimeSystemByKey = function(key){
var selected = this.timeSystems.filter(function (timeSystem){
TimeConductorController.prototype.selectTimeSystemByKey = function (key) {
var selected = this.timeSystems.filter(function (timeSystem) {
return timeSystem.metadata.key === key;
})[0];
this.conductor.timeSystem(selected, selected.defaults().bounds);
};
/**
* Handles time system change from time conductor
*
@ -222,7 +223,7 @@ define(
*/
TimeConductorController.prototype.changeTimeSystem = function (newTimeSystem) {
if (newTimeSystem && (newTimeSystem !== this.$scope.timeSystemModel.selected)) {
if (newTimeSystem.defaults()){
if (newTimeSystem.defaults()) {
var deltas = newTimeSystem.defaults().deltas || {start: 0, end: 0};
var bounds = newTimeSystem.defaults().bounds || {start: 0, end: 0};

View File

@ -58,13 +58,13 @@ define(['./TimeConductorController'], function (TimeConductorController) {
});
function getListener(name) {
return mockTimeConductor.on.calls.filter(function (call){
return mockTimeConductor.on.calls.filter(function (call) {
return call.args[0] === name;
})[0].args[1];
}
describe("", function (){
beforeEach(function() {
describe("", function () {
beforeEach(function () {
controller = new TimeConductorController(
mockScope,
mockWindow,
@ -183,7 +183,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
var ts2Metadata;
var ts3Metadata;
var mockTimeSystemConstructors;
beforeEach(function () {
mode = "realtime";
ts1Metadata = {
@ -304,7 +304,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
metadata: {
key: 'testTimeSystem'
},
defaults: function() {
defaults: function () {
return {
bounds: defaultBounds
};
@ -313,7 +313,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
mockTimeSystems = [
// Wrap as constructor function
function() {
function () {
return timeSystem;
}
];

View File

@ -33,12 +33,12 @@ define(
function TimeConductorMode(metadata, conductor, timeSystems) {
this.conductor = conductor;
this._metadata = metadata;
this._deltas = undefined;
this._tickSource = undefined;
this._tickSourceUnlisten = undefined;
this._timeSystems = timeSystems;
this._availableTickSources = undefined;
this.mdata = metadata;
this.dlts = undefined;
this.source = undefined;
this.sourceUnlisten = undefined;
this.systems = timeSystems;
this.availableSources = undefined;
this.changeTimeSystem = this.changeTimeSystem.bind(this);
this.tick = this.tick.bind(this);
@ -52,9 +52,9 @@ define(
if (metadata.key === 'fixed') {
//Fixed automatically supports all time systems
this._availableTimeSystems = timeSystems;
this.availableSystems = timeSystems;
} else {
this._availableTimeSystems = timeSystems.filter(function (timeSystem) {
this.availableSystems = timeSystems.filter(function (timeSystem) {
//Only include time systems that have tick sources that
// support the current mode
return timeSystem.tickSources().some(function (tickSource) {
@ -86,10 +86,10 @@ define(
this.deltas(defaults.deltas);
// Tick sources are mode-specific, so restrict tick sources to only those supported by the current mode.
var key = this._metadata.key;
var key = this.mdata.key;
var tickSources = timeSystem.tickSources();
if (tickSources) {
this._availableTickSources = tickSources.filter(function (source){
this.availableSources = tickSources.filter(function (source) {
return source.metadata.mode === key;
});
}
@ -102,11 +102,11 @@ define(
* @returns {ModeMetadata}
*/
TimeConductorMode.prototype.metadata = function () {
return this._metadata;
return this.mdata;
};
TimeConductorMode.prototype.availableTimeSystems = function () {
return this._availableTimeSystems;
return this.availableSystems;
};
/**
@ -115,7 +115,7 @@ define(
* @returns {Array.<T>}
*/
TimeConductorMode.prototype.availableTickSources = function (timeSystem) {
return this._availableTickSources;
return this.availableSources;
};
/**
@ -126,26 +126,26 @@ define(
*/
TimeConductorMode.prototype.tickSource = function (tickSource) {
if (arguments.length > 0) {
if (this._tickSourceUnlisten) {
this._tickSourceUnlisten();
if (this.sourceUnlisten) {
this.sourceUnlisten();
}
this._tickSource = tickSource;
this.source = tickSource;
if (tickSource) {
this._tickSourceUnlisten = tickSource.listen(this.tick);
this.sourceUnlisten = tickSource.listen(this.tick);
//Now following a tick source
this.conductor.follow(true);
} else {
this.conductor.follow(false);
}
}
return this._tickSource;
return this.source;
};
TimeConductorMode.prototype.destroy = function () {
this.conductor.off('timeSystem', this.changeTimeSystem);
if (this._tickSourceUnlisten) {
this._tickSourceUnlisten();
if (this.sourceUnlisten) {
this.sourceUnlisten();
}
};
@ -179,21 +179,21 @@ define(
if (arguments.length !== 0) {
var oldEnd = this.conductor.bounds().end;
if (this._deltas && this._deltas.end !== undefined){
if (this.dlts && this.dlts.end !== undefined) {
//Calculate the previous raw end value (without delta)
oldEnd = oldEnd - this._deltas.end;
oldEnd = oldEnd - this.dlts.end;
}
this._deltas = deltas;
this.dlts = deltas;
var newBounds = {
start: oldEnd - this._deltas.start,
end: oldEnd + this._deltas.end
start: oldEnd - this.dlts.start,
end: oldEnd + this.dlts.end
};
this.conductor.bounds(newBounds);
}
return this._deltas;
return this.dlts;
};
return TimeConductorMode;

View File

@ -118,7 +118,7 @@ define(['./TimeConductorMode'], function (TimeConductorMode) {
fixedTimeSystem.defaults.andReturn(defaults);
});
it ("sets defaults from new time system", function() {
it ("sets defaults from new time system", function () {
mode = new TimeConductorMode(fixedModeMetaData, mockTimeConductor, mockTimeSystems);
spyOn(mode, "deltas");
mode.deltas.andCallThrough();
@ -127,7 +127,7 @@ define(['./TimeConductorMode'], function (TimeConductorMode) {
expect(mockTimeConductor.bounds).toHaveBeenCalledWith(defaults.bounds);
expect(mode.deltas).toHaveBeenCalledWith(defaults.deltas);
});
it ("If a tick source is available, sets the tick source", function() {
it ("If a tick source is available, sets the tick source", function () {
mode = new TimeConductorMode(realtimeModeMetaData, mockTimeConductor, mockTimeSystems);
mode.changeTimeSystem(realtimeTimeSystem);
@ -139,7 +139,7 @@ define(['./TimeConductorMode'], function (TimeConductorMode) {
describe("Setting a tick source", function () {
var mockUnlistener;
beforeEach(function() {
beforeEach(function () {
mockUnlistener = jasmine.createSpy("unlistener");
mockTickSource.listen.andReturn(mockUnlistener);
@ -147,31 +147,31 @@ define(['./TimeConductorMode'], function (TimeConductorMode) {
mode.tickSource(mockTickSource);
});
it ("Unlistens from old tick source", function() {
it ("Unlistens from old tick source", function () {
mode.tickSource(mockTickSource);
expect(mockUnlistener).toHaveBeenCalled();
});
it ("Listens to new tick source", function() {
it ("Listens to new tick source", function () {
expect(mockTickSource.listen).toHaveBeenCalledWith(mode.tick);
});
it ("Sets 'follow' state on time conductor", function() {
it ("Sets 'follow' state on time conductor", function () {
expect(mockTimeConductor.follow).toHaveBeenCalledWith(true);
});
it ("on destroy, unlistens from tick source", function() {
it ("on destroy, unlistens from tick source", function () {
mode.destroy();
expect(mockUnlistener).toHaveBeenCalled();
});
});
describe("setting deltas", function () {
beforeEach(function() {
beforeEach(function () {
mode = new TimeConductorMode(realtimeModeMetaData, mockTimeConductor, mockTimeSystems);
});
it ("sets the bounds on the time conductor based on new delta" +
" values", function() {
" values", function () {
var deltas = {
start: 20,
end: 10
@ -187,10 +187,10 @@ define(['./TimeConductorMode'], function (TimeConductorMode) {
});
describe("ticking", function () {
beforeEach(function() {
beforeEach(function () {
mode = new TimeConductorMode(realtimeModeMetaData, mockTimeConductor, mockTimeSystems);
});
it ("sets bounds based on current delta values", function() {
it ("sets bounds based on current delta values", function () {
var deltas = {
start: 20,
end: 10
@ -202,7 +202,7 @@ define(['./TimeConductorMode'], function (TimeConductorMode) {
expect(mockTimeConductor.bounds).toHaveBeenCalledWith({
start: time - deltas.start,
end:time + deltas.end
end: time + deltas.end
});
});
});

View File

@ -34,7 +34,7 @@ define(['./TimeConductorValidation'], function (TimeConductorValidation) {
});
describe("Validates start and end values using Time Conductor", function () {
beforeEach(function() {
beforeEach(function () {
var mockBounds = {
start: 10,
end: 20

View File

@ -36,13 +36,12 @@ define(
* @constructor
*/
function TimeConductorViewService(conductor, timeSystems) {
this._timeSystems = timeSystems.map(
function (timeSystemConstructor) {
return timeSystemConstructor();
this.systems = timeSystems.map(function (timeSystemConstructor) {
return timeSystemConstructor();
});
this._conductor = conductor;
this._mode = undefined;
this.conductor = conductor;
this.currentMode = undefined;
/**
* @typedef {object} ModeMetadata
@ -53,7 +52,7 @@ define(
* @property {string} name A longer name for the mode
* @property {string} description A description of the mode
*/
this._availableModes = {
this.availModes = {
'fixed': {
key: 'fixed',
cssclass: 'icon-calendar',
@ -64,17 +63,17 @@ define(
};
function hasTickSource(sourceType, timeSystem) {
return timeSystem.tickSources().some(function (tickSource){
return timeSystem.tickSources().some(function (tickSource) {
return tickSource.metadata.mode === sourceType;
});
}
var timeSystemsForMode = function (sourceType) {
return this._timeSystems.filter(hasTickSource.bind(this, sourceType));
return this.systems.filter(hasTickSource.bind(this, sourceType));
}.bind(this);
//Only show 'real-time mode' if appropriate time systems available
if (timeSystemsForMode('realtime').length > 0 ) {
if (timeSystemsForMode('realtime').length > 0) {
var realtimeMode = {
key: 'realtime',
cssclass: 'icon-clock',
@ -82,7 +81,7 @@ define(
name: 'Real-time Mode',
description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.'
};
this._availableModes[realtimeMode.key] = realtimeMode;
this.availModes[realtimeMode.key] = realtimeMode;
}
//Only show 'LAD mode' if appropriate time systems available
@ -94,7 +93,7 @@ define(
name: 'LAD Mode',
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.'
};
this._availableModes[ladMode.key] = ladMode;
this.availModes[ladMode.key] = ladMode;
}
}
@ -125,23 +124,23 @@ define(
}
if (arguments.length === 1) {
var timeSystem = this._conductor.timeSystem();
var timeSystem = this.conductor.timeSystem();
var modes = this.availableModes();
var modeMetaData = modes[newModeKey];
if (this._mode) {
this._mode.destroy();
if (this.currentMode) {
this.currentMode.destroy();
}
this._mode = new TimeConductorMode(modeMetaData, this._conductor, this._timeSystems);
this.currentMode = new TimeConductorMode(modeMetaData, this.conductor, this.systems);
// If no time system set on time conductor, or the currently selected time system is not available in
// the new mode, default to first available time system
if (!timeSystem || !contains(this._mode.availableTimeSystems(), timeSystem)) {
timeSystem = this._mode.availableTimeSystems()[0];
this._conductor.timeSystem(timeSystem, timeSystem.defaults().bounds);
if (!timeSystem || !contains(this.currentMode.availableTimeSystems(), timeSystem)) {
timeSystem = this.currentMode.availableTimeSystems()[0];
this.conductor.timeSystem(timeSystem, timeSystem.defaults().bounds);
}
}
return this._mode ? this._mode.metadata().key : undefined;
return this.currentMode ? this.currentMode.metadata().key : undefined;
};
/**
@ -176,7 +175,7 @@ define(
*/
TimeConductorViewService.prototype.deltas = function () {
//Deltas stored on mode. Use .apply to preserve arguments
return this._mode.deltas.apply(this._mode, arguments);
return this.currentMode.deltas.apply(this.currentMode, arguments);
};
/**
@ -187,7 +186,7 @@ define(
* @returns {ModeMetadata[]}
*/
TimeConductorViewService.prototype.availableModes = function () {
return this._availableModes;
return this.availModes;
};
/**
@ -195,7 +194,7 @@ define(
* mode. Time systems and tick sources are mode dependent
*/
TimeConductorViewService.prototype.availableTimeSystems = function () {
return this._mode.availableTimeSystems();
return this.currentMode.availableTimeSystems();
};
return TimeConductorViewService;

View File

@ -133,7 +133,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService._mode = oldMode;
viewService.currentMode = oldMode;
viewService.mode('fixed');
expect(oldMode.destroy).toHaveBeenCalled();
});
@ -145,7 +145,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
metadata: {
mode: 'realtime'
},
listen: function() {}
listen: function () {}
};
tickingTimeSystem.tickSources.andReturn([mockRealtimeTickSource]);
@ -165,7 +165,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
metadata: {
mode: 'realtime'
},
listen: function() {}
listen: function () {}
};
tickingTimeSystem.tickSources.andReturn([mockRealtimeTickSource]);

View File

@ -32,7 +32,7 @@ define([
* @implements TimeSystem
* @constructor
*/
function UTCTimeSystem ($timeout) {
function UTCTimeSystem($timeout) {
TimeSystem.call(this);
/**
@ -46,14 +46,14 @@ define([
'cssclass': 'icon-clock'
};
this._formats = ['utc'];
this._tickSources = [new LocalClock($timeout, DEFAULT_PERIOD)];
this.fmts = ['utc'];
this.sources = [new LocalClock($timeout, DEFAULT_PERIOD)];
}
UTCTimeSystem.prototype = Object.create(TimeSystem.prototype);
UTCTimeSystem.prototype.formats = function () {
return this._formats;
return this.fmts;
};
UTCTimeSystem.prototype.deltaFormat = function () {
@ -61,7 +61,7 @@ define([
};
UTCTimeSystem.prototype.tickSources = function () {
return this._tickSources;
return this.sources;
};
UTCTimeSystem.prototype.defaults = function (key) {

View File

@ -229,7 +229,7 @@ define(
// Respond to a display bounds change (requery for data)
function changeDisplayBounds(event, bounds, follow) {
//'hack' for follow mode
if (follow === true){
if (follow === true) {
setBasePanZoom(bounds);
} else {
var domainAxis = $scope.axes[0];

View File

@ -239,7 +239,7 @@ define(
it("sets status when plot becomes detached from time conductor", function () {
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
function boundsEvent(){
function boundsEvent() {
fireEvent("telemetry:display:bounds", [
{},
{ start: 10, end: 100 },

View File

@ -80,7 +80,7 @@ define(
HistoricalTableController.prototype.boundsChange = function (event, bounds, follow) {
// If in follow mode, don't bother re-subscribing, data will be
// received from existing subscription.
if (follow!==true) {
if (follow !== true) {
this.subscribe();
}
};