From bcfe80fbdce44ab56b0d7f8fbfe7920bf354fa81 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 24 Jun 2015 12:54:49 -0700 Subject: [PATCH] [Plot] Handle changes to telemetry objects Handle changes to the set of visible telemetry objects in a plot; addresses WTD-619, which is related to WTD-1329. --- .../features/plot/src/elements/PlotUpdater.js | 28 +++++++++---------- .../telemetry/src/TelemetrySubscription.js | 10 ++++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/platform/features/plot/src/elements/PlotUpdater.js b/platform/features/plot/src/elements/PlotUpdater.js index df7eef9abc..e31641f7c7 100644 --- a/platform/features/plot/src/elements/PlotUpdater.js +++ b/platform/features/plot/src/elements/PlotUpdater.js @@ -50,6 +50,7 @@ define( origin = [0, 0], domainExtrema, rangeExtrema, + buffers = {}, bufferArray = [], domainOffset; @@ -61,11 +62,10 @@ define( // Check if this set of ids matches the current set of ids // (used to detect if line preparation can be skipped) function idsMatch(nextIds) { - return nextIds.map(function (id, index) { - return ids[index] === id; - }).reduce(function (a, b) { - return a && b; - }, true); + return ids.length === nextIds.length && + nextIds.every(function (id, index) { + return ids[index] === id; + }); } // Prepare plot lines for this group of telemetry objects @@ -74,7 +74,7 @@ define( next = {}; // Detect if we already have everything we need prepared - if (ids.length === nextIds.length && idsMatch(nextIds)) { + if (idsMatch(nextIds)) { // Nothing to prepare, move on return; } @@ -88,13 +88,13 @@ define( // Create buffers for these objects bufferArray = ids.map(function (id) { - var buffer = new PlotLineBuffer( - domainOffset, - INITIAL_SIZE, - maxPoints - ); - next[id] = lines[id] || new PlotLine(buffer); - return buffer; + buffers[id] = buffers[id] || new PlotLineBuffer( + domainOffset, + INITIAL_SIZE, + maxPoints + ); + next[id] = lines[id] || new PlotLine(buffers[id]); + return buffers[id]; }); } @@ -290,4 +290,4 @@ define( return PlotUpdater; } -); \ No newline at end of file +); diff --git a/platform/telemetry/src/TelemetrySubscription.js b/platform/telemetry/src/TelemetrySubscription.js index f8481eb085..69fd957ac2 100644 --- a/platform/telemetry/src/TelemetrySubscription.js +++ b/platform/telemetry/src/TelemetrySubscription.js @@ -147,7 +147,8 @@ define( telemetryObjects = objects; metadatas = objects.map(lookupMetadata); // Fire callback, as this will be the first time that - // telemetry objects are available + // telemetry objects are available, or these objects + // will have changed. if (callback) { callback(); } @@ -176,9 +177,10 @@ define( } function idsMatch(ids) { - return ids.every(function (id, index) { - return telemetryObjects[index].getId() === id; - }); + return ids.length === telemetryObjects.length && + ids.every(function (id, index) { + return telemetryObjects[index].getId() === id; + }); } function modelChange(model) {