Download code/web/src/components/growth.tsx from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 4.84 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/32bb255ca2b9ad24275909f24cdd584753ee8a4d/code/web/src/components/growth.tsx
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@32bb255ca2b9ad24275909f24cdd584753ee8a4d/code/web/src/components/growth.tsx
-
curl -L -o growth.tsx https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/32bb255ca2b9ad24275909f24cdd584753ee8a4d/code/web/src/components/growth.tsx
4.84 kB
| import { useMemo, useState } from "react" | |
| import { Bar, BarChart, CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts" | |
| import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@/components/ui/chart" | |
| import type { Lineage, Rel } from "@/lib/types" | |
| import { relName, T } from "@/lib/i18n" | |
| import { relConfig, RelLegend, axisTick } from "@/components/rel" | |
| import { md } from "@/lib/format" | |
| const day = (d: Date) => d.toISOString().slice(0, 10) | |
| const addDays = (s: string, n: number) => { | |
| const d = new Date(s + "T00:00:00Z") | |
| d.setUTCDate(d.getUTCDate() + n) | |
| return day(d) | |
| } | |
| /** Running total of each kind of derivative, from the creation dates (full history). */ | |
| export function GrowthLines({ L, rel, today }: { L: Lineage; rel: Rel[]; today: string }) { | |
| const { rows, present } = useMemo(() => { | |
| const present = rel.filter((r) => L.by_relation[r].n > 0) | |
| if (!L.growth.length) return { rows: [], present } | |
| const byDate = new Map<string, Partial<Record<Rel, number>>>() | |
| for (const g of L.growth) { | |
| const m = byDate.get(g.date) ?? {} | |
| m[g.rel] = (m[g.rel] ?? 0) + g.n | |
| byDate.set(g.date, m) | |
| } | |
| const start = [...byDate.keys()].sort()[0] | |
| const run: Record<string, number> = Object.fromEntries(present.map((r) => [r, 0])) | |
| const rows: Record<string, string | number>[] = [] | |
| for (let d = start; d <= today; d = addDays(d, 1)) { | |
| for (const [r, n] of Object.entries(byDate.get(d) ?? {})) run[r] = (run[r] ?? 0) + n | |
| rows.push({ date: d, ...run }) | |
| } | |
| // Long histories are drawn from one point a week, which keeps the curves smooth. | |
| const step = rows.length > 90 ? 7 : 1 | |
| const thin = rows.filter((_, i) => i % step === 0 || i === rows.length - 1) | |
| return { rows: thin, present } | |
| }, [L, rel, today]) | |
| 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 n.add(r); return n }) | |
| return ( | |
| <> | |
| <RelLegend rels={present} hidden={hidden} onToggle={toggle} /> | |
| <ChartContainer config={relConfig(present)} className="aspect-auto h-[320px] w-full"> | |
| <LineChart data={rows} margin={{ left: 4, right: 12, top: 8 }}> | |
| <CartesianGrid vertical={false} /> | |
| <XAxis dataKey="date" tickLine={false} axisLine={false} tick={axisTick} tickFormatter={md} minTickGap={48} /> | |
| <YAxis tickLine={false} axisLine={false} tick={axisTick} width={44} /> | |
| <ChartTooltip content={<ChartTooltipContent labelFormatter={(v) => md(String(v))} />} /> | |
| {present.filter((r) => !hidden.has(r)).map((r) => ( | |
| <Line key={r} dataKey={r} name={relName(r)} type="monotone" stroke={`var(--color-${r})`} | |
| strokeWidth={2} dot={false} animationDuration={900} animationEasing="ease-out" /> | |
| ))} | |
| </LineChart> | |
| </ChartContainer> | |
| </> | |
| ) | |
| } | |
| /** New derivatives per finished week (Monday start); the current week would read as a drop. */ | |
| export function WeeklyBars({ L, today, color = "var(--brand)" }: { L: Lineage; today: string; color?: string }) { | |
| const rows = useMemo(() => { | |
| const monday = (s: string) => { | |
| const d = new Date(s + "T00:00:00Z") | |
| d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 6) % 7)) | |
| return day(d) | |
| } | |
| const weeks = new Map<string, number>() | |
| for (const g of L.growth) weeks.set(monday(g.date), (weeks.get(monday(g.date)) ?? 0) + g.n) | |
| const keys = [...weeks.keys()].sort() | |
| const end = monday(today) | |
| const out: { week: string; n: number }[] = [] | |
| for (let w = keys[0]; w && w < end; w = addDays(w, 7)) out.push({ week: w, n: weeks.get(w) ?? 0 }) | |
| return out | |
| }, [L, today]) | |
| const config = { n: { label: T.newN, color } } satisfies ChartConfig | |
| const weekMax = Math.max(1, ...rows.map((r) => r.n)) | |
| const step = weekMax > 200 ? 100 : weekMax > 60 ? 50 : weekMax > 20 ? 10 : 5 | |
| return ( | |
| <ChartContainer config={config} className="aspect-auto h-[356px] w-full"> | |
| <BarChart data={rows} margin={{ left: 4, right: 4, top: 8 }}> | |
| <CartesianGrid vertical={false} /> | |
| <XAxis dataKey="week" tickLine={false} axisLine={false} tick={axisTick} tickFormatter={md} minTickGap={40} /> | |
| <YAxis tickLine={false} axisLine={false} tick={axisTick} width={36} allowDecimals={false} | |
| domain={[0, (max: number) => Math.ceil(max / step) * step]} tickCount={Math.max(2, Math.ceil(weekMax / step) + 1)} /> | |
| <ChartTooltip cursor={{ fill: "var(--muted)" }} | |
| content={<ChartTooltipContent labelFormatter={(v) => T.weekOf(md(String(v)))} />} /> | |
| <Bar dataKey="n" fill="var(--color-n)" radius={[4, 4, 0, 0]} maxBarSize={22} animationDuration={900} animationEasing="ease-out" /> | |
| </BarChart> | |
| </ChartContainer> | |
| ) | |
| } | |