diff --git a/platform/features/plot/src/elements/PlotUpdater.js b/platform/features/plot/src/elements/PlotUpdater.js index 08485763d5..caf3abf3a2 100644 --- a/platform/features/plot/src/elements/PlotUpdater.js +++ b/platform/features/plot/src/elements/PlotUpdater.js @@ -31,6 +31,7 @@ define( 'use strict'; var MAX_POINTS = 86400, + PADDING_RATIO = 0.10, // Padding percentage for top & bottom INITIAL_SIZE = 675; // 1/128 of MAX_POINTS /** @@ -135,6 +136,16 @@ define( return extrema[0]; } + // Expand range slightly so points near edges are visible + function expandRange() { + var padding = PADDING_RATIO * dimensions[1], + top; + padding = Math.max(padding, 1.0); + top = Math.ceil(origin[1] + dimensions[1] + padding / 2); + origin[1] = Math.floor(origin[1] - padding / 2); + dimensions[1] = top - origin[1]; + } + // Update dimensions and origin based on extrema of plots function updateBounds() { if (bufferArray.length > 0) { @@ -147,11 +158,13 @@ define( }).reduce(reduceExtrema); // Calculate best-fit dimensions - dimensions = (rangeExtrema[0] === rangeExtrema[1]) ? - [dimensionsOf(domainExtrema), 2.0 ] : - [dimensionsOf(domainExtrema), dimensionsOf(rangeExtrema)]; + dimensions = + [dimensionsOf(domainExtrema), dimensionsOf(rangeExtrema)]; origin = [originOf(domainExtrema), originOf(rangeExtrema)]; + // Enforce some minimum visible area + expandRange(); + // ...then enforce a fixed duration if needed if (fixedDuration !== undefined) { origin[0] = origin[0] + dimensions[0] - fixedDuration; diff --git a/platform/features/plot/test/elements/PlotUpdaterSpec.js b/platform/features/plot/test/elements/PlotUpdaterSpec.js index 6bd98ffbb4..9d7ab563de 100644 --- a/platform/features/plot/test/elements/PlotUpdaterSpec.js +++ b/platform/features/plot/test/elements/PlotUpdaterSpec.js @@ -187,7 +187,21 @@ define( expect(updater.getDomainOffset()).toBeDefined(); }); + it("provides some margin for the range", function () { + var mockObject = mockSubscription.getTelemetryObjects()[0]; + + mockSeries.getPointCount.andReturn(3); + mockSeries.getDomainValue.andCallFake(function (i) { + return 1000 + i * 1000; + }); + mockSeries.getRangeValue.andCallFake(function (i) { + return 10 + i; // 10, 20, 30 + }); + updater.addHistorical(mockObject, mockSeries); + expect(updater.getOrigin()[1]).toBeLessThan(10); + expect(updater.getDimensions()[1]).toBeGreaterThan(20); + }); }); } -); \ No newline at end of file +);