gazeplotter
Version:
Gazeplotter is a Svelte application for visualizing eye-tracking data.
28 lines (27 loc) • 890 B
JavaScript
/**
* Splits a string chunks produced by EyeParser into rows and columns.
*
* It can happen that a row is split into multiple chunks, so we need to
* keep track of the last row and append the next chunk to it.
*/
export class EyeSplitter {
rowDelimiter;
lastRow = '';
constructor(settings) {
this.rowDelimiter = settings.rowDelimiter;
}
splitChunk(chunk) {
const completeRows = (this.lastRow + chunk).split(this.rowDelimiter);
const completeRowsLength = completeRows.length;
if (completeRowsLength < 2) {
this.lastRow += chunk;
return [];
}
this.lastRow = completeRows[completeRowsLength - 1];
return completeRows.slice(0, completeRowsLength - 1);
}
release() {
const lastRow = this.lastRow + this.rowDelimiter;
return lastRow.split(this.rowDelimiter);
}
}