mirror of
https://github.com/nasa/openmct.git
synced 2025-01-30 08:04:03 +00:00
[Plot] Separate out formatter
Separate out plot label formatter to simplify PlotController, to simplify test and maintenance. WTD-533
This commit is contained in:
parent
5bfa9c76a7
commit
bb708e9a05
@ -9,9 +9,10 @@ define(
|
||||
"./PlotPalette",
|
||||
"./PlotPanZoomStack",
|
||||
"./PlotPosition",
|
||||
"../lib/moment.min.js"
|
||||
"./PlotTickGenerator",
|
||||
"./PlotFormatter"
|
||||
],
|
||||
function (PlotPreparer, PlotPalette, PlotPanZoomStack, PlotPosition) {
|
||||
function (PlotPreparer, PlotPalette, PlotPanZoomStack, PlotPosition, PlotTickGenerator, PlotFormatter) {
|
||||
"use strict";
|
||||
|
||||
var AXIS_DEFAULTS = [
|
||||
@ -29,20 +30,15 @@ define(
|
||||
var mousePosition,
|
||||
marqueeStart,
|
||||
panZoomStack = new PlotPanZoomStack([], []),
|
||||
formatter = new PlotFormatter(),
|
||||
domainOffset;
|
||||
|
||||
function formatDomainValue(v) {
|
||||
return moment.utc(v).format("YYYY-DDD HH:mm:ss");
|
||||
}
|
||||
|
||||
function formatRangeValue(v) {
|
||||
return v.toFixed(1);
|
||||
}
|
||||
|
||||
// Utility, for map/forEach loops. Index 0 is domain,
|
||||
// index 1 is range.
|
||||
function formatValue(v, i) {
|
||||
return (i ? formatRangeValue : formatDomainValue)(v);
|
||||
return (i ?
|
||||
formatter.formatRangeValue :
|
||||
formatter.formatDomainValue)(v);
|
||||
}
|
||||
|
||||
function mousePositionToDomainRange(mousePosition, domainOffset) {
|
||||
@ -56,20 +52,6 @@ define(
|
||||
).getPosition();
|
||||
}
|
||||
|
||||
function generateTicks(start, span, count, format) {
|
||||
var step = span / (count - 1),
|
||||
result = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < count; i += 1) {
|
||||
result.push({
|
||||
label: format(i * step + start)
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function updateMarqueeBox() {
|
||||
$scope.draw.boxes = marqueeStart ?
|
||||
[{
|
||||
@ -86,9 +68,8 @@ define(
|
||||
$scope.draw.origin = panZoom.origin;
|
||||
}
|
||||
|
||||
|
||||
function plotTelemetry() {
|
||||
var telemetry, prepared, data;
|
||||
var telemetry, prepared, tickGenerator, data;
|
||||
|
||||
telemetry = $scope.telemetry;
|
||||
|
||||
@ -104,18 +85,12 @@ define(
|
||||
($scope.axes[1].active || {}).key
|
||||
);
|
||||
|
||||
$scope.axes[0].ticks = generateTicks(
|
||||
prepared.getOrigin()[0] + prepared.getDomainOffset(),
|
||||
prepared.getDimensions()[0],
|
||||
DOMAIN_TICKS,
|
||||
formatDomainValue
|
||||
);
|
||||
$scope.axes[1].ticks = generateTicks(
|
||||
prepared.getOrigin()[1],
|
||||
prepared.getDimensions()[1],
|
||||
RANGE_TICKS,
|
||||
formatRangeValue
|
||||
);
|
||||
tickGenerator = new PlotTickGenerator(prepared, formatter);
|
||||
|
||||
$scope.axes[0].ticks =
|
||||
tickGenerator.generateDomainTicks(DOMAIN_TICKS);
|
||||
$scope.axes[1].ticks =
|
||||
tickGenerator.generateRangeTicks(RANGE_TICKS);
|
||||
|
||||
panZoomStack.setBasePanZoom(
|
||||
prepared.getOrigin(),
|
||||
|
28
platform/features/plot/src/PlotFormatter.js
Normal file
28
platform/features/plot/src/PlotFormatter.js
Normal file
@ -0,0 +1,28 @@
|
||||
/*global define,moment*/
|
||||
|
||||
define(
|
||||
["../lib/moment.min"],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
var DATE_FORMAT = "YYYY-DDD HH:mm:ss";
|
||||
|
||||
function PlotFormatter() {
|
||||
function formatDomainValue(v) {
|
||||
return moment.utc(v).format(DATE_FORMAT);
|
||||
}
|
||||
|
||||
function formatRangeValue(v) {
|
||||
return v.toFixed(1);
|
||||
}
|
||||
|
||||
return {
|
||||
formatDomainValue: formatDomainValue,
|
||||
formatRangeValue: formatRangeValue
|
||||
};
|
||||
}
|
||||
|
||||
return PlotFormatter;
|
||||
|
||||
}
|
||||
);
|
48
platform/features/plot/src/PlotTickGenerator.js
Normal file
48
platform/features/plot/src/PlotTickGenerator.js
Normal file
@ -0,0 +1,48 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
function PlotTickGenerator(preparer, formatter) {
|
||||
|
||||
function generateTicks(start, span, count, format) {
|
||||
var step = span / (count - 1),
|
||||
result = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < count; i += 1) {
|
||||
result.push({
|
||||
label: format(i * step + start)
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
generateDomainTicks: function (count) {
|
||||
return generateTicks(
|
||||
preparer.getOrigin()[0] + preparer.getDomainOffset(),
|
||||
preparer.getDimensions()[0],
|
||||
count,
|
||||
formatter.formatDomainValue
|
||||
);
|
||||
},
|
||||
generateRangeTicks: function (count) {
|
||||
return generateTicks(
|
||||
preparer.getOrigin()[1],
|
||||
preparer.getDimensions()[1],
|
||||
count,
|
||||
formatter.formatRangeValue
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return PlotTickGenerator;
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user