Skip to content

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

feat(dashboards): add big number chart type (#6933)

Marc Klingen39e4a7533a7a
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index ed3ee7cd9f..30d9508ddf 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -109,7 +109,8 @@ export const DashboardWidgetChartType = {
BAR_TIME_SERIES: "BAR_TIME_SERIES",
HORIZONTAL_BAR: "HORIZONTAL_BAR",
VERTICAL_BAR: "VERTICAL_BAR",
- PIE: "PIE"
+ PIE: "PIE",
+ NUMBER: "NUMBER"
} as const;
export type DashboardWidgetChartType = (typeof DashboardWidgetChartType)[keyof typeof DashboardWidgetChartType];
export type Account = {
diff --git a/packages/shared/prisma/migrations/20250520123737_add_single_aggregate_chart_type/migration.sql b/packages/shared/prisma/migrations/20250520123737_add_single_aggregate_chart_type/migration.sql
new file mode 100644
index 0000000000..40b472d87f
--- /dev/null
+++ b/packages/shared/prisma/migrations/20250520123737_add_single_aggregate_chart_type/migration.sql
@@ -0,0 +1,2 @@
+-- AlterEnum
+ALTER TYPE "DashboardWidgetChartType" ADD VALUE 'NUMBER';
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index c1e5ac63c1..3e4e0d6925 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -1127,6 +1127,7 @@ enum DashboardWidgetChartType {
HORIZONTAL_BAR
VERTICAL_BAR
PIE
+ NUMBER
}
model DashboardWidget {
diff --git a/packages/shared/src/server/services/DashboardService/types.ts b/packages/shared/src/server/services/DashboardService/types.ts
index 23dce06d33..3c1f8f3fce 100644
--- a/packages/shared/src/server/services/DashboardService/types.ts
+++ b/packages/shared/src/server/services/DashboardService/types.ts
@@ -24,6 +24,10 @@ export const PieChartConfig = BaseTotalValueChartConfig.extend({
type: z.literal("PIE"),
});
+export const BigNumberChartConfig = BaseTotalValueChartConfig.extend({
+ type: z.literal("NUMBER"),
+});
+
// Define dimension schema
export const DimensionSchema = z.object({
field: z.string(),
@@ -42,6 +46,7 @@ export const ChartConfigSchema = z.discriminatedUnion("type", [
HorizontalBarChartConfig,
VerticalBarChartConfig,
PieChartConfig,
+ BigNumberChartConfig,
]);
export const DashboardDefinitionWidgetWidgetSchema = z.object({
diff --git a/web/src/features/widgets/chart-library/BigNumber.tsx b/web/src/features/widgets/chart-library/BigNumber.tsx
new file mode 100644
index 0000000000..393463302e
--- /dev/null
+++ b/web/src/features/widgets/chart-library/BigNumber.tsx
@@ -0,0 +1,22 @@
+import { cn } from "@/src/utils/tailwind";
+
+export const BigNumber = ({
+ className,
+ metric,
+}: {
+ className?: string;
+ metric: React.ReactNode;
+}) => {
+ return (
+ <div
+ 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>
+ );
+};
diff --git a/web/src/features/widgets/chart-library/Chart.tsx b/web/src/features/widgets/chart-library/Chart.tsx
index 1362e95335..f973a80826 100644
--- a/web/src/features/widgets/chart-library/Chart.tsx
+++ b/web/src/features/widgets/chart-library/Chart.tsx
@@ -9,6 +9,7 @@ import PieChart from "@/src/features/widgets/chart-library/PieChart";
import { type DashboardWidgetChartType } from "@langfuse/shared/src/db";
import { Button } from "@/src/components/ui/button";
import { AlertCircle } from "lucide-react";
+import { BigNumber } from "@/src/features/widgets/chart-library/BigNumber";
export const Chart = ({
chartType,
@@ -51,6 +52,14 @@ export const Chart = ({
return <VerticalBarChart data={renderedData.slice(0, rowLimit)} />;
case "PIE":
return <PieChart data={renderedData.slice(0, rowLimit)} />;
+ case "NUMBER": {
+ // Show the sum of all metrics, or just the first metric if only one
+ const value =
+ renderedData.length === 1
+ ? renderedData[0].metric
+ : renderedData.reduce((acc, d) => acc + (d.metric || 0), 0);
+ return <BigNumber metric={value} />;
+ }
default:
return <HorizontalBarChart data={renderedData.slice(0, rowLimit)} />;
}
diff --git a/web/src/features/widgets/components/WidgetForm.tsx b/web/src/features/widgets/components/WidgetForm.tsx
index 030b7b214f..4b17f79586 100644
--- a/web/src/features/widgets/components/WidgetForm.tsx
+++ b/web/src/features/widgets/components/WidgetForm.tsx
@@ -45,12 +45,66 @@ import {
PieChart,
LineChart,
BarChartHorizontal,
+ Hash,
} from "lucide-react";
import {
buildWidgetName,
buildWidgetDescription,
} from "@/src/features/widgets/utils";
+type ChartType = {
+ group: "time-series" | "total-value";
+ name: string;
+ value: DashboardWidgetChartType;
+ icon: React.ElementType;
+ supportsBreakdown: boolean;
+};
+
+const chartTypes: ChartType[] = [
+ {
+ group: "total-value",
+ name: "Big Number",
+ value: "NUMBER",
+ icon: Hash,
+ supportsBreakdown: false,
+ },
+ {
+ group: "time-series",
+ name: "Line Chart",
+ value: "LINE_TIME_SERIES",
+ icon: LineChart,
+ supportsBreakdown: true,
+ },
+ {
+ group: "time-series",
+ name: "Vertical Bar Chart",
+ value: "BAR_TIME_SERIES",
+ icon: BarChart,
+ supportsBreakdown: true,
+ },
+ {
+ group: "total-value",
+ name: "Horizontal Bar Chart",
+ value: "HORIZONTAL_BAR",
+ icon: BarChartHorizontal,
+ supportsBreakdown: true,
+ },
+ {
+ group: "total-value",
+ name: "Vertical Bar Chart",
+ value: "VERTICAL_BAR",
+ icon: BarChart,
+ supportsBreakdown: true,
+ },
+ {
+ group: "total-value",
+ name: "Pie Chart",
+ value: "PIE",
+ icon: PieChart,
+ supportsBreakdown: true,
+ },
+];
+
export function WidgetForm({
initialValues,
projectId,
@@ -226,51 +280,23 @@ export function WidgetForm({
},
];
- // Chart type options
- type ChartType = {
- group: "time-series" | "total-value";
- name: string;
- value: DashboardWidgetChartType;
- icon: React.ElementType;
- };
-
- const chartTypes: ChartType[] = useMemo(
- () => [
- {
- group: "time-series",
- name: "Line Chart",
- value: "LINE_TIME_SERIES",
- icon: LineChart,
- },
- {
- group: "time-series",
- name: "Vertical Bar Chart",
- value: "BAR_TIME_SERIES",
- icon: BarChart,
- },
- {
- group: "total-value",
- name: "Horizontal Bar Chart",
- value: "HORIZONTAL_BAR",
- icon: BarChartHorizontal,
- },
- {
- group: "total-value",
- name: "Vertical Bar Chart",
- value: "VERTICAL_BAR",
- icon: BarChart,
- },
- { group: "total-value", name: "Pie Chart", value: "PIE", icon: PieChart },
- ],
- [],
- );
+ // When chart type does not support breakdown, wipe the breakdown dimension
+ useEffect(() => {
+ if (
+ chartTypes.find((c) => c.value === selectedChartType)
+ ?.supportsBreakdown === false &&
+ selectedDimension !== "none"
+ ) {
+ setSelectedDimension("none");
+ }
+ }, [selectedChartType, selectedDimension]);
// Set aggregation to "count" when metric is "count"
useEffect(() => {
- if (selectedMeasure === "count") {
+ if (selectedMeasure === "count" && selectedAggregation !== "count") {
setSelectedAggregation("count");
}
- }, [selectedMeasure]);
+ }, [selectedMeasure, selectedAggregation]);
// Get available metrics for the selected view
const availableMetrics = useMemo(() => {
@@ -554,38 +580,41 @@ export function WidgetForm({
</div>
{/* Dimension Selection (Breakdown) */}
- <div className="space-y-2">
- <Label htmlFor="dimension-select">
- Breakdown Dimension (Optional)
- </Label>
- <Select
- value={selectedDimension}
- onValueChange={setSelectedDimension}
- >
- <SelectTrigger id="dimension-select">
- <SelectValue placeholder="Select a dimension" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="none">None</SelectItem>
- {availableDimensions.map((dimension) => {
- const meta =
- viewDeclarations[selectedView]?.dimensions?.[
- dimension.value
- ];
- return (
- <WidgetPropertySelectItem
- key={dimension.value}
- value={dimension.value}
- label={dimension.label}
- description={meta?.description}
- unit={meta?.unit}
- type={meta?.type}
- />
- );
- })}
- </SelectContent>
- </Select>
- </div>
+ {chartTypes.find((c) => c.value === selectedChartType)
+ ?.supportsBreakdown && (
+ <div className="space-y-2">
+ <Label htmlFor="dimension-select">
+ Breakdown Dimension (Optional)
+ </Label>
+ <Select
+ value={selectedDimension}
+ onValueChange={setSelectedDimension}
+ >
+ <SelectTrigger id="dimension-select">
+ <SelectValue placeholder="Select a dimension" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="none">None</SelectItem>
+ {availableDimensions.map((dimension) => {
+ const meta =
+ viewDeclarations[selectedView]?.dimensions?.[
+ dimension.value
+ ];
+ return (
+ <WidgetPropertySelectItem
+ key={dimension.value}
+ value={dimension.value}
+ label={dimension.label}
+ description={meta?.description}
+ unit={meta?.unit}
+ type={meta?.type}
+ />
+ );
+ })}
+ </SelectContent>
+ </Select>
+ </div>
+ )}
</div>
{/* Visualization Section */}
@@ -638,7 +667,6 @@ export function WidgetForm({
.map((chart) => (
<SelectItem key={chart.value} value={chart.value}>
<div className="flex items-center">
- {" "}
{React.createElement(chart.icon, {
className: "mr-2 w-4",
})}
@@ -654,7 +682,6 @@ export function WidgetForm({
.map((chart) => (
<SelectItem key={chart.value} value={chart.value}>
<div className="flex items-center">
- {" "}
{React.createElement(chart.icon, {
className: "mr-2 w-4",
})}
@@ -677,30 +704,32 @@ export function WidgetForm({
/>
</div>
- {/* Row Limit Selection - Only shown for non-time series charts */}
- {!isTimeSeriesChart(
- selectedChartType as DashboardWidgetChartType,
- ) && (
- <div className="space-y-2">
- <Label htmlFor="row-limit">
- Breakdown Row Limit (0-1000)
- </Label>
- <Input
- id="row-limit"
- type="number"
- min={0}
- max={1000}
- value={rowLimit}
- onChange={(e) => {
- const value = parseInt(e.target.value);
- if (!isNaN(value) && value >= 0 && value <= 1000) {
- setRowLimit(value);
- }
- }}
- placeholder="Enter breakdown row limit (0-1000)"
- />
- </div>
- )}
+ {/* Row Limit Selection - Only shown for non-time series charts that support breakdown */}
+ {chartTypes.find((c) => c.value === selectedChartType)
+ ?.supportsBreakdown &&
+ !isTimeSeriesChart(
+ selectedChartType as DashboardWidgetChartType,
+ ) && (
+ <div className="space-y-2">
+ <Label htmlFor="row-limit">
+ Breakdown Row Limit (0-1000)
+ </Label>
+ <Input
+ id="row-limit"
+ type="number"
+ min={0}
+ max={1000}
+ value={rowLimit}
+ onChange={(e) => {
+ const value = parseInt(e.target.value);
+ if (!isNaN(value) && value >= 0 && value <= 1000) {
+ setRowLimit(value);
+ }
+ }}
+ placeholder="Enter breakdown row limit (0-1000)"
+ />
+ </div>
+ )}
</div>
</CardContent>
<CardFooter className="mt-auto">