Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
feat(frontend): restore the YouTube channel charts with Intent UI
spacesdrivec17da3b16cca
diff --git a/frontend/src/features/analytics/channel/ChannelContentTab.tsx b/frontend/src/features/analytics/channel/ChannelContentTab.tsxindex ad1ce2f..4e7c132 100644--- a/frontend/src/features/analytics/channel/ChannelContentTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelContentTab.tsx@@ -1,16 +1,19 @@-import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as ReTooltip, PieChart, Pie, Cell, Legend } from 'recharts';+import { BarChart } from '@/components/ui/bar-chart';import MetricBox from '@/components/MetricBox';import ChartPanel from '@/components/ChartPanel';-import SurfaceBox from '@/components/SurfaceBox';-import RankingBarChart from '@/components/RankingBarChart';-import { SERIES, axisProps, axisTick, gridProps, legendStyle, rankingSummary, tooltipCursor, tooltipStyle } from '@/lib/chart';+import DonutChart from '@/components/DonutChart';+import ExactTooltip from '@/components/ExactTooltip';+import { SERIES, pointsOf, rankingSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';-import { fmtNum, fmtPercent } from '../../../utils/formatters';+import { fmtNum, fmtNumFull, fmtPercent } from '../../../utils/formatters';import { categoryDataOf, durationDataOf, viewRangeDataOf } from './channelChartData.ts';import type { VideoAnalytics } from '@shared/types/youtube.ts';const { quality: Quality, comments: Captions, consistency: Licensed, regularVideos: Embeddable, audience: Kids, duration: Duration } = METRIC_ICONS;+const BY_CATEGORY = { value: { label: 'Videos', color: SERIES.neutral } };+const BY_VIEW_RANGE = { count: { label: 'Videos', color: SERIES.neutral } };+export interface ChannelContentTabProps {analytics: VideoAnalytics;}@@ -31,37 +34,34 @@ export default function ChannelContentTab({ analytics }: ChannelContentTabProps)<MetricBox small icon={<Duration />} label="Average length" value={analytics.avgDurationFormatted} period={period} /></div><div className="grid grid-cols-1 gap-4 md:grid-cols-2">- <ChartPanel- title="Videos by length"- empty={durationData.length === 0}- summary={rankingSummary(durationData, fmtNum, 'videos')}- table={{ caption: 'Videos by length', columns: [{ key: 'name', label: 'Length' }, { key: 'value', label: 'Videos', numeric: true }], rows: durationData }}- >- <PieChart>- <Pie data={durationData} dataKey="value" nameKey="name" cx="50%" cy="50%" outerRadius={95} innerRadius={55} paddingAngle={2} strokeWidth={0}>- {durationData.map(slice => <Cell key={slice.name} fill={slice.color} />)}- </Pie>- <ReTooltip contentStyle={tooltipStyle} />- <Legend iconType="circle" iconSize={8} wrapperStyle={legendStyle} />- </PieChart>+ <ChartPanel title="Length distribution" empty={durationData.length === 0} description={rankingSummary(durationData, fmtNumFull, 'videos')}>+ <DonutChart data={durationData} height={280} />+ </ChartPanel>+ <ChartPanel title="Videos by category" empty={categoryData.length === 0} description={rankingSummary(categoryData, fmtNumFull, 'videos')}>+ <BarChart+ data={categoryData}+ dataKey="name"+ layout="vertical"+ config={BY_CATEGORY}+ containerHeight={280}+ legend={false}+ tooltip={<ExactTooltip />}+ xAxisProps={{ type: 'number', allowDecimals: false, tickFormatter: fmtNum }}+ yAxisProps={{ width: 120 }}+ /></ChartPanel>- <SurfaceBox title="Videos by category">- <RankingBarChart rows={categoryData} label="Videos" title="Videos by category" emptyMessage="No category information on these videos" />- </SurfaceBox></div>- <ChartPanel- title="Videos by view range"- height={240}- summary={rankingSummary(viewRanges.map(row => ({ name: row.range, value: row.count })), fmtNum, 'videos')}- table={{ caption: 'Videos by view range', columns: [{ key: 'range', label: 'Views' }, { key: 'count', label: 'Videos', numeric: true }], rows: viewRanges }}- >- <BarChart data={viewRanges}>- <CartesianGrid {...gridProps} vertical={false} />- <XAxis dataKey="range" tick={{ ...axisTick, fontSize: 10 }} angle={-15} textAnchor="end" height={60} />- <YAxis {...axisProps} allowDecimals={false} />- <ReTooltip contentStyle={tooltipStyle} cursor={tooltipCursor} />- <Bar dataKey="count" fill={SERIES.neutral} radius={[4, 4, 0, 0]} name="Videos" />- </BarChart>+ <ChartPanel title="Videos by view range" height={240} description={rankingSummary(pointsOf(viewRanges, 'range', 'count'), fmtNumFull, 'videos')}>+ <BarChart+ data={viewRanges}+ dataKey="range"+ config={BY_VIEW_RANGE}+ containerHeight={240}+ legend={false}+ tooltip={<ExactTooltip />}+ xAxisProps={{ angle: -15, textAnchor: 'end', height: 60 }}+ yAxisProps={{ allowDecimals: false }}+ /></ChartPanel></>);diff --git a/frontend/src/features/analytics/channel/ChannelEngagementTab.tsx b/frontend/src/features/analytics/channel/ChannelEngagementTab.tsxindex 449f1b2..f27631e 100644--- a/frontend/src/features/analytics/channel/ChannelEngagementTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelEngagementTab.tsx@@ -4,7 +4,7 @@ import Num from '@/components/Num';import { SERIES } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';import { fmtPercent } from '../../../utils/formatters';-import { likesPerComment, monthlyChartText, rateOf } from './channelChartData.ts';+import { likesPerComment, monthlySummary, rateOf } from './channelChartData.ts';import ChannelVideoTable from './ChannelVideoTable';import TrendArea from './TrendArea';import type { VideoAnalytics } from '@shared/types/youtube.ts';@@ -17,8 +17,6 @@ export interface ChannelEngagementTabProps {export default function ChannelEngagementTab({ analytics }: ChannelEngagementTabProps) {const period = `Last ${analytics.totalVideos} videos`;- const engagement = monthlyChartText(analytics.engagementTrend || [], 'engagement rate', true);- const likeRate = monthlyChartText(analytics.likeRateTrend || [], 'like rate', true);return (<><div className="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-6">@@ -30,21 +28,11 @@ export default function ChannelEngagementTab({ analytics }: ChannelEngagementTab<MetricBox small icon={<Ratio />} label="Likes per comment" value={likesPerComment(analytics)} period={period} /></div><div className="grid grid-cols-1 gap-4 md:grid-cols-2">- <ChartPanel- title="Engagement rate by upload month"- subheader="Likes and comments per view for the videos published each month"- summary={engagement.summary}- table={{ caption: 'Engagement rate by upload month', columns: [{ key: 'month', label: 'Month' }, { key: 'value', label: 'Engagement rate', numeric: true }], rows: engagement.rows }}- >- <TrendArea data={analytics.engagementTrend || []} color={SERIES.primary} name="Engagement rate" percent gradientId="egGrad" />+ <ChartPanel title="Engagement rate by month" description={monthlySummary(analytics.engagementTrend || [], 'engagement rate', true)}>+ <TrendArea data={analytics.engagementTrend || []} color={SERIES.primary} name="Engagement rate" percent /></ChartPanel>- <ChartPanel- title="Like rate by upload month"- subheader="Likes per view for the videos published each month"- summary={likeRate.summary}- table={{ caption: 'Like rate by upload month', columns: [{ key: 'month', label: 'Month' }, { key: 'value', label: 'Like rate', numeric: true }], rows: likeRate.rows }}- >- <TrendArea data={analytics.likeRateTrend || []} color={SERIES.neutral} name="Like rate" percent gradientId="lrGrad" />+ <ChartPanel title="Like rate by month" description={monthlySummary(analytics.likeRateTrend || [], 'like rate', true)}>+ <TrendArea data={analytics.likeRateTrend || []} color={SERIES.neutral} name="Like rate" percent /></ChartPanel></div><ChannelVideoTable title="Top 10 by engagement rate" videos={analytics.top10ByEngagement} />diff --git a/frontend/src/features/analytics/channel/ChannelGrowthTab.tsx b/frontend/src/features/analytics/channel/ChannelGrowthTab.tsxindex fb0998e..42ffff8 100644--- a/frontend/src/features/analytics/channel/ChannelGrowthTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelGrowthTab.tsx@@ -1,13 +1,13 @@-import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as ReTooltip } from 'recharts';+import { BarChart } from '@/components/ui/bar-chart';import MetricBox from '@/components/MetricBox';import ChartPanel from '@/components/ChartPanel';+import ExactTooltip from '@/components/ExactTooltip';import Num from '@/components/Num';import { PLATFORM_META } from '@/lib/accounts';-import { SERIES, axisProps, gridProps, tooltipCursor, tooltipStyle, trendSummary } from '@/lib/chart';+import { SERIES, pointsOf, trendSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';import { fmtNum, fmtNumFull } from '../../../utils/formatters';-import type { NumberLike } from '../../../utils/formatters';-import { monthlyChartText, uploadsByMonthOf } from './channelChartData.ts';+import { monthlySummary, uploadsByMonthOf } from './channelChartData.ts';import MetricGrid from './MetricGrid';import TrendArea from './TrendArea';import type { VideoAnalytics } from '@shared/types/youtube.ts';@@ -15,7 +15,7 @@ import type { ChannelDetails } from './channelChartData.ts';const { views: Views, audience: Audience, period: Estimate } = METRIC_ICONS;-const full = (value: unknown) => fmtNumFull(value as NumberLike);+const UPLOADS = { uploads: { label: 'Uploads', color: SERIES.neutral } };export interface ChannelGrowthTabProps {channel: ChannelDetails;@@ -23,7 +23,6 @@ export interface ChannelGrowthTabProps {}export default function ChannelGrowthTab({ channel, analytics }: ChannelGrowthTabProps) {- const views = monthlyChartText(analytics.viewsTrend || [], 'views');const uploads = uploadsByMonthOf(analytics.viewsTrend);return (<>@@ -33,36 +32,20 @@ export default function ChannelGrowthTab({ channel, analytics }: ChannelGrowthTa<MetricBox small icon={<Estimate />} label="Views in a year" value={<Num value={channel.estimatedYearlyViews} />} period="Estimate" subtitle={`About ${fmtNum(channel.estimatedMonthlyViews)} a month at the daily average`} /><MetricBox small icon={<Estimate />} label="Subscribers in a year" value={<Num value={channel.estimatedYearlySubGain} />} period="Estimate" subtitle={`About ${fmtNum(channel.estimatedMonthlySubGain)} a month at the daily average`} /></MetricGrid>- <ChartPanel- title="Lifetime views of videos, by upload month"- subheader="Every view a video has had so far, counted in the month it was published"- height={300}- summary={views.summary}- table={{- caption: 'Lifetime views of videos, by upload month',- columns: [{ key: 'month', label: 'Upload month' }, { key: 'value', label: 'Views', numeric: true, format: full }],- rows: views.rows,- }}- >- <TrendArea data={analytics.viewsTrend || []} color={PLATFORM_META.youtube.series} name="Views" gradientId="viewGrad" />+ <ChartPanel title="Views by month" height={300} description={monthlySummary(analytics.viewsTrend || [], 'views')}>+ <TrendArea data={analytics.viewsTrend || []} color={PLATFORM_META.youtube.series} name="Views" height={300} /></ChartPanel>- <ChartPanel- title="Uploads by month"- height={240}- summary={trendSummary(uploads.map(point => ({ name: point.month, value: point.uploads })), fmtNum, 'uploads')}- table={{- caption: 'Uploads by month',- columns: [{ key: 'month', label: 'Month' }, { key: 'uploads', label: 'Uploads', numeric: true, format: full }],- rows: uploads,- }}- >- <BarChart data={uploads}>- <CartesianGrid {...gridProps} vertical={false} />- <XAxis dataKey="month" {...axisProps} />- <YAxis {...axisProps} allowDecimals={false} />- <ReTooltip contentStyle={tooltipStyle} cursor={tooltipCursor} />- <Bar dataKey="uploads" fill={SERIES.neutral} radius={[4, 4, 0, 0]} name="Uploads" />- </BarChart>+ <ChartPanel title="Uploads by month" height={240} description={trendSummary(pointsOf(uploads, 'month', 'uploads'), fmtNumFull, 'uploads')}>+ <BarChart+ data={uploads}+ dataKey="month"+ config={UPLOADS}+ containerHeight={240}+ legend={false}+ tooltip={<ExactTooltip />}+ valueFormatter={fmtNum}+ yAxisProps={{ allowDecimals: false }}+ /></ChartPanel></>);diff --git a/frontend/src/features/analytics/channel/ChannelPublishingTab.tsx b/frontend/src/features/analytics/channel/ChannelPublishingTab.tsxindex 96a0d1e..84eb0ac 100644--- a/frontend/src/features/analytics/channel/ChannelPublishingTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelPublishingTab.tsx@@ -1,15 +1,20 @@-import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as ReTooltip } from 'recharts';+import { AreaChart } from '@/components/ui/area-chart';+import { BarChart } from '@/components/ui/bar-chart';import MetricBox from '@/components/MetricBox';import ChartPanel from '@/components/ChartPanel';-import { SERIES, axisProps, gridProps, rankingSummary, tooltipCursor, tooltipStyle } from '@/lib/chart';+import ExactTooltip from '@/components/ExactTooltip';+import { SERIES, pointsOf, rankingSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';-import { fmtNum } from '../../../utils/formatters';+import { fmtNumFull } from '../../../utils/formatters';import { dayDataOf, hourDataOf, peakHourLabel } from './channelChartData.ts';import MetricGrid from './MetricGrid';import type { VideoAnalytics } from '@shared/types/youtube.ts';const { period: Day, time: Hour, videos: Uploads, consistency: Consistency } = METRIC_ICONS;+const BY_DAY = { count: { label: 'Videos', color: SERIES.neutral } };+const BY_HOUR = { count: { label: 'Videos', color: SERIES.warm } };+export interface ChannelPublishingTabProps {analytics: VideoAnalytics;}@@ -26,31 +31,28 @@ export default function ChannelPublishingTab({ analytics }: ChannelPublishingTab<MetricBox small icon={<Consistency />} label="Consistency" value={`${analytics.consistencyScore} of 100`} subtitle="How evenly uploads spread across active weeks" /></MetricGrid><div className="grid grid-cols-1 gap-4 md:grid-cols-2">- <ChartPanel- title="Uploads by day of week"- summary={rankingSummary(days.map(day => ({ name: day.day, value: day.count })), fmtNum, 'videos')}- table={{ caption: 'Uploads by day of week', columns: [{ key: 'day', label: 'Day' }, { key: 'count', label: 'Videos', numeric: true }], rows: days }}- >- <BarChart data={days}>- <CartesianGrid {...gridProps} vertical={false} />- <XAxis dataKey="day" {...axisProps} />- <YAxis {...axisProps} allowDecimals={false} />- <ReTooltip contentStyle={tooltipStyle} cursor={tooltipCursor} />- <Bar dataKey="count" fill={SERIES.neutral} radius={[4, 4, 0, 0]} name="Videos" />- </BarChart>+ <ChartPanel title="Uploads by day of week" description={rankingSummary(pointsOf(days, 'day', 'count'), fmtNumFull, 'videos')}>+ <BarChart+ data={days}+ dataKey="day"+ config={BY_DAY}+ containerHeight={280}+ legend={false}+ tooltip={<ExactTooltip />}+ yAxisProps={{ allowDecimals: false }}+ /></ChartPanel>- <ChartPanel- title="Uploads by hour (UTC)"- summary={rankingSummary(hours.map(hour => ({ name: hour.hour, value: hour.count })), fmtNum, 'videos')}- table={{ caption: 'Uploads by hour (UTC)', columns: [{ key: 'hour', label: 'Hour' }, { key: 'count', label: 'Videos', numeric: true }], rows: hours }}- >- <BarChart data={hours}>- <CartesianGrid {...gridProps} vertical={false} />- <XAxis dataKey="hour" {...axisProps} interval={2} />- <YAxis {...axisProps} allowDecimals={false} />- <ReTooltip contentStyle={tooltipStyle} cursor={tooltipCursor} />- <Bar dataKey="count" fill={SERIES.warm} radius={[3, 3, 0, 0]} name="Videos" />- </BarChart>+ <ChartPanel title="Uploads by hour (UTC)" description={rankingSummary(pointsOf(hours, 'hour', 'count'), fmtNumFull, 'videos')}>+ <AreaChart+ data={hours}+ dataKey="hour"+ config={BY_HOUR}+ containerHeight={280}+ legend={false}+ tooltip={<ExactTooltip />}+ yAxisProps={{ allowDecimals: false }}+ areaProps={{ type: 'monotone' }}+ /></ChartPanel></div></>diff --git a/frontend/src/features/analytics/channel/ChannelShortsTab.tsx b/frontend/src/features/analytics/channel/ChannelShortsTab.tsxindex e50c5bb..245ac36 100644--- a/frontend/src/features/analytics/channel/ChannelShortsTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelShortsTab.tsx@@ -1,23 +1,22 @@-import type { TooltipValueType } from 'recharts';-import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as ReTooltip, PieChart, Pie, Cell, Legend } from 'recharts';+import { BarChart } from '@/components/ui/bar-chart';import MetricBox from '@/components/MetricBox';import ChartPanel from '@/components/ChartPanel';+import DonutChart from '@/components/DonutChart';+import ExactTooltip from '@/components/ExactTooltip';import Num from '@/components/Num';-import { SERIES, axisProps, gridProps, legendStyle, rankingSummary, tooltipCursor, tooltipStyle } from '@/lib/chart';+import { SERIES, rankingSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';import { fmtNum, fmtNumFull } from '../../../utils/formatters';-import type { NumberLike } from '../../../utils/formatters';import { shortsComparisonOf, splitDataOf } from './channelChartData.ts';import MetricGrid from './MetricGrid';import type { VideoAnalytics } from '@shared/types/youtube.ts';const { shorts: Shorts, regularVideos: Regular, averageViews: AverageViews } = METRIC_ICONS;-function fullNumber(value: TooltipValueType | undefined): string {- return fmtNumFull(value as number);-}--const full = (value: unknown) => fmtNumFull(value as NumberLike);+const COMPARISON = {+ Shorts: { label: 'Shorts', color: SERIES.primary },+ Regular: { label: 'Regular videos', color: SERIES.neutral },+};export interface ChannelShortsTabProps {analytics: VideoAnalytics;@@ -40,40 +39,23 @@ export default function ChannelShortsTab({ analytics }: ChannelShortsTabProps) {title="Content split"className="md:col-span-2"empty={splitData.length === 0}- summary={rankingSummary(splitData, fmtNum, 'videos')}- table={{ caption: 'Content split', columns: [{ key: 'name', label: 'Kind' }, { key: 'value', label: 'Videos', numeric: true, format: full }], rows: splitData }}+ description={rankingSummary(splitData, fmtNumFull, 'videos')}>- <PieChart>- <Pie data={splitData} dataKey="value" nameKey="name" cx="50%" cy="50%" outerRadius={95} innerRadius={55} paddingAngle={2} strokeWidth={0}>- {splitData.map(slice => <Cell key={slice.name} fill={slice.color} />)}- </Pie>- <ReTooltip contentStyle={tooltipStyle} />- <Legend iconType="circle" iconSize={8} wrapperStyle={legendStyle} />- </PieChart>+ <DonutChart data={splitData} height={280} /></ChartPanel><ChartPaneltitle="Shorts compared with regular videos"className="md:col-span-3"- summary={`${viewsLead} get more views on average: ${fmtNum(analytics.avgShortViews)} per Short against ${fmtNum(analytics.avgRegularViews)} per regular video.`}- table={{- caption: 'Shorts compared with regular videos',- columns: [- { key: 'metric', label: 'Average' },- { key: 'Shorts', label: 'Shorts', numeric: true, format: full },- { key: 'Regular', label: 'Regular videos', numeric: true, format: full },- ],- rows: comparison,- }}+ description={`${viewsLead} get more views on average: ${fmtNumFull(analytics.avgShortViews)} per Short against ${fmtNumFull(analytics.avgRegularViews)} per regular video.`}>- <BarChart data={comparison}>- <CartesianGrid {...gridProps} vertical={false} />- <XAxis dataKey="metric" {...axisProps} />- <YAxis {...axisProps} tickFormatter={fmtNum} />- <ReTooltip contentStyle={tooltipStyle} cursor={tooltipCursor} formatter={fullNumber} />- <Bar dataKey="Shorts" fill={SERIES.primary} radius={[4, 4, 0, 0]} />- <Bar dataKey="Regular" name="Regular videos" fill={SERIES.neutral} radius={[4, 4, 0, 0]} />- <Legend wrapperStyle={legendStyle} />- </BarChart>+ <BarChart+ data={comparison}+ dataKey="metric"+ config={COMPARISON}+ containerHeight={280}+ tooltip={<ExactTooltip />}+ valueFormatter={fmtNum}+ /></ChartPanel></div></>diff --git a/frontend/src/features/analytics/channel/ChannelTagsTab.tsx b/frontend/src/features/analytics/channel/ChannelTagsTab.tsxindex a096f30..a83b8e4 100644--- a/frontend/src/features/analytics/channel/ChannelTagsTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelTagsTab.tsx@@ -1,20 +1,25 @@+import { BarChart } from '@/components/ui/bar-chart';import MetricBox from '@/components/MetricBox';-import SurfaceBox from '@/components/SurfaceBox';-import RankingBarChart from '@/components/RankingBarChart';+import ChartPanel from '@/components/ChartPanel';+import ExactTooltip from '@/components/ExactTooltip';+import { SERIES, pointsOf, rankingSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';-import { fmtPercent } from '../../../utils/formatters';+import { fmtNum, fmtNumFull, fmtPercent } from '../../../utils/formatters';import MetricGrid from './MetricGrid';import TagCloud from './TagCloud';import type { VideoAnalytics } from '@shared/types/youtube.ts';const { tags: Tags, comments: Captions, quality: Quality, regularVideos: Embeddable } = METRIC_ICONS;+const TAG_USAGE = { count: { label: 'Videos using this tag', color: SERIES.neutral } };+export interface ChannelTagsTabProps {analytics: VideoAnalytics;}export default function ChannelTagsTab({ analytics }: ChannelTagsTabProps) {const tags = analytics.tagFrequency || [];+ const topTags = tags.slice(0, 20).map(({ tag, count }) => ({ tag, count }));return (<><MetricGrid>@@ -25,13 +30,19 @@ export default function ChannelTagsTab({ analytics }: ChannelTagsTabProps) {</MetricGrid><TagCloud tags={tags} />{tags.length > 0 && (- <SurfaceBox title="Tag usage, top 20">- <RankingBarChart- rows={tags.slice(0, 20).map(({ tag, count }) => ({ name: tag, value: count }))}- label="Videos using this tag"- title="Tag usage, top 20"+ <ChartPanel title="Tag usage, top 20" height={400} description={rankingSummary(pointsOf(topTags, 'tag', 'count'), fmtNumFull, 'videos')}>+ <BarChart+ data={topTags}+ dataKey="tag"+ layout="vertical"+ config={TAG_USAGE}+ containerHeight={400}+ legend={false}+ tooltip={<ExactTooltip />}+ xAxisProps={{ type: 'number', allowDecimals: false, tickFormatter: fmtNum }}+ yAxisProps={{ width: 140 }}/>- </SurfaceBox>+ </ChartPanel>)}</>);diff --git a/frontend/src/features/analytics/channel/ChannelVideosTab.tsx b/frontend/src/features/analytics/channel/ChannelVideosTab.tsxindex 9bf32a6..540e88e 100644--- a/frontend/src/features/analytics/channel/ChannelVideosTab.tsx+++ b/frontend/src/features/analytics/channel/ChannelVideosTab.tsx@@ -1,22 +1,36 @@-import SurfaceBox from '@/components/SurfaceBox';-import RankingBarChart from '@/components/RankingBarChart';-import { PLATFORM_META } from '@/lib/accounts';+import { BarChart } from '@/components/ui/bar-chart';+import ChartPanel from '@/components/ChartPanel';+import ExactTooltip from '@/components/ExactTooltip';+import { SERIES, pointsOf, rankingSummary } from '@/lib/chart';+import { fmtNum, fmtNumFull } from '../../../utils/formatters';import { topVideoRowsOf, topVideosChartOf } from './channelChartData.ts';import ChannelVideoTable from './ChannelVideoTable';import type { VideoAnalytics } from '@shared/types/youtube.ts';+const TOP_VIDEOS = {+ views: { label: 'Views', color: SERIES.primary },+ likes: { label: 'Likes', color: SERIES.neutral },+};+export interface ChannelVideosTabProps {analytics: VideoAnalytics;}-// views alone: likes are a different scale and would hide in the same bars; they are in the table belowexport default function ChannelVideosTab({ analytics }: ChannelVideosTabProps) {- const rows = topVideosChartOf(analytics.top10ByViews).map(video => ({ name: video.name, value: video.views }));+ const topVideos = topVideosChartOf(analytics.top10ByViews);return (<>- <SurfaceBox title="Top 10 videos by views">- <RankingBarChart rows={rows} label="Views" title="Top 10 videos by views" color={PLATFORM_META.youtube.series} />- </SurfaceBox>+ <ChartPanel title="Top 10 videos by views" height={320} description={rankingSummary(pointsOf(topVideos, 'name', 'views'), fmtNumFull, 'views')}>+ <BarChart+ data={topVideos}+ dataKey="name"+ config={TOP_VIDEOS}+ containerHeight={320}+ tooltip={<ExactTooltip />}+ valueFormatter={fmtNum}+ xAxisProps={{ angle: -15, textAnchor: 'end', height: 70 }}+ />+ </ChartPanel><ChannelVideoTable title="Top videos by views and likes" videos={topVideoRowsOf(analytics)} /></>);diff --git a/frontend/src/features/analytics/channel/TrendArea.tsx b/frontend/src/features/analytics/channel/TrendArea.tsxindex 3d1cff8..355b70a 100644--- a/frontend/src/features/analytics/channel/TrendArea.tsx+++ b/frontend/src/features/analytics/channel/TrendArea.tsx@@ -1,47 +1,32 @@-import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip as ReTooltip } from 'recharts';-import type { TooltipValueType } from 'recharts';-import { axisProps, gridProps, tooltipStyle } from '@/lib/chart';-import { fmtNum, fmtNumFull } from '../../../utils/formatters';+import { AreaChart } from '@/components/ui/area-chart';+import ExactTooltip from '@/components/ExactTooltip';+import { fmtNum } from '../../../utils/formatters';import type { YouTubeMonthlyRate, YouTubeMonthlyViews } from '@shared/types/youtube.ts';export interface TrendAreaProps {data: (YouTubeMonthlyViews | YouTubeMonthlyRate)[];- dataKey?: string;color: string;name: string;percent?: boolean;- gradientId: string;- // ChartPanel passes these on to the svg so the focusable plot has a name- title?: string;- desc?: string;+ height?: number;}-function percentTick(value: number | string): string {+function percentTick(value: number): string {return `${value}%`;}-function fullNumber(value: TooltipValueType | undefined): string {- return fmtNumFull(value as number);-}--function percentValue(value: TooltipValueType | undefined): string {- return `${value}%`;-}--export default function TrendArea({ data, dataKey = 'value', color, name, percent = false, gradientId, title, desc }: TrendAreaProps) {+export default function TrendArea({ data, color, name, percent = false, height = 280 }: TrendAreaProps) {+ const rows = data.map(point => ({ month: point.month, value: Number(point.value) || 0 }));return (- <AreaChart data={data} title={title} desc={desc}>- <defs>- <linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">- <stop offset="5%" stopColor={color} stopOpacity={0.2} />- <stop offset="95%" stopColor={color} stopOpacity={0} />- </linearGradient>- </defs>- <CartesianGrid {...gridProps} vertical={false} />- <XAxis dataKey="month" {...axisProps} />- <YAxis {...axisProps} tickFormatter={percent ? percentTick : fmtNum} width={48} />- <ReTooltip contentStyle={tooltipStyle} cursor={{ stroke: 'var(--line-strong)' }} formatter={percent ? percentValue : fullNumber} />- <Area type="monotone" dataKey={dataKey} stroke={color} fill={`url(#${gradientId})`} strokeWidth={2} name={name} />- </AreaChart>+ <AreaChart+ data={rows}+ dataKey="month"+ config={{ value: { label: name, color } }}+ containerHeight={height}+ legend={false}+ tooltip={<ExactTooltip format={percent ? percentTick : undefined} />}+ valueFormatter={percent ? percentTick : fmtNum}+ areaProps={{ type: 'monotone' }}+ />);}diff --git a/frontend/src/features/analytics/channel/channelChartData.ts b/frontend/src/features/analytics/channel/channelChartData.tsindex da101e2..eb90d59 100644--- a/frontend/src/features/analytics/channel/channelChartData.ts+++ b/frontend/src/features/analytics/channel/channelChartData.ts@@ -1,5 +1,5 @@import { SERIES, trendSummary } from '../../../lib/chart.ts';-import { CATEGORY_MAP, fmtDate, fmtNum, fmtPercent } from '../../../utils/formatters.ts';+import { CATEGORY_MAP, fmtDate, fmtNum, fmtNumFull, fmtPercent } from '../../../utils/formatters.ts';import type {VideoAnalytics, YouTubeAnalyticsPayload, YouTubeDurationDistribution, YouTubeMonthlyViews, YouTubeVideoSummary,YouTubeViewsDistribution,@@ -67,7 +67,6 @@ export function shortsComparisonOf(analytics: Pick<VideoAnalytics, 'avgShortView];}-// every title gets the ellipsis, even short ones// an ellipsis only when the title was actually cutfunction shortTitle(title: string, max = 28): string {return title.length > max ? `${title.slice(0, max)}…` : title;@@ -129,12 +128,8 @@ export interface MonthlyPoint {value: number | string;}-// the takeaway in words and the numbers as rows, for a month-by-month chart-export function monthlyChartText(data: readonly MonthlyPoint[], unit: string, percent = false) {+// the takeaway of a month-by-month chart in words, read by screen readers in place of the plot+export function monthlySummary(data: readonly MonthlyPoint[], unit: string, percent = false): string {const points = data.map(point => ({ name: point.month, value: Number(point.value) || 0 }));- const format = percent ? (value: number) => `${value}%` : fmtNum;- return {- summary: trendSummary(points, format, unit),- rows: points.map(point => ({ month: point.name, value: percent ? `${point.value}%` : point.value })),- };+ return trendSummary(points, percent ? (value: number) => `${value}%` : fmtNumFull, unit);}diff --git a/frontend/tests/features/analytics/channel/channelChartData.test.ts b/frontend/tests/features/analytics/channel/channelChartData.test.tsindex 3f06cbc..6312fdb 100644--- a/frontend/tests/features/analytics/channel/channelChartData.test.ts+++ b/frontend/tests/features/analytics/channel/channelChartData.test.ts@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';import {watchUrl, channelMeta, dayDataOf, hourDataOf, durationDataOf, categoryDataOf, splitDataOf, shortsComparisonOf,topVideosChartOf, topVideoRowsOf, viewRangeDataOf, uploadsByMonthOf, rateOf, likesPerComment, peakHourLabel,- bestVideosOf, likesLabel,+ bestVideosOf, likesLabel, monthlySummary,} from '../../../../src/features/analytics/channel/channelChartData.ts';import type { VideoAnalytics, YouTubeVideoSummary } from '../../../../../shared/types/youtube.ts';@@ -82,3 +82,10 @@ test('best videos and like labels', () => {assert.equal(likesLabel(null), 'likes hidden');assert.equal(likesLabel(1500), '1.5K likes');});++test('a monthly description reads the trend in full numbers, or as rates', () => {+ const views = [{ month: 'Jan 2026', value: 1200 }, { month: 'Feb 2026', value: 5400 }];+ assert.equal(monthlySummary(views, 'views'), 'From Jan 2026 to Feb 2026: 1,200 to 5,400 views. Peak 5,400 in Feb 2026.');+ const rates = [{ month: 'Jan 2026', value: '4.5' }, { month: 'Feb 2026', value: '3.1' }];+ assert.equal(monthlySummary(rates, 'like rate', true), 'From Jan 2026 to Feb 2026: 4.5% to 3.1% like rate. Peak 4.5% in Jan 2026.');+});