2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
2014-12-24 18:25:46 +00:00
|
|
|
|
|
|
|
define(
|
2015-10-27 18:21:44 +00:00
|
|
|
[],
|
|
|
|
function () {
|
2014-12-24 18:25:46 +00:00
|
|
|
|
2014-12-24 18:34:43 +00:00
|
|
|
/**
|
|
|
|
* The TelemetryFormatter is responsible for formatting (as text
|
|
|
|
* for display) values along either the domain (usually time) or
|
|
|
|
* the range (usually value) of a data series.
|
2015-08-07 18:44:54 +00:00
|
|
|
* @memberof platform/telemetry
|
2014-12-24 18:34:43 +00:00
|
|
|
* @constructor
|
2015-10-30 21:08:11 +00:00
|
|
|
* @param {FormatService} formatService the service to user to format
|
|
|
|
* domain values
|
|
|
|
* @param {string} defaultFormatKey the format to request when no
|
|
|
|
* format has been otherwise specified
|
2014-12-24 18:34:43 +00:00
|
|
|
*/
|
2015-11-02 20:28:46 +00:00
|
|
|
function TelemetryFormatter(formatService, defaultFormatKey) {
|
2015-10-27 18:21:44 +00:00
|
|
|
this.formatService = formatService;
|
2015-10-30 20:17:53 +00:00
|
|
|
this.defaultFormat = formatService.getFormat(defaultFormatKey);
|
2015-08-14 23:47:20 +00:00
|
|
|
}
|
2014-12-24 18:25:46 +00:00
|
|
|
|
2015-08-14 23:47:20 +00:00
|
|
|
/**
|
|
|
|
* Format a domain value.
|
2015-10-27 18:21:44 +00:00
|
|
|
* @param {number} v the domain value; usually, a timestamp
|
2015-08-14 23:47:20 +00:00
|
|
|
* in milliseconds since start of 1970
|
2015-10-27 18:21:44 +00:00
|
|
|
* @param {string} [key] a key which identifies the format
|
|
|
|
* to use
|
2015-08-14 23:47:20 +00:00
|
|
|
* @returns {string} a textual representation of the
|
|
|
|
* data and time, suitable for display.
|
|
|
|
*/
|
|
|
|
TelemetryFormatter.prototype.formatDomainValue = function (v, key) {
|
2015-10-30 20:17:53 +00:00
|
|
|
var formatter = (key === undefined) ?
|
|
|
|
this.defaultFormat :
|
|
|
|
this.formatService.getFormat(key);
|
|
|
|
|
2015-11-02 20:28:46 +00:00
|
|
|
return isNaN(v) ? "" : formatter.format(v);
|
2015-08-14 23:47:20 +00:00
|
|
|
};
|
2014-12-24 18:25:46 +00:00
|
|
|
|
2015-08-14 23:47:20 +00:00
|
|
|
/**
|
|
|
|
* Format a range value.
|
|
|
|
* @param {number} v the range value; a numeric value
|
|
|
|
* @param {string} [key] the key which identifies the
|
|
|
|
* range; if unspecified or unknown, this will
|
|
|
|
* be treated as a numeric value.
|
|
|
|
* @returns {string} a textual representation of the
|
|
|
|
* value, suitable for display.
|
|
|
|
*/
|
|
|
|
TelemetryFormatter.prototype.formatRangeValue = function (v, key) {
|
2016-03-21 21:35:58 +00:00
|
|
|
return String(v);
|
2015-08-14 23:47:20 +00:00
|
|
|
};
|
2014-12-24 18:25:46 +00:00
|
|
|
|
|
|
|
return TelemetryFormatter;
|
|
|
|
}
|
2015-08-07 18:44:54 +00:00
|
|
|
);
|