mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
Merge pull request #779 from nasa/precision-778b
[Data Formats] Format numeric values with full precision
This commit is contained in:
commit
3e4a3aeb9b
@ -26,6 +26,8 @@ define(
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
var DIGITS = 3;
|
||||
|
||||
/**
|
||||
* Wraps a `TelemetryFormatter` to provide formats for domain and
|
||||
* range values; provides a single place to track domain/range
|
||||
@ -63,6 +65,10 @@ define(
|
||||
};
|
||||
|
||||
PlotTelemetryFormatter.prototype.formatRangeValue = function (value) {
|
||||
if (typeof value === 'number') {
|
||||
return value.toFixed(DIGITS);
|
||||
}
|
||||
|
||||
return this.telemetryFormatter
|
||||
.formatRangeValue(value, this.rangeFormat);
|
||||
};
|
||||
|
@ -55,14 +55,17 @@ define(
|
||||
.toHaveBeenCalledWith(12321, domainFormat);
|
||||
});
|
||||
|
||||
it("includes format in formatRangeValue calls", function () {
|
||||
it("includes format in formatRangeValue calls for strings", function () {
|
||||
mockFormatter.formatRangeValue.andReturn("formatted!");
|
||||
expect(formatter.formatRangeValue(12321))
|
||||
expect(formatter.formatRangeValue('foo'))
|
||||
.toEqual("formatted!");
|
||||
expect(mockFormatter.formatRangeValue)
|
||||
.toHaveBeenCalledWith(12321, rangeFormat);
|
||||
.toHaveBeenCalledWith('foo', rangeFormat);
|
||||
});
|
||||
|
||||
it("formats numeric values with three fixed digits", function () {
|
||||
expect(formatter.formatRangeValue(10)).toEqual("10.000");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -26,10 +26,6 @@ define(
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
// Date format to use for domain values; in particular,
|
||||
// use day-of-year instead of month/day
|
||||
var VALUE_FORMAT_DIGITS = 3;
|
||||
|
||||
/**
|
||||
* The TelemetryFormatter is responsible for formatting (as text
|
||||
* for display) values along either the domain (usually time) or
|
||||
@ -73,7 +69,7 @@ define(
|
||||
* value, suitable for display.
|
||||
*/
|
||||
TelemetryFormatter.prototype.formatRangeValue = function (v, key) {
|
||||
return isNaN(v) ? String(v) : v.toFixed(VALUE_FORMAT_DIGITS);
|
||||
return String(v);
|
||||
};
|
||||
|
||||
return TelemetryFormatter;
|
||||
|
@ -59,7 +59,10 @@ define(
|
||||
});
|
||||
|
||||
it("formats ranges as values", function () {
|
||||
expect(formatter.formatRangeValue(10)).toEqual("10.000");
|
||||
var value = 3.14159265352979323846264338, // not pi
|
||||
formatted = formatter.formatRangeValue(value);
|
||||
// Make sure we don't lose information by formatting
|
||||
expect(parseFloat(formatted)).toEqual(value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user