File size: 9,071 Bytes
0fff343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
"use client";

import { useId, useRef, useState } from "react";
import { ParamKey } from "./paramHelpContent";
import { useParamHelp } from "./ParamHelpProvider";

/**
 * "How these parameters relate" β€” a collapsed disclosure with a clean
 * HTML/flex pipeline diagram inside. Presentation only.
 *
 * Centered single-column layout, max-width 460px, width 100% β€” never
 * wider than the panel, never overflowing. Each step is a neutral box;
 * between consecutive boxes sits a coloured "pill" naming the
 * parameter(s) that govern that transition, with a calm ↓ between
 * pill and the next box.
 */
export default function ParameterFlow() {
  const [open, setOpen] = useState(false);
  const panelId = useId();
  return (
    <div className="mb-4 -mt-2 text-xs">
      <button
        type="button"
        onClick={() => setOpen((o) => !o)}
        aria-expanded={open}
        aria-controls={panelId}
        className="inline-flex items-center gap-1.5 rounded text-ink hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
      >
        <span
          aria-hidden
          style={{
            display: "inline-block",
            transition: "transform 120ms ease",
            transform: open ? "rotate(90deg)" : "rotate(0deg)",
          }}
        >
          β–Έ
        </span>
        <span className="font-medium">How these parameters relate</span>
      </button>
      {open && (
        <div id={panelId} className="mt-3 w-full">
          <Pipeline />
          <Legend />
        </div>
      )}
    </div>
  );
}

// ---------- diagram model ------------------------------------------------

type PillKind = "SPACE" | "EFFORT" | "VALIDATION";

interface Box {
  title: string;
  sub?: string;
  amber?: boolean;
}

/** A pill is a list of inline fragments: either a plain string or a
 * {bold} fragment so we can highlight just the parameter name. The
 * bold fragments carry an optional ``paramKey`` β€” when present, that
 * fragment is rendered as a button that opens the ParamHelp modal. */
type Frag = string | { bold: string; paramKey?: ParamKey };
interface Pill {
  kind: PillKind;
  /** Optional small text prefix (e.g. "↻ " for the loop pill). */
  prefix?: string;
  fragments: Frag[];
}

const PILL_STYLES: Record<PillKind, { bg: string; fg: string }> = {
  SPACE: { bg: "#E7EFF1", fg: "#2C5563" },
  EFFORT: { bg: "#F6ECE0", fg: "#8A4E20" },
  VALIDATION: { bg: "#ECEBE6", fg: "#5A6670" },
};

const BOXES: Box[] = [
  { title: "~20,000 genes", sub: "every gene measured" },
  { title: "Gene pool β€” N genes", sub: "the shortlist the engine draws from" },
  { title: "One program", sub: "Select β†’ Reduce β†’ Fit" },
  { title: "One generation", sub: "every program scored & ranked" },
  { title: "Winning program" },
  { title: "permutation p", sub: "could this be luck?", amber: true },
];

const PILLS: Pill[] = [
  {
    kind: "SPACE",
    fragments: [
      { bold: "Prefilter top-N", paramKey: "prefilter_n" },
      " β€” keep the N most promising genes (off by default = all ~20,000)",
    ],
  },
  {
    kind: "SPACE",
    fragments: [
      { bold: "Max sets", paramKey: "max_sets" },
      " Γ— ",
      { bold: "Genes/set", paramKey: "genes_per_set" },
      " β€” pick 1–2 sets, each ≀ G genes",
    ],
  },
  {
    kind: "EFFORT",
    fragments: [
      { bold: "Population", paramKey: "population" },
      " β€” programs compete each round Β· ",
      { bold: "Ξ»", paramKey: "lambda" },
      " β€” taxes extra genes",
    ],
  },
  {
    kind: "EFFORT",
    prefix: "↻ ",
    fragments: [
      "Γ— ",
      { bold: "Generations", paramKey: "generations" },
      " β€” breed the best, repeat Β· ",
      { bold: "Seed", paramKey: "seed" },
      " β€” fixes the randomness",
    ],
  },
  {
    kind: "VALIDATION",
    fragments: [
      { bold: "Permutations", paramKey: "permutations" },
      " β€” re-run on N shuffled-label sets",
    ],
  },
];

// ---------- render -------------------------------------------------------

function Pipeline() {
  return (
    <div
      style={{
        maxWidth: 460,
        width: "100%",
        marginInline: "auto",
        display: "flex",
        flexDirection: "column",
        alignItems: "stretch",
        gap: 8,
      }}
    >
      {BOXES.map((b, i) => (
        <div key={`group-${i}`} style={{ display: "contents" }}>
          <BoxRow box={b} />
          {i < PILLS.length && (
            <>
              <PillRow pill={PILLS[i]} />
              <Arrow />
            </>
          )}
        </div>
      ))}
    </div>
  );
}

function BoxRow({ box }: { box: Box }) {
  return (
    <div
      style={{
        width: "100%",
        background: box.amber ? "#FBF1E6" : "#F5F4F0",
        border: `1px solid ${box.amber ? "#BC6B2E" : "#D9D6CE"}`,
        borderRadius: 12,
        padding: "12px 14px",
        textAlign: "center",
        fontFamily: '"Helvetica Neue", Helvetica, Arial, sans-serif',
        lineHeight: 1.3,
      }}
    >
      <div
        style={{
          fontSize: 13,
          fontWeight: 600,
          color: "#23303A",
        }}
      >
        {box.title}
      </div>
      {box.sub && (
        <div
          style={{
            marginTop: 2,
            fontSize: 11.5,
            color: "#6E7F8C",
          }}
        >
          {box.sub}
        </div>
      )}
    </div>
  );
}

function PillRow({ pill }: { pill: Pill }) {
  const { bg, fg } = PILL_STYLES[pill.kind];
  return (
    <div
      style={{
        display: "flex",
        justifyContent: "center",
        width: "100%",
      }}
    >
      <div
        style={{
          maxWidth: "92%",
          background: bg,
          color: fg,
          borderRadius: 14,
          padding: "6px 12px",
          fontSize: 12.5,
          lineHeight: 1.35,
          textAlign: "center",
          whiteSpace: "normal",
          overflowWrap: "break-word",
          wordBreak: "normal",
          fontFamily: '"Helvetica Neue", Helvetica, Arial, sans-serif',
        }}
      >
        {pill.prefix && (
          <span style={{ marginRight: 2 }} aria-hidden>
            {pill.prefix}
          </span>
        )}
        {pill.fragments.map((f, i) => {
          if (typeof f === "string") return <span key={i}>{f}</span>;
          if (!f.paramKey) {
            return (
              <strong key={i} style={{ fontWeight: 600 }}>
                {f.bold}
              </strong>
            );
          }
          return <ParamPillButton key={i} bold={f.bold} paramKey={f.paramKey} colour={fg} />;
        })}
      </div>
    </div>
  );
}

function ParamPillButton({
  bold,
  paramKey,
  colour,
}: {
  bold: string;
  paramKey: ParamKey;
  colour: string;
}) {
  const ref = useRef<HTMLButtonElement>(null);
  const { open } = useParamHelp();
  return (
    <button
      ref={ref}
      type="button"
      aria-haspopup="dialog"
      aria-label={`About ${bold}`}
      onClick={(e) => {
        e.stopPropagation();
        e.preventDefault();
        open(paramKey, ref.current);
      }}
      style={{
        background: "transparent",
        border: "none",
        padding: 0,
        font: "inherit",
        color: colour,
        fontWeight: 600,
        textDecoration: "underline",
        textDecorationStyle: "dotted",
        textDecorationColor: `${colour}66`,
        textUnderlineOffset: 2,
        cursor: "pointer",
      }}
      onMouseOver={(e) => {
        (e.currentTarget.style as any).textDecorationStyle = "solid";
      }}
      onMouseOut={(e) => {
        (e.currentTarget.style as any).textDecorationStyle = "dotted";
      }}
    >
      {bold}
    </button>
  );
}

function Arrow() {
  return (
    <div
      aria-hidden
      style={{
        textAlign: "center",
        color: "#B9B6AE",
        fontSize: 16,
        lineHeight: 1,
        userSelect: "none",
      }}
    >
      ↓
    </div>
  );
}

function Legend() {
  return (
    <div
      style={{
        maxWidth: 460,
        width: "100%",
        marginInline: "auto",
        marginTop: 12,
        display: "flex",
        flexWrap: "wrap",
        justifyContent: "center",
        gap: "6px 14px",
        fontSize: 11,
        color: "#6E7F8C",
      }}
    >
      <LegendItem fill="#E7EFF1" ink="#2C5563">
        teal = where it searches
      </LegendItem>
      <LegendItem fill="#F6ECE0" ink="#8A4E20">
        amber = how hard it searches
      </LegendItem>
      <LegendItem fill="#ECEBE6" ink="#5A6670">
        grey = validation
      </LegendItem>
    </div>
  );
}

function LegendItem({
  fill,
  ink,
  children,
}: {
  fill: string;
  ink: string;
  children: React.ReactNode;
}) {
  return (
    <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
      <span
        aria-hidden
        style={{
          display: "inline-block",
          width: 10,
          height: 10,
          borderRadius: 999,
          background: fill,
          border: `1px solid ${ink}33`,
        }}
      />
      {children}
    </span>
  );
}