diff --git a/stats/src/components/overview/WatchTimeChart.tsx b/stats/src/components/overview/WatchTimeChart.tsx index b8f40dfe..7ab1e6c6 100644 --- a/stats/src/components/overview/WatchTimeChart.tsx +++ b/stats/src/components/overview/WatchTimeChart.tsx @@ -1,7 +1,15 @@ import { useState } from 'react'; -import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; +import { + BarChart, + Bar, + CartesianGrid, + XAxis, + YAxis, + Tooltip, + ResponsiveContainer, +} from 'recharts'; import { epochDayToDate } from '../../lib/formatters'; -import { CHART_THEME } from '../../lib/chart-theme'; +import { CHART_DEFAULTS, CHART_THEME, TOOLTIP_CONTENT_STYLE } from '../../lib/chart-theme'; import type { DailyRollup } from '../../types/stats'; interface WatchTimeChartProps { @@ -52,28 +60,23 @@ export function WatchTimeChart({ rollups }: WatchTimeChartProps) { ))} - - + + + diff --git a/stats/src/components/trends/StackedTrendChart.tsx b/stats/src/components/trends/StackedTrendChart.tsx index c56a8bce..c196728d 100644 --- a/stats/src/components/trends/StackedTrendChart.tsx +++ b/stats/src/components/trends/StackedTrendChart.tsx @@ -1,4 +1,13 @@ -import { AreaChart, Area, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; +import { + AreaChart, + Area, + CartesianGrid, + XAxis, + YAxis, + Tooltip, + ResponsiveContainer, +} from 'recharts'; +import { CHART_DEFAULTS, CHART_THEME, TOOLTIP_CONTENT_STYLE } from '../../lib/chart-theme'; import { epochDayToDate } from '../../lib/formatters'; export interface PerAnimeDataPoint { @@ -64,14 +73,6 @@ export function StackedTrendChart({ title, data, colorPalette }: StackedTrendCha const { points, seriesKeys } = buildLineData(data); const colors = colorPalette ?? DEFAULT_LINE_COLORS; - const tooltipStyle = { - background: '#363a4f', - border: '1px solid #494d64', - borderRadius: 6, - color: '#cad3f5', - fontSize: 12, - }; - if (points.length === 0) { return (
@@ -84,21 +85,22 @@ export function StackedTrendChart({ title, data, colorPalette }: StackedTrendCha return (

{title}

- - + + + - + {seriesKeys.map((key, i) => ( (formatter ? [formatter(v), title] : [String(v), title]); return (

{title}

- + {type === 'bar' ? ( - + + - + ) : ( - + + - + )} diff --git a/stats/src/lib/chart-theme.test.ts b/stats/src/lib/chart-theme.test.ts new file mode 100644 index 00000000..1288914d --- /dev/null +++ b/stats/src/lib/chart-theme.test.ts @@ -0,0 +1,16 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { CHART_DEFAULTS, CHART_THEME, TOOLTIP_CONTENT_STYLE } from './chart-theme'; + +test('CHART_THEME exposes a grid color', () => { + assert.equal(CHART_THEME.grid, '#494d64'); +}); + +test('CHART_DEFAULTS uses 11px ticks for legibility', () => { + assert.equal(CHART_DEFAULTS.tickFontSize, 11); +}); + +test('TOOLTIP_CONTENT_STYLE mirrors the shared tooltip colors', () => { + assert.equal(TOOLTIP_CONTENT_STYLE.background, CHART_THEME.tooltipBg); + assert.ok(String(TOOLTIP_CONTENT_STYLE.border).includes(CHART_THEME.tooltipBorder)); +}); diff --git a/stats/src/lib/chart-theme.ts b/stats/src/lib/chart-theme.ts index 549b0157..ffb62173 100644 --- a/stats/src/lib/chart-theme.ts +++ b/stats/src/lib/chart-theme.ts @@ -5,4 +5,21 @@ export const CHART_THEME = { tooltipText: '#cad3f5', tooltipLabel: '#b8c0e0', barFill: '#8aadf4', + grid: '#494d64', + axisLine: '#494d64', } as const; + +export const CHART_DEFAULTS = { + height: 160, + tickFontSize: 11, + margin: { top: 8, right: 8, bottom: 0, left: 0 }, + grid: { strokeDasharray: '3 3', vertical: false }, +} as const; + +export const TOOLTIP_CONTENT_STYLE = { + background: CHART_THEME.tooltipBg, + border: `1px solid ${CHART_THEME.tooltipBorder}`, + borderRadius: 6, + color: CHART_THEME.tooltipText, + fontSize: 12, +};