dashboard opt
This commit is contained in:
@@ -31,6 +31,16 @@ export function InlineVisualizationCard({ viz }: InlineVisualizationCardProps) {
|
|||||||
const columns = objectRows.length > 0 ? Object.keys(objectRows[0]) : [];
|
const columns = objectRows.length > 0 ? Object.keys(objectRows[0]) : [];
|
||||||
|
|
||||||
const buildPendingChart = (): Omit<ChartConfig, 'layout'> => {
|
const buildPendingChart = (): Omit<ChartConfig, 'layout'> => {
|
||||||
|
if (view === "table") {
|
||||||
|
return {
|
||||||
|
id: Date.now().toString(),
|
||||||
|
title: viz.chartSpec?.title || "Generated Analysis",
|
||||||
|
type: "table",
|
||||||
|
data: objectRows,
|
||||||
|
sql: viz.sql,
|
||||||
|
chartSpec: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
const mark = viz.chartSpec?.mark;
|
const mark = viz.chartSpec?.mark;
|
||||||
const markType = typeof mark === "string" ? mark : mark?.type;
|
const markType = typeof mark === "string" ? mark : mark?.type;
|
||||||
const dashboardType = markType === "line" ? "line" : "bar";
|
const dashboardType = markType === "line" ? "line" : "bar";
|
||||||
|
|||||||
@@ -20,6 +20,16 @@ export function VisualizationPanel() {
|
|||||||
|
|
||||||
const buildPendingChart = (): Omit<ChartConfig, 'layout'> | null => {
|
const buildPendingChart = (): Omit<ChartConfig, 'layout'> | null => {
|
||||||
if (!currentData || !currentSQL) return null;
|
if (!currentData || !currentSQL) return null;
|
||||||
|
if (view === "table") {
|
||||||
|
return {
|
||||||
|
id: Date.now().toString(),
|
||||||
|
title: currentChartSpec?.title || 'Generated Analysis',
|
||||||
|
type: "table",
|
||||||
|
data: currentData,
|
||||||
|
sql: currentSQL,
|
||||||
|
chartSpec: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
const mark = currentChartSpec?.mark;
|
const mark = currentChartSpec?.mark;
|
||||||
const markType = typeof mark === "string" ? mark : mark?.type;
|
const markType = typeof mark === "string" ? mark : mark?.type;
|
||||||
const dashboardType = markType === "line" ? "line" : "bar";
|
const dashboardType = markType === "line" ? "line" : "bar";
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { useDashboardStore } from '../store/dashboardStore';
|
|||||||
import { useProjectStore } from '../store/projectStore';
|
import { useProjectStore } from '../store/projectStore';
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||||
import { X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, LineChart, Line } from 'recharts';
|
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, LineChart, Line } from 'recharts';
|
||||||
import { VegaChart } from "@/components/VegaChart";
|
import { VegaChart } from "@/components/VegaChart";
|
||||||
@@ -11,6 +13,7 @@ import 'react-grid-layout/css/styles.css';
|
|||||||
import 'react-resizable/css/styles.css';
|
import 'react-resizable/css/styles.css';
|
||||||
|
|
||||||
const CHART_COLORS = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#06b6d4'];
|
const CHART_COLORS = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#06b6d4'];
|
||||||
|
const TABLE_PREVIEW_LIMIT = 20;
|
||||||
|
|
||||||
function isNumericValue(value: unknown) {
|
function isNumericValue(value: unknown) {
|
||||||
if (typeof value === 'number') return Number.isFinite(value);
|
if (typeof value === 'number') return Number.isFinite(value);
|
||||||
@@ -103,13 +106,22 @@ export function Dashboard() {
|
|||||||
isDraggable
|
isDraggable
|
||||||
isResizable
|
isResizable
|
||||||
>
|
>
|
||||||
{charts.map((chart) => (
|
{charts.map((chart) => {
|
||||||
|
const rows = chart.data as Record<string, unknown>[];
|
||||||
|
const columns = Object.keys(rows[0] || {});
|
||||||
|
const previewRows = chart.type === "table" ? rows.slice(0, TABLE_PREVIEW_LIMIT) : rows;
|
||||||
|
const isTableTruncated = chart.type === "table" && rows.length > TABLE_PREVIEW_LIMIT;
|
||||||
|
return (
|
||||||
<div key={chart.id} className="relative group">
|
<div key={chart.id} className="relative group">
|
||||||
<Card className="h-full flex flex-col shadow-sm border-muted">
|
<Card className="h-full flex flex-col shadow-sm border-muted">
|
||||||
<CardHeader className="pb-2 shrink-0 flex flex-row items-center justify-between space-y-0">
|
<CardHeader className="pb-2 shrink-0 flex flex-row items-center justify-between space-y-0">
|
||||||
<div>
|
<div>
|
||||||
<CardTitle className="text-base">{chart.title}</CardTitle>
|
<CardTitle className="text-base">{chart.title}</CardTitle>
|
||||||
<CardDescription className="text-xs">{chart.type.toUpperCase()} Chart</CardDescription>
|
<CardDescription className="text-xs">
|
||||||
|
{chart.type === "table"
|
||||||
|
? `TABLE · ${rows.length} 行 · ${columns.length} 列`
|
||||||
|
: `${chart.type.toUpperCase()} Chart`}
|
||||||
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -122,7 +134,47 @@ export function Dashboard() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex-1 min-h-0 p-2">
|
<CardContent className="flex-1 min-h-0 p-2">
|
||||||
{(() => {
|
{(() => {
|
||||||
const rows = chart.data as Record<string, unknown>[];
|
if (chart.type === "table") {
|
||||||
|
if (rows.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="h-full w-full flex items-center justify-center text-xs text-zinc-500">
|
||||||
|
当前表格没有可展示数据
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (columns.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="h-full w-full flex items-center justify-center text-xs text-zinc-500">
|
||||||
|
当前表格数据缺少可展示字段
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="h-full w-full flex flex-col gap-2">
|
||||||
|
<div className="text-[11px] text-zinc-500 px-1">
|
||||||
|
{isTableTruncated ? `预览前 ${TABLE_PREVIEW_LIMIT} 行 / 共 ${rows.length} 行,${columns.length} 列` : `共 ${rows.length} 行,${columns.length} 列`}
|
||||||
|
</div>
|
||||||
|
<ScrollArea className="flex-1 w-full border rounded-md">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
{columns.map((col) => <TableHead key={col}>{col}</TableHead>)}
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{previewRows.map((row, i) => (
|
||||||
|
<TableRow key={i}>
|
||||||
|
{columns.map((col) => (
|
||||||
|
<TableCell key={`${i}-${col}`}>{String(row[col] ?? "")}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</ScrollArea>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
if (chart.chartSpec && rows.length > 0) {
|
if (chart.chartSpec && rows.length > 0) {
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full rounded-xl border border-zinc-100 p-2">
|
<div className="h-full w-full rounded-xl border border-zinc-100 p-2">
|
||||||
@@ -172,7 +224,7 @@ export function Dashboard() {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
))}
|
)})}
|
||||||
</ResponsiveGridLayout>
|
</ResponsiveGridLayout>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ type GridLayout = { i: string; x: number; y: number; w: number; h: number };
|
|||||||
export interface ChartConfig {
|
export interface ChartConfig {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
type: 'bar' | 'line';
|
type: 'bar' | 'line' | 'table';
|
||||||
data: ChartRow[];
|
data: ChartRow[];
|
||||||
sql: string;
|
sql: string;
|
||||||
chartSpec?: ChartSpec | null;
|
chartSpec?: ChartSpec | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user