diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index 19aee9ca11..2aef3e3418 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -31,10 +31,19 @@ define( "./elements/PlotPalette", "./elements/PlotAxis", "./elements/PlotLimitTracker", + "./elements/PlotTelemetryFormatter", "./modes/PlotModeOptions", "./SubPlotFactory" ], - function (PlotUpdater, PlotPalette, PlotAxis, PlotLimitTracker, PlotModeOptions, SubPlotFactory) { + function ( + PlotUpdater, + PlotPalette, + PlotAxis, + PlotLimitTracker, + PlotTelemetryFormatter, + PlotModeOptions, + SubPlotFactory + ) { "use strict"; var AXIS_DEFAULTS = [ @@ -62,7 +71,10 @@ define( PLOT_FIXED_DURATION ) { var self = this, - subPlotFactory = new SubPlotFactory(telemetryFormatter), + plotTelemetryFormatter = + new PlotTelemetryFormatter(telemetryFormatter), + subPlotFactory = + new SubPlotFactory(plotTelemetryFormatter), cachedObjects = [], updater, lastBounds, @@ -189,6 +201,11 @@ define( releaseSubscription(); subscribe($scope.domainObject); setBasePanZoom(bounds); + $scope.axes[0].choose(bounds.domain); + } + + function updateDomainFormat(format) { + plotTelemetryFormatter.setDomainFormat(format); } this.modeOptions = new PlotModeOptions([], subPlotFactory); @@ -205,6 +222,9 @@ define( // Subscribe to telemetry when a domain object becomes available $scope.$watch('domainObject', subscribe); + // Reformat timestamps when needed + $scope.$watch('axes[0].active.format', updateDomainFormat); + // Respond to external bounds changes $scope.$on("telemetry:display:bounds", changeDisplayBounds); diff --git a/platform/features/plot/src/SubPlot.js b/platform/features/plot/src/SubPlot.js index dfcaadf352..051f95f2a8 100644 --- a/platform/features/plot/src/SubPlot.js +++ b/platform/features/plot/src/SubPlot.js @@ -121,9 +121,9 @@ define( // Utility, for map/forEach loops. Index 0 is domain, // index 1 is range. function formatValue(v, i) { - return (i ? - formatter.formatRangeValue : - formatter.formatDomainValue)(v); + return i ? + formatter.formatRangeValue(v) : + formatter.formatDomainValue(v); } this.hoverCoordinates = this.mousePosition && diff --git a/platform/features/plot/src/elements/PlotAxis.js b/platform/features/plot/src/elements/PlotAxis.js index 25795fd347..cee7acef8a 100644 --- a/platform/features/plot/src/elements/PlotAxis.js +++ b/platform/features/plot/src/elements/PlotAxis.js @@ -80,6 +80,16 @@ define( this.options = options; } + PlotAxis.prototype.choose = function (key) { + var i; + for (i = 0; i < this.options.length; i += 1) { + if (this.options[i].key === key) { + this.active = this.options[i]; + return; + } + } + }; + return PlotAxis; } diff --git a/platform/features/plot/src/elements/PlotTelemetryFormatter.js b/platform/features/plot/src/elements/PlotTelemetryFormatter.js new file mode 100644 index 0000000000..abe916e99d --- /dev/null +++ b/platform/features/plot/src/elements/PlotTelemetryFormatter.js @@ -0,0 +1,53 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define*/ + +define( + [], + function () { + 'use strict'; + + function PlotTelemetryFormatter(telemetryFormatter) { + this.telemetryFormatter = telemetryFormatter; + } + + PlotTelemetryFormatter.prototype.setDomainFormat = function (key) { + this.domainFormat = key; + }; + + PlotTelemetryFormatter.prototype.setRangeFormat = function (key) { + this.rangeFormat = key; + }; + + PlotTelemetryFormatter.prototype.formatDomainValue = function (value) { + return this.telemetryFormatter + .formatDomainValue(value, this.domainFormat); + }; + + PlotTelemetryFormatter.prototype.formatRangeValue = function (value) { + return this.telemetryFormatter + .formatRangeValue(value, this.rangeFormat); + }; + + return PlotTelemetryFormatter; + } +); diff --git a/platform/features/plot/src/elements/PlotTickGenerator.js b/platform/features/plot/src/elements/PlotTickGenerator.js index f759b6bcd6..8fa957fae7 100644 --- a/platform/features/plot/src/elements/PlotTickGenerator.js +++ b/platform/features/plot/src/elements/PlotTickGenerator.js @@ -43,6 +43,14 @@ define( this.formatter = formatter; } + // For phantomjs compatibility, for headless testing + // (Function.prototype.bind unsupported) + function bind(fn, thisObj) { + return fn.bind ? fn.bind(thisObj) : function () { + return fn.apply(thisObj, arguments); + }; + } + // Generate ticks; interpolate from start up to // start + span in count steps, using the provided // formatter to represent each value. @@ -72,7 +80,7 @@ define( panZoom.origin[0], panZoom.dimensions[0], count, - this.formatter.formatDomainValue + bind(this.formatter.formatDomainValue, this.formatter) ); }; @@ -87,7 +95,7 @@ define( panZoom.origin[1], panZoom.dimensions[1], count, - this.formatter.formatRangeValue + bind(this.formatter.formatRangeValue, this.formatter) ); };