diff --git a/platform/features/plot/bundle.json b/platform/features/plot/bundle.json index 42766bd3ab..8f5e134e57 100644 --- a/platform/features/plot/bundle.json +++ b/platform/features/plot/bundle.json @@ -20,7 +20,7 @@ { "key": "PlotController", "implementation": "PlotController.js", - "depends": [ "$scope" ] + "depends": [ "$scope", "telemetryFormatter" ] } ] } diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index 2cc77ccb8f..dca8175ad4 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -8,9 +8,10 @@ define( "./elements/PlotPreparer", "./elements/PlotPalette", "./elements/PlotAxis", - "./modes/PlotModeOptions" + "./modes/PlotModeOptions", + "./SubPlotFactory" ], - function (PlotPreparer, PlotPalette, PlotAxis, PlotModeOptions) { + function (PlotPreparer, PlotPalette, PlotAxis, PlotModeOptions, SubPlotFactory) { "use strict"; var AXIS_DEFAULTS = [ @@ -29,8 +30,9 @@ define( * * @constructor */ - function PlotController($scope) { - var modeOptions = new PlotModeOptions([]), + function PlotController($scope, telemetryFormatter) { + var subPlotFactory = new SubPlotFactory(telemetryFormatter), + modeOptions = new PlotModeOptions([], subPlotFactory), subplots = [], domainOffset; diff --git a/platform/features/plot/src/SubPlot.js b/platform/features/plot/src/SubPlot.js index 7a9ebfc49b..1de8e0d65c 100644 --- a/platform/features/plot/src/SubPlot.js +++ b/platform/features/plot/src/SubPlot.js @@ -22,14 +22,14 @@ define( * @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom * 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 // state in local variables to allow for fast look-up, // as is normal for controllers. var draw = {}, rangeTicks = [], domainTicks = [], - formatter = new PlotFormatter(), + formatter = telemetryFormatter, domainOffset, mousePosition, marqueeStart, diff --git a/platform/features/plot/src/SubPlotFactory.js b/platform/features/plot/src/SubPlotFactory.js new file mode 100644 index 0000000000..662bab5eb6 --- /dev/null +++ b/platform/features/plot/src/SubPlotFactory.js @@ -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; + + } +); \ No newline at end of file diff --git a/platform/features/plot/src/elements/PlotTickGenerator.js b/platform/features/plot/src/elements/PlotTickGenerator.js index 80b92a27cf..4d54758803 100644 --- a/platform/features/plot/src/elements/PlotTickGenerator.js +++ b/platform/features/plot/src/elements/PlotTickGenerator.js @@ -13,7 +13,7 @@ define( * @constructor * @param {PlotPanZoomStack} panZoomStack the pan-zoom stack for * 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. */ function PlotTickGenerator(panZoomStack, formatter) { diff --git a/platform/features/plot/src/modes/PlotModeOptions.js b/platform/features/plot/src/modes/PlotModeOptions.js index d91f43c43e..3d66b5b9bf 100644 --- a/platform/features/plot/src/modes/PlotModeOptions.js +++ b/platform/features/plot/src/modes/PlotModeOptions.js @@ -27,7 +27,7 @@ define( * @param {DomainObject[]} the telemetry objects being * represented in this plot view */ - function PlotModeOptions(telemetryObjects) { + function PlotModeOptions(telemetryObjects, subPlotFactory) { var options = telemetryObjects.length > 1 ? [ OVERLAID, STACKED ] : [ OVERLAID ], mode = options[0], // Initial selection (overlaid) @@ -44,7 +44,10 @@ define( getModeHandler: function () { // Lazily initialize if (!modeHandler) { - modeHandler = mode.factory(telemetryObjects); + modeHandler = mode.factory( + telemetryObjects, + subPlotFactory + ); } return modeHandler; }, diff --git a/platform/features/plot/src/modes/PlotOverlayMode.js b/platform/features/plot/src/modes/PlotOverlayMode.js index e754faf249..de4445961e 100644 --- a/platform/features/plot/src/modes/PlotOverlayMode.js +++ b/platform/features/plot/src/modes/PlotOverlayMode.js @@ -11,10 +11,13 @@ define( * @constructor * @param {DomainObject[]} the domain objects to be plotted */ - function PlotOverlayMode(telemetryObjects) { + function PlotOverlayMode(telemetryObjects, subPlotFactory) { var domainOffset, panZoomStack = new PlotPanZoomStack([], []), - subplot = new SubPlot(telemetryObjects, panZoomStack), + subplot = subPlotFactory.createSubPlot( + telemetryObjects, + panZoomStack + ), subplots = [ subplot ]; function plotTelemetry(prepared) { diff --git a/platform/features/plot/src/modes/PlotStackMode.js b/platform/features/plot/src/modes/PlotStackMode.js index f8e5167205..25ad2e0304 100644 --- a/platform/features/plot/src/modes/PlotStackMode.js +++ b/platform/features/plot/src/modes/PlotStackMode.js @@ -11,12 +11,12 @@ define( * @constructor * @param {DomainObject[]} the domain objects to be plotted */ - function PlotStackMode(telemetryObjects) { + function PlotStackMode(telemetryObjects, subPlotFactory) { var domainOffset, panZoomStackGroup = new PlotPanZoomStackGroup(telemetryObjects.length), subplots = telemetryObjects.map(function (telemetryObject, i) { - return new SubPlot( + return subPlotFactory.createSubPlot( [telemetryObject], panZoomStackGroup.getPanZoomStack(i) );