Skip to content

The only tool you need to know what is happening and how to fix it.

Making the website chart responsive

narrow-adventurea517be5e016c
diff --git a/website/components/benchmark-index-chart.tsx b/website/components/benchmark-index-chart.tsx
index 484418bd..9ba54983 100644
--- a/website/components/benchmark-index-chart.tsx
+++ b/website/components/benchmark-index-chart.tsx
@@ -42,6 +42,8 @@ const WEIGHTS_TEXT = {
const PLOT_HEIGHT = 300;
const GRID = [0, 25, 50, 75, 100];
+const BAR_GAP = 24;
+const LABEL_COLUMN_MIN = 68;
export function BenchmarkIndexChart({
views,
@@ -57,6 +59,8 @@ export function BenchmarkIndexChart({
const bars = [...view.bars].sort((a, b) => value(b) - value(a));
const dense = bars.length > 8;
const minWidth = dense ? 64 + bars.length * 46 : 0;
+ const legendBelow =
+ bars.length * LABEL_COLUMN_MIN + (bars.length - 1) * BAR_GAP;
const metricLabel = METRICS.find((m) => m.id === metric)!.label;
return (
@@ -159,7 +163,20 @@ export function BenchmarkIndexChart({
</span>
</div>
- <div className="mt-3 overflow-x-auto pb-1">
+ <div
+ className="mt-3 overflow-x-auto pb-1"
+ data-bars={bars.length}
+ style={{ containerType: "inline-size", containerName: "index-chart" }}
+ >
+ {dense ? null : (
+ <style>{`
+ @container index-chart (max-width: ${legendBelow - 1}px) {
+ [data-bars="${bars.length}"] .index-chart-row { gap: 10px; }
+ [data-bars="${bars.length}"] .index-chart-labels { display: none; }
+ [data-bars="${bars.length}"] .index-chart-legend { display: grid; }
+ }
+ `}</style>
+ )}
<div style={{ minWidth, paddingLeft: dense ? 64 : 0 }}>
<div className="relative" style={{ height: PLOT_HEIGHT }}>
{GRID.map((g) => (
@@ -177,15 +194,16 @@ export function BenchmarkIndexChart({
/>
))}
<div
- className="absolute inset-0 flex items-end justify-center"
- style={{ gap: dense ? 6 : 24 }}
+ className={`absolute inset-0 flex items-end justify-center ${
+ dense ? "gap-1.5" : "index-chart-row gap-6"
+ }`}
>
{bars.map((b) => {
const v = value(b);
return (
<div
key={b.id}
- className="flex h-full flex-1 items-end justify-center"
+ className="flex h-full min-w-0 flex-1 items-end justify-center"
style={{ maxWidth: dense ? 56 : 120 }}
>
<div
@@ -217,13 +235,14 @@ export function BenchmarkIndexChart({
</div>
<div
- className="flex justify-center"
- style={{ gap: dense ? 6 : 24 }}
+ className={`flex justify-center ${
+ dense ? "gap-1.5" : "index-chart-row gap-6"
+ }`}
>
{bars.map((b) => (
<div
key={b.id}
- className="flex flex-1 flex-col items-center"
+ className="flex min-w-0 flex-1 flex-col items-center"
style={{ maxWidth: dense ? 56 : 120 }}
>
<span
@@ -251,7 +270,7 @@ export function BenchmarkIndexChart({
</span>
</div>
) : (
- <div className="mt-2 text-center text-[0.875rem] leading-snug text-fg-1">
+ <div className="index-chart-labels mt-2 text-center text-[0.875rem] leading-snug text-fg-1">
{b.label}
{b.detail ? (
<span className="block text-[0.75rem] text-fg-3">
@@ -264,6 +283,26 @@ export function BenchmarkIndexChart({
))}
</div>
</div>
+
+ {dense ? null : (
+ <ul className="index-chart-legend mt-4 hidden grid-cols-1 gap-x-6 gap-y-2 text-[0.8125rem] leading-snug text-fg-1 @min-[30rem]/index-chart:grid-cols-2">
+ {bars.map((b) => (
+ <li key={b.id} className="flex items-center gap-2">
+ <span
+ aria-hidden
+ className="inline-block h-3 w-3 shrink-0 rounded-[3px]"
+ style={{ background: MODEL_COLOR[b.model] }}
+ />
+ <span>
+ {b.label}
+ {b.detail ? (
+ <span className="text-fg-3"> · {b.detail}</span>
+ ) : null}
+ </span>
+ </li>
+ ))}
+ </ul>
+ )}
</div>
</div>
</div>