mirror of
https://github.com/nasa/openmct.git
synced 2025-06-12 20:28:14 +00:00
[Code Style] Use prototypes in Plot bundle
WTD-1482.
This commit is contained in:
@ -30,15 +30,53 @@ define(
|
||||
key: "stacked",
|
||||
name: "Stacked",
|
||||
glyph: "m",
|
||||
factory: PlotStackMode
|
||||
Constructor: PlotStackMode
|
||||
},
|
||||
OVERLAID = {
|
||||
key: "overlaid",
|
||||
name: "Overlaid",
|
||||
glyph: "6",
|
||||
factory: PlotOverlayMode
|
||||
Constructor: PlotOverlayMode
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles distinct behavior associated with different
|
||||
* plot modes.
|
||||
*
|
||||
* @interface platform/features/plot.PlotModeHandler
|
||||
* @private
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plot telemetry to the sub-plot(s) managed by this mode.
|
||||
* @param {platform/features/plot.PlotUpdater} updater a source
|
||||
* of data that is ready to plot
|
||||
* @method platform/features/plot.PlotModeHandler#plotTelemetry
|
||||
*/
|
||||
/**
|
||||
* Get all sub-plots to be displayed in this mode; used
|
||||
* to populate the plot template.
|
||||
* @return {platform/features/plot.SubPlot[]} all sub-plots to
|
||||
* display in this mode
|
||||
* @method platform/features/plot.PlotModeHandler#getSubPlots
|
||||
*/
|
||||
/**
|
||||
* Check if we are not in our base pan-zoom state (that is,
|
||||
* there are some temporary user modifications to the
|
||||
* current pan-zoom state.)
|
||||
* @returns {boolean} true if not in the base pan-zoom state
|
||||
* @method platform/features/plot.PlotModeHandler#isZoomed
|
||||
*/
|
||||
/**
|
||||
* Undo the most recent pan/zoom change and restore
|
||||
* the prior state.
|
||||
* @method platform/features/plot.PlotModeHandler#stepBackPanZoom
|
||||
*/
|
||||
/**
|
||||
* Undo all pan/zoom change and restore the base state.
|
||||
* @method platform/features/plot.PlotModeHandler#unzoom
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determines which plotting modes (stacked/overlaid)
|
||||
* are applicable in a given plot view, maintains current
|
||||
@ -46,73 +84,74 @@ define(
|
||||
* different behaviors associated with these modes.
|
||||
* @memberof platform/features/plot
|
||||
* @constructor
|
||||
* @param {DomainObject[]} the telemetry objects being
|
||||
* @param {DomainObject[]} telemetryObjects the telemetry objects being
|
||||
* represented in this plot view
|
||||
* @param {platform/features/plot.SubPlotFactory} subPlotFactory a
|
||||
* factory for creating sub-plots
|
||||
*/
|
||||
function PlotModeOptions(telemetryObjects, subPlotFactory) {
|
||||
var options = telemetryObjects.length > 1 ?
|
||||
[ OVERLAID, STACKED ] : [ OVERLAID ],
|
||||
mode = options[0], // Initial selection (overlaid)
|
||||
modeHandler;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get a handler for the current mode. This will handle
|
||||
* plotting telemetry, providing subplots for the template,
|
||||
* and view-level interactions with pan-zoom state.
|
||||
* @returns {PlotOverlayMode|PlotStackMode} a handler
|
||||
* for the current mode
|
||||
* @memberof platform/features/plot.PlotModeOptions#
|
||||
*/
|
||||
getModeHandler: function () {
|
||||
// Lazily initialize
|
||||
if (!modeHandler) {
|
||||
modeHandler = mode.factory(
|
||||
telemetryObjects,
|
||||
subPlotFactory
|
||||
);
|
||||
}
|
||||
return modeHandler;
|
||||
},
|
||||
/**
|
||||
* Get all mode options available for each plot. Each
|
||||
* mode contains a `name` and `glyph` field suitable
|
||||
* for display in a template.
|
||||
* @return {Array} the available modes
|
||||
* @memberof platform/features/plot.PlotModeOptions#
|
||||
*/
|
||||
getModeOptions: function () {
|
||||
return options;
|
||||
},
|
||||
/**
|
||||
* Get the plotting mode option currently in use.
|
||||
* This will be one of the elements returned from
|
||||
* `getModeOptions`.
|
||||
* @return {object} the current mode
|
||||
* @memberof platform/features/plot.PlotModeOptions#
|
||||
*/
|
||||
getMode: function () {
|
||||
return mode;
|
||||
},
|
||||
/**
|
||||
* Set the plotting mode option to use.
|
||||
* The passed argument must be one of the options
|
||||
* returned by `getModeOptions`.
|
||||
* @param {object} option one of the plot mode options
|
||||
* from `getModeOptions`
|
||||
* @memberof platform/features/plot.PlotModeOptions#
|
||||
*/
|
||||
setMode: function (option) {
|
||||
if (mode !== option) {
|
||||
mode = option;
|
||||
// Clear the existing mode handler, so it
|
||||
// can be instantiated next time it's needed.
|
||||
modeHandler = undefined;
|
||||
}
|
||||
}
|
||||
};
|
||||
this.options = telemetryObjects.length > 1 ?
|
||||
[ OVERLAID, STACKED ] : [ OVERLAID ];
|
||||
this.mode = this.options[0]; // Initial selection (overlaid)
|
||||
this.telemetryObjects = telemetryObjects;
|
||||
this.subPlotFactory = subPlotFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a handler for the current mode. This will handle
|
||||
* plotting telemetry, providing subplots for the template,
|
||||
* and view-level interactions with pan-zoom state.
|
||||
* @returns {PlotOverlayMode|PlotStackMode} a handler
|
||||
* for the current mode
|
||||
*/
|
||||
PlotModeOptions.prototype.getModeHandler = function () {
|
||||
// Lazily initialize
|
||||
if (!this.modeHandler) {
|
||||
this.modeHandler = new this.mode.Constructor(
|
||||
this.telemetryObjects,
|
||||
this.subPlotFactory
|
||||
);
|
||||
}
|
||||
return this.modeHandler;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all mode options available for each plot. Each
|
||||
* mode contains a `name` and `glyph` field suitable
|
||||
* for display in a template.
|
||||
* @return {Array} the available modes
|
||||
*/
|
||||
PlotModeOptions.prototype.getModeOptions = function () {
|
||||
return this.options;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the plotting mode option currently in use.
|
||||
* This will be one of the elements returned from
|
||||
* `getModeOptions`.
|
||||
* @return {*} the current mode
|
||||
*/
|
||||
PlotModeOptions.prototype.getMode = function () {
|
||||
return this.mode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the plotting mode option to use.
|
||||
* The passed argument must be one of the options
|
||||
* returned by `getModeOptions`.
|
||||
* @param {object} option one of the plot mode options
|
||||
* from `getModeOptions`
|
||||
*/
|
||||
PlotModeOptions.prototype.setMode = function (option) {
|
||||
if (this.mode !== option) {
|
||||
this.mode = option;
|
||||
// Clear the existing mode handler, so it
|
||||
// can be instantiated next time it's needed.
|
||||
this.modeHandler = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return PlotModeOptions;
|
||||
}
|
||||
);
|
||||
|
@ -31,81 +31,59 @@ define(
|
||||
* is one sub-plot which contains all plotted objects.
|
||||
* @memberof platform/features/plot
|
||||
* @constructor
|
||||
* @implements {platform/features/plot.PlotModeHandler}
|
||||
* @param {DomainObject[]} the domain objects to be plotted
|
||||
*/
|
||||
function PlotOverlayMode(telemetryObjects, subPlotFactory) {
|
||||
var domainOffset,
|
||||
panZoomStack = new PlotPanZoomStack([], []),
|
||||
subplot = subPlotFactory.createSubPlot(
|
||||
telemetryObjects,
|
||||
panZoomStack
|
||||
),
|
||||
subplots = [ subplot ];
|
||||
this.panZoomStack = new PlotPanZoomStack([], []);
|
||||
this.subplot = subPlotFactory.createSubPlot(
|
||||
telemetryObjects,
|
||||
this.panZoomStack
|
||||
);
|
||||
this.subplots = [ this.subplot ];
|
||||
}
|
||||
|
||||
function plotTelemetry(prepared) {
|
||||
// Fit to the boundaries of the data, but don't
|
||||
// override any user-initiated pan-zoom changes.
|
||||
panZoomStack.setBasePanZoom(
|
||||
prepared.getOrigin(),
|
||||
prepared.getDimensions()
|
||||
);
|
||||
PlotOverlayMode.prototype.plotTelemetry = function (updater) {
|
||||
// Fit to the boundaries of the data, but don't
|
||||
// override any user-initiated pan-zoom changes.
|
||||
this.panZoomStack.setBasePanZoom(
|
||||
updater.getOrigin(),
|
||||
updater.getDimensions()
|
||||
);
|
||||
|
||||
// Track the domain offset, used to bias domain values
|
||||
// to minimize loss of precision when converted to 32-bit
|
||||
// floating point values for display.
|
||||
subplot.setDomainOffset(prepared.getDomainOffset());
|
||||
// Track the domain offset, used to bias domain values
|
||||
// to minimize loss of precision when converted to 32-bit
|
||||
// floating point values for display.
|
||||
this.subplot.setDomainOffset(updater.getDomainOffset());
|
||||
|
||||
// Draw the buffers. Select color by index.
|
||||
subplot.getDrawingObject().lines = prepared.getLineBuffers().map(function (buf, i) {
|
||||
// Draw the buffers. Select color by index.
|
||||
this.subplot.getDrawingObject().lines =
|
||||
updater.getLineBuffers().map(function (buf, i) {
|
||||
return {
|
||||
buffer: buf.getBuffer(),
|
||||
color: PlotPalette.getFloatColor(i),
|
||||
points: buf.getLength()
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Plot telemetry to the sub-plot(s) managed by this mode.
|
||||
* @param {PlotPreparer} prepared the prepared data to plot
|
||||
* @memberof platform/features/plot.PlotOverlayMode#
|
||||
*/
|
||||
plotTelemetry: plotTelemetry,
|
||||
/**
|
||||
* Get all sub-plots to be displayed in this mode; used
|
||||
* to populate the plot template.
|
||||
* @return {SubPlot[]} all sub-plots to display in this mode
|
||||
* @memberof platform/features/plot.PlotOverlayMode#
|
||||
*/
|
||||
getSubPlots: function () {
|
||||
return subplots;
|
||||
},
|
||||
/**
|
||||
* Check if we are not in our base pan-zoom state (that is,
|
||||
* there are some temporary user modifications to the
|
||||
* current pan-zoom state.)
|
||||
* @returns {boolean} true if not in the base pan-zoom state
|
||||
* @memberof platform/features/plot.PlotOverlayMode#
|
||||
*/
|
||||
isZoomed: function () {
|
||||
return panZoomStack.getDepth() > 1;
|
||||
},
|
||||
/**
|
||||
* Undo the most recent pan/zoom change and restore
|
||||
* the prior state.
|
||||
* @memberof platform/features/plot.PlotOverlayMode#
|
||||
*/
|
||||
stepBackPanZoom: function () {
|
||||
panZoomStack.popPanZoom();
|
||||
subplot.update();
|
||||
},
|
||||
unzoom: function () {
|
||||
panZoomStack.clearPanZoom();
|
||||
subplot.update();
|
||||
}
|
||||
};
|
||||
}
|
||||
PlotOverlayMode.prototype.getSubPlots = function () {
|
||||
return this.subplots;
|
||||
};
|
||||
|
||||
PlotOverlayMode.prototype.isZoomed = function () {
|
||||
return this.panZoomStack.getDepth() > 1;
|
||||
};
|
||||
|
||||
PlotOverlayMode.prototype.stepBackPanZoom = function () {
|
||||
this.panZoomStack.popPanZoom();
|
||||
this.subplot.update();
|
||||
};
|
||||
|
||||
PlotOverlayMode.prototype.unzoom = function () {
|
||||
this.panZoomStack.clearPanZoom();
|
||||
this.subplot.update();
|
||||
};
|
||||
|
||||
return PlotOverlayMode;
|
||||
}
|
||||
|
@ -31,99 +31,76 @@ define(
|
||||
* is one sub-plot for each plotted object.
|
||||
* @memberof platform/features/plot
|
||||
* @constructor
|
||||
* @implements {platform/features/plot.PlotModeHandler}
|
||||
* @param {DomainObject[]} the domain objects to be plotted
|
||||
*/
|
||||
function PlotStackMode(telemetryObjects, subPlotFactory) {
|
||||
var domainOffset,
|
||||
panZoomStackGroup =
|
||||
new PlotPanZoomStackGroup(telemetryObjects.length),
|
||||
subplots = telemetryObjects.map(function (telemetryObject, i) {
|
||||
var self = this;
|
||||
|
||||
this.panZoomStackGroup =
|
||||
new PlotPanZoomStackGroup(telemetryObjects.length);
|
||||
|
||||
this.subplots = telemetryObjects.map(function (telemetryObject, i) {
|
||||
return subPlotFactory.createSubPlot(
|
||||
[telemetryObject],
|
||||
panZoomStackGroup.getPanZoomStack(i)
|
||||
self.panZoomStackGroup.getPanZoomStack(i)
|
||||
);
|
||||
});
|
||||
|
||||
function plotTelemetryTo(subplot, prepared, index) {
|
||||
var buffer = prepared.getLineBuffers()[index];
|
||||
|
||||
// Track the domain offset, used to bias domain values
|
||||
// to minimize loss of precision when converted to 32-bit
|
||||
// floating point values for display.
|
||||
subplot.setDomainOffset(prepared.getDomainOffset());
|
||||
|
||||
// Draw the buffers. Always use the 0th color, because there
|
||||
// is one line per plot.
|
||||
subplot.getDrawingObject().lines = [{
|
||||
buffer: buffer.getBuffer(),
|
||||
color: PlotPalette.getFloatColor(0),
|
||||
points: buffer.getLength()
|
||||
}];
|
||||
}
|
||||
|
||||
function plotTelemetry(prepared) {
|
||||
// Fit to the boundaries of the data, but don't
|
||||
// override any user-initiated pan-zoom changes.
|
||||
panZoomStackGroup.setBasePanZoom(
|
||||
prepared.getOrigin(),
|
||||
prepared.getDimensions()
|
||||
);
|
||||
|
||||
subplots.forEach(function (subplot, index) {
|
||||
plotTelemetryTo(subplot, prepared, index);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Plot telemetry to the sub-plot(s) managed by this mode.
|
||||
* @param {PlotPreparer} prepared the prepared data to plot
|
||||
* @memberof platform/features/plot.PlotStackMode#
|
||||
*/
|
||||
plotTelemetry: plotTelemetry,
|
||||
/**
|
||||
* Get all sub-plots to be displayed in this mode; used
|
||||
* to populate the plot template.
|
||||
* @return {SubPlot[]} all sub-plots to display in this mode
|
||||
* @memberof platform/features/plot.PlotStackMode#
|
||||
*/
|
||||
getSubPlots: function () {
|
||||
return subplots;
|
||||
},
|
||||
/**
|
||||
* Check if we are not in our base pan-zoom state (that is,
|
||||
* there are some temporary user modifications to the
|
||||
* current pan-zoom state.)
|
||||
* @returns {boolean} true if not in the base pan-zoom state
|
||||
* @memberof platform/features/plot.PlotStackMode#
|
||||
*/
|
||||
isZoomed: function () {
|
||||
return panZoomStackGroup.getDepth() > 1;
|
||||
},
|
||||
/**
|
||||
* Undo the most recent pan/zoom change and restore
|
||||
* the prior state.
|
||||
* @memberof platform/features/plot.PlotStackMode#
|
||||
*/
|
||||
stepBackPanZoom: function () {
|
||||
panZoomStackGroup.popPanZoom();
|
||||
subplots.forEach(function (subplot) {
|
||||
subplot.update();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Undo all pan/zoom changes and restore the initial state.
|
||||
* @memberof platform/features/plot.PlotStackMode#
|
||||
*/
|
||||
unzoom: function () {
|
||||
panZoomStackGroup.clearPanZoom();
|
||||
subplots.forEach(function (subplot) {
|
||||
subplot.update();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
PlotStackMode.prototype.plotTelemetryTo = function (subplot, prepared, index) {
|
||||
var buffer = prepared.getLineBuffers()[index];
|
||||
|
||||
// Track the domain offset, used to bias domain values
|
||||
// to minimize loss of precision when converted to 32-bit
|
||||
// floating point values for display.
|
||||
subplot.setDomainOffset(prepared.getDomainOffset());
|
||||
|
||||
// Draw the buffers. Always use the 0th color, because there
|
||||
// is one line per plot.
|
||||
subplot.getDrawingObject().lines = [{
|
||||
buffer: buffer.getBuffer(),
|
||||
color: PlotPalette.getFloatColor(0),
|
||||
points: buffer.getLength()
|
||||
}];
|
||||
};
|
||||
|
||||
PlotStackMode.prototype.plotTelemetry = function (prepared) {
|
||||
var self = this;
|
||||
// Fit to the boundaries of the data, but don't
|
||||
// override any user-initiated pan-zoom changes.
|
||||
this.panZoomStackGroup.setBasePanZoom(
|
||||
prepared.getOrigin(),
|
||||
prepared.getDimensions()
|
||||
);
|
||||
|
||||
this.subplots.forEach(function (subplot, index) {
|
||||
self.plotTelemetryTo(subplot, prepared, index);
|
||||
});
|
||||
};
|
||||
|
||||
PlotStackMode.prototype.getSubPlots = function () {
|
||||
return this.subplots;
|
||||
};
|
||||
|
||||
PlotStackMode.prototype.isZoomed = function () {
|
||||
return this.panZoomStackGroup.getDepth() > 1;
|
||||
};
|
||||
|
||||
PlotStackMode.prototype.stepBackPanZoom = function () {
|
||||
this.panZoomStackGroup.popPanZoom();
|
||||
this.subplots.forEach(function (subplot) {
|
||||
subplot.update();
|
||||
});
|
||||
};
|
||||
|
||||
PlotStackMode.prototype.unzoom = function () {
|
||||
this.panZoomStackGroup.clearPanZoom();
|
||||
this.subplots.forEach(function (subplot) {
|
||||
subplot.update();
|
||||
});
|
||||
};
|
||||
|
||||
return PlotStackMode;
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user