Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat(jobs-activity): update JobsActivityCard to label slices directly on the chart and add arcLabelLines function
Khuram Niaz69901ed1993d
diff --git a/__tests__/JobsActivityCard.spec.tsx b/__tests__/JobsActivityCard.spec.tsxindex 2638363..cf2f7e1 100644--- a/__tests__/JobsActivityCard.spec.tsx+++ b/__tests__/JobsActivityCard.spec.tsx@@ -64,15 +64,13 @@ describe("JobsActivityCard", () => {expect(within(total).getByText("16 jobs")).toBeInTheDocument();});- it("lists every slice with its hours in the legend", () => {+ it("labels the slices on the chart instead of in a legend", () => {render(<JobsActivityCard data={data} />);- const legend = screen.getByTestId("jobs-activity-legend");-- expect(within(legend).getByText("Jobsync")).toBeInTheDocument();- expect(within(legend).getByText("28.1h")).toBeInTheDocument();- expect(within(legend).getByText("Other")).toBeInTheDocument();- expect(within(legend).getByText("17.5h")).toBeInTheDocument();+ expect(+ screen.queryByTestId("jobs-activity-legend"),+ ).not.toBeInTheDocument();+ expect(screen.getByTestId("donut")).toBeInTheDocument();});it("feeds the same slices to the donut", () => {diff --git a/__tests__/jobsActivityChart.spec.ts b/__tests__/jobsActivityChart.spec.tsindex 6c17842..1fb85e0 100644--- a/__tests__/jobsActivityChart.spec.ts+++ b/__tests__/jobsActivityChart.spec.ts@@ -1,5 +1,6 @@import {buildDonutSlices,+ arcLabelLines,OTHER_SLICE_ID,} from "@/components/dashboard/jobsActivityChart";@@ -76,3 +77,27 @@ describe("buildDonutSlices", () => {expect(buildDonutSlices([], 0, "light")).toEqual([]);});});++describe("arcLabelLines", () => {+ it("splits the name and the hours onto separate lines", () => {+ expect(+ arcLabelLines({+ id: "Jobsync",+ label: "Jobsync",+ value: 28.1,+ color: "#2a9d90",+ }),+ ).toEqual(["Jobsync", "28.1h"]);+ });++ it("trims a long activity name so it cannot run off the card", () => {+ expect(+ arcLabelLines({+ id: "x",+ label: "Interview Preparation Deep Dive",+ value: 4,+ color: "#2a9d90",+ }),+ ).toEqual(["Interview Prepa…", "4h"]);+ });+});diff --git a/src/components/dashboard/JobsActivityCard.tsx b/src/components/dashboard/JobsActivityCard.tsxindex 0710838..47482d8 100644--- a/src/components/dashboard/JobsActivityCard.tsx+++ b/src/components/dashboard/JobsActivityCard.tsx@@ -1,6 +1,7 @@"use client";-import { ResponsivePie } from "@nivo/pie";+import { PieSvgProps, ResponsivePie } from "@nivo/pie";+import { animated } from "@react-spring/web";import { useTheme } from "next-themes";import { TrendingDown, TrendingUp } from "lucide-react";import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";@@ -8,7 +9,12 @@ import { JobsActivitySummary } from "@/actions/dashboard.actions";import { usePersistedTabIndex } from "@/hooks/usePersistedTabIndex";import { APP_CONSTANTS } from "@/lib/constants";import { cn } from "@/lib/utils";-import { buildDonutSlices, OTHER_SLICE_ID } from "./jobsActivityChart";+import {+ ARC_LABEL_TEXT_COLOR,+ arcLabelLines,+ buildDonutSlices,+ DonutSlice,+} from "./jobsActivityChart";interface JobsActivityCardProps {data: {@@ -17,20 +23,52 @@ interface JobsActivityCardProps {}[];}+type ArcLinkLabelProps = Parameters<+ NonNullable<PieSvgProps<DonutSlice>["arcLinkLabelComponent"]>+>[0];++// nivo renders an arc link label as one <text>, so stacking the hours under+// the name needs a custom component rather than a label formatter.+function ArcLinkLabel({ datum, style }: ArcLinkLabelProps) {+ const [name, hours] = arcLabelLines(datum.data);++ return (+ <animated.g opacity={style.opacity}>+ <animated.path+ fill="none"+ stroke={style.linkColor}+ strokeWidth={style.thickness}+ d={style.path}+ />+ <animated.text+ transform={style.textPosition}+ textAnchor={style.textAnchor}+ dominantBaseline="central"+ fill={style.textColor}+ fontSize={11}+ >+ <tspan x={0} dy="-0.5em">+ {name}+ </tspan>+ <tspan x={0} dy="1.15em" fontWeight={600}>+ {hours}+ </tspan>+ </animated.text>+ </animated.g>+ );+}+export default function JobsActivityCard({ data }: JobsActivityCardProps) {const [activeIndex, selectTab] = usePersistedTabIndex(APP_CONSTANTS.DASHBOARD_JOBS_ACTIVITY_STORAGE_KEY,data.map((item) => item.label),);const { resolvedTheme } = useTheme();+ const theme = resolvedTheme === "light" ? "light" : "dark";const current = data[activeIndex];const { jobsApplied, jobsTrend, topActivities, otherHours, totalHours } =current.summary;- const slices = buildDonutSlices(- topActivities,- otherHours,- resolvedTheme === "light" ? "light" : "dark",- );+ const slices = buildDonutSlices(topActivities, otherHours, theme);return (<Card className="@lg:col-span-2">@@ -62,108 +100,80 @@ export default function JobsActivityCard({ data }: JobsActivityCardProps) {</div></div></CardHeader>- <CardContent className="@container/jobsactivity">- <div className="flex flex-col items-center gap-4 @sm/jobsactivity:flex-row @sm/jobsactivity:gap-6">- <div className="relative h-[148px] w-[148px] shrink-0">- {slices.length === 0 ? (- <div className="h-full w-full rounded-full border-[20px] border-muted" />- ) : (- <ResponsivePie- data={slices}- margin={{ top: 4, right: 4, bottom: 4, left: 4 }}- innerRadius={0.72}- padAngle={2}- cornerRadius={2}- activeOuterRadiusOffset={4}- colors={{ datum: "data.color" }}- borderWidth={0}- enableArcLabels={false}- enableArcLinkLabels={false}- theme={{- tooltip: {- container: { background: "#1e293b", color: "#fff" },- },- }}- tooltip={({ datum }) => (- <div- style={{- background: "#1e293b",- color: "#fff",- padding: "6px 12px",- borderRadius: "4px",- fontSize: "12px",- whiteSpace: "nowrap",- }}- >- <strong>{datum.data.label}</strong> — {datum.value}h- </div>- )}- />- )}- <div- className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-px text-center"- data-testid="jobs-activity-total"- >- <span className="text-xl font-bold leading-tight tabular-nums">- {totalHours}h- </span>- <span className="text-sm text-muted-foreground tabular-nums">- {jobsApplied} {jobsApplied === 1 ? "job" : "jobs"}- </span>- {jobsTrend !== 0 && (- <span- className={cn(- "flex items-center gap-0.5 text-[10px] tabular-nums",- jobsTrend > 0 ? "text-emerald-600" : "text-rose-600",- )}- >- {jobsTrend > 0 ? (- <TrendingUp className="h-3 w-3" />- ) : (- <TrendingDown className="h-3 w-3" />- )}- {Math.abs(jobsTrend)}%- </span>- )}- </div>- </div>-- <div- className="flex w-full min-w-0 flex-col gap-2.5"- data-testid="jobs-activity-legend"- >- {slices.length === 0 ? (- <p className="text-sm text-muted-foreground">+ <CardContent>+ <div className="relative h-[200px] w-full">+ {slices.length === 0 ? (+ <div className="flex h-full w-full items-center justify-center">+ <div className="h-[132px] w-[132px] rounded-full border-[18px] border-muted" />+ <p className="absolute inset-x-0 bottom-0 text-center text-sm text-muted-foreground">No activities recorded</p>- ) : (- slices.map((slice) => (+ </div>+ ) : (+ <ResponsivePie+ data={slices}+ margin={{ top: 26, right: 84, bottom: 26, left: 84 }}+ innerRadius={0.72}+ padAngle={2}+ cornerRadius={2}+ activeOuterRadiusOffset={4}+ colors={{ datum: "data.color" }}+ borderWidth={0}+ enableArcLabels={false}+ enableArcLinkLabels+ arcLinkLabelComponent={ArcLinkLabel}+ arcLinkLabelsThickness={2}+ arcLinkLabelsDiagonalLength={10}+ arcLinkLabelsStraightLength={12}+ arcLinkLabelsTextOffset={4}+ arcLinkLabelsColor={{ from: "data.color" }}+ arcLinkLabelsTextColor={ARC_LABEL_TEXT_COLOR[theme]}+ theme={{+ text: { fontSize: 11 },+ tooltip: {+ container: { background: "#1e293b", color: "#fff" },+ },+ }}+ tooltip={({ datum }) => (<div- key={slice.id}- className="flex min-w-0 items-center gap-2.5 text-sm"+ style={{+ background: "#1e293b",+ color: "#fff",+ padding: "6px 12px",+ borderRadius: "4px",+ fontSize: "12px",+ whiteSpace: "nowrap",+ }}>- <span- className="h-2.5 w-2.5 shrink-0 rounded-sm"- style={{ backgroundColor: slice.color }}- />- <span- className={cn(- "min-w-0 truncate",- slice.id === OTHER_SLICE_ID && "text-muted-foreground",- )}- >- {slice.label}- </span>- <span- className={cn(- "ml-auto shrink-0 font-semibold tabular-nums",- slice.id === OTHER_SLICE_ID && "text-muted-foreground",- )}- >- {slice.value}h- </span>+ <strong>{datum.data.label}</strong> — {datum.value}h</div>- ))+ )}+ />+ )}+ <div+ className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-px text-center"+ data-testid="jobs-activity-total"+ >+ <span className="text-xl font-bold leading-tight tabular-nums">+ {totalHours}h+ </span>+ <span className="text-sm text-muted-foreground tabular-nums">+ {jobsApplied} {jobsApplied === 1 ? "job" : "jobs"}+ </span>+ {jobsTrend !== 0 && (+ <span+ className={cn(+ "flex items-center gap-0.5 text-[10px] tabular-nums",+ jobsTrend > 0 ? "text-emerald-600" : "text-rose-600",+ )}+ >+ {jobsTrend > 0 ? (+ <TrendingUp className="h-3 w-3" />+ ) : (+ <TrendingDown className="h-3 w-3" />+ )}+ {Math.abs(jobsTrend)}%+ </span>)}</div></div>diff --git a/src/components/dashboard/jobsActivityChart.ts b/src/components/dashboard/jobsActivityChart.tsindex 11324ef..03be866 100644--- a/src/components/dashboard/jobsActivityChart.ts+++ b/src/components/dashboard/jobsActivityChart.ts@@ -46,3 +46,23 @@ export function buildDonutSlices(return slices;}++// Arc link label text, kept neutral rather than tinted from the slice so+// the grey "Other" hue never has to double as readable body text.+export const ARC_LABEL_TEXT_COLOR = {+ light: "#334155",+ dark: "#e2e8f0",+} as const;++const ARC_LABEL_MAX_CHARS = 16;++// The label renders as two lines, so the name is trimmed rather than left+// to run off the card edge.+export function arcLabelLines(slice: DonutSlice): [string, string] {+ const name =+ slice.label.length > ARC_LABEL_MAX_CHARS+ ? `${slice.label.slice(0, ARC_LABEL_MAX_CHARS - 1).trimEnd()}…`+ : slice.label;++ return [name, `${slice.value}h`];+}