[Telemetry] Refactor plot to use TelemetryFormatter

Refactor plot view to use an injected telemetry formatter,
instead of explicitly including moment. WTD-599.
This commit is contained in:
Victor Woeltjen
2014-12-24 10:59:34 -08:00
parent b080f90f64
commit fc0376296d
8 changed files with 62 additions and 14 deletions

View File

@ -20,7 +20,7 @@
{ {
"key": "PlotController", "key": "PlotController",
"implementation": "PlotController.js", "implementation": "PlotController.js",
"depends": [ "$scope" ] "depends": [ "$scope", "telemetryFormatter" ]
} }
] ]
} }

View File

@ -8,9 +8,10 @@ define(
"./elements/PlotPreparer", "./elements/PlotPreparer",
"./elements/PlotPalette", "./elements/PlotPalette",
"./elements/PlotAxis", "./elements/PlotAxis",
"./modes/PlotModeOptions" "./modes/PlotModeOptions",
"./SubPlotFactory"
], ],
function (PlotPreparer, PlotPalette, PlotAxis, PlotModeOptions) { function (PlotPreparer, PlotPalette, PlotAxis, PlotModeOptions, SubPlotFactory) {
"use strict"; "use strict";
var AXIS_DEFAULTS = [ var AXIS_DEFAULTS = [
@ -29,8 +30,9 @@ define(
* *
* @constructor * @constructor
*/ */
function PlotController($scope) { function PlotController($scope, telemetryFormatter) {
var modeOptions = new PlotModeOptions([]), var subPlotFactory = new SubPlotFactory(telemetryFormatter),
modeOptions = new PlotModeOptions([], subPlotFactory),
subplots = [], subplots = [],
domainOffset; domainOffset;

View File

@ -22,14 +22,14 @@ define(
* @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom * @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom
* states which is applicable to this sub-plot * states which is applicable to this sub-plot
*/ */
function SubPlot(telemetryObjects, panZoomStack) { function SubPlot(telemetryObjects, panZoomStack, telemetryFormatter) {
// We are used from a template often, so maintain // We are used from a template often, so maintain
// state in local variables to allow for fast look-up, // state in local variables to allow for fast look-up,
// as is normal for controllers. // as is normal for controllers.
var draw = {}, var draw = {},
rangeTicks = [], rangeTicks = [],
domainTicks = [], domainTicks = [],
formatter = new PlotFormatter(), formatter = telemetryFormatter,
domainOffset, domainOffset,
mousePosition, mousePosition,
marqueeStart, marqueeStart,

View File

@ -0,0 +1,40 @@
/*global define*/
define(
["./SubPlot"],
function (SubPlot) {
"use strict";
/**
* Utility factory; wraps the SubPlot constructor and adds
* in a reference to the telemetryFormatter, which will be
* used to represent telemetry values (timestamps or data
* values) as human-readable strings.
* @constructor
*/
function SubPlotFactory(telemetryFormatter) {
return {
/**
* Instantiate a new sub-plot.
* @param {DomainObject[]} telemetryObjects the domain objects
* which will be plotted in this sub-plot
* @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom
* states which is applicable to this sub-plot
* @returns {SubPlot} the instantiated sub-plot
* @method
* @memberof SubPlotFactory
*/
createSubPlot: function (telemetryObjects, panZoomStack) {
return new SubPlot(
telemetryObjects,
panZoomStack,
telemetryFormatter
);
}
};
}
return SubPlotFactory;
}
);

View File

@ -13,7 +13,7 @@ define(
* @constructor * @constructor
* @param {PlotPanZoomStack} panZoomStack the pan-zoom stack for * @param {PlotPanZoomStack} panZoomStack the pan-zoom stack for
* this plot, used to determine plot boundaries * this plot, used to determine plot boundaries
* @param {PlotFormatter} formatter used to format (for display) * @param {TelemetryFormatter} formatter used to format (for display)
* domain and range values. * domain and range values.
*/ */
function PlotTickGenerator(panZoomStack, formatter) { function PlotTickGenerator(panZoomStack, formatter) {

View File

@ -27,7 +27,7 @@ define(
* @param {DomainObject[]} the telemetry objects being * @param {DomainObject[]} the telemetry objects being
* represented in this plot view * represented in this plot view
*/ */
function PlotModeOptions(telemetryObjects) { function PlotModeOptions(telemetryObjects, subPlotFactory) {
var options = telemetryObjects.length > 1 ? var options = telemetryObjects.length > 1 ?
[ OVERLAID, STACKED ] : [ OVERLAID ], [ OVERLAID, STACKED ] : [ OVERLAID ],
mode = options[0], // Initial selection (overlaid) mode = options[0], // Initial selection (overlaid)
@ -44,7 +44,10 @@ define(
getModeHandler: function () { getModeHandler: function () {
// Lazily initialize // Lazily initialize
if (!modeHandler) { if (!modeHandler) {
modeHandler = mode.factory(telemetryObjects); modeHandler = mode.factory(
telemetryObjects,
subPlotFactory
);
} }
return modeHandler; return modeHandler;
}, },

View File

@ -11,10 +11,13 @@ define(
* @constructor * @constructor
* @param {DomainObject[]} the domain objects to be plotted * @param {DomainObject[]} the domain objects to be plotted
*/ */
function PlotOverlayMode(telemetryObjects) { function PlotOverlayMode(telemetryObjects, subPlotFactory) {
var domainOffset, var domainOffset,
panZoomStack = new PlotPanZoomStack([], []), panZoomStack = new PlotPanZoomStack([], []),
subplot = new SubPlot(telemetryObjects, panZoomStack), subplot = subPlotFactory.createSubPlot(
telemetryObjects,
panZoomStack
),
subplots = [ subplot ]; subplots = [ subplot ];
function plotTelemetry(prepared) { function plotTelemetry(prepared) {

View File

@ -11,12 +11,12 @@ define(
* @constructor * @constructor
* @param {DomainObject[]} the domain objects to be plotted * @param {DomainObject[]} the domain objects to be plotted
*/ */
function PlotStackMode(telemetryObjects) { function PlotStackMode(telemetryObjects, subPlotFactory) {
var domainOffset, var domainOffset,
panZoomStackGroup = panZoomStackGroup =
new PlotPanZoomStackGroup(telemetryObjects.length), new PlotPanZoomStackGroup(telemetryObjects.length),
subplots = telemetryObjects.map(function (telemetryObject, i) { subplots = telemetryObjects.map(function (telemetryObject, i) {
return new SubPlot( return subPlotFactory.createSubPlot(
[telemetryObject], [telemetryObject],
panZoomStackGroup.getPanZoomStack(i) panZoomStackGroup.getPanZoomStack(i)
); );