Download code/web/src/components/daily.tsx from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 5.43 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/refs%2Fpr%2F1/code/web/src/components/daily.tsx
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@refs/pr/1/code/web/src/components/daily.tsx
-
curl -L -o daily.tsx https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/refs%2Fpr%2F1/code/web/src/components/daily.tsx
5.43 kB
| import { useMemo, useState } from "react" | |
| import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts" | |
| import { ChartContainer, ChartTooltip } from "@/components/ui/chart" | |
| import type { Lineage, Rel } from "@/lib/types" | |
| import { relName, T } from "@/lib/i18n" | |
| import { isoDay, mdy, num, toTime } from "@/lib/format" | |
| import { timeTicks } from "@/lib/ticks" | |
| import { Panel, Section } from "@/components/layout" | |
| import { axisTick, relColor, relConfig, RelLegend } from "@/components/rel" | |
| /** | |
| * Downloads per day of the community models, stacked by kind, about a week per point (the | |
| * hub-stats history, then our snapshots); drawn like the other time charts on the page. | |
| */ | |
| export function DailyLines({ L, rel, download }: { L: Lineage; rel: Rel[]; download?: string }) { | |
| const { rows, present, thin } = useMemo(() => { | |
| const days = [...new Set(L.daily.map((d) => d.day))].sort() | |
| // biggest kinds at the bottom of the stack | |
| const total = (r: Rel) => L.daily.reduce((a, d) => a + (d.rel === r ? d.n : 0), 0) | |
| const present = rel.filter((r) => total(r) > 0).sort((a, b) => total(b) - total(a)) | |
| const at = new Map(L.daily.map((d) => [`${d.day}|${d.rel}`, d.n])) | |
| const rows = days.map((day) => ({ t: toTime(day), ...Object.fromEntries(present.map((r) => [r, at.get(`${day}|${r}`) ?? 0])) })) | |
| // a sliver of the total gets no outline, or it would trace the top of the stack in its colour | |
| const all = present.reduce((a, r) => a + total(r), 0) || 1 | |
| const thin = new Set(present.filter((r) => total(r) / all < 0.02)) | |
| return { rows, present, thin } | |
| }, [L, rel]) | |
| const [hidden, setHidden] = useState<Set<Rel>>(new Set()) | |
| const toggle = (r: Rel) => setHidden((h) => { | |
| const n = new Set(h) | |
| if (n.has(r)) n.delete(r) | |
| else if (n.size < present.length - 1) n.add(r) | |
| return n | |
| }) | |
| const { ticks, label } = useMemo(() => (rows.length ? timeTicks(rows[0].t, rows.at(-1)!.t) : { ticks: [], label: String }), [rows]) | |
| if (rows.length < 2) return null | |
| const shown = present.filter((r) => !hidden.has(r)) | |
| return ( | |
| <Section title={T.dailyDownloads}> | |
| <Panel download={download}> | |
| <RelLegend rels={[...present].sort((a, b) => rel.indexOf(a) - rel.indexOf(b))} hidden={hidden} onToggle={toggle} /> | |
| <ChartContainer config={relConfig(present)} className="aspect-auto h-[360px] w-full"> | |
| <AreaChart data={rows} margin={{ left: 4, right: 12, top: 8 }}> | |
| <defs> | |
| {present.map((r) => ( | |
| <linearGradient key={r} id={`dd-${r}`} x1="0" y1="0" x2="0" y2="1"> | |
| <stop offset="0" stopColor={relColor(r)} stopOpacity={0.5} /> | |
| <stop offset="1" stopColor={relColor(r)} stopOpacity={0.08} /> | |
| </linearGradient> | |
| ))} | |
| </defs> | |
| <CartesianGrid vertical={false} /> | |
| <XAxis dataKey="t" type="number" scale="time" domain={["dataMin", "dataMax"]} ticks={ticks} | |
| tickFormatter={label} tickLine={false} axisLine={false} tick={axisTick} /> | |
| <YAxis tickLine={false} axisLine={false} tick={axisTick} width={56} tickFormatter={(v) => num(Number(v))} /> | |
| <ChartTooltip cursor={{ stroke: "var(--muted-foreground)", strokeOpacity: 0.4 }} | |
| content={({ active, payload }) => { | |
| if (!active || !payload?.length) return null | |
| const row = payload[0].payload as Record<string, number> | |
| const items = [...shown].reverse().filter((r) => row[r] > 0) | |
| return ( | |
| <div className="min-w-[13rem] rounded-xl border border-border/60 bg-background px-3.5 py-3 text-[15px] shadow-xl"> | |
| <div className="text-muted-foreground">{mdy(isoDay(row.t))}</div> | |
| <div className="mt-0.5 font-display text-[24px] leading-tight font-semibold tabular-nums"> | |
| {num(shown.reduce((a, r) => a + (row[r] ?? 0), 0))} | |
| </div> | |
| <div className="mt-2 space-y-1"> | |
| {items.map((r) => ( | |
| <div key={r} className="flex items-center justify-between gap-6"> | |
| <span className="inline-flex items-center gap-2 text-muted-foreground"> | |
| <span className="size-2.5 rounded-full" style={{ background: relColor(r) }} /> | |
| {relName(r)} | |
| </span> | |
| <span className="font-medium tabular-nums">{num(row[r])}</span> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ) | |
| }} /> | |
| {shown.map((r) => ( | |
| <Area key={r} dataKey={r} stackId="d" type="monotone" stroke={relColor(r)} strokeWidth={thin.has(r) ? 0 : 1.75} | |
| fill={`url(#dd-${r})`} dot={false} activeDot={{ r: 4, strokeWidth: 2, stroke: "var(--card)" }} | |
| animationDuration={1100} animationEasing="ease-out" /> | |
| ))} | |
| </AreaChart> | |
| </ChartContainer> | |
| </Panel> | |
| </Section> | |
| ) | |
| } | |