[Plot] Fix disappearing plot bug

Fix buffer resize operation as plots fill, WTD-782.
This commit is contained in:
Victor Woeltjen 2015-01-30 12:26:42 -08:00
parent 4fb750c0e0
commit b1485e716c

View File

@ -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);