Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made waveform smoother #3352

Merged
merged 5 commits into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 20 additions & 30 deletions src/Components/TeleIcu/Patient/Waveform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,41 @@ export type WaveformType = {
export default function Waveform(props: { wave: WaveformType }) {
const wave = props.wave;
const data = wave.data.split(" ").map(Number);
const [viewableData, setViewableData] = useState<number[]>([]);
const [queueData, setQueueData] = useState<number[]>([]);
const [xData, setXData] = useState<number[]>([]);

const viewable = 800;
const seconds = 5000;
const length = data.length;
const tpf = seconds / length;
const viewable = 300;
const tpf = 4000 / data.length;

const [pointer, setPointer] = useState(viewable);
useEffect(() => {
setQueueData(queueData.concat(data));
setXData(Array.from(Array(viewable).keys()));

/* // Uncoment to see data intervals
let seconds = 1;
console.log("Data recieved");
let timer = setInterval(() => {
console.log(seconds);
seconds++;
}, 1000);
return () => clearInterval(timer);
*/
}, [props]);

useEffect(() => {
let timeout = setTimeout(() => {
if (!data[pointer + 1]) {
return;
}
let newArr = viewableData.slice(1);
newArr.push(data[pointer + 1]);
setViewableData(newArr);
setPointer(pointer + 1);
setQueueData(queueData.slice(1));
}, tpf);

return () => clearTimeout(timeout);
}, [viewableData]);

useEffect(() => {
const wave = props.wave;
const data = wave.data.split(" ").map(Number);

setViewableData(data.slice(0, viewable));
setPointer(viewable);

let newX = [];
for (let i = 0; i < viewable; i++) {
newX[i] = i + 1;
}
setXData(newX);
}, [props]);
}, [queueData]);

return (
<div className="w-full">
<LinePlot
title="ECG"
name="ECG"
xData={xData}
yData={viewableData}
yData={queueData.slice(0, viewable)}
low={wave["data-low-limit"]}
high={wave["data-high-limit"]}
classes="h-full"
Expand Down