From b080f90f64f1ed79171ba41fe3dcd83f6ec819ef Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 24 Dec 2014 10:34:43 -0800 Subject: [PATCH] [Telemetry] Move formatter implementation Move implementation of formatter used for display of domain values out of plot, and into the telemetry bundle, from which it can be exposed as a general-use service. WTD-599. --- .../plot/src/elements/PlotFormatter.js | 48 ------------------- platform/telemetry/src/TelemetryFormatter.js | 39 +++++++++++++-- 2 files changed, 34 insertions(+), 53 deletions(-) delete mode 100644 platform/features/plot/src/elements/PlotFormatter.js diff --git a/platform/features/plot/src/elements/PlotFormatter.js b/platform/features/plot/src/elements/PlotFormatter.js deleted file mode 100644 index a3b7abe2dd..0000000000 --- a/platform/features/plot/src/elements/PlotFormatter.js +++ /dev/null @@ -1,48 +0,0 @@ -/*global define,moment*/ - -define( - ["../../lib/moment.min"], - function () { - "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"; - - /** - * The PlotFormatter is responsible for formatting (as text - * for display) values along either the domain or range of a - * plot. - */ - function PlotFormatter() { - function formatDomainValue(v) { - return isNaN(v) ? "" : moment.utc(v).format(DATE_FORMAT); - } - - function formatRangeValue(v) { - return isNaN(v) ? "" : v.toFixed(1); - } - - return { - /** - * Format a domain value. - * @param {number} v the domain value; a timestamp - * in milliseconds since start of 1970 - * @returns {string} a textual representation of the - * data and time, suitable for display. - */ - formatDomainValue: formatDomainValue, - /** - * Format a range value. - * @param {number} v the range value; a numeric value - * @returns {string} a textual representation of the - * value, suitable for display. - */ - formatRangeValue: formatRangeValue - }; - } - - return PlotFormatter; - - } -); \ No newline at end of file diff --git a/platform/telemetry/src/TelemetryFormatter.js b/platform/telemetry/src/TelemetryFormatter.js index 409cb27f60..85ec7ff29a 100644 --- a/platform/telemetry/src/TelemetryFormatter.js +++ b/platform/telemetry/src/TelemetryFormatter.js @@ -5,18 +5,47 @@ define( function () { "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", + VALUE_FORMAT_DIGITS = 3; + + /** + * 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. + * @constructor + */ function TelemetryFormatter() { - - function formatDomainValue(key, value) { - + function formatDomainValue(v, key) { + return isNaN(v) ? "" : moment.utc(v).format(DATE_FORMAT); } - function formatRangeValue(key, value) { - + function formatRangeValue(v, key) { + return isNaN(v) ? "" : v.toFixed(3); } return { + /** + * Format a domain value. + * @param {number} v the domain value; a timestamp + * in milliseconds since start of 1970 + * @param {string} [key] the key which identifies the + * domain; if unspecified or unknown, this will + * be treated as a standard timestamp. + * @returns {string} a textual representation of the + * data and time, suitable for display. + */ formatDomainValue: formatDomainValue, + /** + * 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. + */ formatRangeValue: formatRangeValue }; }