Skip to content

Commit

Permalink
[Time Conductor] #933 Fixed code style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Sep 6, 2016
1 parent c6eaa3d commit 7af5875
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 113 deletions.
34 changes: 23 additions & 11 deletions platform/commonUI/formats/src/UTCTimeFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ define(
}

conductor.on('bounds', amendRequests);
return function() {
return function () {
unsubscribeFunc();
conductor.off('bounds', amendRequests);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define(['./TickSource'], function (TickSource) {
* @implements TickSource
* @constructor
*/
function LocalClock ($timeout, period) {
function LocalClock($timeout, period) {
TickSource.call(this);

this.metadata = {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define([], function () {
* @interface
* @constructor
*/
function TickSource () {
function TickSource() {
this.listeners = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define([], function () {
* @interface
* @constructor
*/
function TimeSystem () {
function TimeSystem() {
/**
* @typedef TimeSystemMetadata
* @property {string} key
Expand All @@ -35,7 +35,6 @@ define([], function () {
* @type {TimeSystemMetadata}
*/
this.metadata = undefined;
this._tickSources = [];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -127,7 +127,7 @@ define(
}
};

return function(conductor, formatService) {
return function (conductor, formatService) {
return new MCTConductorAxis(conductor, formatService);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -89,7 +89,7 @@ define(['./MctConductorAxis'], function (MctConductorAxis) {
var mockTimeSystem;
var mockFormat;

beforeEach(function() {
beforeEach(function () {
mockTimeSystem = jasmine.createSpyObj("timeSystem", [
"formats",
"isUTCBased"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define([], function () {
}

NumberFormat.prototype.format = function (value) {
if (isNaN(value)){
if (isNaN(value)) {
return '';
} else {
return '' + value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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();
});

//Set the initial state of the view based on current time conductor
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);
Expand All @@ -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();

Expand Down Expand Up @@ -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;
});
});
};

/**
Expand Down Expand Up @@ -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
*
Expand All @@ -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};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -183,7 +183,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
var ts2Metadata;
var ts3Metadata;
var mockTimeSystemConstructors;

beforeEach(function () {
mode = "realtime";
ts1Metadata = {
Expand Down Expand Up @@ -304,7 +304,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
metadata: {
key: 'testTimeSystem'
},
defaults: function() {
defaults: function () {
return {
bounds: defaultBounds
};
Expand All @@ -313,7 +313,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {

mockTimeSystems = [
// Wrap as constructor function
function() {
function () {
return timeSystem;
}
];
Expand Down
Loading

0 comments on commit 7af5875

Please sign in to comment.