From 2ff863b296a5957a3790c94298b2c9d811ee6a69 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 7 Apr 2026 22:55:07 +0530 Subject: [PATCH] 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. --- .../analytics/exif/AlbumPhotosChart.tsx | 12 +- .../analytics/exif/AssetHeatMap.tsx | 148 ++++---- .../analytics/exif/EXIFDistribution.tsx | 31 +- .../analytics/exif/GeoPhotosChart.tsx | 10 +- .../analytics/exif/PeopleNamesChart.tsx | 10 +- src/components/ui/horizontal-bar-chart.tsx | 101 ++++++ src/pages/analytics/exif.tsx | 334 +++++++++++++----- 7 files changed, 474 insertions(+), 172 deletions(-) create mode 100644 src/components/ui/horizontal-bar-chart.tsx diff --git a/src/components/analytics/exif/AlbumPhotosChart.tsx b/src/components/analytics/exif/AlbumPhotosChart.tsx index 08ffca6..b50b8fc 100644 --- a/src/components/analytics/exif/AlbumPhotosChart.tsx +++ b/src/components/analytics/exif/AlbumPhotosChart.tsx @@ -26,14 +26,14 @@ export default function AlbumPhotosChart() { return ( - + /> ); } diff --git a/src/components/analytics/exif/AssetHeatMap.tsx b/src/components/analytics/exif/AssetHeatMap.tsx index 3352dd5..1418185 100644 --- a/src/components/analytics/exif/AssetHeatMap.tsx +++ b/src/components/analytics/exif/AssetHeatMap.tsx @@ -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([]); const [loading, setLoading] = useState(false); - const [weeksPerMonth, setWeeksPerMonth] = useState([]); // Store weeks per month + const [weeksPerMonth, setWeeksPerMonth] = useState([]); 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 ( +
+
+
+ ); + } + return ( -
-

Past Year

- {loading ? ( -

Loading...

- ) : ( -
- - - - {weeksPerMonth.map((weeks, index) => ( - - ))} - -
+
+ + + + + ))} + + + + {heatMapData[0]?.map((_, rowIndex) => ( + + + {heatMapData.map((column, colIndex) => ( + ))} - - - {heatMapData[0]?.map((_, rowIndex) => ( - - {heatMapData.map((column, colIndex) => ( - +
+ {weeksPerMonth.map((weeks, index) => ( + + {months[index]} +
+ {dayLabels[rowIndex]} + - {months[index]} - + {column[rowIndex]?.date ? ( + + +
+ + + ) : ( +
+ )} +
- { - column[rowIndex]?.date ? ( - - -
- ) :
+ ))} +
+
- } - - ))} -
-
- )} + {/* Legend */} +
+ Less + {COLOR_SCALE.map((color, i) => ( +
+ ))} + More +
); } diff --git a/src/components/analytics/exif/EXIFDistribution.tsx b/src/components/analytics/exif/EXIFDistribution.tsx index b53ac40..e5dae3d 100644 --- a/src/components/analytics/exif/EXIFDistribution.tsx +++ b/src/components/analytics/exif/EXIFDistribution.tsx @@ -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([]); - const [loading, setLoading] = useState(false); + const [chartData, setChartData] = useState([]); + const [loading, setLoading] = useState(true); const [errorMessage, setErrorMessage] = useState(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 ( - - + + ); } diff --git a/src/components/analytics/exif/GeoPhotosChart.tsx b/src/components/analytics/exif/GeoPhotosChart.tsx index 5d7f15f..c6789ff 100644 --- a/src/components/analytics/exif/GeoPhotosChart.tsx +++ b/src/components/analytics/exif/GeoPhotosChart.tsx @@ -27,13 +27,13 @@ export default function GeoPhotosChart() { return ( - + /> ); } diff --git a/src/components/analytics/exif/PeopleNamesChart.tsx b/src/components/analytics/exif/PeopleNamesChart.tsx index e90d9bf..85cbcca 100644 --- a/src/components/analytics/exif/PeopleNamesChart.tsx +++ b/src/components/analytics/exif/PeopleNamesChart.tsx @@ -27,13 +27,13 @@ export default function PeopleNamesChart() { return ( - + /> ); } diff --git a/src/components/ui/horizontal-bar-chart.tsx b/src/components/ui/horizontal-bar-chart.tsx new file mode 100644 index 0000000..e66cda4 --- /dev/null +++ b/src/components/ui/horizontal-bar-chart.tsx @@ -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 ( +
+
+
+ ); + } + + if (errorMessage) { + return ( +
+ {errorMessage} +
+ ); + } + + if (!data.length) { + return ( +
+ No data available +
+ ); + } + + return ( +
+ {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 ( +
+
+ + {item.label} + + + {displayValue} + +
+
+
+
+
+ ); + })} +
+ ); +} diff --git a/src/pages/analytics/exif.tsx b/src/pages/analytics/exif.tsx index edc9073..c79b683 100644 --- a/src/pages/analytics/exif.tsx +++ b/src/pages/analytics/exif.tsx @@ -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 ( +
+
+
+
+

+ {label} +

+

+ {loading ? ( + + ) : ( + value.toLocaleString() + )} +

+
+
+ {icon} +
+
+
+ ); +} + +interface SectionHeaderProps { + icon: React.ReactNode; + title: string; + description: string; +} + +function SectionHeader({ icon, title, description }: SectionHeaderProps) { + return ( +
+
+ {icon} +
+
+

{title}

+

{description}

+
+
+ ); +} + 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 ( -
-
-
- {["Total", "Images", "Videos"].map((type, i) => ( - - - {type} - - - {loading ? "Loading..." : statistics[type.toLowerCase() as keyof typeof statistics].toLocaleString()} - - - ))} - - - Live Photos - - - {loading ? "Loading..." : livePhotoStatistics.total.toLocaleString()} +
+
+ {/* ── Stats ── */} +
+ } + accent="bg-blue-500 text-blue-600" + /> + } + accent="bg-emerald-500 text-emerald-600" + /> + } + accent="bg-orange-500 text-orange-600" + /> + } + accent="bg-violet-500 text-violet-600" + /> +
+ + {/* ── Activity Heatmap ── */} +
+ } + title="Activity" + description="Photo capture frequency over the past year" + /> + + + -
- - - {/* New Analytics Charts */} -
- - - -
- -
- {exifCharts.map((chart) => ( - - ))} + -
+ {/* ── Library Overview ── */} +
+ } + title="Library Overview" + description="High-level stats about your photo library" + /> +
+ + + +
+
+ + {/* ── Storage ── */} +
+ } + title="Storage" + description="Disk usage breakdown across users" + /> +
+ +
+
+ + {/* ── Camera & Gear ── */} +
+ } + title="Camera & Gear" + description="Equipment used across your photo library" + /> +
+ {cameraCharts.map((chart) => ( + + ))} +
+
+ + {/* ── Location ── */} +
+ } + title="Location" + description="Where your photos were taken" + /> +
+ {locationCharts.map((chart) => ( + + ))} +
+
+ + {/* ── Technical ── */} +
+ } + title="Technical" + description="Camera settings and exposure data" + /> +
+ {technicalCharts.map((chart) => ( + + ))} +
+
);