refactor: layout and log components

This commit is contained in:
Slinetrac
2025-10-14 22:13:14 +08:00
parent 06dc7a6ef4
commit 5d114806f7
2 changed files with 41 additions and 11 deletions

View File

@@ -173,7 +173,11 @@ export function TrafficGraph({ ref }: { ref?: Ref<TrafficRef> }) {
context.globalAlpha = upLineAlpha; context.globalAlpha = upLineAlpha;
context.lineWidth = upLineWidth; context.lineWidth = upLineWidth;
context.strokeStyle = upLineColor; context.strokeStyle = upLineColor;
lineStyle ? drawBezier(listUp, offset) : drawLine(listUp, offset); if (lineStyle) {
drawBezier(listUp, offset);
} else {
drawLine(listUp, offset);
}
context.stroke(); context.stroke();
context.closePath(); context.closePath();
@@ -181,7 +185,11 @@ export function TrafficGraph({ ref }: { ref?: Ref<TrafficRef> }) {
context.globalAlpha = downLineAlpha; context.globalAlpha = downLineAlpha;
context.lineWidth = downLineWidth; context.lineWidth = downLineWidth;
context.strokeStyle = downLineColor; context.strokeStyle = downLineColor;
lineStyle ? drawBezier(listDown, offset) : drawLine(listDown, offset); if (lineStyle) {
drawBezier(listDown, offset);
} else {
drawLine(listDown, offset);
}
context.stroke(); context.stroke();
context.closePath(); context.closePath();

View File

@@ -1,4 +1,5 @@
import { styled, Box } from "@mui/material"; import { styled, Box } from "@mui/material";
import type { ReactNode } from "react";
import { SearchState } from "@/components/base/base-search-box"; import { SearchState } from "@/components/base/base-search-box";
@@ -67,17 +68,38 @@ const LogItem = ({ value, searchState }: Props) => {
} }
const flags = searchState.matchCase ? "g" : "gi"; const flags = searchState.matchCase ? "g" : "gi";
const parts = text.split(new RegExp(`(${pattern})`, flags)); const regex = new RegExp(pattern, flags);
const elements: ReactNode[] = [];
let lastIndex = 0;
let match: RegExpExecArray | null;
return parts.map((part, index) => { while ((match = regex.exec(text)) !== null) {
return index % 2 === 1 ? ( const start = match.index;
<span key={index} className="highlight"> const matchText = match[0];
{part}
</span> if (matchText === "") {
) : ( regex.lastIndex += 1;
part continue;
}
if (start > lastIndex) {
elements.push(text.slice(lastIndex, start));
}
elements.push(
<span key={`highlight-${start}`} className="highlight">
{matchText}
</span>,
); );
});
lastIndex = start + matchText.length;
}
if (lastIndex < text.length) {
elements.push(text.slice(lastIndex));
}
return elements.length ? elements : text;
} catch { } catch {
return text; return text;
} }