From cd8deca1b359b5c97aa3cea9a2ee2d445cc7e532 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 10 Dec 2014 20:16:23 -0800 Subject: [PATCH] [Plot] Add initial stack-plot implementation Add initial implementation of stacked mode for Plot view. Note that this will not stack correctly due to markup/style issues. WTD-625. --- .../plot/src/modes/PlotModeOptions.js | 6 +- .../features/plot/src/modes/PlotStackMode.js | 71 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 platform/features/plot/src/modes/PlotStackMode.js diff --git a/platform/features/plot/src/modes/PlotModeOptions.js b/platform/features/plot/src/modes/PlotModeOptions.js index dcae8cff59..6937b001c6 100644 --- a/platform/features/plot/src/modes/PlotModeOptions.js +++ b/platform/features/plot/src/modes/PlotModeOptions.js @@ -1,15 +1,15 @@ /*global define*/ define( - ["./PlotOverlayMode"], - function (PlotOverlayMode, PlotStackedMode) { + ["./PlotOverlayMode", "./PlotStackMode"], + function (PlotOverlayMode, PlotStackMode) { "use strict"; var STACKED = { key: "stacked", name: "Stacked", glyph: "8", - factory: PlotOverlayMode + factory: PlotStackMode }, OVERLAID = { key: "overlaid", diff --git a/platform/features/plot/src/modes/PlotStackMode.js b/platform/features/plot/src/modes/PlotStackMode.js new file mode 100644 index 0000000000..7e8a052127 --- /dev/null +++ b/platform/features/plot/src/modes/PlotStackMode.js @@ -0,0 +1,71 @@ +/*global define*/ + +define( + ["../SubPlot", "../elements/PlotPalette", "../elements/PlotPanZoomStack"], + function (SubPlot, PlotPalette, PlotPanZoomStack) { + "use strict"; + + function PlotStackMode(telemetryObjects) { + var domainOffset, + panZoomStack = new PlotPanZoomStack([], []), + subplots = telemetryObjects.map(function (telemetryObject) { + return new SubPlot([telemetryObject], panZoomStack); + }); + + function plotTelemetryTo(subplot, prepared, index) { + var buffer = prepared.getBuffers()[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 + subplot.getDrawingObject().lines = [{ + buffer: buffer, + color: PlotPalette.getFloatColor(0), + points: buffer.length / 2 + }]; + + subplot.update(); + } + + 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() + ); + + subplots.forEach(function (subplot, index) { + plotTelemetryTo(subplot, prepared, index); + }); + } + + return { + plotTelemetry: plotTelemetry, + getSubPlots: function () { + return subplots; + }, + isZoomed: function () { + return panZoomStack.getDepth() > 1; + }, + stepBackPanZoom: function () { + panZoomStack.pop(); + subplots.forEach(function (subplot) { + subplot.update(); + }); + }, + unzoom: function () { + panZoomStack.clearPanZoom(); + subplots.forEach(function (subplot) { + subplot.update(); + }); + } + }; + } + + return PlotStackMode; + } +); \ No newline at end of file