Skip to content

Commit 868fc67

Browse files
committed
do pure x/y fit to avoid awkward zoomed-in on-render
1 parent 1f289e4 commit 868fc67

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

packages/web/src/ee/features/chat/components/chatThread/mermaidDiagram.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ const PANEL_MIN_HEIGHT = 240;
163163
const PANEL_VIEWPORT_MARGIN = 24;
164164
// Fallback when no scroll-area ancestor can be measured.
165165
const PANEL_FALLBACK_MAX_HEIGHT = 720;
166-
// Cap on enlarging a wide diagram: at most this many column-widths wide.
167-
const PANEL_MAX_OVERFLOW_FACTOR = 2.5;
168166

169167
// Zoom limits and the button step are relative to the fitted ("100%") scale, so
170168
// the usable range and ±25% readout steps are consistent across diagram sizes.
@@ -197,10 +195,11 @@ interface DiagramFit {
197195
panelHeight: number | null;
198196
}
199197

200-
// Pure fit, as a transform scale where 1 = "fills the available width". Inline
201-
// and fullscreen contain-fit the whole diagram; the panel contain-fits unless
202-
// the diagram is wider than the column, in which case it's enlarged to use the
203-
// readable height and overflows horizontally (bounded so it can't explode).
198+
// Pure fit, as a transform scale where 1 = "fills the available width". Both the
199+
// panel and fullscreen contain-fit the whole diagram, respecting width and
200+
// height, so it never overflows the container in either dimension (zoom/pan to
201+
// inspect details). The panel additionally grows its height to the fitted
202+
// diagram, clamped to the readable area.
204203
const computeFit = (
205204
{ width: iw, height: ih }: IntrinsicSize,
206205
availWidth: number,
@@ -211,20 +210,13 @@ const computeFit = (
211210
const widthFitHeight = availWidth * (ih / iw);
212211
const heightFitScale = availHeight / widthFitHeight;
213212

213+
// Contain-fit: never wider than the box, shrink to fit the height if tall.
214+
const fitScale = Math.min(1, heightFitScale) * FIT_MARGIN;
215+
214216
if (!autoHeight) {
215-
// Contain-fit: never wider than the box, shrink to fit the height if tall.
216-
const fitScale = Math.min(1, heightFitScale) * FIT_MARGIN;
217217
return { fitScale, panelHeight: null };
218218
}
219219

220-
const isWiderThanPanel = iw > availWidth;
221-
const fitScale = (isWiderThanPanel
222-
// Enlarge into the readable height and overflow horizontally (drag to
223-
// pan); never below filling the column width, capped at N column-widths.
224-
? Math.min(Math.max(heightFitScale, 1), PANEL_MAX_OVERFLOW_FACTOR)
225-
// Contain-fit: the whole diagram stays visible.
226-
: Math.min(1, heightFitScale)) * FIT_MARGIN;
227-
228220
const panelHeight = Math.round(Math.min(availHeight, Math.max(PANEL_MIN_HEIGHT, widthFitHeight * fitScale)));
229221
return { fitScale, panelHeight };
230222
};

0 commit comments

Comments
 (0)