🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): misc improvements to dashboards including mobile view, big number chart, truncate title/description, enforce min height/width of widgets (#7082)
Marc Klingenc60e58a568b0
diff --git a/web/src/features/widgets/chart-library/BigNumber.tsx b/web/src/features/widgets/chart-library/BigNumber.tsxindex 393463302e..e4d18f8c90 100644--- a/web/src/features/widgets/chart-library/BigNumber.tsx+++ b/web/src/features/widgets/chart-library/BigNumber.tsx@@ -1,4 +1,96 @@import { cn } from "@/src/utils/tailwind";+import { useEffect, useRef, useState } from "react";++// Format large numbers with appropriate units and dynamic decimal places+const formatBigNumber = (+ value: number,+ maxCharacters?: number,+): { formatted: string; unit: string } => {+ const absValue = Math.abs(value);++ // Calculate how many decimal places we can afford based on available space+ const getOptimalDecimalPlaces = (+ baseNumber: number,+ unit: string,+ maxChars?: number,+ ): number => {+ if (!maxChars) return 1; // Default to 1 decimal place++ const baseStr = Math.floor(Math.abs(baseNumber)).toString();+ const signLength = value < 0 ? 1 : 0;+ const availableForDecimals =+ maxChars - baseStr.length - unit.length - signLength - 1; // -1 for decimal point++ return Math.max(0, Math.min(3, availableForDecimals)); // Max 3 decimal places, min 0+ };++ if (absValue >= 1e12) {+ const baseValue = value / 1e12;+ const decimals = getOptimalDecimalPlaces(baseValue, "T", maxCharacters);+ return {+ formatted: baseValue.toFixed(decimals).replace(/\.?0+$/, ""),+ unit: "T",+ };+ } else if (absValue >= 1e9) {+ const baseValue = value / 1e9;+ const decimals = getOptimalDecimalPlaces(baseValue, "B", maxCharacters);+ return {+ formatted: baseValue.toFixed(decimals).replace(/\.?0+$/, ""),+ unit: "B",+ };+ } else if (absValue >= 1e6) {+ const baseValue = value / 1e6;+ const decimals = getOptimalDecimalPlaces(baseValue, "M", maxCharacters);+ return {+ formatted: baseValue.toFixed(decimals).replace(/\.?0+$/, ""),+ unit: "M",+ };+ } else if (absValue >= 1e3) {+ const baseValue = value / 1e3;+ const decimals = getOptimalDecimalPlaces(baseValue, "K", maxCharacters);+ return {+ formatted: baseValue.toFixed(decimals).replace(/\.?0+$/, ""),+ unit: "K",+ };+ } else if (absValue >= 1) {+ // For numbers >= 1, show dynamic decimal places based on space+ const decimals = maxCharacters+ ? Math.min(+ 3,+ Math.max(+ 0,+ maxCharacters -+ Math.floor(absValue).toString().length -+ (value < 0 ? 1 : 0) -+ 1,+ ),+ )+ : 2;+ return {+ formatted: value.toFixed(decimals).replace(/\.?0+$/, ""),+ unit: "",+ };+ } else if (absValue > 0) {+ // For small numbers, show as many meaningful decimal places as space allows+ // Find the first significant digit and show a few more places+ const str = absValue.toString();+ const firstSignificantIndex = str.search(/[1-9]/);++ if (firstSignificantIndex === -1) return { formatted: "0", unit: "" };++ // Calculate how many decimal places we need to show meaningful digits+ const neededDecimals = firstSignificantIndex + 2; // Show 2 significant digits+ const maxAllowedDecimals = maxCharacters ? maxCharacters - 2 : 6; // Account for "0."+ const decimals = Math.min(neededDecimals, maxAllowedDecimals, 8); // Max 8 decimal places++ return {+ formatted: value.toFixed(decimals).replace(/\.?0+$/, ""),+ unit: "",+ };+ } else {+ return { formatted: "0", unit: "" };+ }+};export const BigNumber = ({className,@@ -7,16 +99,137 @@ export const BigNumber = ({className?: string;metric: React.ReactNode;}) => {+ const containerRef = useRef<HTMLDivElement>(null);+ const textRef = useRef<HTMLSpanElement>(null);+ const [fontSize, setFontSize] = useState("text-6xl");+ const [maxCharacters, setMaxCharacters] = useState<number>();++ // Convert metric to number if it's a string or number, otherwise use original+ const numericValue =+ typeof metric === "string" || typeof metric === "number"+ ? parseFloat(String(metric))+ : null;++ const displayValue =+ numericValue !== null && !isNaN(numericValue)+ ? formatBigNumber(numericValue, maxCharacters)+ : { formatted: String(metric), unit: "" };++ useEffect(() => {+ const resizeObserver = new ResizeObserver(() => {+ if (!containerRef.current || !textRef.current) return;++ const container = containerRef.current;++ // Get container dimensions+ const containerWidth = container.clientWidth;+ const containerHeight = container.clientHeight;+ const availableWidth = containerWidth * 0.95; // Use more width (was 0.9)+ const availableHeight = containerHeight * 0.9; // Use more height (was 0.8)++ // Start with a large font size and scale down+ const baseFontSizes = [+ { class: "text-8xl", px: 128 },+ { class: "text-7xl", px: 96 },+ { class: "text-6xl", px: 72 },+ { class: "text-5xl", px: 60 },+ { class: "text-4xl", px: 48 },+ { class: "text-3xl", px: 36 },+ { class: "text-2xl", px: 24 },+ { class: "text-xl", px: 20 },+ { class: "text-lg", px: 18 },+ { class: "text-base", px: 16 },+ { class: "text-sm", px: 14 },+ ];++ let selectedFontSize = "text-sm";+ let calculatedMaxChars = 0;++ // Test each font size to find the largest that fits+ for (const { class: fontClass, px } of baseFontSizes) {+ // Estimate how many characters can fit - less conservative character width+ const charWidth = px * 0.55; // Less conservative (was 0.6)+ const maxChars = Math.floor(availableWidth / charWidth);++ // Quick test with current display value+ const testDisplayValue =+ numericValue !== null && !isNaN(numericValue)+ ? formatBigNumber(numericValue, maxChars)+ : { formatted: String(metric), unit: "" };++ const textLength = (testDisplayValue.formatted + testDisplayValue.unit)+ .length;+ const estimatedWidth = textLength * charWidth;+ const estimatedHeight = px * 1.1; // Less conservative line height (was 1.2)++ if (+ estimatedWidth <= availableWidth &&+ estimatedHeight <= availableHeight+ ) {+ selectedFontSize = fontClass;+ calculatedMaxChars = maxChars;+ break;+ }+ }++ setFontSize(selectedFontSize);+ setMaxCharacters(calculatedMaxChars);+ });++ if (containerRef.current) {+ resizeObserver.observe(containerRef.current);+ }++ return () => resizeObserver.disconnect();+ }, [numericValue, metric]);+return (<div+ ref={containerRef}className={cn("flex h-full w-full flex-col items-center justify-center",className,)}>- <span className="text-center text-6xl font-extrabold tracking-tight">- {metric}- </span>+ <div className="flex items-baseline justify-center gap-1">+ <span+ ref={textRef}+ className={cn("text-center font-extrabold tracking-tight", fontSize)}+ title={+ numericValue !== null && !isNaN(numericValue)+ ? numericValue.toString()+ : String(metric)+ }+ >+ {displayValue.formatted}+ </span>+ {displayValue.unit && (+ <span+ className={cn(+ "font-bold text-muted-foreground",+ fontSize === "text-8xl"+ ? "text-4xl"+ : fontSize === "text-7xl"+ ? "text-3xl"+ : fontSize === "text-6xl"+ ? "text-2xl"+ : fontSize === "text-5xl"+ ? "text-xl"+ : fontSize === "text-4xl"+ ? "text-lg"+ : fontSize === "text-3xl"+ ? "text-base"+ : fontSize === "text-2xl"+ ? "text-sm"+ : fontSize === "text-xl"+ ? "text-sm"+ : "text-xs",+ )}+ >+ {displayValue.unit}+ </span>+ )}+ </div></div>);};diff --git a/web/src/features/widgets/chart-library/Chart.tsx b/web/src/features/widgets/chart-library/Chart.tsxindex f973a80826..abd6e49da0 100644--- a/web/src/features/widgets/chart-library/Chart.tsx+++ b/web/src/features/widgets/chart-library/Chart.tsx@@ -86,7 +86,7 @@ export const Chart = ({);return (- <CardContent className={"h-full"}>+ <CardContent className="h-full p-0">{shouldWarn ? renderWarning() : renderChart()}</CardContent>);diff --git a/web/src/features/widgets/components/DashboardGrid.tsx b/web/src/features/widgets/components/DashboardGrid.tsxindex ed2ea3143a..a0a60cebb4 100644--- a/web/src/features/widgets/components/DashboardGrid.tsx+++ b/web/src/features/widgets/components/DashboardGrid.tsx@@ -4,10 +4,28 @@ import "react-resizable/css/styles.css";import { type WidgetPlacement } from "../components/DashboardWidget";import { DashboardWidget } from "@/src/features/widgets";import { type FilterState } from "@langfuse/shared";-import { useState, useCallback } from "react";+import { useState, useCallback, useEffect } from "react";const ResponsiveGridLayout = WidthProvider(Responsive);+// Hook to detect screen size+function useMediaQuery(query: string) {+ const [matches, setMatches] = useState(false);++ useEffect(() => {+ const media = window.matchMedia(query);+ if (media.matches !== matches) {+ setMatches(media.matches);+ }+ const listener = () => setMatches(media.matches);+ media.addEventListener("change", listener);+ return () => media.removeEventListener("change", listener);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [query]);++ return matches;+}+export function DashboardGrid({widgets,onChange,@@ -31,6 +49,9 @@ export function DashboardGrid({}) {const [rowHeight, setRowHeight] = useState(150);+ // Detect if screen is medium or smaller (1024px and below)+ const isSmallScreen = useMediaQuery("(max-width: 1024px)");+const handleWidthChange = useCallback((containerWidth: number) => {const calculatedRowHeight = ((containerWidth / 12) * 9) / 16;@@ -48,11 +69,18 @@ export function DashboardGrid({y: w.y,w: w.x_size,h: w.y_size,- isDraggable: canEdit,+ isDraggable: canEdit && !isSmallScreen, // Disable dragging on small screens+ minW: 2,+ minH: 2,}));const handleLayoutChange = (newLayout: any[]) => {- if (!canEdit) return;+ // Safety checks: prevent layout changes on small screens and when editing is disabled+ // This prevents unintended saves during responsive transitions or on mobile devices+ if (!canEdit || isSmallScreen) return;++ // Additional safety: ensure the layout change is meaningful+ if (!newLayout || newLayout.length === 0) return;// Update widget positions based on the new layoutconst updatedWidgets = widgets.map((w) => {@@ -71,6 +99,34 @@ export function DashboardGrid({onChange(updatedWidgets);};+ // Render flex layout for small screens+ if (isSmallScreen) {+ return (+ <div className="flex w-full flex-col gap-4">+ {widgets+ .sort((a, b) => a.y - b.y || a.x - b.x) // Sort by position for consistent order+ .map((widget) => (+ <div+ key={widget.id}+ className="w-full"+ style={{ height: "300px" }} // Fixed height for all widgets on small screens+ >+ <DashboardWidget+ dashboardId={dashboardId}+ projectId={projectId}+ placement={widget}+ dateRange={dateRange}+ filterState={filterState}+ onDeleteWidget={onDeleteWidget}+ dashboardOwner={dashboardOwner || "PROJECT"}+ />+ </div>+ ))}+ </div>+ );+ }++ // Render grid layout for larger screensreturn (<ResponsiveGridLayoutclassName="layout"diff --git a/web/src/features/widgets/components/DashboardWidget.tsx b/web/src/features/widgets/components/DashboardWidget.tsxindex 5abada633e..f849b56d76 100644--- a/web/src/features/widgets/components/DashboardWidget.tsx+++ b/web/src/features/widgets/components/DashboardWidget.tsx@@ -196,8 +196,8 @@ export function DashboardWidget({<divclassName={`group flex h-full w-full flex-col overflow-hidden rounded-lg border bg-background p-4`}>- <div className="mb-2 flex items-center justify-between">- <span className="font-medium">+ <div className="flex items-center justify-between">+ <span className="truncate font-medium" title={widget.data.name}>{widget.data.name}{" "}{dashboardOwner === "PROJECT" && widget.data.owner === "LANGFUSE"? " ( 🪢 )"@@ -207,7 +207,7 @@ export function DashboardWidget({<div className="flex space-x-2"><GripVerticalIconsize={16}- className="drag-handle hidden cursor-grab text-muted-foreground hover:text-foreground active:cursor-grabbing group-hover:block"+ className="drag-handle hidden cursor-grab text-muted-foreground hover:text-foreground active:cursor-grabbing lg:group-hover:block"/>{widget.data.owner === "PROJECT" ? (<button@@ -236,7 +236,10 @@ export function DashboardWidget({</div>)}</div>- <div className="mb-4 text-sm text-muted-foreground">+ <div+ className="mb-4 truncate text-sm text-muted-foreground"+ title={widget.data.description}+ >{widget.data.description}</div><div className="min-h-0 flex-1">diff --git a/web/src/features/widgets/components/WidgetForm.tsx b/web/src/features/widgets/components/WidgetForm.tsxindex 4b17f79586..232f5f3897 100644--- a/web/src/features/widgets/components/WidgetForm.tsx+++ b/web/src/features/widgets/components/WidgetForm.tsx@@ -744,8 +744,12 @@ export function WidgetForm({<div className="w-2/3"><Card className={"aspect-video"}><CardHeader>- <CardTitle>{widgetName}</CardTitle>- <CardDescription>{widgetDescription}</CardDescription>+ <CardTitle className="truncate" title={widgetName}>+ {widgetName}+ </CardTitle>+ <CardDescription className="truncate" title={widgetDescription}>+ {widgetDescription}+ </CardDescription></CardHeader>{queryResult.data ? (<Chart