From b1485e716c9bee7a2519c51f31a102ebd716a400 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 30 Jan 2015 12:26:42 -0800 Subject: [PATCH] [Plot] Fix disappearing plot bug Fix buffer resize operation as plots fill, WTD-782. --- .../features/plot/src/elements/PlotUpdater.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/platform/features/plot/src/elements/PlotUpdater.js b/platform/features/plot/src/elements/PlotUpdater.js index f59fda4e52..312f625963 100644 --- a/platform/features/plot/src/elements/PlotUpdater.js +++ b/platform/features/plot/src/elements/PlotUpdater.js @@ -32,20 +32,23 @@ define( lengthArray = [], bufferArray = []; + // Double the size of a Float32Array + function doubleSize(buffer) { + var doubled = new Float32Array(buffer.length * 2); + doubled.set(buffer); // Copy contents of original + return doubled; + } + // Make sure there is enough space in a buffer to accomodate a // new point at the specified index. This will updates buffers[id] // if necessary. function ensureBufferSize(buffer, id, index) { // Check if we don't have enough room - if (index > buffer.length / 2) { + if (index > (buffer.length / 2 - 1)) { // If we don't, can we expand? if (index < MAX_POINTS) { // Double the buffer size - buffer = buffers[id] = new Float32Array( - buffer, - 0, - buffer.length * 2 - ); + buffer = buffers[id] = doubleSize(buffer); } else { // Just shift the existing buffer buffer.copyWithin(0, 2);