Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

feat: adds file stats trend graph

towfiqia729d58847f1
diff --git a/frontend/package.json b/frontend/package.json
index 925a6d3..e197954 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -20,10 +20,12 @@
"dependencies": {
"@tanstack/react-query-devtools": "^5.96.0",
"@tanstack/react-query-persist-client": "^5.96.0",
+ "chart.js": "^4.5.1",
"comlink": "^4.4.2",
"dexie": "^4.2.1",
"marked": "^16.2.1",
"nanoid": "^5.0.9",
+ "react-chartjs-2": "^5.3.1",
"react-toastify": "^11.0.5",
"react-tooltip": "^5.29.1",
"react-window": "^1.8.11"
diff --git a/frontend/src/components/Plan/PlanSizeChart/PlanSizeChart.module.scss b/frontend/src/components/Plan/PlanSizeChart/PlanSizeChart.module.scss
new file mode 100644
index 0000000..580aac0
--- /dev/null
+++ b/frontend/src/components/Plan/PlanSizeChart/PlanSizeChart.module.scss
@@ -0,0 +1,76 @@
+.chartWrap {
+ position: relative;
+ width: 100%;
+ height: 100%;
+ min-height: 60px;
+}
+
+.chartCanvas {
+ position: absolute;
+ inset: 0;
+}
+
+.rangeSelector {
+ position: absolute;
+ top: -28px;
+ right: 0;
+ z-index: 2;
+}
+
+.rangeBtn {
+ background: var(--content-background-color);
+ color: var(--content-text-color-light);
+ border-radius: 4px;
+ font-size: 0.6875rem;
+ font-weight: 600;
+ padding: 2px 8px;
+ cursor: pointer;
+ line-height: 1.4;
+
+ &:hover {
+ color: var(--primary-color);
+ border-color: var(--primary-color);
+ }
+}
+
+.rangeMenu {
+ position: absolute;
+ top: calc(100% + 4px);
+ right: 0;
+ margin: 0;
+ padding: 4px 0;
+ list-style: none;
+ background: var(--content-background-color);
+ border: 1px solid var(--line-color);
+ border-radius: 4px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
+ min-width: 70px;
+
+ li {
+ padding: 4px 10px;
+ font-size: 0.75rem;
+ cursor: pointer;
+ color: var(--content-text-color);
+
+ &:hover {
+ background: var(--primary-color-light);
+ color: var(--primary-color);
+ }
+
+ &.active {
+ color: var(--primary-color);
+ font-weight: 600;
+ }
+ }
+}
+
+.empty {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 6px;
+ height: 100%;
+ font-size: 0.75rem;
+ color: var(--content-text-color-light);
+ opacity: 0.7;
+}
diff --git a/frontend/src/components/Plan/PlanSizeChart/PlanSizeChart.tsx b/frontend/src/components/Plan/PlanSizeChart/PlanSizeChart.tsx
new file mode 100644
index 0000000..249b540
--- /dev/null
+++ b/frontend/src/components/Plan/PlanSizeChart/PlanSizeChart.tsx
@@ -0,0 +1,163 @@
+import { useMemo, useRef, useState, useEffect } from 'react';
+import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Filler, Tooltip, Legend, ChartOptions } from 'chart.js';
+import { Line } from 'react-chartjs-2';
+import Icon from '../../common/Icon/Icon';
+import { Backup } from '../../../@types/backups';
+import { formatBytes, formatNumberToK, isDarkMode } from '../../../utils/helpers';
+import classes from './PlanSizeChart.module.scss';
+
+ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Filler, Tooltip, Legend);
+
+type RangeKey = '7d' | '14d' | '1m' | '3m' | '6m';
+
+const RANGE_OPTIONS: { key: RangeKey; label: string; days: number }[] = [
+ { key: '7d', label: '7d', days: 7 },
+ { key: '14d', label: '14d', days: 14 },
+ { key: '1m', label: '1m', days: 30 },
+ { key: '3m', label: '3m', days: 90 },
+ { key: '6m', label: '6m', days: 180 },
+];
+
+interface PlanSizeChartProps {
+ backups: Backup[];
+}
+
+const PlanSizeChart = ({ backups }: PlanSizeChartProps) => {
+ const [range, setRange] = useState<RangeKey>('3m');
+ const [open, setOpen] = useState(false);
+ const dropdownRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ if (!open) return;
+ const onClick = (e: MouseEvent) => {
+ if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) {
+ setOpen(false);
+ }
+ };
+ document.addEventListener('mousedown', onClick);
+ return () => document.removeEventListener('mousedown', onClick);
+ }, [open]);
+
+ const activeRange = RANGE_OPTIONS.find((r) => r.key === range) || RANGE_OPTIONS[3];
+
+ const filtered = useMemo(() => {
+ const cutoff = Date.now() - activeRange.days * 24 * 60 * 60 * 1000;
+ return [...(backups || [])]
+ .filter((b) => {
+ const t = new Date(b.started).getTime();
+ return !isNaN(t) && t >= cutoff;
+ })
+ .sort((a, b) => new Date(a.started).getTime() - new Date(b.started).getTime());
+ }, [backups, activeRange.days]);
+
+ const labels = filtered.map((b) => new Date(b.started).toLocaleString());
+ const sizeData = filtered.map((b) => b.totalSize || 0);
+ const filesData = filtered.map((b) => b.totalFiles || 0);
+
+ const data = {
+ labels,
+ datasets: [
+ {
+ label: 'Size',
+ data: sizeData,
+ yAxisID: 'ySize',
+ borderColor: 'transparent',
+ backgroundColor: 'rgba(87, 132, 255, 0.12)',
+ fill: true,
+ tension: 0.4,
+ borderWidth: 1.5,
+ pointRadius: 0,
+ pointHoverRadius: 4,
+ pointHoverBackgroundColor: 'rgba(87, 90, 255, 1)',
+ },
+ {
+ label: 'Files',
+ data: filesData,
+ yAxisID: 'yFiles',
+ borderColor: '#9a9bff',
+ backgroundColor: 'transparent',
+ borderDash: [3, 3],
+ fill: false,
+ tension: 0.4,
+ borderWidth: 1.2,
+ pointRadius: 0,
+ pointHoverRadius: 4,
+ pointHoverBackgroundColor: 'rgba(87, 90, 255, 1)',
+ },
+ ],
+ };
+
+ const options: ChartOptions<'line'> = {
+ responsive: true,
+ animation: false,
+ maintainAspectRatio: false,
+ interaction: { mode: 'index', intersect: false },
+ plugins: {
+ legend: { display: false },
+ tooltip: {
+ displayColors: false,
+ backgroundColor: isDarkMode ? 'rgba(0, 0, 0, 0.9)' : 'rgba(255, 255, 255, 1)',
+ titleColor: isDarkMode ? '#fff' : '#666',
+ bodyColor: isDarkMode ? '#ccc' : '#888',
+ padding: 8,
+ titleFont: { size: 11 },
+ bodyFont: { size: 11 },
+ callbacks: {
+ title: (items) => {
+ const idx = items[0]?.dataIndex ?? 0;
+ const b = filtered[idx];
+ return b ? new Date(b.started).toLocaleString() : '';
+ },
+ label: (ctx) => {
+ if (ctx.dataset.label === 'Size') return `Size: ${formatBytes(ctx.parsed.y || 0)}`;
+ return `Files: ${formatNumberToK(ctx.parsed.y || 0)}`;
+ },
+ },
+ },
+ },
+ scales: {
+ x: { display: false },
+ ySize: { display: false, beginAtZero: true },
+ yFiles: { display: false, beginAtZero: true, position: 'right' },
+ },
+ };
+
+ return (
+ <div className={classes.chartWrap}>
+ <div className={classes.rangeSelector} ref={dropdownRef}>
+ <button type="button" className={classes.rangeBtn} onClick={() => setOpen((v) => !v)}>
+ {activeRange.label}
+ </button>
+ {open && (
+ <ul className={classes.rangeMenu}>
+ {RANGE_OPTIONS.slice()
+ .reverse()
+ .map((opt) => (
+ <li
+ key={opt.key}
+ className={opt.key === range ? classes.active : ''}
+ onClick={() => {
+ setRange(opt.key);
+ setOpen(false);
+ }}
+ >
+ {opt.label}
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ {filtered.length === 0 ? (
+ <div className={classes.empty}>
+ <Icon type="folders" size={16} /> No data in range
+ </div>
+ ) : (
+ <div className={classes.chartCanvas}>
+ <Line data={data} options={options} />
+ </div>
+ )}
+ </div>
+ );
+};
+
+export default PlanSizeChart;
diff --git a/frontend/src/components/Plan/PlanStats/PlanStats.module.scss b/frontend/src/components/Plan/PlanStats/PlanStats.module.scss
index bd5eb37..4b706d5 100644
--- a/frontend/src/components/Plan/PlanStats/PlanStats.module.scss
+++ b/frontend/src/components/Plan/PlanStats/PlanStats.module.scss
@@ -16,6 +16,15 @@
span {
color: var(--icon-color);
}
+ .widgetSubTitle {
+ margin-left: 4px;
+ i {
+ font-style: normal;
+ font-family: sans-serif;
+ font-size: 9px;
+ padding: 0 2px;
+ }
+ }
}
.sources,
@@ -83,12 +92,17 @@
}
.snapshots {
width: 24%;
+ padding: 20px 0 0 0;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
.snapshotsContent {
display: flex;
justify-content: space-around;
align-items: center;
- height: 100%;
- margin-top: 8px;
+ height: 70px;
+ margin-top: 16px;
+ position: relative;
& > div {
text-align: center;
diff --git a/frontend/src/components/Plan/PlanStats/PlanStats.tsx b/frontend/src/components/Plan/PlanStats/PlanStats.tsx
index 5b299df..bf8a99e 100644
--- a/frontend/src/components/Plan/PlanStats/PlanStats.tsx
+++ b/frontend/src/components/Plan/PlanStats/PlanStats.tsx
@@ -1,9 +1,11 @@
import Icon from '../../common/Icon/Icon';
import { Plan } from '../../../@types/plans';
-import { formatBytes, formatNumberToK, formatIntervalDisplay } from '../../../utils/helpers';
+import { formatIntervalDisplay } from '../../../utils/helpers';
import PlanHistory from '../PlanHistory/PlanHistory';
+import PlanSizeChart from '../PlanSizeChart/PlanSizeChart';
import classes from './PlanStats.module.scss';
import PlanStorageInfo from '../PlanStorageInfo/PlanStorageInfo';
+import { formatBytes, formatNumberToK } from '../../../utils/helpers';
interface PlanStatsProps {
plan: Plan;
@@ -61,18 +63,13 @@ const PlanStats = ({ plan, isSync, lastBackupItem }: PlanStatsProps) => {
</div>
<div className={classes.snapshots}>
<div className={classes.widgetTitle}>
- <Icon type="folders" size={12} /> Source Stats
+ <Icon type="folders" size={12} /> Stats{' '}
+ <span className={classes.widgetSubTitle}>
+ {formatNumberToK(totalFiles)} files <i>|</i> {formatBytes(totalSize)}
+ </span>
</div>
<div className={classes.snapshotsContent}>
- <div>
- <span>{totalFiles ? formatNumberToK(totalFiles) : 0}</span>
- <span>Files</span>
- </div>
- <div></div>
- <div>
- <span>{totalSize ? formatBytes(totalSize) : '0.00B'}</span>
- <span>Size</span>
- </div>
+ <PlanSizeChart backups={plan.backups} />
</div>
</div>
<div className={classes.health}>
diff --git a/frontend/src/utils/helpers.ts b/frontend/src/utils/helpers.ts
index 042fc3b..1591cfe 100644
--- a/frontend/src/utils/helpers.ts
+++ b/frontend/src/utils/helpers.ts
@@ -30,6 +30,8 @@ export const isMobile = (): boolean => {
return false;
};
+export const isDarkMode = window.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
+
const formatter = new Intl.RelativeTimeFormat('en');
export const timeAgo = (input: Date) => {
const date = input instanceof Date ? input : new Date(input);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d91f77e..e77a24f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -210,6 +210,9 @@ importers:
'@tanstack/react-query-persist-client':
specifier: ^5.96.0
+ chart.js:
+ specifier: ^4.5.1
+ version: 4.5.1
comlink:
specifier: ^4.4.2
version: 4.4.2
@@ -225,6 +228,9 @@ importers:
react:
specifier: ^18.3.1
version: 18.3.1
+ react-chartjs-2:
+ specifier: ^5.3.1
react-dom:
specifier: ^18.3.1
version: 18.3.1([email protected])
@@ -276,7 +282,7 @@ importers:
version: 10.1.8([email protected])
eslint-plugin-import:
specifier: ^2.32.0
- version: 2.32.0([email protected])
eslint-plugin-react-hooks:
specifier: ^7.0.1
version: 7.0.1([email protected])
@@ -1981,6 +1987,9 @@ packages:
peerDependencies:
jsep: ^0.4.0||^1.0.0
+ '@kurkle/[email protected]':
+ resolution: {integrity: sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==}
+
'@napi-rs/[email protected]':
resolution: {integrity: sha512-CA83rDeyONDADO25JLZsh3eHY8yTEtm/RS6ecPsY+1v+dSawzT9GywBMu2r6uOp1IEhQs/xAfxgybGAFr17lSA==}
engines: {node: '>= 10'}
@@ -3161,6 +3170,10 @@ packages:
resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==}
engines: {node: '>=10'}
+ resolution: {integrity: sha512-GIjfiT9dbmHRiYi6Nl2yFCq7kkwdkp1W/lp2J99rX0yo9tgJGn3lKQATztIjb5tVtevcBtIdICNWqlq5+E8/Pw==}
+ engines: {pnpm: '>=8'}
+
resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==}
engines: {node: '>= 14.16.0'}
@@ -5299,6 +5312,12 @@ packages:
resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==}
hasBin: true
+ resolution: {integrity: sha512-h5IPXKg9EXpjoBzUfyWJvllMjG2mQ4EiuHQFhms/AjUm0XSZHhyRy2xVmLXHKrtcdrPO4mnGqRtYoD0vp95A0A==}
+ peerDependencies:
+ chart.js: ^4.1.1
+ react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
+
resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==}
peerDependencies:
@@ -8143,6 +8162,8 @@ snapshots:
dependencies:
jsep: 1.4.0
+ '@kurkle/[email protected]': {}
+
'@napi-rs/[email protected]':
optional: true
@@ -9361,6 +9382,10 @@ snapshots:
+ dependencies:
+ '@kurkle/color': 0.3.4
+
dependencies:
readdirp: 4.1.2
@@ -10001,16 +10026,17 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
debug: 3.2.7
optionalDependencies:
+ '@typescript-eslint/parser': 8.56.0([email protected])([email protected])
eslint: 10.0.0
eslint-import-resolver-node: 0.3.9
transitivePeerDependencies:
- supports-color
dependencies:
'@rtsao/scc': 1.1.0
array-includes: 3.1.9
@@ -10021,7 +10047,7 @@ snapshots:
doctrine: 2.1.0
eslint: 10.0.0
eslint-import-resolver-node: 0.3.9
- eslint-module-utils: 2.12.1([email protected])([email protected])
hasown: 2.0.2
is-core-module: 2.16.1
is-glob: 4.0.3
@@ -10032,6 +10058,8 @@ snapshots:
semver: 6.3.1
string.prototype.trimend: 1.0.9
tsconfig-paths: 3.15.0
+ optionalDependencies:
+ '@typescript-eslint/parser': 8.56.0([email protected])([email protected])
transitivePeerDependencies:
- eslint-import-resolver-typescript
- eslint-import-resolver-webpack
@@ -11761,6 +11789,11 @@ snapshots:
minimist: 1.2.8
strip-json-comments: 2.0.1
+ dependencies:
+ chart.js: 4.5.1
+ react: 18.3.1
+
dependencies:
loose-envify: 1.4.0