Skip to content

Commit e0e22c8

Browse files
author
Ritika Mishra
committed
improved logic of filter for eight channel
1 parent 7c55080 commit e0e22c8

File tree

2 files changed

+91
-59
lines changed

2 files changed

+91
-59
lines changed

src/components/Canvas.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ const Canvas = forwardRef(
164164
return; // Exit if the ref is null
165165
}
166166

167+
currentSweepPos.current = new Array(numChannels).fill(0);
168+
sweepPositions.current = new Array(numChannels).fill(0);
169+
167170
// Clear existing child elements
168171
while (container.firstChild) {
169172
const firstChild = container.firstChild;
@@ -186,62 +189,53 @@ const Canvas = forwardRef(
186189
const newWglPlots: WebglPlot[] = [];
187190
const newLines: WebglLine[] = [];
188191

189-
// // Create grid lines
192+
// Create grid lines
190193
const canvasWrapper = document.createElement("div");
191-
canvasWrapper.className = "absolute inset-0"; // Make the wrapper fill the parent container
192-
const opacityDarkMajor = "0.2"; // Opacity for every 5th line in dark theme
193-
const opacityDarkMinor = "0.05"; // Opacity for other lines in dark theme
194-
const opacityLightMajor = "0.4"; // Opacity for every 5th line in light theme
195-
const opacityLightMinor = "0.1"; // Opacity for other lines in light theme
194+
canvasWrapper.className = "absolute inset-0";
195+
const opacityDarkMajor = "0.2";
196+
const opacityDarkMinor = "0.05";
197+
const opacityLightMajor = "0.4";
198+
const opacityLightMinor = "0.1";
196199
const distanceminor = samplingRate * 0.04;
197-
const numGridLines = getpoints(selectedBits ?? 10) * 4 / distanceminor;
200+
const numGridLines = (getpoints(selectedBits ?? 10) * 4) / distanceminor;
201+
198202
for (let j = 1; j < numGridLines; j++) {
199203
const gridLineX = document.createElement("div");
200204
gridLineX.className = "absolute bg-[rgb(128,128,128)]";
201205
gridLineX.style.width = "1px";
202206
gridLineX.style.height = "100%";
203-
const divPoint = (j / numGridLines) * 100
204-
const a = parseFloat(divPoint.toFixed(3));
205-
gridLineX.style.left = `${a}%`
206-
gridLineX.style.top = "0";
207+
gridLineX.style.left = `${((j / numGridLines) * 100).toFixed(3)}%`;
207208
gridLineX.style.opacity = j % 5 === 0 ? (theme === "dark" ? opacityDarkMajor : opacityLightMajor) : (theme === "dark" ? opacityDarkMinor : opacityLightMinor);
208-
209-
// Append grid lines to the wrapper
210209
canvasWrapper.appendChild(gridLineX);
211210
}
211+
212212
const horizontalline = 50;
213213
for (let j = 1; j < horizontalline; j++) {
214214
const gridLineY = document.createElement("div");
215215
gridLineY.className = "absolute bg-[rgb(128,128,128)]";
216216
gridLineY.style.height = "1px";
217217
gridLineY.style.width = "100%";
218-
const distance = (j / horizontalline) * 100
219-
const distancetop = parseFloat(distance.toFixed(3));
220-
gridLineY.style.top = `${distancetop}%`;
221-
gridLineY.style.left = "0";
218+
gridLineY.style.top = `${((j / horizontalline) * 100).toFixed(3)}%`;
222219
gridLineY.style.opacity = j % 5 === 0 ? (theme === "dark" ? opacityDarkMajor : opacityLightMajor) : (theme === "dark" ? opacityDarkMinor : opacityLightMinor);
223-
224-
// Append grid lines to the wrapper
225220
canvasWrapper.appendChild(gridLineY);
226221
}
227-
canvasContainerRef.current.appendChild(canvasWrapper);
228-
// Iterate only over selected channels
222+
container.appendChild(canvasWrapper);
223+
224+
// Create canvases for each selected channel
229225
selectedChannels.forEach((channelNumber) => {
230226
const canvasWrapper = document.createElement("div");
231-
canvasWrapper.className = "canvas-container relative flex-[1_1_0%]"; // Add relative positioning for absolute grid positioning
227+
canvasWrapper.className = "canvas-container relative flex-[1_1_0%]";
232228

233229
const canvas = document.createElement("canvas");
234-
canvas.id = `canvas${channelNumber}`; // Use channelNumber directly
230+
canvas.id = `canvas${channelNumber}`;
235231
canvas.width = container.clientWidth;
236232
canvas.height = container.clientHeight / selectedChannels.length;
237233
canvas.className = "w-full h-full block rounded-xl";
238234

239-
// Create a badge for the channel number
240235
const badge = document.createElement("div");
241236
badge.className = "absolute text-gray-500 text-sm rounded-full p-2 m-2";
242-
badge.innerText = `CH${channelNumber}`; // Use channelNumber directly
237+
badge.innerText = `CH${channelNumber}`;
243238

244-
// Append the canvas and badge to the container
245239
canvasWrapper.appendChild(badge);
246240
canvasWrapper.appendChild(canvas);
247241
container.appendChild(canvasWrapper);
@@ -276,7 +270,7 @@ const Canvas = forwardRef(
276270
new ColorRGBA(40 / 255, 110 / 255, 140 / 255, 1), // Darkened #35A5CC
277271
new ColorRGBA(35 / 255, 120 / 255, 130 / 255, 1), // Darkened #30A8B4
278272
new ColorRGBA(35 / 255, 125 / 255, 120 / 255, 1), // Darkened #32ABA2
279-
273+
280274
];
281275

282276
const colorsLight: ColorRGBA[] = [
@@ -288,7 +282,7 @@ const Canvas = forwardRef(
288282
new ColorRGBA(53 / 255, 165 / 255, 204 / 255, 0.8), // Slightly transparent #35A5CC
289283
new ColorRGBA(48 / 255, 168 / 255, 180 / 255, 0.8), // Slightly transparent #30A8B4
290284
new ColorRGBA(50 / 255, 171 / 255, 162 / 255, 0.8), // Slightly transparent #32ABA2
291-
285+
292286
];
293287

294288
// Swap light and dark colors for themes
@@ -429,6 +423,18 @@ const Canvas = forwardRef(
429423

430424
}, [animate]);
431425

426+
useEffect(() => {
427+
const handleResize = () => {
428+
createCanvases();
429+
430+
};
431+
window.addEventListener("resize", handleResize);
432+
return () => {
433+
window.removeEventListener("resize", handleResize);
434+
};
435+
}, [createCanvases]);
436+
437+
432438
return (
433439
<main className=" flex flex-col flex-[1_1_0%] min-h-80 bg-highlight rounded-2xl m-4 relative"
434440
ref={canvasContainerRef}

0 commit comments

Comments
 (0)