Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

2.6 KB
Raw Blame
"use client";

import { PieChart as PieChartIcon } from "lucide-react";
import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer } from "recharts";
import { EmptyState } from "../shared/empty-state";
import { commitCategoryColor } from "../shared/series";

interface CommitCategoryDonutProps {
  categories: Record<string, number>;
}

const CATEGORY_ORDER = ["feature", "fix", "refactor", "dependency"];

export function CommitCategoryDonut({ categories }: CommitCategoryDonutProps) {
  const data = CATEGORY_ORDER.map((key) => ({
    name: key.charAt(0).toUpperCase() + key.slice(1),
    value: categories[key] || 0,
    key,
  })).filter((d) => d.value > 0);

  const total = data.reduce((sum, d) => sum + d.value, 0);
  if (total === 0) {
    return (
      <EmptyState
        icon={<PieChartIcon className="h-8 w-8" />}
        title="No commit data"
        description="No commit category data is available for this repository."
      />
    );
  }

  const dominant = data.reduce((a, b) => (a.value >= b.value ? a : b));

  return (
    <div className="relative flex items-center justify-center">
      <ResponsiveContainer width={180} height={180}>
        <PieChart>
          <Pie
            data={data}
            cx="50%"
            cy="50%"
            innerRadius={50}
            outerRadius={75}
            paddingAngle={2}
            dataKey="value"
            startAngle={90}
            endAngle={-270}
          >
            {data.map((entry) => (
              <Cell
                key={entry.key}
                fill={commitCategoryColor(entry.key)}
                strokeWidth={0}
              />
            ))}
          </Pie>
          <Tooltip
            contentStyle={{
              background: "var(--color-bg-overlay)",
              border: "1px solid var(--color-border-default)",
              borderRadius: "6px",
              fontSize: "12px",
              color: "var(--color-text-primary)",
            }}
            formatter={(value, name) => {
              const n = typeof value === "number" ? value : 0;
              return [
                `${n} commits (${Math.round((n / total) * 100)}%)`,
                name,
              ];
            }}
          />
        </PieChart>
      </ResponsiveContainer>
      <div className="absolute flex flex-col items-center pointer-events-none">
        <span className="text-lg font-bold text-[var(--color-text-primary)] tabular-nums">
          {Math.round((dominant.value / total) * 100)}%
        </span>
        <span className="text-[10px] text-[var(--color-text-tertiary)] capitalize">
          {dominant.name}
        </span>
      </div>
    </div>
  );
}