diff --git a/platform/commonUI/formats/bundle.js b/platform/commonUI/formats/bundle.js index 51a04d695e..0aea5e531e 100644 --- a/platform/commonUI/formats/bundle.js +++ b/platform/commonUI/formats/bundle.js @@ -22,13 +22,9 @@ define([ "./src/FormatProvider", - "./src/UTCTimeFormat", - "./src/DurationFormat", 'legacyRegistry' ], function ( FormatProvider, - UTCTimeFormat, - DurationFormat, legacyRegistry ) { @@ -46,22 +42,6 @@ define([ ] } ], - "formats": [ - { - "key": "utc", - "implementation": UTCTimeFormat - }, - { - "key": "duration", - "implementation": DurationFormat - } - ], - "constants": [ - { - "key": "DEFAULT_TIME_FORMAT", - "value": "utc" - } - ], "licenses": [ { "name": "d3", diff --git a/platform/commonUI/formats/src/FormatProvider.js b/platform/commonUI/formats/src/FormatProvider.js index e9b7e93bc9..70bbac508e 100644 --- a/platform/commonUI/formats/src/FormatProvider.js +++ b/platform/commonUI/formats/src/FormatProvider.js @@ -30,19 +30,23 @@ define([ * An object used to convert between numeric values and text values, * typically used to display these values to the user and to convert * user input to a numeric format, particularly for time formats. - * @interface {Format} + * @interface Format */ - /** * Parse text (typically user input) to a numeric value. * Behavior is undefined when the text cannot be parsed; * `validate` should be called first if the text may be invalid. - * @method parse + * @method Format#parse * @memberof Format# * @param {string} text the text to parse * @returns {number} the parsed numeric value */ + /** + * @property {string} key A unique identifier for this formatter. + * @memberof Format# + */ + /** * Determine whether or not some text (typically user input) can * be parsed to a numeric value by this format. @@ -58,10 +62,12 @@ define([ * @method format * @memberof Format# * @param {number} value the numeric value to format - * @param {number} [threshold] Optionally provides context to the - * format request, allowing for scale-appropriate formatting. This value - * should be the minimum unit to be represented by this format, in ms. For - * example, to display seconds, a threshold of 1 * 1000 should be provided. + * @param {number} [minValue] Contextual information for scaled formatting used in linear scales such as conductor + * and plot axes. Specifies the smallest number on the scale. + * @param {number} [maxValue] Contextual information for scaled formatting used in linear scales such as conductor + * and plot axes. Specifies the largest number on the scale + * @param {number} [count] Contextual information for scaled formatting used in linear scales such as conductor + * and plot axes. The number of labels on the scale. * @returns {string} the text representation of the value */ diff --git a/platform/commonUI/formats/test/UTCTimeFormatSpec.js b/platform/commonUI/formats/test/UTCTimeFormatSpec.js deleted file mode 100644 index 967cd7137f..0000000000 --- a/platform/commonUI/formats/test/UTCTimeFormatSpec.js +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************** - * Open MCT, Copyright (c) 2014-2017, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT 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 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( - ['../src/UTCTimeFormat', 'moment'], - function (UTCTimeFormat, moment) { - - describe("The UTCTimeFormat", function () { - var format; - - beforeEach(function () { - format = new UTCTimeFormat(); - }); - - it("formats UTC timestamps", function () { - var timestamp = 12345670000, - formatted = format.format(timestamp); - expect(formatted).toEqual(jasmine.any(String)); - expect(moment.utc(formatted).valueOf()).toEqual(timestamp); - }); - - it("displays with millisecond precision", function () { - var timestamp = 12345670789, - formatted = format.format(timestamp); - expect(moment.utc(formatted).valueOf()).toEqual(timestamp); - }); - - it("validates time inputs", function () { - expect(format.validate("1977-05-25 11:21:22")).toBe(true); - expect(format.validate("garbage text")).toBe(false); - }); - - it("parses valid input", function () { - var text = "1977-05-25 11:21:22", - parsed = format.parse(text); - expect(parsed).toEqual(jasmine.any(Number)); - expect(parsed).toEqual(moment.utc(text).valueOf()); - }); - }); - } -); diff --git a/src/api/telemetry/TelemetryAPI.js b/src/api/telemetry/TelemetryAPI.js index 5b1cdcf734..3edf6a06e2 100644 --- a/src/api/telemetry/TelemetryAPI.js +++ b/src/api/telemetry/TelemetryAPI.js @@ -316,6 +316,17 @@ define([ return this.formatMapCache.get(metadata); }; + /** + * Register a new telemetry data formatter. + * @param {Format} format the + */ + TelemetryAPI.prototype.addFormat = function (format) { + this.MCT.legacyExtension('formats', { + key: format.key, + implementation: function () { return format } + }); + }; + /** * Get a limit evaluator for this domain object. * Limit Evaluators help you evaluate limit and alarm status of individual telemetry datums for display purposes without having to interact directly with the Limit API. diff --git a/platform/commonUI/formats/src/DurationFormat.js b/src/plugins/utcTimeSystem/DurationFormat.js similarity index 98% rename from platform/commonUI/formats/src/DurationFormat.js rename to src/plugins/utcTimeSystem/DurationFormat.js index 12ce3b3c6b..ecc9701b9d 100644 --- a/platform/commonUI/formats/src/DurationFormat.js +++ b/src/plugins/utcTimeSystem/DurationFormat.js @@ -44,6 +44,7 @@ define([ * @memberof platform/commonUI/formats */ function DurationFormat() { + this.key = "duration" } DurationFormat.prototype.format = function (value) { diff --git a/platform/commonUI/formats/src/UTCTimeFormat.js b/src/plugins/utcTimeSystem/UTCTimeFormat.js similarity index 70% rename from platform/commonUI/formats/src/UTCTimeFormat.js rename to src/plugins/utcTimeSystem/UTCTimeFormat.js index 6d747a1391..6a8ebb9c39 100644 --- a/platform/commonUI/formats/src/UTCTimeFormat.js +++ b/src/plugins/utcTimeSystem/UTCTimeFormat.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2017, United States Government + * Open MCT, Copyright (c) 2014-2016, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * @@ -49,6 +49,7 @@ define([ * @memberof platform/commonUI/formats */ function UTCTimeFormat() { + this.key = "utc"; } /** @@ -64,7 +65,7 @@ define([ * * Licensed */ - return [ + var format = [ [".SSS", function (m) { return m.milliseconds(); }], @@ -91,25 +92,32 @@ define([ return true; }] ].filter(function (row) { - return row[1](momentified); - })[0][0]; + return row[1](momentified); + })[0][0]; + + if (format !== undefined) { + return moment.utc(d).format(format); + } } /** - * - * @param value - * @param {Scale} [scale] Optionally provides context to the - * format request, allowing for scale-appropriate formatting. - * @returns {string} the formatted date + * @param {number} value The value to format. + * @param {number} [minValue] Contextual information for scaled formatting used in linear scales such as conductor + * and plot axes. Specifies the smallest number on the scale. + * @param {number} [maxValue] Contextual information for scaled formatting used in linear scales such as conductor + * and plot axes. Specifies the largest number on the scale + * @param {number} [count] Contextual information for scaled formatting used in linear scales such as conductor + * and plot axes. The number of labels on the scale. + * @returns {string} the formatted date(s). If multiple values were requested, then an array of + * formatted values will be returned. Where a value could not be formatted, `undefined` will be returned at its position + * in the array. */ - UTCTimeFormat.prototype.format = function (value, scale) { - if (scale !== undefined) { - var scaledFormat = getScaledFormat(value, scale); - if (scaledFormat) { - return moment.utc(value).format(scaledFormat); - } + UTCTimeFormat.prototype.format = function (value, minValue, maxValue, count) { + if (arguments.length > 1) { + return getScaledFormat(value); + } else { + return moment.utc(value).format(DATE_FORMAT) + "Z"; } - return moment.utc(value).format(DATE_FORMAT) + "Z"; }; UTCTimeFormat.prototype.parse = function (text) { @@ -121,4 +129,4 @@ define([ }; return UTCTimeFormat; -}); +}); \ No newline at end of file diff --git a/platform/commonUI/formats/src/UTCTimeFormatSpec.js b/src/plugins/utcTimeSystem/UTCTimeFormatSpec.js similarity index 100% rename from platform/commonUI/formats/src/UTCTimeFormatSpec.js rename to src/plugins/utcTimeSystem/UTCTimeFormatSpec.js diff --git a/src/plugins/utcTimeSystem/plugin.js b/src/plugins/utcTimeSystem/plugin.js index e6bcb3edf6..0dfc53cd20 100644 --- a/src/plugins/utcTimeSystem/plugin.js +++ b/src/plugins/utcTimeSystem/plugin.js @@ -22,10 +22,14 @@ define([ "./UTCTimeSystem", - "./LocalClock" + "./LocalClock", + "./UTCTimeFormat", + "./DurationFormat", ], function ( UTCTimeSystem, - LocalClock + LocalClock, + UTCTimeFormat, + DurationFormat ) { /** * Install a time system that supports UTC times. It also installs a local @@ -36,6 +40,13 @@ define([ var timeSystem = new UTCTimeSystem(); openmct.time.addTimeSystem(timeSystem); openmct.time.addClock(new LocalClock(100)); + openmct.telemetry.addFormat(new UTCTimeFormat()); + openmct.telemetry.addFormat(new DurationFormat()); + + openmct.legacyExtension("constants", { + "key": "DEFAULT_TIME_FORMAT", + "value": "utc" + }); } }; });