[Scrolling] Add JSDoc, clean up

Clean up scripts for Scrolling List view and add
some JSDoc. WTD-534.
This commit is contained in:
Victor Woeltjen
2014-12-02 15:21:26 -08:00
parent d304cc4343
commit e711073cb5
4 changed files with 74 additions and 13 deletions

View File

@ -1,27 +1,45 @@
/*global define,Promise*/ /*global define,moment*/
/** /**
* Module defining DomainColumn. Created by vwoeltje on 11/18/14. * Module defining DomainColumn. Created by vwoeltje on 11/18/14.
*/ */
define( define(
[], ["../../plot/lib/moment.min"],
function () { function () {
"use strict"; "use strict";
// Date format to use for domain values; in particular,
// use day-of-year instead of month/day
var DATE_FORMAT = "YYYY-DDD HH:mm:ss";
/** /**
* A column which will report telemetry domain values
* (typically, timestamps.) Used by the ScrollingListController.
* *
* @constructor * @constructor
* @param domainMetadata an object with the machine- and human-
* readable names for this domain (in `key` and `name`
* fields, respectively.)
*/ */
function DomainColumn(domainMetadata) { function DomainColumn(domainMetadata) {
return { return {
/**
* Get the title to display in this column's header.
* @returns {string} the title to display
*/
getTitle: function () { getTitle: function () {
return domainMetadata.name; return domainMetadata.name;
}, },
/**
* Get the text to display inside a row under this
* column.
* @returns {string} the text to display
*/
getValue: function (domainObject, data, index) { getValue: function (domainObject, data, index) {
return data.getDomainValue( return moment.utc(data.getDomainValue(
index, index,
domainMetadata.key domainMetadata.key
); )).format(DATE_FORMAT);
} }
}; };
} }

View File

@ -9,14 +9,25 @@ define(
"use strict"; "use strict";
/** /**
* A column which will report the name of the domain object
* which exposed specific telemetry values.
* *
* @constructor * @constructor
*/ */
function NameColumn() { function NameColumn() {
return { return {
/**
* Get the title to display in this column's header.
* @returns {string} the title to display
*/
getTitle: function () { getTitle: function () {
return "Name"; return "Name";
}, },
/**
* Get the text to display inside a row under this
* column. This returns the domain object's name.
* @returns {string} the text to display
*/
getValue: function (domainObject) { getValue: function (domainObject) {
return domainObject.getModel().name; return domainObject.getModel().name;
} }

View File

@ -9,19 +9,31 @@ define(
"use strict"; "use strict";
/** /**
* A column which will report telemetry range values
* (typically, measurements.) Used by the ScrollingListController.
* *
* @constructor * @constructor
* @param rangeMetadata an object with the machine- and human-
* readable names for this range (in `key` and `name`
* fields, respectively.)
*/ */
function RangeColumn(rangeMetadata) { function RangeColumn(rangeMetadata) {
return { return {
/**
* Get the title to display in this column's header.
* @returns {string} the title to display
*/
getTitle: function () { getTitle: function () {
return rangeMetadata.name; return rangeMetadata.name;
}, },
/**
* Get the text to display inside a row under this
* column.
* @returns {string} the text to display
*/
getValue: function (domainObject, data, index) { getValue: function (domainObject, data, index) {
return data.getRangeValue( var value = data.getRangeValue(index, rangeMetadata.key);
index, return value && value.toFixed(3);
rangeMetadata.key
);
} }
}; };
} }

View File

@ -11,7 +11,8 @@ define(
var ROW_COUNT = 18; var ROW_COUNT = 18;
/** /**
* * The ScrollingListController is responsible for populating
* the contents of the scrolling list view.
* @constructor * @constructor
*/ */
function ScrollingListController($scope) { function ScrollingListController($scope) {
@ -85,18 +86,25 @@ define(
// in the data set on the next iteration // in the data set on the next iteration
used[candidate.objectIndex] = used[candidate.objectIndex] + 1; used[candidate.objectIndex] = used[candidate.objectIndex] + 1;
} else { } else {
break; // Ran out of candidates; not enough data points available // Ran out of candidates; not enough data points
// available to fill all rows.
break;
} }
} }
return latest; return latest;
} }
// Get a set of populated, ready-to-display rows for the
// latest data values.
function getRows(telemetry) { function getRows(telemetry) {
var datas = telemetry.getResponse(), var datas = telemetry.getResponse(),
objects = telemetry.getTelemetryObjects(), objects = telemetry.getTelemetryObjects(),
values = getLatestDataValues(datas); values = getLatestDataValues(datas);
// Each value will become a row, which will contain
// some value in each column (rendering by the
// column object itself)
return values.map(function (value) { return values.map(function (value) {
return columns.map(function (column) { return columns.map(function (column) {
return column.getValue( return column.getValue(
@ -108,17 +116,22 @@ define(
}); });
} }
// Update the contents
function updateRows() { function updateRows() {
var telemetry = $scope.telemetry; var telemetry = $scope.telemetry;
$scope.rows = telemetry ? getRows(telemetry) : []; $scope.rows = telemetry ? getRows(telemetry) : [];
} }
function setupColumns() { // Set up columns based on telemetry metadata. This will
var telemetry = $scope.telemetry, // include one column for each domain and range type, as
domainKeys = {}, // well as a column for the domain object name.
function setupColumns(telemetry) {
var domainKeys = {},
rangeKeys = {}, rangeKeys = {},
metadata; metadata;
// Add a domain to the set of columns, if a domain
// with the same key has not yet been inclued.
function addDomain(domain) { function addDomain(domain) {
var key = domain.key; var key = domain.key;
if (key && !domainKeys[key]) { if (key && !domainKeys[key]) {
@ -126,6 +139,8 @@ define(
} }
} }
// Add a range to the set of columns, if a range
// with the same key has not yet been inclued.
function addRange(range) { function addRange(range) {
var key = range.key; var key = range.key;
if (key && !rangeKeys[key]) { if (key && !rangeKeys[key]) {
@ -133,6 +148,8 @@ define(
} }
} }
// We cannot proceed if the telemetry controller
// is not available; clear all rows/columns.
if (!telemetry) { if (!telemetry) {
columns = []; columns = [];
$scope.rows = []; $scope.rows = [];
@ -158,10 +175,13 @@ define(
columns.push(new RangeColumn({ name: "Value" })); columns.push(new RangeColumn({ name: "Value" }));
} }
// We have all columns now, so populate the headers
// for these columns in the scope.
$scope.headers = columns.map(function (column) { $scope.headers = columns.map(function (column) {
return column.getTitle(); return column.getTitle();
}); });
// Fill in the contents of the rows.
updateRows(); updateRows();
} }