[Plot] Begin refactoring for stacked plots

Begin refactoring Plot view to support stacked plots;
separate out behavior which needs to occur per-plot
from area which should occur per-view, and add a
handler for the Overlay mode. WTD-625.
This commit is contained in:
Victor Woeltjen
2014-12-10 19:51:27 -08:00
parent 1c3d2d923f
commit 784b2b6186
5 changed files with 307 additions and 202 deletions

View File

@ -8,21 +8,30 @@ define(
var STACKED = {
key: "stacked",
name: "Stacked",
glyph: "8"
glyph: "8",
factory: PlotOverlayMode
},
OVERLAID = {
key: "overlaid",
name: "Overlaid",
glyph: "6"
glyph: "6",
factory: PlotStackedMode
};
function PlotModeOptions(telemetryObjects) {
var options = telemetryObjects.length > 1 ?
[ OVERLAID, STACKED ] : [ OVERLAID ],
mode = options[0];
mode = options[0],
modeHandler;
return {
getModeHandler: function () {
if (!modeHandler) {
modeHandler = mode.factory(telemetryObjects);
}
return modeHandler;
},
getModeOptions: function () {
return options;
},
@ -30,7 +39,10 @@ define(
return mode;
},
setMode: function (option) {
mode = option;
if (mode !== option) {
mode = option;
modeHandler = undefined;
}
}
};
}

View File

@ -0,0 +1,60 @@
/*global define*/
define(
["../SubPlot", "../elements/PlotPalette", "../elements/PlotPanZoomStack"],
function (SubPlot, PlotPalette, PlotPanZoomStack) {
"use strict";
function PlotOverlayMode(telemetryObjects) {
var domainOffset,
panZoomStack = new PlotPanZoomStack([], []),
subplot = new SubPlot(telemetryObjects, panZoomStack),
subplots = [ 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()
);
// Track the domain offset, used to bias domain values
// to minimize loss of precision when converted to 32-bit
// floating point values for display.
domainOffset = prepared.getDomainOffset();
// Draw the buffers. Select color by index.
subplot.getDrawingObject().lines = prepared.getBuffers().map(function (buf, i) {
return {
buffer: buf,
color: PlotPalette.getFloatColor(i),
points: buf.length / 2
};
});
subplot.update();
}
return {
plotTelemetry: plotTelemetry,
getSubPlots: function () {
return subplots;
},
isZoomed: function () {
return panZoomStack.getDepth() > 1;
},
stepBackPanZoom: function () {
panZoomStack.pop();
subplot.update();
},
unzoom: function () {
panZoomStack.clearPanZoom();
subplot.update();
}
};
}
return PlotOverlayMode;
}
);