Skip to content

Commit 6ec5047

Browse files
authored
Fix width for component (#7294)
This just UI render fix when chart has many point, (>40) make everything dynamically shrink to browser view and no overflow https://torchci-git-fixwidth-fbopensource.vercel.app/benchmark/compilers_regression
1 parent 76c0136 commit 6ec5047

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

torchci/components/benchmark/v3/components/common/navigate.tsx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ export async function navigateToDataGrid(
2121
openToggleSectionById(toggleId);
2222
await delay(350); // wait for toggle animation
2323
}
24-
const target = scrollToDataGridView(sectionId, keywords, field);
25-
await delay(300); // wait for scroll animation
24+
const target = await scrollToDataGridView(sectionId, keywords, field);
2625
return target;
2726
}
2827

29-
function scrollToDataGridView(
28+
async function scrollToDataGridView(
3029
sectionId: string,
3130
keywords: string[],
3231
field?: string
@@ -58,7 +57,7 @@ function scrollToDataGridView(
5857
);
5958
if (cell) {
6059
target = cell;
61-
scrollingToElement(cell);
60+
await scrollingToElement(cell);
6261
}
6362
}
6463
return target;
@@ -85,7 +84,7 @@ export async function navigateToEchartInGroup(
8584
return null;
8685
}
8786
// scroll into view
88-
scrollingToElement(target);
87+
await scrollingToElement(target);
8988
return target;
9089
}
9190

@@ -94,11 +93,35 @@ export function getElementById(id: string): HTMLElement | null {
9493
return document.getElementById(id);
9594
}
9695

97-
export async function scrollingToElement(
98-
target: HTMLElement | null,
99-
delay_ts: number = 200
100-
) {
96+
export async function scrollingToElement(target: HTMLElement | null) {
10197
if (!target) return null;
10298
target.scrollIntoView({ behavior: "smooth", block: "center" });
103-
await delay(delay_ts);
99+
await waitUntilElementVisible(target);
100+
}
101+
102+
// Wait until element is visible in the viewport (with timeout)
103+
export async function waitUntilElementVisible(
104+
el: HTMLElement | null,
105+
timeout = 1500
106+
): Promise<void> {
107+
if (!el) {
108+
return;
109+
}
110+
const start = performance.now();
111+
return new Promise((resolve) => {
112+
const check = () => {
113+
const rect = el.getBoundingClientRect();
114+
const inView =
115+
rect.top >= 0 &&
116+
rect.bottom <=
117+
(window.innerHeight || document.documentElement.clientHeight);
118+
119+
if (inView || performance.now() - start > timeout) {
120+
resolve();
121+
} else {
122+
requestAnimationFrame(check);
123+
}
124+
};
125+
requestAnimationFrame(check);
126+
});
104127
}

torchci/components/benchmark/v3/components/dataRender/components/benchmarkTimeSeries/components/BenchmarkTimeSeriesChart/BenchmarkTimeSeriesChartGroup.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ export default function BenchmarkTimeSeriesChartGroup({
8989
chartGroup?.chart
9090
);
9191

92-
console.log(g.labels.join("-"), chartGroup?.sectionSelectMode);
93-
const enableSelectMode =
94-
chartGroup?.sectionSelectMode?.[g.labels.join("-")] ?? true;
92+
const maxTimeSeries = groupSeries
93+
.map((s) => s.data.length)
94+
.reduce((a, b) => Math.max(a, b));
9595
return (
9696
<Grid
9797
key={g.key}
98-
size={{ xs: 12, md: 12, lg: 6 }}
98+
size={{ xs: 12, md: 12, lg: maxTimeSeries > 40 ? 12 : 6 }}
9999
id={toBenchmarkTimeseriesChartGroupId(g.key)}
100100
>
101101
<Typography variant="h6" sx={{ mb: 1.5 }}>

torchci/components/benchmark/v3/components/dataRender/components/benchmarkTimeSeries/components/BenchmarkTimeSeriesComparisonSection/BenchmarkTimeSeriesComparisonTableSlider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function BenchmarkTimeSeriesComparisonTableSlider({
116116
[ids, onChange]
117117
);
118118

119-
const minWidth = Math.max(200, 50 * ids.length);
119+
const minWidth = Math.min(200, 50 * ids.length);
120120

121121
return (
122122
<Paper sx={{ p: 2, width: "100%", minWidth }}>

torchci/components/benchmark/v3/configs/teams/compilers/CompilerPrecomputeConfirmDialogContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ export const CompilerPrecomputeConfirmDialogContent: React.FC<
5050
const tableId = toBenchamrkTimeSeriesComparisonTableId(
5151
`metric=${left.metric}`
5252
);
53+
5354
const table = getElementById(tableId);
5455
// if the table is not exist,scroll to the toggle section
5556
if (!table) {
5657
scrollingToElement(elToggle);
5758
triggerUpdate();
5859
return;
5960
}
61+
6062
const cell = await navigateToDataGrid(
6163
tableId,
6264
[`${left?.compiler}`],

torchci/components/benchmark/v3/pages/BenchmarkRegressionPage.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Box } from "@mui/system";
12
import dayjs from "dayjs";
23
import utc from "dayjs/plugin/utc";
34
import { BenchmarkDashboardStoreProvider } from "lib/benchmark/store/benchmark_dashboard_provider";
@@ -19,12 +20,12 @@ export default function BenchmarkRegressionPage({
1920

2021
return (
2122
<BenchmarkDashboardStoreProvider key={benchmarkId} initial={initial}>
22-
<div style={{ display: "flex" }}>
23+
<Box style={{ display: "flex", minWidth: "800px", width: "100%" }}>
2324
<BenchmarkSideBar />
24-
<main style={{ flex: 1 }}>
25+
<Box style={{ flex: 1, minWidth: "600px" }}>
2526
<Comp />
26-
</main>
27-
</div>
27+
</Box>
28+
</Box>
2829
</BenchmarkDashboardStoreProvider>
2930
);
3031
}

0 commit comments

Comments
 (0)