feat: redesign analytics exif page with sectioned layout and bar charts

Reorganize the exif analytics page into labeled sections (Camera & Gear,
Location, Technical, Storage) with icon headers. Replace donut charts
with horizontal bar charts for multi-category EXIF distributions.
Improve heatmap with emerald color scale, day labels, and legend.
Add polished stat cards with icons and skeleton loading states.
This commit is contained in:
Varun committed 2026-04-07 22:55:07 +05:30
1 parent 6dff749479
commit 2ff863b296
7 files changed
+474 -172

No files matched your search

@@ -26,14 +26,14 @@ export default function AlbumPhotosChart() {
return (
<Card
title="Album Distribution"
description="Distribution of photos in and out of albums"
title="Album Coverage"
description="In albums vs unorganized"
>
<PieChart
data={chartData}
loading={loading}
<PieChart
data={chartData}
loading={loading}
errorMessage={errorMessage}
/>
/>
</Card>
);
}
+88 -60
View File
@@ -8,12 +8,23 @@ type HeatMapEntry = {
count: number;
};
const COLOR_SCALE = [
"bg-zinc-100 dark:bg-zinc-800/60",
"bg-emerald-200 dark:bg-emerald-900/70",
"bg-emerald-300 dark:bg-emerald-800/80",
"bg-emerald-400 dark:bg-emerald-700",
"bg-emerald-500 dark:bg-emerald-600",
"bg-emerald-600 dark:bg-emerald-500",
];
const LEGEND_LABELS = ["None", "", "", "", "", "Max"];
export default function AssetHeatMap() {
const { exImmichUrl } = useConfig();
const [heatMapData, setHeatMapData] = useState<HeatMapEntry[][]>([]);
const [loading, setLoading] = useState(false);
const [weeksPerMonth, setWeeksPerMonth] = useState<number[]>([]); // Store weeks per month
const [weeksPerMonth, setWeeksPerMonth] = useState<number[]>([]);
const fetchHeatMapData = async () => {
setLoading(true);
@@ -32,38 +43,35 @@ export default function AssetHeatMap() {
const currentDate = new Date();
const months: string[] = [];
// Build an array of the last 12 months
for (let i = 0; i < 12; i++) {
months.push(currentDate.toLocaleString("default", { month: "short" }));
currentDate.setMonth(currentDate.getMonth() - 1);
}
months.reverse();
// Flatten heatMapData to calculate min and max counts
const flattenedData = heatMapData.flat();
const minCount = Math.min(...flattenedData.map((entry) => entry.count));
const maxCount = Math.max(...flattenedData.map((entry) => entry.count));
// Check if a week contains a date with the first day of the month
const hasFirstDayOfMonth = (arr: HeatMapEntry[]) => {
return arr.some((entry) => new Date(entry.date).getDate() === 1);
};
const getColor = (count: number) => {
if (count === -1) return "";
if (count === 0) return COLOR_SCALE[0];
// Calculate thresholds based on the data range
const range = maxCount - minCount;
const threshold1 = minCount + range * 0.2;
const threshold2 = minCount + range * 0.4;
const threshold3 = minCount + range * 0.6;
const threshold4 = minCount + range * 0.8;
if (count === 0) return "bg-zinc-200 dark:bg-zinc-800";
if (count <= threshold1) return "bg-green-200";
if (count <= threshold2) return "bg-green-400";
if (count <= threshold3) return "bg-green-500";
if (count <= threshold4) return "bg-green-600";
return "bg-green-800";
if (count <= threshold1) return COLOR_SCALE[1];
if (count <= threshold2) return COLOR_SCALE[2];
if (count <= threshold3) return COLOR_SCALE[3];
if (count <= threshold4) return COLOR_SCALE[4];
return COLOR_SCALE[5];
};
const formatHeatMapData = (data: HeatMapEntry[]) => {
@@ -86,60 +94,80 @@ export default function AssetHeatMap() {
return chunks;
};
const dayLabels = ["", "Mon", "", "Wed", "", "Fri", ""];
if (loading) {
return (
<div className="flex items-center justify-center h-32">
<div className="h-5 w-5 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent" />
</div>
);
}
return (
<div className="py-4 w-full">
<h2 className="text-xl font-bold mb-4">Past Year</h2>
{loading ? (
<p>Loading...</p>
) : (
<div className="overflow-x-auto">
<table className="table-auto border-separate border-spacing-1 w-full">
<thead>
<tr>
{weeksPerMonth.map((weeks, index) => (
<th
key={index}
className="text-center"
colSpan={weeks || 4}
<div className="w-full">
<div className="overflow-x-auto">
<table className="table-auto border-separate border-spacing-[3px]">
<thead>
<tr>
<th className="w-8" />
{weeksPerMonth.map((weeks, index) => (
<th
key={index}
className="text-xs font-medium text-muted-foreground pb-1"
colSpan={weeks || 4}
>
{months[index]}
</th>
))}
</tr>
</thead>
<tbody>
{heatMapData[0]?.map((_, rowIndex) => (
<tr key={rowIndex}>
<td className="text-[10px] text-muted-foreground pr-2 text-right w-8 select-none">
{dayLabels[rowIndex]}
</td>
{heatMapData.map((column, colIndex) => (
<td
key={colIndex}
className={`h-[14px] w-[14px] ${getColor(column[rowIndex]?.count ?? -1)} rounded-sm transition-colors`}
>
{months[index]}
</th>
{column[rowIndex]?.date ? (
<Tooltip
delayDuration={0}
content={`${column[rowIndex]?.count ?? 0} photos on ${column[rowIndex]?.date}`}
>
<a
href={`${exImmichUrl}/search?query=%7B%22takenAfter%22%3A%22${column[rowIndex]?.date ?? "N/A"}T00%3A00%3A00.000Z%22%2C%22takenBefore%22%3A%22${column[rowIndex]?.date ?? "N/A"}T23%3A59%3A59.999Z%22%7D`}
className="block h-[14px] w-[14px] rounded-sm hover:ring-2 hover:ring-foreground/20 transition-shadow"
target="_blank"
>
<div className="h-[14px] w-[14px]" />
</a>
</Tooltip>
) : (
<div className="h-[14px] w-[14px]" />
)}
</td>
))}
</tr>
</thead>
<tbody>
{heatMapData[0]?.map((_, rowIndex) => (
<tr key={rowIndex}>
{heatMapData.map((column, colIndex) => (
<td
key={colIndex}
className={`h-[20px] w-[20px] ${getColor(column[rowIndex]?.count ?? -1)} rounded`}
// style={{ width: `calc(${100 / 60}%)` }}
>
{
column[rowIndex]?.date ? (
<Tooltip delayDuration={0} content={`Date: ${column[rowIndex]?.date ?? "N/A"} - Count: ${column[rowIndex]?.count ?? 0}`}>
<a
href={`${exImmichUrl}/search?query=%7B%22takenAfter%22%3A%22${column[rowIndex]?.date ?? "N/A"}T00%3A00%3A00.000Z%22%2C%22takenBefore%22%3A%22${column[rowIndex]?.date ?? "N/A"}T23%3A59%3A59.999Z%22%7D`}
className="block h-[20px] max-w-[20px]"
target="_blank"
>
<div
className="h-[20px] max-w-[20px]"
/>
</a></Tooltip>) : <div
className="h-[20px] max-w-[20px]"
/>
))}
</tbody>
</table>
</div>
}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
)}
{/* Legend */}
<div className="flex items-center justify-end gap-1.5 mt-3 text-[10px] text-muted-foreground select-none">
<span>Less</span>
{COLOR_SCALE.map((color, i) => (
<div
key={i}
className={`h-[12px] w-[12px] rounded-sm ${color}`}
/>
))}
<span>More</span>
</div>
</div>
);
}
@@ -1,5 +1,6 @@
import { Card } from "@/components/ui/card";
import PieChart, { IPieChartData } from "@/components/ui/pie-chart";
import HorizontalBarChart from "@/components/ui/horizontal-bar-chart";
import { IBarChartData } from "@/components/ui/horizontal-bar-chart";
import { getExifDistribution, ISupportedEXIFColumns } from "@/handlers/api/analytics.handler";
import React, { useEffect, useState } from "react";
import { ValueType } from "recharts/types/component/DefaultTooltipContent";
@@ -14,14 +15,20 @@ export interface IEXIFDistributionProps {
export default function EXIFDistribution(
{ column, title, description, tooltipValueFormatter }: IEXIFDistributionProps
) {
const [chartData, setChartData] = useState<IPieChartData[]>([]);
const [loading, setLoading] = useState(false);
const [chartData, setChartData] = useState<IBarChartData[]>([]);
const [loading, setLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const fetchData = async () => {
return getExifDistribution(column)
.then(setChartData)
.finally(() => setLoading(false));
setLoading(true);
try {
const data = await getExifDistribution(column);
setChartData(data);
} catch (error: any) {
setErrorMessage(error?.message || "Failed to load data");
} finally {
setLoading(false);
}
};
useEffect(() => {
@@ -29,11 +36,13 @@ export default function EXIFDistribution(
}, [column]);
return (
<Card
title={title}
description={description}
>
<PieChart data={chartData} loading={loading} errorMessage={errorMessage} tooltipValueFormatter={tooltipValueFormatter} />
<Card title={title} description={description}>
<HorizontalBarChart
data={chartData}
loading={loading}
errorMessage={errorMessage}
tooltipValueFormatter={tooltipValueFormatter}
/>
</Card>
);
}
@@ -27,13 +27,13 @@ export default function GeoPhotosChart() {
return (
<Card
title="Geo Data"
description="Distribution of photos with and without geo data"
description="Photos with vs without location"
>
<PieChart
data={chartData}
loading={loading}
<PieChart
data={chartData}
loading={loading}
errorMessage={errorMessage}
/>
/>
</Card>
);
}
@@ -27,13 +27,13 @@ export default function PeopleNamesChart() {
return (
<Card
title="People Names"
description="Distribution of people with and without names"
description="Named vs unnamed people"
>
<PieChart
data={chartData}
loading={loading}
<PieChart
data={chartData}
loading={loading}
errorMessage={errorMessage}
/>
/>
</Card>
);
}
+101
View File
@@ -0,0 +1,101 @@
import { CHART_COLORS } from "@/config/constants/chart.constant";
import React, { useMemo } from "react";
import {
Bar,
BarChart,
XAxis,
YAxis,
Tooltip,
ResponsiveContainer,
Cell,
} from "recharts";
import { ValueType } from "recharts/types/component/DefaultTooltipContent";
export interface IBarChartData {
label: string;
value: number;
valueLabel?: string;
}
interface HorizontalBarChartProps {
data: IBarChartData[];
loading?: boolean;
errorMessage?: string | null;
tooltipValueFormatter?: (value: number | string | undefined | ValueType) => string;
maxItems?: number;
}
export default function HorizontalBarChart({
data: _data,
loading,
errorMessage,
tooltipValueFormatter,
maxItems = 10,
}: HorizontalBarChartProps) {
const data = useMemo(() => {
return _data.slice(0, maxItems).map((item, index) => ({
...item,
fill: CHART_COLORS[index % CHART_COLORS.length],
}));
}, [_data, maxItems]);
const total = useMemo(() => data.reduce((sum, d) => sum + d.value, 0), [data]);
if (loading) {
return (
<div className="flex items-center justify-center h-[200px]">
<div className="h-5 w-5 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent" />
</div>
);
}
if (errorMessage) {
return (
<div className="flex items-center justify-center h-[200px] text-sm text-muted-foreground">
{errorMessage}
</div>
);
}
if (!data.length) {
return (
<div className="flex items-center justify-center h-[200px] text-sm text-muted-foreground">
No data available
</div>
);
}
return (
<div className="space-y-2">
{data.map((item, index) => {
const percentage = total > 0 ? (item.value / total) * 100 : 0;
const displayValue = tooltipValueFormatter
? tooltipValueFormatter(item.value)
: item.valueLabel || item.value.toLocaleString();
return (
<div key={item.label} className="group">
<div className="flex items-center justify-between text-sm mb-1">
<span className="text-foreground truncate max-w-[60%]" title={item.label}>
{item.label}
</span>
<span className="text-muted-foreground tabular-nums font-mono text-xs">
{displayValue}
</span>
</div>
<div className="h-2 w-full rounded-full bg-muted overflow-hidden">
<div
className="h-full rounded-full transition-all duration-500 ease-out"
style={{
width: `${Math.max(percentage, 1)}%`,
backgroundColor: CHART_COLORS[index % CHART_COLORS.length],
opacity: 0.85,
}}
/>
</div>
</div>
);
})}
</div>
);
}
+249 -85
View File
@@ -1,4 +1,3 @@
import { Inter } from "next/font/google";
import PageLayout from "@/components/layouts/PageLayout";
import Header from "@/components/shared/Header";
import EXIFDistribution, {
@@ -7,8 +6,6 @@ import EXIFDistribution, {
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import AssetHeatMap from "@/components/analytics/exif/AssetHeatMap";
import PeopleNamesChart from "@/components/analytics/exif/PeopleNamesChart";
@@ -17,66 +14,138 @@ import AlbumPhotosChart from "@/components/analytics/exif/AlbumPhotosChart";
import { useEffect, useState } from "react";
import { getAssetStatistics, getLivePhotoStatistics } from "@/handlers/api/analytics.handler";
import { humanizeBytes } from "@/helpers/string.helper";
import {
Camera,
Image,
Video,
Aperture,
MapPin,
SlidersHorizontal,
BarChart3,
Users,
Globe,
FolderOpen,
} from "lucide-react";
const exifCharts: IEXIFDistributionProps[] = [
{
column: "storage",
title: "Storage",
description: "Distribution of storage",
tooltipValueFormatter: (value) => humanizeBytes(value as number * 1000000),
},
const cameraCharts: IEXIFDistributionProps[] = [
{
column: "make",
title: "Make",
description: "Distribution of camera make",
description: "Camera manufacturer breakdown",
},
{
column: "model",
title: "Model",
description: "Distribution of camera model",
},
{
column: "focal-length",
title: "Focal Length",
description: "Distribution of focal length",
},
{
column: "city",
title: "City",
description: "Distribution of city",
},
{
column: "state",
title: "State",
description: "Distribution of state",
},
{
column: "country",
title: "Country",
description: "Distribution of country",
},
{
column: "iso",
title: "ISO",
description: "Distribution of ISO",
},
{
column: "exposureTime",
title: "Exposure Time",
description: "Distribution of exposure time",
description: "Camera model breakdown",
},
{
column: "lensModel",
title: "Lens Model",
description: "Distribution of lens model",
description: "Lens usage across your library",
},
];
const locationCharts: IEXIFDistributionProps[] = [
{
column: "city",
title: "City",
description: "Top cities by photo count",
},
{
column: "state",
title: "State",
description: "Top states by photo count",
},
{
column: "country",
title: "Country",
description: "Top countries by photo count",
},
];
const technicalCharts: IEXIFDistributionProps[] = [
{
column: "focal-length",
title: "Focal Length",
description: "Focal length distribution",
},
{
column: "iso",
title: "ISO",
description: "ISO sensitivity distribution",
},
{
column: "exposureTime",
title: "Exposure Time",
description: "Shutter speed distribution",
},
{
column: "projectionType",
title: "Projection Type",
description: "Distribution of projection type",
description: "Image projection types",
},
];
const storageChart: IEXIFDistributionProps = {
column: "storage",
title: "Storage",
description: "Storage usage by user",
tooltipValueFormatter: (value) => humanizeBytes(value as number * 1000000),
};
interface StatCardProps {
label: string;
value: number;
loading: boolean;
icon: React.ReactNode;
accent: string;
}
function StatCard({ label, value, loading, icon, accent }: StatCardProps) {
return (
<div className="group relative overflow-hidden rounded-xl border bg-card p-5 transition-all duration-300 hover:shadow-md">
<div className={`absolute inset-0 opacity-[0.03] ${accent}`} />
<div className="relative flex items-center justify-between">
<div className="space-y-1">
<p className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
{label}
</p>
<p className="text-2xl font-bold tabular-nums tracking-tight">
{loading ? (
<span className="inline-block h-8 w-20 animate-pulse rounded bg-muted" />
) : (
value.toLocaleString()
)}
</p>
</div>
<div className={`rounded-lg p-2.5 ${accent} bg-opacity-10 text-opacity-80`}>
{icon}
</div>
</div>
</div>
);
}
interface SectionHeaderProps {
icon: React.ReactNode;
title: string;
description: string;
}
function SectionHeader({ icon, title, description }: SectionHeaderProps) {
return (
<div className="flex items-center gap-3 mb-4 mt-2">
<div className="flex items-center justify-center rounded-lg bg-muted p-2 text-muted-foreground">
{icon}
</div>
<div>
<h2 className="text-lg font-semibold tracking-tight">{title}</h2>
<p className="text-sm text-muted-foreground">{description}</p>
</div>
</div>
);
}
export default function ExifDataAnalytics() {
const [statistics, setStatistics] = useState({ images: 0, videos: 0, total: 0 });
const [loading, setLoading] = useState(false);
@@ -110,49 +179,144 @@ export default function ExifDataAnalytics() {
return (
<PageLayout className="!p-0 !mb-0 relative">
<Header leftComponent="Exif Data" />
<div className="p-4">
<div className="grid grid-cols-4 gap-4">
{["Total", "Images", "Videos"].map((type, i) => (
<Card key={i}>
<CardHeader>
<CardTitle className="text-center text-lg font-mono">{type}</CardTitle>
</CardHeader>
<CardContent className="text-center text-3xl font-mono">
{loading ? "Loading..." : statistics[type.toLowerCase() as keyof typeof statistics].toLocaleString()}
</CardContent>
</Card>
))}
<Card>
<CardHeader>
<CardTitle className="text-center text-lg font-mono">Live Photos</CardTitle>
</CardHeader>
<CardContent className="text-center text-3xl font-mono">
{loading ? "Loading..." : livePhotoStatistics.total.toLocaleString()}
<Header leftComponent="Analytics" />
<div className="p-5 space-y-8">
{/* ── Stats ── */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<StatCard
label="Total Assets"
value={statistics.total}
loading={loading}
icon={<BarChart3 className="h-5 w-5" />}
accent="bg-blue-500 text-blue-600"
/>
<StatCard
label="Images"
value={statistics.images}
loading={loading}
icon={<Image className="h-5 w-5" />}
accent="bg-emerald-500 text-emerald-600"
/>
<StatCard
label="Videos"
value={statistics.videos}
loading={loading}
icon={<Video className="h-5 w-5" />}
accent="bg-orange-500 text-orange-600"
/>
<StatCard
label="Live Photos"
value={livePhotoStatistics.total}
loading={loading}
icon={<Aperture className="h-5 w-5" />}
accent="bg-violet-500 text-violet-600"
/>
</div>
{/* ── Activity Heatmap ── */}
<section>
<SectionHeader
icon={<BarChart3 className="h-4 w-4" />}
title="Activity"
description="Photo capture frequency over the past year"
/>
<Card className="overflow-hidden">
<CardContent className="p-4">
<AssetHeatMap />
</CardContent>
</Card>
</div>
<AssetHeatMap />
{/* New Analytics Charts */}
<div className="grid grid-cols-3 gap-4 mb-6">
<PeopleNamesChart />
<GeoPhotosChart />
<AlbumPhotosChart />
</div>
<div className="grid grid-cols-3 gap-4">
{exifCharts.map((chart) => (
<EXIFDistribution
key={chart.column}
column={chart.column}
title={chart.title}
description={chart.description}
tooltipValueFormatter={chart.tooltipValueFormatter}
/>
))}
</section>
</div>
{/* ── Library Overview ── */}
<section>
<SectionHeader
icon={<SlidersHorizontal className="h-4 w-4" />}
title="Library Overview"
description="High-level stats about your photo library"
/>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<PeopleNamesChart />
<GeoPhotosChart />
<AlbumPhotosChart />
</div>
</section>
{/* ── Storage ── */}
<section>
<SectionHeader
icon={<FolderOpen className="h-4 w-4" />}
title="Storage"
description="Disk usage breakdown across users"
/>
<div className="max-w-md">
<EXIFDistribution
column={storageChart.column}
title={storageChart.title}
description={storageChart.description}
tooltipValueFormatter={storageChart.tooltipValueFormatter}
/>
</div>
</section>
{/* ── Camera & Gear ── */}
<section>
<SectionHeader
icon={<Camera className="h-4 w-4" />}
title="Camera & Gear"
description="Equipment used across your photo library"
/>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
{cameraCharts.map((chart) => (
<EXIFDistribution
key={chart.column}
column={chart.column}
title={chart.title}
description={chart.description}
tooltipValueFormatter={chart.tooltipValueFormatter}
/>
))}
</div>
</section>
{/* ── Location ── */}
<section>
<SectionHeader
icon={<MapPin className="h-4 w-4" />}
title="Location"
description="Where your photos were taken"
/>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
{locationCharts.map((chart) => (
<EXIFDistribution
key={chart.column}
column={chart.column}
title={chart.title}
description={chart.description}
tooltipValueFormatter={chart.tooltipValueFormatter}
/>
))}
</div>
</section>
{/* ── Technical ── */}
<section>
<SectionHeader
icon={<SlidersHorizontal className="h-4 w-4" />}
title="Technical"
description="Camera settings and exposure data"
/>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
{technicalCharts.map((chart) => (
<EXIFDistribution
key={chart.column}
column={chart.column}
title={chart.title}
description={chart.description}
tooltipValueFormatter={chart.tooltipValueFormatter}
/>
))}
</div>
</section>
</div>
</PageLayout>
);