2014-12-02 14:38:03 -08:00
|
|
|
/*global define*/
|
2014-12-01 09:41:39 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Module defining PlotController. Created by vwoeltje on 11/12/14.
|
|
|
|
*/
|
|
|
|
define(
|
2014-12-01 13:48:38 -08:00
|
|
|
[
|
2014-12-01 18:21:51 -08:00
|
|
|
"./elements/PlotPreparer",
|
|
|
|
"./elements/PlotPalette",
|
2014-12-10 18:29:18 -08:00
|
|
|
"./elements/PlotAxis",
|
2014-12-24 10:59:34 -08:00
|
|
|
"./modes/PlotModeOptions",
|
|
|
|
"./SubPlotFactory"
|
2014-12-01 13:48:38 -08:00
|
|
|
],
|
2014-12-24 10:59:34 -08:00
|
|
|
function (PlotPreparer, PlotPalette, PlotAxis, PlotModeOptions, SubPlotFactory) {
|
2014-12-01 09:41:39 -08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var AXIS_DEFAULTS = [
|
|
|
|
{ "name": "Time" },
|
|
|
|
{ "name": "Value" }
|
2014-12-12 14:37:06 -08:00
|
|
|
];
|
2014-12-01 09:41:39 -08:00
|
|
|
|
|
|
|
/**
|
2014-12-02 14:38:03 -08:00
|
|
|
* The PlotController is responsible for any computation/logic
|
|
|
|
* associated with displaying the plot view. Specifically, these
|
|
|
|
* responsibilities include:
|
|
|
|
*
|
|
|
|
* * Describing axes and labeling.
|
|
|
|
* * Handling user interactions.
|
|
|
|
* * Deciding what needs to be drawn in the chart area.
|
2014-12-01 09:41:39 -08:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
*/
|
2015-01-29 09:05:40 -08:00
|
|
|
function PlotController($scope, telemetryFormatter, telemetrySubscriber) {
|
2014-12-24 10:59:34 -08:00
|
|
|
var subPlotFactory = new SubPlotFactory(telemetryFormatter),
|
|
|
|
modeOptions = new PlotModeOptions([], subPlotFactory),
|
2014-12-10 19:51:27 -08:00
|
|
|
subplots = [],
|
2015-01-29 09:05:40 -08:00
|
|
|
subscription,
|
2014-12-01 09:41:39 -08:00
|
|
|
domainOffset;
|
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Populate the scope with axis information (specifically, options
|
|
|
|
// available for each axis.)
|
2014-12-01 18:13:03 -08:00
|
|
|
function setupAxes(metadatas) {
|
|
|
|
$scope.axes = [
|
|
|
|
new PlotAxis("domain", metadatas, AXIS_DEFAULTS[0]),
|
|
|
|
new PlotAxis("range", metadatas, AXIS_DEFAULTS[1])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Respond to newly-available telemetry data; update the
|
|
|
|
// drawing area accordingly.
|
2014-12-01 18:13:03 -08:00
|
|
|
function plotTelemetry() {
|
2014-12-02 14:38:03 -08:00
|
|
|
var prepared, datas, telemetry;
|
2014-12-01 18:13:03 -08:00
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Get a reference to the TelemetryController
|
2014-12-01 18:13:03 -08:00
|
|
|
telemetry = $scope.telemetry;
|
2014-12-01 09:41:39 -08:00
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Nothing to plot without TelemetryController
|
2014-12-01 09:41:39 -08:00
|
|
|
if (!telemetry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Ensure axes have been initialized (we will want to
|
|
|
|
// get the active axis below)
|
2014-12-01 18:13:03 -08:00
|
|
|
if (!$scope.axes) {
|
|
|
|
setupAxes(telemetry.getMetadata());
|
|
|
|
}
|
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Get data sets
|
|
|
|
datas = telemetry.getResponse();
|
2014-12-01 09:41:39 -08:00
|
|
|
|
2014-12-02 14:38:03 -08:00
|
|
|
// Prepare data sets for rendering
|
2014-12-01 13:27:30 -08:00
|
|
|
prepared = new PlotPreparer(
|
2014-12-02 14:38:03 -08:00
|
|
|
datas,
|
2014-12-01 09:41:39 -08:00
|
|
|
($scope.axes[0].active || {}).key,
|
|
|
|
($scope.axes[1].active || {}).key
|
|
|
|
);
|
|
|
|
|
2014-12-10 19:51:27 -08:00
|
|
|
modeOptions.getModeHandler().plotTelemetry(prepared);
|
2014-12-01 09:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-12-12 14:37:06 -08:00
|
|
|
// Trigger an update of a specific subplot;
|
|
|
|
// used in a loop to update all subplots.
|
2014-12-11 19:33:09 -08:00
|
|
|
function updateSubplot(subplot) {
|
|
|
|
subplot.update();
|
|
|
|
}
|
|
|
|
|
2014-12-12 14:37:06 -08:00
|
|
|
// Set up available modes (stacked/overlaid), based on the
|
|
|
|
// set of telemetry objects in this plot view.
|
2014-12-10 18:29:18 -08:00
|
|
|
function setupModes(telemetryObjects) {
|
2014-12-24 11:14:38 -08:00
|
|
|
modeOptions = new PlotModeOptions(
|
|
|
|
telemetryObjects || [],
|
|
|
|
subPlotFactory
|
|
|
|
);
|
2014-12-10 18:29:18 -08:00
|
|
|
}
|
|
|
|
|
2014-12-12 15:14:20 -08:00
|
|
|
// Update all sub-plots
|
|
|
|
function update() {
|
|
|
|
modeOptions.getModeHandler()
|
|
|
|
.getSubPlots()
|
|
|
|
.forEach(updateSubplot);
|
|
|
|
}
|
|
|
|
|
2015-01-29 09:05:40 -08:00
|
|
|
function updateValues() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new subscription; telemetrySubscriber gets
|
|
|
|
// to do the meaningful work here.
|
|
|
|
function subscribe(domainObject) {
|
|
|
|
subscription = domainObject && telemetrySubscriber.subscribe(
|
|
|
|
domainObject,
|
|
|
|
updateValues
|
|
|
|
);
|
|
|
|
}
|
2014-12-01 09:41:39 -08:00
|
|
|
|
|
|
|
return {
|
2014-12-02 14:38:03 -08:00
|
|
|
/**
|
|
|
|
* Get the color (as a style-friendly string) to use
|
|
|
|
* for plotting the trace at the specified index.
|
|
|
|
* @param {number} index the index of the trace
|
|
|
|
* @returns {string} the color, in #RRGGBB form
|
|
|
|
*/
|
2014-12-01 09:41:39 -08:00
|
|
|
getColor: function (index) {
|
|
|
|
return PlotPalette.getStringColor(index);
|
|
|
|
},
|
2014-12-02 14:38:03 -08:00
|
|
|
/**
|
|
|
|
* Check if the plot is zoomed or panned out
|
|
|
|
* of its default state (to determine whether back/unzoom
|
|
|
|
* controls should be shown)
|
|
|
|
* @returns {boolean} true if not in default state
|
|
|
|
*/
|
2014-12-01 09:41:39 -08:00
|
|
|
isZoomed: function () {
|
2014-12-10 19:51:27 -08:00
|
|
|
return modeOptions.getModeHandler().isZoomed();
|
2014-12-01 09:41:39 -08:00
|
|
|
},
|
2014-12-02 14:38:03 -08:00
|
|
|
/**
|
|
|
|
* Undo the most recent pan/zoom change and restore
|
|
|
|
* the prior state.
|
|
|
|
*/
|
2014-12-01 09:41:39 -08:00
|
|
|
stepBackPanZoom: function () {
|
2014-12-10 19:51:27 -08:00
|
|
|
return modeOptions.getModeHandler().stepBackPanZoom();
|
2014-12-01 09:41:39 -08:00
|
|
|
},
|
2014-12-02 14:38:03 -08:00
|
|
|
/**
|
|
|
|
* Undo all pan/zoom changes and restore the initial state.
|
|
|
|
*/
|
2014-12-01 09:41:39 -08:00
|
|
|
unzoom: function () {
|
2014-12-10 19:51:27 -08:00
|
|
|
return modeOptions.getModeHandler().unzoom();
|
2014-12-10 18:29:18 -08:00
|
|
|
},
|
2014-12-10 18:38:42 -08:00
|
|
|
/**
|
|
|
|
* Get the mode options (Stacked/Overlaid) that are applicable
|
|
|
|
* for this plot.
|
|
|
|
*/
|
2014-12-10 18:29:18 -08:00
|
|
|
getModeOptions: function () {
|
2014-12-10 19:51:27 -08:00
|
|
|
return modeOptions.getModeOptions();
|
2014-12-10 18:29:18 -08:00
|
|
|
},
|
2014-12-10 18:38:42 -08:00
|
|
|
/**
|
|
|
|
* Get the current mode that is applicable to this plot. This
|
|
|
|
* will include key, name, and glyph fields.
|
|
|
|
*/
|
2014-12-10 18:29:18 -08:00
|
|
|
getMode: function () {
|
2014-12-10 19:51:27 -08:00
|
|
|
return modeOptions.getMode();
|
2014-12-10 18:29:18 -08:00
|
|
|
},
|
2014-12-10 18:38:42 -08:00
|
|
|
/**
|
|
|
|
* Set the mode which should be active in this plot.
|
|
|
|
* @param mode one of the mode options returned from
|
|
|
|
* getModeOptions()
|
|
|
|
*/
|
2014-12-10 18:29:18 -08:00
|
|
|
setMode: function (mode) {
|
2014-12-12 15:14:20 -08:00
|
|
|
modeOptions.setMode(mode);
|
|
|
|
plotTelemetry();
|
2014-12-10 19:51:27 -08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Get all individual plots contained within this Plot view.
|
|
|
|
* (Multiple may be contained when in Stacked mode).
|
|
|
|
* @returns {SubPlot[]} all subplots in this Plot view
|
|
|
|
*/
|
|
|
|
getSubPlots: function () {
|
|
|
|
return modeOptions.getModeHandler().getSubPlots();
|
2014-12-11 19:33:09 -08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Explicitly update all plots.
|
|
|
|
*/
|
2015-01-29 09:05:40 -08:00
|
|
|
update: update,
|
|
|
|
/**
|
|
|
|
* Check if a request is pending (to show the wait spinner)
|
|
|
|
*/
|
|
|
|
isRequestPending: function () {
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-01 09:41:39 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return PlotController;
|
|
|
|
}
|
|
|
|
);
|