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",
|
|
|
|
"./elements/PlotPanZoomStack",
|
|
|
|
"./elements/PlotPosition",
|
|
|
|
"./elements/PlotTickGenerator",
|
|
|
|
"./elements/PlotFormatter",
|
2014-12-10 18:29:18 -08:00
|
|
|
"./elements/PlotAxis",
|
|
|
|
"./modes/PlotModeOptions"
|
2014-12-01 13:48:38 -08:00
|
|
|
],
|
2014-12-01 18:21:51 -08:00
|
|
|
function (
|
|
|
|
PlotPreparer,
|
|
|
|
PlotPalette,
|
|
|
|
PlotPanZoomStack,
|
|
|
|
PlotPosition,
|
|
|
|
PlotTickGenerator,
|
|
|
|
PlotFormatter,
|
2014-12-10 18:29:18 -08:00
|
|
|
PlotAxis,
|
|
|
|
PlotModeOptions
|
2014-12-01 18:21:51 -08:00
|
|
|
) {
|
2014-12-01 09:41:39 -08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var AXIS_DEFAULTS = [
|
|
|
|
{ "name": "Time" },
|
|
|
|
{ "name": "Value" }
|
|
|
|
],
|
|
|
|
DOMAIN_TICKS = 5,
|
|
|
|
RANGE_TICKS = 7;
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
function PlotController($scope) {
|
2014-12-10 19:51:27 -08:00
|
|
|
var modeOptions = new PlotModeOptions([]),
|
|
|
|
subplots = [],
|
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-11 19:33:09 -08:00
|
|
|
function updateSubplot(subplot) {
|
|
|
|
subplot.update();
|
|
|
|
}
|
|
|
|
|
2014-12-10 18:29:18 -08:00
|
|
|
function setupModes(telemetryObjects) {
|
2014-12-10 19:51:27 -08:00
|
|
|
modeOptions = new PlotModeOptions(telemetryObjects || []);
|
2014-12-10 18:29:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$watch("telemetry.getTelemetryObjects()", setupModes);
|
2014-12-01 09:41:39 -08:00
|
|
|
$scope.$watch("telemetry.getMetadata()", setupAxes);
|
|
|
|
$scope.$on("telemetryUpdate", plotTelemetry);
|
|
|
|
|
|
|
|
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-10 19:51:27 -08:00
|
|
|
return modeOptions.setMode(mode);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
update: function () {
|
|
|
|
modeOptions.getModeHandler()
|
|
|
|
.getSubPlots()
|
|
|
|
.forEach(updateSubplot);
|
2014-12-01 09:41:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return PlotController;
|
|
|
|
}
|
|
|
|
);
|