Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(topics): shrink hover to size (#18699)

Nimare864d75adec6
diff --git a/web/src/features/topics/EmbeddingMapView.stories.tsx b/web/src/features/topics/EmbeddingMapView.stories.tsx
index 729f191039..8b7fd07a84 100644
--- a/web/src/features/topics/EmbeddingMapView.stories.tsx
+++ b/web/src/features/topics/EmbeddingMapView.stories.tsx
@@ -320,6 +320,22 @@ const meta = preview.meta({
export const Default = meta.story({});
+export const SummaryLengths = meta.story({
+ args: {
+ data: {
+ ...data,
+ points: [
+ data.points[0],
+ {
+ ...data.points[1],
+ summary:
+ "The customer asks how to connect a new integration, configure its authentication credentials, and verify that events arrive in the correct project. The assistant walks through setup, explains how to troubleshoot missing events, and confirms that the connection is working before ending the conversation.",
+ },
+ ],
+ },
+ },
+});
+
export const SelectedTopic = meta.story({
args: { selectedTopic: "billing", selectedTraceId: "trace-billing" },
});
diff --git a/web/src/features/topics/map/TopicMapExplorer.tsx b/web/src/features/topics/map/TopicMapExplorer.tsx
index ef0b794a11..b3728b7ec1 100644
--- a/web/src/features/topics/map/TopicMapExplorer.tsx
+++ b/web/src/features/topics/map/TopicMapExplorer.tsx
@@ -657,9 +657,11 @@ function MapLabels({
)}
style={{
left: rect.x,
- top: rect.y,
+ top: rect.anchorY,
width: rect.width,
- height: rect.height,
+ maxHeight: rect.height,
+ // Percentages use the rendered height; clamp keeps the card inside its reserved bounds.
+ translate: `0 clamp(${rect.y - rect.anchorY}px, ${-100 * rect.anchorFraction}%, calc(${rect.y + rect.height - rect.anchorY}px - 100%))`,
borderLeftColor: trace?.point.color ?? zone!.color,
borderLeftWidth: 2,
}}
diff --git a/web/src/features/topics/map/prepare-topic-map.ts b/web/src/features/topics/map/prepare-topic-map.ts
index 4716e8d658..3a705cc357 100644
--- a/web/src/features/topics/map/prepare-topic-map.ts
+++ b/web/src/features/topics/map/prepare-topic-map.ts
@@ -547,11 +547,16 @@ export function zoneHalo(
};
}
+type MapHoverRectangle = MapRectangle & {
+ anchorY: number;
+ anchorFraction: 0 | 0.5 | 1;
+};
+
function hoverRectangle(
anchor: MapRectangle,
size: Size,
desired: Size,
-): MapRectangle | null {
+): MapHoverRectangle | null {
if (size.width <= 0 || size.height <= 0) return null;
const margin = Math.min(12, size.width / 4, size.height / 4);
const width = Math.min(desired.width, size.width - margin * 2);
@@ -565,12 +570,27 @@ function hoverRectangle(
top: number,
w = width,
h = height,
- ): MapRectangle => ({
- x: Math.min(Math.max(margin, left), size.width - w - margin),
- y: Math.min(Math.max(margin, top), size.height - h - margin),
- width: w,
- height: h,
- });
+ ): MapHoverRectangle => {
+ const x = Math.min(Math.max(margin, left), size.width - w - margin);
+ const y = Math.min(Math.max(margin, top), size.height - h - margin);
+ let anchorY = center.y;
+ let anchorFraction: MapHoverRectangle["anchorFraction"] = 0.5;
+ if (y + h <= anchor.y - 4) {
+ anchorY = y + h;
+ anchorFraction = 1;
+ } else if (y >= anchor.y + anchor.height + 4) {
+ anchorY = y;
+ anchorFraction = 0;
+ }
+ return {
+ x,
+ y,
+ width: w,
+ height: h,
+ anchorY,
+ anchorFraction,
+ };
+ };
const candidates = [
[anchor.x + anchor.width + 12, center.y - height / 2],
[anchor.x - width - 12, center.y - height / 2],
@@ -590,13 +610,13 @@ function hoverRectangle(
const regions = [
{
x: anchor.x + anchor.width + 12,
- y: margin,
+ y: center.y - height / 2,
width: size.width - margin - anchor.x - anchor.width - 12,
height: size.height - margin * 2,
},
{
x: margin,
- y: margin,
+ y: center.y - height / 2,
width: anchor.x - margin - 12,
height: size.height - margin * 2,
},
@@ -608,7 +628,7 @@ function hoverRectangle(
},
{
x: margin,
- y: margin,
+ y: anchor.y - height - 12,
width: size.width - margin * 2,
height: anchor.y - margin - 12,
},
@@ -630,13 +650,13 @@ type TraceHover = {
topicName: string | undefined;
node: TopicMapNode;
position: MapPosition;
- card: MapRectangle;
+ card: MapHoverRectangle;
excerpt: string;
reading: boolean;
};
type ZoneHover = MapZone & {
position: MapPosition;
- label: MapRectangle;
+ label: MapHoverRectangle;
detail: string;
};
export function prepareMapHover(