Skip to content

Commit

Permalink
fix(web): fix monitor yaxis overflow (#1928)
Browse files Browse the repository at this point in the history
* fix(web): fix monitor yaxis overflow
  • Loading branch information
0fatal committed Apr 3, 2024
1 parent 11e156e commit 5bc23e3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
21 changes: 19 additions & 2 deletions web/src/pages/app/setting/SysSetting/AppMonitor/AreaCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export default function AreaCard(props: {
maxValue: number;
unit: string;
className?: string;
longestTick: string;
onLongestTickChange: (val: string) => void;
}) {
const {
data,
Expand All @@ -104,6 +106,8 @@ export default function AreaCard(props: {
maxValue,
unit,
className,
longestTick,
onLongestTickChange,
} = props;
const [chartData, setChartData] = useState<any[]>([]);
useEffect(() => {
Expand Down Expand Up @@ -147,6 +151,14 @@ export default function AreaCard(props: {
);
}, [data, dataNumber, title]);

const tickFormatter = (val: string) => {
const formattedTick = val.toString();
if (longestTick.length < formattedTick.length) {
onLongestTickChange(formattedTick);
}
return val;
};

return (
<div className={className}>
<div className="mb-3 flex justify-between font-medium text-grayModern-900">
Expand Down Expand Up @@ -178,7 +190,7 @@ export default function AreaCard(props: {
)}
</div>
<ResponsiveContainer width="100%" height="100%">
<AreaChart data={chartData} margin={{ left: -28, top: 6 }} syncId="sync">
<AreaChart data={chartData} margin={{ top: 6 }} syncId="sync">
<CartesianGrid stroke="#f5f5f5" vertical={false} />
<XAxis
dataKey="xData"
Expand All @@ -190,7 +202,12 @@ export default function AreaCard(props: {
domain={[Date.now() - 60 * 60 * 1000, Date.now()]}
stroke="#C0C2D2"
/>
<YAxis fontSize="10" stroke="#9CA2A8" />
<YAxis
fontSize="10"
stroke="#9CA2A8"
width={longestTick.length * 8 + 8}
tickFormatter={tickFormatter}
/>
<ReferenceLine
y={maxValue}
strokeDasharray="3 3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export default function PieCard(props: {
></span>
<p>{entry.value}</p>
</span>
<p className="ml-3 mt-1">{formatSize(pieData[index]?.value * 1024 * 1024)}</p>
<p className="text-nowrap ml-3 mt-1">
{formatSize(pieData[index]?.value * 1024 * 1024)}
</p>
</div>
))}
</ul>
Expand Down
6 changes: 6 additions & 0 deletions web/src/pages/app/setting/SysSetting/AppMonitor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default function AppMonitor() {
return cpuData.length > memoryData.length ? [t("All"), ...cpuData] : [t("All"), ...memoryData];
}, [monitorData, t]);

const [longestTick, setLongestTick] = useState("");

return (
<div className="flex w-full">
{isLoading ? (
Expand All @@ -66,6 +68,8 @@ export default function AppMonitor() {
unit="Core"
maxValue={limitCPU / 1000}
className="h-1/2 p-4"
longestTick={longestTick}
onLongestTickChange={(val) => setLongestTick(val)}
/>
<AreaCard
data={monitorData?.data?.memoryUsage}
Expand All @@ -77,6 +81,8 @@ export default function AppMonitor() {
maxValue={limitMemory}
dataNumber={dataNumber}
className="h-1/2 p-4"
longestTick={longestTick}
onLongestTickChange={(val) => setLongestTick(val)}
/>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export default function AreaCard(props: {
unit: string;
className?: string;
syncId: string;
tableMarginLeft: number;
longestTick: string;
onLongestTickChange: (val: string) => void;
}) {
const {
data,
Expand All @@ -124,7 +125,8 @@ export default function AreaCard(props: {
unit,
className,
syncId,
tableMarginLeft,
longestTick,
onLongestTickChange,
} = props;
const [chartData, setChartData] = useState<any[]>([]);
useEffect(() => {
Expand Down Expand Up @@ -173,6 +175,14 @@ export default function AreaCard(props: {
}
}, [data, podName, title]);

const tickFormatter = (val: string) => {
const formattedTick = val.toString();
if (longestTick.length < formattedTick.length) {
onLongestTickChange(formattedTick);
}
return val;
};

return (
<div className={className}>
<div className="mb-3 flex justify-between font-medium text-grayModern-900">
Expand Down Expand Up @@ -205,7 +215,7 @@ export default function AreaCard(props: {
<ResponsiveContainer width="100%" height="100%">
<AreaChart
data={chartData}
margin={{ left: tableMarginLeft, top: 6 }}
margin={{ top: 6 }}
{...(syncId !== "" ? { syncId: syncId } : {})}
>
<CartesianGrid stroke="#f5f5f5" vertical={false} />
Expand All @@ -219,7 +229,12 @@ export default function AreaCard(props: {
domain={[Date.now() - 60 * 60 * 1000, Date.now()]}
stroke="#C0C2D2"
/>
<YAxis fontSize="10" stroke="#9CA2A8" />
<YAxis
fontSize="10"
stroke="#9CA2A8"
width={longestTick.length * 8 + 8}
tickFormatter={tickFormatter}
/>

{maxValue !== 0 && (
<ReferenceLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function PieCard(props: {
></span>
<p>{entry.value}</p>
</span>
<p className="ml-3 mt-1">{(pieData[index]?.value).toFixed(3)} MB</p>
<p className="text-nowrap ml-3 mt-1">{(pieData[index]?.value).toFixed(3)} MB</p>
</div>
))}
</ul>
Expand Down
21 changes: 15 additions & 6 deletions web/src/pages/app/setting/SysSetting/DatabaseMonitor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export default function DatabaseMonitor() {
return [t("All"), ...uniquePods];
}, [cpuData, memoryData, t]);

const [longestTick, setLongestTick] = useState("");
const [longestTick1, setLongestTick1] = useState("");

return (
<Tabs variant="enclosed" isLazy={true}>
<TabList>
Expand Down Expand Up @@ -107,7 +110,8 @@ export default function DatabaseMonitor() {
maxValue={limitCPU / 1000}
className="h-1/3 p-4"
syncId="tab1"
tableMarginLeft={-28}
longestTick={longestTick}
onLongestTickChange={(val) => setLongestTick(val)}
/>
<AreaCard
data={resourceData?.data?.memory}
Expand All @@ -120,7 +124,8 @@ export default function DatabaseMonitor() {
podName={podName}
className="h-1/3 p-4"
syncId="tab1"
tableMarginLeft={-28}
longestTick={longestTick}
onLongestTickChange={(val) => setLongestTick(val)}
/>
<AreaCard
data={connectionData?.data?.connections}
Expand All @@ -133,7 +138,8 @@ export default function DatabaseMonitor() {
podName={podName}
className="h-1/3 p-4"
syncId="tab1"
tableMarginLeft={-28}
longestTick={longestTick}
onLongestTickChange={(val) => setLongestTick(val)}
/>
</div>

Expand Down Expand Up @@ -194,7 +200,8 @@ export default function DatabaseMonitor() {
maxValue={0}
className="h-1/3 p-4"
syncId=""
tableMarginLeft={-25}
longestTick={longestTick1}
onLongestTickChange={(val) => setLongestTick1(val)}
/>
<AreaCard
data={performanceData?.data?.queryOperations}
Expand All @@ -207,7 +214,8 @@ export default function DatabaseMonitor() {
podName={podName}
className="h-1/3 p-4"
syncId=""
tableMarginLeft={-26}
longestTick={longestTick1}
onLongestTickChange={(val) => setLongestTick1(val)}
/>
<AreaCard
data={performanceData?.data?.pageFaults}
Expand All @@ -220,7 +228,8 @@ export default function DatabaseMonitor() {
podName={podName}
className="h-1/3 p-4"
syncId=""
tableMarginLeft={-25}
longestTick={longestTick1}
onLongestTickChange={(val) => setLongestTick1(val)}
/>
</div>
) : (
Expand Down

0 comments on commit 5bc23e3

Please sign in to comment.