fix: 비교창 스크롤 수정 변경

main
jschoi 8 months ago
parent 20a1a4f268
commit b73d3a509d

@ -9,14 +9,14 @@ import {
} from "vue"; } from "vue";
import Plotly from "plotly.js-dist-min"; import Plotly from "plotly.js-dist-min";
/** ===== Types ===== */ /* ===== Types ===== */
type MetricKV = { key: string; value: number }; type MetricKV = { key: string; value: number };
type RunDetailType = { type RunDetailType = {
info: any; info: any;
data: { metrics: MetricKV[]; params?: any[]; tags?: any[] }; data: { metrics: MetricKV[]; params?: any[]; tags?: any[] };
}; };
/** ===== Props / Emits ===== */ /* ===== Props / Emits ===== */
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
modelValue: boolean; modelValue: boolean;
@ -46,7 +46,7 @@ const emit = defineEmits<{
(e: "update:selectedMetricKeys", v: string[]): void; (e: "update:selectedMetricKeys", v: string[]): void;
}>(); }>();
/** ===== local refs ===== */ /* ===== local refs ===== */
const dialogOpen = computed({ const dialogOpen = computed({
get: () => props.modelValue, get: () => props.modelValue,
set: (v: boolean) => emit("update:modelValue", v), set: (v: boolean) => emit("update:modelValue", v),
@ -63,7 +63,7 @@ const selectedMetricKeysProxy = computed({
const elCompare = ref<HTMLDivElement | null>(null); const elCompare = ref<HTMLDivElement | null>(null);
const loading = ref(false); const loading = ref(false);
/** ===== helpers ===== */ /* ===== helpers ===== */
const fmtNumber = (v: number | null, digits = 3) => { const fmtNumber = (v: number | null, digits = 3) => {
if (v == null || !Number.isFinite(v)) return ""; if (v == null || !Number.isFinite(v)) return "";
const abs = Math.abs(v); const abs = Math.abs(v);
@ -75,8 +75,8 @@ const fmtNumber = (v: number | null, digits = 3) => {
const normalizeArray = (vals: (number | null)[]) => { const normalizeArray = (vals: (number | null)[]) => {
const xs = vals.filter((v): v is number => Number.isFinite(v as number)); const xs = vals.filter((v): v is number => Number.isFinite(v as number));
if (xs.length === 0) return vals; if (xs.length === 0) return vals;
const min = Math.min(...xs), const min = Math.min(...xs);
max = Math.max(...xs); const max = Math.max(...xs);
if (max === min) return vals.map((v) => (v == null ? v : 1)); if (max === min) return vals.map((v) => (v == null ? v : 1));
return vals.map((v) => (v == null ? v : (v - min) / (max - min))); return vals.map((v) => (v == null ? v : (v - min) / (max - min)));
}; };
@ -86,7 +86,7 @@ const valueOf = (run: RunDetailType, key: string): number | null => {
return Number.isFinite(m as number) ? Number(m) : null; return Number.isFinite(m as number) ? Number(m) : null;
}; };
/** ===== derived ===== */ /* ===== derived ===== */
const compareRuns = computed<RunDetailType[]>( const compareRuns = computed<RunDetailType[]>(
() => () =>
selectedRunIdsProxy.value selectedRunIdsProxy.value
@ -109,7 +109,25 @@ const activeMetricKeys = computed<string[]>(() =>
: commonMetricKeys.value, : commonMetricKeys.value,
); );
/** ===== chart ===== */ /* ===== responsive widths for horizontal scroll =====
- 그래프: 막대 개수에 비례해 내부 너비를 크게 잡아 가로 스크롤 허용
- 테이블: (메트릭 + Run 컬럼 1) * 160px 정도로 최소 너비 설정
*/
const chartInnerWidth = computed(() => {
// byMetric: X = metric , byRun: X = run
const xCount =
props.compareChartMode === "byMetric"
? activeMetricKeys.value.length
: compareRuns.value.length;
// 140px, 900px
return Math.max(900, xCount * 140 + 240);
});
const tableInnerWidth = computed(() => {
const cols = 1 + activeMetricKeys.value.length; // Run + metric
return Math.max(900, cols * 160);
});
/* ===== chart ===== */
const commonLayout: Partial<any> = { const commonLayout: Partial<any> = {
autosize: true, autosize: true,
margin: { t: 28, r: 12, b: 56, l: 56 }, margin: { t: 28, r: 12, b: 56, l: 56 },
@ -181,6 +199,7 @@ function drawCompareChart() {
? createTracesByMetric(metricKeys, runsData) ? createTracesByMetric(metricKeys, runsData)
: createTracesByRun(metricKeys, runsData); : createTracesByRun(metricKeys, runsData);
// byMetric ()
if (props.compareChartMode === "byMetric") { if (props.compareChartMode === "byMetric") {
const varianceOrder = metricKeys const varianceOrder = metricKeys
.map((k, idx) => { .map((k, idx) => {
@ -216,7 +235,7 @@ function drawCompareChart() {
); );
} }
/** ===== load & watch ===== */ /* ===== load & watch ===== */
async function loadCompareData() { async function loadCompareData() {
if (!dialogOpen.value) return; if (!dialogOpen.value) return;
loading.value = true; loading.value = true;
@ -250,9 +269,9 @@ onBeforeUnmount(() => window.removeEventListener("resize", onResize));
</script> </script>
<template> <template>
<v-dialog v-model="dialogOpen" max-width="1000"> <!-- 가로도 넉넉히, 세로는 90vh 제한 -->
<v-dialog v-model="dialogOpen" max-width="80vw">
<v-card class="rounded-lg overflow-hidden"> <v-card class="rounded-lg overflow-hidden">
<!-- 헤더: Deploy Model 스타일 적용 -->
<v-card-title <v-card-title
class="text-white font-weight-bold text-h6" class="text-white font-weight-bold text-h6"
style="background-color: #1976d2" style="background-color: #1976d2"
@ -260,7 +279,9 @@ onBeforeUnmount(() => window.removeEventListener("resize", onResize));
Compare Runs Compare Runs
</v-card-title> </v-card-title>
<!-- 상단: 선택 섹션 --> <!-- 본문 전체에 세로 스크롤 -->
<div class="scroll-y">
<!-- 상단 선택 섹션 -->
<v-card-text class="pa-6"> <v-card-text class="pa-6">
<v-row dense class="mb-2"> <v-row dense class="mb-2">
<v-col cols="12"> <v-col cols="12">
@ -316,7 +337,9 @@ onBeforeUnmount(() => window.removeEventListener("resize", onResize));
<v-chip size="small" color="primary" variant="tonal"> <v-chip size="small" color="primary" variant="tonal">
Mode: Mode:
{{ {{
props.compareChartMode === "byMetric" ? "By Metric" : "By Run" props.compareChartMode === "byMetric"
? "By Metric"
: "By Run"
}} }}
</v-chip> </v-chip>
<v-chip size="small" color="secondary" variant="tonal"> <v-chip size="small" color="secondary" variant="tonal">
@ -335,7 +358,7 @@ onBeforeUnmount(() => window.removeEventListener("resize", onResize));
</v-row> </v-row>
</v-card-text> </v-card-text>
<!-- 차트 & 테이블 섹션 ( 카드로 감싸기) --> <!-- 차트 (가로 스크롤) -->
<v-card-text class="pt-0 px-6 pb-2"> <v-card-text class="pt-0 px-6 pb-2">
<v-card variant="tonal" class="mb-4"> <v-card variant="tonal" class="mb-4">
<v-card-title class="py-2 px-4">Metrics (grouped bar)</v-card-title> <v-card-title class="py-2 px-4">Metrics (grouped bar)</v-card-title>
@ -344,14 +367,22 @@ onBeforeUnmount(() => window.removeEventListener("resize", onResize));
<div v-if="loading" class="my-2"> <div v-if="loading" class="my-2">
<v-progress-linear indeterminate /> <v-progress-linear indeterminate />
</div> </div>
<div ref="elCompare" style="width: 100%; height: 420px"></div> <div class="scroll-x">
<div
ref="elCompare"
:style="{ width: chartInnerWidth + 'px', height: '420px' }"
/>
</div>
</v-card-text> </v-card-text>
</v-card> </v-card>
<!-- 테이블 (가로 스크롤) -->
<v-card variant="tonal"> <v-card variant="tonal">
<v-card-title class="py-2 px-4">Comparison Table</v-card-title> <v-card-title class="py-2 px-4">Comparison Table</v-card-title>
<v-divider /> <v-divider />
<v-card-text class="px-0"> <v-card-text class="px-0">
<div class="scroll-x">
<div :style="{ minWidth: tableInnerWidth + 'px' }">
<v-table density="comfortable"> <v-table density="comfortable">
<thead> <thead>
<tr> <tr>
@ -365,23 +396,37 @@ onBeforeUnmount(() => window.removeEventListener("resize", onResize));
{{ r.info.run_name || r.info.run_id }} {{ r.info.run_name || r.info.run_id }}
</td> </td>
<td v-for="k in activeMetricKeys" :key="k"> <td v-for="k in activeMetricKeys" :key="k">
{{ r.data.metrics.find((m) => m.key === k)?.value ?? "—" }} {{
r.data.metrics.find((m) => m.key === k)?.value ??
"—"
}}
</td> </td>
</tr> </tr>
</tbody> </tbody>
</v-table> </v-table>
</div>
</div>
</v-card-text> </v-card-text>
</v-card> </v-card>
</v-card-text> </v-card-text>
</div>
<!-- 액션 --> <!-- 액션 -->
<v-card-actions class="justify-end"> <v-card-actions class="justify-end">
<v-btn variant="text" class="text-white" @click="dialogOpen = false"> <v-btn variant="text" class="text-white" @click="dialogOpen = false"
CLOSE >CLOSE</v-btn
</v-btn> >
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-dialog> </v-dialog>
</template> </template>
<style scoped></style> <style scoped>
.scroll-y {
max-height: 90vh; /* 다이얼로그 본문 세로 스크롤 */
overflow-y: auto;
}
.scroll-x {
overflow-x: auto; /* 가로 스크롤 */
}
</style>

Loading…
Cancel
Save