tfrere HF Staff commited on
Commit
624060e
·
1 Parent(s): bfe491f

update authors and pie chart

Browse files
app/.astro/settings.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:585e9065073b0b2528747f99b78ccc382984e713ac7e6a5c9f99a47956e3f42e
3
  size 58
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c8899b8bb86e440bbb98ab000b4c5a0d30bd1a50a97745f7b6c971eca2f6616
3
  size 58
app/src/components/Hero.astro CHANGED
@@ -5,26 +5,51 @@ interface Props {
5
  title: string; // may contain HTML (e.g., <br/>)
6
  titleRaw?: string; // plain title for slug/PDF (optional)
7
  description?: string;
8
- authors?: Array<string | { name: string; url?: string; affiliationIndices?: number[] }>;
 
 
9
  affiliations?: Array<{ id: number; name: string; url?: string }>;
10
  affiliation?: string; // legacy single affiliation
11
  published?: string;
12
  doi?: string;
 
13
  }
14
 
15
- const { title, titleRaw, description, authors = [], affiliations = [], affiliation, published, doi } = Astro.props as Props;
 
 
 
 
 
 
 
 
 
 
16
 
17
  type Author = { name: string; url?: string; affiliationIndices?: number[] };
18
 
19
- function normalizeAuthors(input: Array<string | { name?: string; url?: string; link?: string; affiliationIndices?: number[] }>): Author[] {
 
 
 
 
 
 
 
 
 
 
20
  return (Array.isArray(input) ? input : [])
21
  .map((a) => {
22
- if (typeof a === 'string') {
23
  return { name: a } as Author;
24
  }
25
- const name = (a?.name ?? '').toString();
26
  const url = (a?.url ?? a?.link) as string | undefined;
27
- const affiliationIndices = Array.isArray((a as any)?.affiliationIndices) ? (a as any).affiliationIndices : undefined;
 
 
28
  return { name, url, affiliationIndices } as Author;
29
  })
30
  .filter((a) => a.name && a.name.trim().length > 0);
@@ -35,35 +60,41 @@ const normalizedAuthors: Author[] = normalizeAuthors(authors as any);
35
  // Determine if affiliation superscripts should be shown (only when there are multiple distinct affiliations referenced by authors)
36
  const authorAffiliationIndexSet = new Set<number>();
37
  for (const author of normalizedAuthors) {
38
- const indices = Array.isArray(author.affiliationIndices) ? author.affiliationIndices : [];
 
 
39
  for (const idx of indices) {
40
- if (typeof idx === 'number') {
41
  authorAffiliationIndexSet.add(idx);
42
  }
43
  }
44
  }
45
  const shouldShowAffiliationSupers = authorAffiliationIndexSet.size > 1;
46
- const hasMultipleAffiliations = Array.isArray(affiliations) && affiliations.length > 1;
 
47
 
48
  function stripHtml(text: string): string {
49
- return String(text || '').replace(/<[^>]*>/g, '');
50
  }
51
 
52
  function slugify(text: string): string {
53
- return String(text || '')
54
- .normalize('NFKD')
55
- .replace(/\p{Diacritic}+/gu, '')
56
- .toLowerCase()
57
- .replace(/[^a-z0-9]+/g, '-')
58
- .replace(/^-+|-+$/g, '')
59
- .slice(0, 120) || 'article';
 
 
60
  }
61
 
62
  const pdfBase = titleRaw ? stripHtml(titleRaw) : stripHtml(title);
63
  const pdfFilename = `${slugify(pdfBase)}.pdf`;
64
  ---
 
65
  <section class="hero">
66
- <h1 class="hero-title" set:html={title}></h1>
67
  <div class="hero-banner">
68
  <HtmlEmbed src="banner.html" frameless />
69
  {description && <p class="hero-desc">{description}</p>}
@@ -72,53 +103,80 @@ const pdfFilename = `${slugify(pdfBase)}.pdf`;
72
 
73
  <header class="meta" aria-label="Article meta information">
74
  <div class="meta-container">
75
- {normalizedAuthors.length > 0 && (
76
- <div class="meta-container-cell">
77
- <h3>Author{normalizedAuthors.length > 1 ? 's' : ''}</h3>
78
- <ul class="authors">
79
- {normalizedAuthors.map((a, i) => {
80
- const supers = shouldShowAffiliationSupers && Array.isArray(a.affiliationIndices) && a.affiliationIndices.length
81
- ? <sup>{a.affiliationIndices.join(',')}</sup>
82
- : null;
83
- return (
84
- <li>
85
- {a.url ? <a href={a.url}>{a.name}</a> : a.name}{supers}
86
- </li>
87
- );
88
- })}
89
- </ul>
90
- </div>
91
- )}
92
- {(Array.isArray(affiliations) && affiliations.length > 0) && (
93
- <div class="meta-container-cell">
94
- <h3>Affiliation{affiliations.length > 1 ? 's' : ''}</h3>
95
- {hasMultipleAffiliations ? (
96
- <ol class="affiliations">
97
- {affiliations.map((af) => (
98
- <li value={af.id}>{af.url ? <a href={af.url} target="_blank" rel="noopener noreferrer">{af.name}</a> : af.name}</li>
99
- ))}
100
- </ol>
101
- ) : (
102
- <p>
103
- {affiliations[0]?.url
104
- ? <a href={affiliations[0].url} target="_blank" rel="noopener noreferrer">{affiliations[0].name}</a>
105
- : affiliations[0]?.name}
106
- </p>
107
- )}
108
- </div>
109
- )}
110
- {(!affiliations || affiliations.length === 0) && affiliation && (
111
- <div class="meta-container-cell">
112
- <h3>Affiliation</h3>
113
- <p>{affiliation}</p>
114
- </div>
115
- )}
116
- {published && (
117
- <div class="meta-container-cell meta-container-cell--published">
118
- <h3>Published</h3>
119
- <p>{published}</p>
120
- </div>
121
- )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  <!-- {doi && (
123
  <div class="meta-container-cell">
124
  <h3>DOI</h3>
@@ -126,16 +184,164 @@ const pdfFilename = `${slugify(pdfBase)}.pdf`;
126
  </div>
127
  )} -->
128
  <div class="meta-container-cell meta-container-cell--pdf">
129
- <h3>PDF</h3>
130
- <p>
131
- <a class="button" href={`/${pdfFilename}`} download={pdfFilename} aria-label={`Download PDF ${pdfFilename}`}>
132
- Download PDF
133
- </a>
134
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  </div>
136
  </div>
137
  </header>
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  <style>
141
  /* Hero (full-width) */
@@ -179,13 +385,13 @@ const pdfFilename = `${slugify(pdfBase)}.pdf`;
179
  gap: 8px;
180
  }
181
  /* Subtle underline for links in meta; keep buttons without underline */
182
- .meta-container a {
183
  color: var(--primary-color);
184
  text-decoration: underline;
185
  text-underline-offset: 2px;
186
  text-decoration-thickness: 0.06em;
187
  text-decoration-color: var(--link-underline);
188
- transition: text-decoration-color .15s ease-in-out;
189
  }
190
  .meta-container a:hover {
191
  text-decoration-color: var(--link-underline-hover);
@@ -198,6 +404,7 @@ const pdfFilename = `${slugify(pdfBase)}.pdf`;
198
  display: flex;
199
  flex-direction: column;
200
  gap: 8px;
 
201
  }
202
  .meta-container-cell h3 {
203
  margin: 0;
@@ -205,15 +412,21 @@ const pdfFilename = `${slugify(pdfBase)}.pdf`;
205
  font-weight: 400;
206
  color: var(--muted-color);
207
  text-transform: uppercase;
208
- letter-spacing: .02em;
209
  }
210
  .meta-container-cell p {
211
  margin: 0;
212
- }
213
  .authors {
214
  margin: 0;
215
  list-style-type: none;
216
  padding-left: 0;
 
 
 
 
 
 
217
  }
218
  .affiliations {
219
  margin: 0;
@@ -227,12 +440,153 @@ const pdfFilename = `${slugify(pdfBase)}.pdf`;
227
  flex-wrap: wrap;
228
  row-gap: 12px;
229
  }
230
-
 
 
 
 
 
 
 
231
  @media print {
232
  .meta-container-cell--pdf {
233
  display: none !important;
234
  }
235
  }
236
- </style>
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  title: string; // may contain HTML (e.g., <br/>)
6
  titleRaw?: string; // plain title for slug/PDF (optional)
7
  description?: string;
8
+ authors?: Array<
9
+ string | { name: string; url?: string; affiliationIndices?: number[] }
10
+ >;
11
  affiliations?: Array<{ id: number; name: string; url?: string }>;
12
  affiliation?: string; // legacy single affiliation
13
  published?: string;
14
  doi?: string;
15
+ pdfProOnly?: boolean; // Gate PDF download to Pro users only
16
  }
17
 
18
+ const {
19
+ title,
20
+ titleRaw,
21
+ description,
22
+ authors = [],
23
+ affiliations = [],
24
+ affiliation,
25
+ published,
26
+ doi,
27
+ pdfProOnly = false,
28
+ } = Astro.props as Props;
29
 
30
  type Author = { name: string; url?: string; affiliationIndices?: number[] };
31
 
32
+ function normalizeAuthors(
33
+ input: Array<
34
+ | string
35
+ | {
36
+ name?: string;
37
+ url?: string;
38
+ link?: string;
39
+ affiliationIndices?: number[];
40
+ }
41
+ >,
42
+ ): Author[] {
43
  return (Array.isArray(input) ? input : [])
44
  .map((a) => {
45
+ if (typeof a === "string") {
46
  return { name: a } as Author;
47
  }
48
+ const name = (a?.name ?? "").toString();
49
  const url = (a?.url ?? a?.link) as string | undefined;
50
+ const affiliationIndices = Array.isArray((a as any)?.affiliationIndices)
51
+ ? (a as any).affiliationIndices
52
+ : undefined;
53
  return { name, url, affiliationIndices } as Author;
54
  })
55
  .filter((a) => a.name && a.name.trim().length > 0);
 
60
  // Determine if affiliation superscripts should be shown (only when there are multiple distinct affiliations referenced by authors)
61
  const authorAffiliationIndexSet = new Set<number>();
62
  for (const author of normalizedAuthors) {
63
+ const indices = Array.isArray(author.affiliationIndices)
64
+ ? author.affiliationIndices
65
+ : [];
66
  for (const idx of indices) {
67
+ if (typeof idx === "number") {
68
  authorAffiliationIndexSet.add(idx);
69
  }
70
  }
71
  }
72
  const shouldShowAffiliationSupers = authorAffiliationIndexSet.size > 1;
73
+ const hasMultipleAffiliations =
74
+ Array.isArray(affiliations) && affiliations.length > 1;
75
 
76
  function stripHtml(text: string): string {
77
+ return String(text || "").replace(/<[^>]*>/g, "");
78
  }
79
 
80
  function slugify(text: string): string {
81
+ return (
82
+ String(text || "")
83
+ .normalize("NFKD")
84
+ .replace(/\p{Diacritic}+/gu, "")
85
+ .toLowerCase()
86
+ .replace(/[^a-z0-9]+/g, "-")
87
+ .replace(/^-+|-+$/g, "")
88
+ .slice(0, 120) || "article"
89
+ );
90
  }
91
 
92
  const pdfBase = titleRaw ? stripHtml(titleRaw) : stripHtml(title);
93
  const pdfFilename = `${slugify(pdfBase)}.pdf`;
94
  ---
95
+
96
  <section class="hero">
97
+ <h1 class="hero-title" set:html={title} />
98
  <div class="hero-banner">
99
  <HtmlEmbed src="banner.html" frameless />
100
  {description && <p class="hero-desc">{description}</p>}
 
103
 
104
  <header class="meta" aria-label="Article meta information">
105
  <div class="meta-container">
106
+ {
107
+ normalizedAuthors.length > 0 && (
108
+ <div class="meta-container-cell">
109
+ <h3>Author{normalizedAuthors.length > 1 ? "s" : ""}</h3>
110
+ <ul class="authors">
111
+ {normalizedAuthors.map((a, i) => {
112
+ const supers =
113
+ shouldShowAffiliationSupers &&
114
+ Array.isArray(a.affiliationIndices) &&
115
+ a.affiliationIndices.length ? (
116
+ <sup>{a.affiliationIndices.join(", ")}</sup>
117
+ ) : null;
118
+ return (
119
+ <li>
120
+ {a.url ? <a href={a.url}>{a.name}</a> : a.name}{supers}{i < normalizedAuthors.length - 1 && <span set:html=",&nbsp;" />}
121
+ </li>
122
+ );
123
+ })}
124
+ </ul>
125
+ </div>
126
+ )
127
+ }
128
+ {
129
+ Array.isArray(affiliations) && affiliations.length > 0 && (
130
+ <div class="meta-container-cell meta-container-cell--affiliations">
131
+ <h3>Affiliation{affiliations.length > 1 ? "s" : ""}</h3>
132
+ {hasMultipleAffiliations ? (
133
+ <ol class="affiliations">
134
+ {affiliations.map((af) => (
135
+ <li value={af.id}>
136
+ {af.url ? (
137
+ <a href={af.url} target="_blank" rel="noopener noreferrer">
138
+ {af.name}
139
+ </a>
140
+ ) : (
141
+ af.name
142
+ )}
143
+ </li>
144
+ ))}
145
+ </ol>
146
+ ) : (
147
+ <p>
148
+ {affiliations[0]?.url ? (
149
+ <a
150
+ href={affiliations[0].url}
151
+ target="_blank"
152
+ rel="noopener noreferrer"
153
+ >
154
+ {affiliations[0].name}
155
+ </a>
156
+ ) : (
157
+ affiliations[0]?.name
158
+ )}
159
+ </p>
160
+ )}
161
+ </div>
162
+ )
163
+ }
164
+ {
165
+ (!affiliations || affiliations.length === 0) && affiliation && (
166
+ <div class="meta-container-cell meta-container-cell--affiliations">
167
+ <h3>Affiliation</h3>
168
+ <p>{affiliation}</p>
169
+ </div>
170
+ )
171
+ }
172
+ {
173
+ published && (
174
+ <div class="meta-container-cell meta-container-cell--published">
175
+ <h3>Published</h3>
176
+ <p>{published}</p>
177
+ </div>
178
+ )
179
+ }
180
  <!-- {doi && (
181
  <div class="meta-container-cell">
182
  <h3>DOI</h3>
 
184
  </div>
185
  )} -->
186
  <div class="meta-container-cell meta-container-cell--pdf">
187
+ <div class="pdf-header-wrapper">
188
+ <h3>PDF</h3>
189
+ <span class="pro-badge-wrapper" style="display: none;">
190
+ <span class="pro-badge-prefix">- you are</span>
191
+ <span class="pro-badge">PRO</span>
192
+ </span>
193
+ <span class="pro-only-label" style="display: none;">
194
+ <span class="pro-only-dash">-</span>
195
+ <span class="pro-only-text">pro only</span>
196
+ <svg class="pro-only-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
197
+ <rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
198
+ <path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
199
+ </svg>
200
+ </span>
201
+ </div>
202
+ <div id="pdf-download-container" data-pdf-pro-only={pdfProOnly.toString()}>
203
+ <p class="pdf-loading">Checking access...</p>
204
+ <p class="pdf-pro-only" style="display: none;">
205
+ <a
206
+ class="button"
207
+ href={`/${pdfFilename}`}
208
+ download={pdfFilename}
209
+ aria-label={`Download PDF ${pdfFilename}`}
210
+ >
211
+ Download PDF
212
+ </a>
213
+ </p>
214
+ <div class="pdf-locked" style="display: none;">
215
+ <a
216
+ class="button button-locked"
217
+ href="https://huggingface.co/subscribe/pro"
218
+ target="_blank"
219
+ rel="noopener noreferrer"
220
+ >
221
+ <svg class="lock-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" viewBox="0 0 12 12" fill="none">
222
+ <path d="M6.48 1.26c0 1.55.67 2.58 1.5 3.24.86.68 1.9 1 2.58 1.07v.86A5.3 5.3 0 0 0 7.99 7.5a3.95 3.95 0 0 0-1.51 3.24h-.96c0-1.55-.67-2.58-1.5-3.24a5.3 5.3 0 0 0-2.58-1.07v-.86A5.3 5.3 0 0 0 4.01 4.5a3.95 3.95 0 0 0 1.51-3.24h.96Z" fill="currentColor"></path>
223
+ </svg>
224
+ <span class="locked-title">Subscribe to Pro</span>
225
+ </a>
226
+ </div>
227
+ </div>
228
  </div>
229
  </div>
230
  </header>
231
 
232
+ <script>
233
+ // PDF access control for Pro users only
234
+
235
+ // ⚙️ Configuration for local development
236
+ const LOCAL_IS_PRO = false; // Set to true to test Pro access locally
237
+
238
+ const FALLBACK_TIMEOUT_MS = 3000;
239
+ let userPlanChecked = false;
240
+
241
+ // Check if PDF Pro gating is enabled
242
+ const pdfContainer = document.querySelector("#pdf-download-container") as HTMLElement;
243
+ const pdfProOnly = pdfContainer?.getAttribute("data-pdf-pro-only") === "true";
244
+
245
+ /**
246
+ * Check if user has Pro access
247
+ * Isolated logic for Pro user verification
248
+ * Expected plan structure: { user: "pro", org: "enterprise" }
249
+ */
250
+ function isProUser(plan: any): boolean {
251
+ if (!plan) return false;
252
+
253
+ // Check if user property is "pro"
254
+ return plan.user === "pro";
255
+ }
256
+
257
+ /**
258
+ * Update UI based on user's Pro status
259
+ */
260
+ function updatePdfAccess(isPro: boolean) {
261
+ const loadingEl = document.querySelector(".pdf-loading") as HTMLElement;
262
+ const proOnlyEl = document.querySelector(".pdf-pro-only") as HTMLElement;
263
+ const lockedEl = document.querySelector(".pdf-locked") as HTMLElement;
264
+ const proOnlyLabel = document.querySelector(".pro-only-label") as HTMLElement;
265
+ const proBadgeWrapper = document.querySelector(".pro-badge-wrapper") as HTMLElement;
266
+
267
+ // Hide loading state
268
+ if (loadingEl) loadingEl.style.display = "none";
269
+
270
+ // If PDF Pro gating is disabled, just show the download button
271
+ if (!pdfProOnly) {
272
+ if (proOnlyEl) proOnlyEl.style.display = "block";
273
+ if (proOnlyLabel) proOnlyLabel.style.display = "none";
274
+ if (lockedEl) lockedEl.style.display = "none";
275
+ if (proBadgeWrapper) proBadgeWrapper.style.display = "none";
276
+ return;
277
+ }
278
+
279
+ // Show appropriate state based on Pro status
280
+ if (isPro) {
281
+ if (proOnlyEl) proOnlyEl.style.display = "block";
282
+ if (proOnlyLabel) proOnlyLabel.style.display = "none";
283
+ if (lockedEl) lockedEl.style.display = "none";
284
+ if (proBadgeWrapper) proBadgeWrapper.style.display = "inline-flex";
285
+ } else {
286
+ if (proOnlyEl) proOnlyEl.style.display = "none";
287
+ if (proOnlyLabel) proOnlyLabel.style.display = "inline-flex";
288
+ if (lockedEl) lockedEl.style.display = "block";
289
+ if (proBadgeWrapper) proBadgeWrapper.style.display = "none";
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Handle user plan response
295
+ */
296
+ function handleUserPlan(plan: any) {
297
+ userPlanChecked = true;
298
+ const isPro = isProUser(plan);
299
+ updatePdfAccess(isPro);
300
+
301
+ // Optional: log for debugging
302
+ console.log("[PDF Access]", { plan, isPro });
303
+ }
304
+
305
+ /**
306
+ * Fallback behavior when no parent window responds
307
+ * Uses LOCAL_IS_PRO configuration for local development
308
+ */
309
+ function handleFallback() {
310
+ if (LOCAL_IS_PRO) {
311
+ handleUserPlan({ user: "pro" });
312
+ } else {
313
+ handleUserPlan({ user: "free" });
314
+ }
315
+ }
316
+
317
+ // If PDF Pro gating is disabled, show the download button immediately
318
+ if (!pdfProOnly) {
319
+ updatePdfAccess(true);
320
+ } else {
321
+ // Listen for messages from parent window (Hugging Face Spaces)
322
+ window.addEventListener("message", (event) => {
323
+ if (event.data.type === "USER_PLAN") {
324
+ handleUserPlan(event.data.plan);
325
+ }
326
+ });
327
+
328
+ // Request user plan on page load
329
+ if (window.parent && window.parent !== window) {
330
+ // We're in an iframe, request user plan
331
+ window.parent.postMessage({ type: "USER_PLAN_REQUEST" }, "*");
332
+
333
+ // Fallback if no response after timeout
334
+ setTimeout(() => {
335
+ if (!userPlanChecked) {
336
+ handleFallback();
337
+ }
338
+ }, FALLBACK_TIMEOUT_MS);
339
+ } else {
340
+ // Not in iframe (local development), use fallback immediately
341
+ handleFallback();
342
+ }
343
+ }
344
+ </script>
345
 
346
  <style>
347
  /* Hero (full-width) */
 
385
  gap: 8px;
386
  }
387
  /* Subtle underline for links in meta; keep buttons without underline */
388
+ .meta-container a:not(.button) {
389
  color: var(--primary-color);
390
  text-decoration: underline;
391
  text-underline-offset: 2px;
392
  text-decoration-thickness: 0.06em;
393
  text-decoration-color: var(--link-underline);
394
+ transition: text-decoration-color 0.15s ease-in-out;
395
  }
396
  .meta-container a:hover {
397
  text-decoration-color: var(--link-underline-hover);
 
404
  display: flex;
405
  flex-direction: column;
406
  gap: 8px;
407
+ max-width: 250px;
408
  }
409
  .meta-container-cell h3 {
410
  margin: 0;
 
412
  font-weight: 400;
413
  color: var(--muted-color);
414
  text-transform: uppercase;
415
+ letter-spacing: 0.02em;
416
  }
417
  .meta-container-cell p {
418
  margin: 0;
419
+ }
420
  .authors {
421
  margin: 0;
422
  list-style-type: none;
423
  padding-left: 0;
424
+ display: flex;
425
+ flex-wrap: wrap;
426
+ }
427
+ .authors li {
428
+ white-space: nowrap;
429
+ padding:0;
430
  }
431
  .affiliations {
432
  margin: 0;
 
440
  flex-wrap: wrap;
441
  row-gap: 12px;
442
  }
443
+
444
+ @media (max-width: 768px) {
445
+ .meta-container-cell--affiliations,
446
+ .meta-container-cell--pdf {
447
+ text-align: right;
448
+ }
449
+ }
450
+
451
  @media print {
452
  .meta-container-cell--pdf {
453
  display: none !important;
454
  }
455
  }
 
456
 
457
+ /* PDF access control styles */
458
+ .pdf-header-wrapper {
459
+ display: flex;
460
+ align-items: center;
461
+ gap: 6px;
462
+ line-height: 1;
463
+ }
464
+
465
+ .pdf-header-wrapper h3 {
466
+ line-height: 1;
467
+ }
468
+
469
+ .pdf-loading {
470
+ color: var(--muted-color);
471
+ font-size: 0.9em;
472
+ }
473
+
474
+ .pdf-pro-only {
475
+ margin: 0;
476
+ }
477
+
478
+ .pro-badge-wrapper {
479
+ display: inline-flex;
480
+ align-items: center;
481
+ gap: 5px;
482
+ font-style: normal;
483
+ }
484
+
485
+ .pro-badge-prefix {
486
+ font-size: 0.85em;
487
+ opacity: 0.5;
488
+ font-weight: 400;
489
+ font-style: normal;
490
+ }
491
+
492
+ .pro-badge {
493
+ display: inline-block;
494
+ border: 1px solid rgba(0, 0, 0, 0.025);
495
+ background: linear-gradient(to bottom right, #f9a8d4, #86efac, #fde047);
496
+ color: black;
497
+ padding: 1px 5px;
498
+ border-radius: 3px;
499
+ font-size: 0.5rem;
500
+ font-weight: 700;
501
+ font-style: normal;
502
+ letter-spacing: 0.025em;
503
+ text-transform: uppercase;
504
+ }
505
+
506
+ /* Dark mode pro badge */
507
+ :global(.dark) .pro-badge,
508
+ :global([data-theme="dark"]) .pro-badge {
509
+ background: linear-gradient(to bottom right, #ec4899, #22c55e, #eab308);
510
+ border-color: rgba(255, 255, 255, 0.15);
511
+ }
512
+
513
+ .pro-only-label {
514
+ display: inline-flex;
515
+ flex-direction: row;
516
+ align-items: center;
517
+ gap: 5px;
518
+ font-size: 0.85em;
519
+ opacity: 0.5;
520
+ font-weight: 400;
521
+ line-height: 1;
522
+ }
523
+
524
+ .pro-only-dash {
525
+ display: inline-flex;
526
+ align-items: center;
527
+ line-height: 1;
528
+ }
529
+
530
+ .pro-only-icon {
531
+ width: 11px;
532
+ height: 11px;
533
+ flex-shrink: 0;
534
+ display: inline-flex;
535
+ align-items: center;
536
+ }
537
+
538
+ .pro-only-text {
539
+ display: inline-flex;
540
+ align-items: center;
541
+ line-height: 1;
542
+ }
543
+
544
+ .pdf-locked {
545
+ display: block;
546
+ }
547
+
548
+ .button-locked {
549
+ display: inline-flex;
550
+ align-items: center;
551
+ gap: 6px;
552
+ background: linear-gradient(135deg,
553
+ var(--primary-color) 0%,
554
+ oklch(from var(--primary-color) calc(l - 0.1) calc(c + 0.05) calc(h - 60)) 100%);
555
+ border-radius: var(--button-radius);
556
+ padding: var(--button-padding-y) var(--button-padding-x);
557
+ font-size: var(--button-font-size);
558
+ line-height: 1;
559
+ color: var(--on-primary);
560
+ position: relative;
561
+ overflow: hidden;
562
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
563
+ font-weight: normal;
564
+ border-color: rgba(0, 0, 0, 0.15);
565
+ }
566
+
567
+ .button-locked:active {
568
+ transform: translateY(0);
569
+ }
570
 
571
+ .lock-icon {
572
+ font-size: 1em;
573
+ flex-shrink: 0;
574
+ position: relative;
575
+ z-index: 1;
576
+ }
577
+
578
+ .locked-title {
579
+ position: relative;
580
+ z-index: 1;
581
+ }
582
+
583
+ /* Dark mode locked button - inherits from light mode variables */
584
+
585
+ @media (max-width: 768px) {
586
+ .meta-container-cell--pdf {
587
+ display: flex;
588
+ flex-direction: column;
589
+ align-items: flex-end;
590
+ }
591
+ }
592
+ </style>
app/src/content/article.mdx CHANGED
@@ -5,27 +5,41 @@ description: "A new open dataset for data-centric training of Vision Language Mo
5
  authors:
6
  - name: "Luis Wiedmann"
7
  url: "https://huggingface.co/lusxvr"
8
- affiliations: [1]
9
  - name: "Orr Zohar"
10
  url: "https://huggingface.co/orrzohar"
11
- affiliations: [1]
12
- - name: "Andi Marafioti"
13
- url: "https://huggingface.co/andito"
14
- affiliations: [1]
15
  - name: "Amir Mahla"
16
  url: "https://huggingface.co/A-Mahla"
17
  affiliations: [1]
 
 
 
 
 
 
18
  - name: "Thibaud Frere"
19
  url: "https://huggingface.co/tfrere"
20
  affiliations: [1]
21
  - name: "Leandro von Werra"
22
  url: "https://huggingface.co/lvwerra"
23
  affiliations: [1]
 
 
 
 
 
 
24
  affiliations:
25
  - name: "Hugging Face"
26
  url: "https://huggingface.co"
 
 
 
 
27
  published: "Sep 4, 2025"
28
  tags:
 
29
  - research
30
  - vision-language models
31
  - dataset
@@ -33,6 +47,16 @@ seoThumbImage: "/thumb.png"
33
  tableOfContentsAutoCollapse: true
34
  ---
35
 
 
 
 
 
 
 
 
 
 
 
36
  import HtmlEmbed from "../components/HtmlEmbed.astro";
37
  import Wide from "../components/Wide.astro";
38
  import FullWidth from "../components/FullWidth.astro";
@@ -304,7 +328,6 @@ There are multiple ways to count the data in a multimodal dataset. The most comm
304
  After collecting and processing the data, we run multiple experiments and ablations to provide practical recommendations on how to train small, data-centric VLMs.
305
 
306
  ---
307
- <br/>
308
  <Wide>
309
  <HtmlEmbed src="d3-pie.html" id="pie" desc="Figure 1: Distribution of Categories in FineVision by Answer Tokens, Number of Samples, Turns, and Images. While the distributions differ a bit with the different metrics, FineVision provides a good baseline mixture, especially when judging by the number of images in the individual categories. Samples from Chart & Table usually lend themselves well to multi-turn conversations, since multiple similar questions can be asked for a single Chart. Samples from OCR QA often have a lot of answer tokens, since they aim at detailed document understanding, which are rarely answered with a short sentence." align="center" />
310
  </Wide>
 
5
  authors:
6
  - name: "Luis Wiedmann"
7
  url: "https://huggingface.co/lusxvr"
8
+ affiliations: [1, 3]
9
  - name: "Orr Zohar"
10
  url: "https://huggingface.co/orrzohar"
11
+ affiliations: [1,2]
 
 
 
12
  - name: "Amir Mahla"
13
  url: "https://huggingface.co/A-Mahla"
14
  affiliations: [1]
15
+ - name: "Xiaohan Wang"
16
+ url: "https://huggingface.co/xiaohanwang"
17
+ affiliations: [2]
18
+ - name: "Rui Li"
19
+ url: "https://huggingface.co/ruili"
20
+ affiliations: [2]
21
  - name: "Thibaud Frere"
22
  url: "https://huggingface.co/tfrere"
23
  affiliations: [1]
24
  - name: "Leandro von Werra"
25
  url: "https://huggingface.co/lvwerra"
26
  affiliations: [1]
27
+ - name: "Aritra Roy Gosthipaty"
28
+ url: "https://huggingface.co/ariG23498"
29
+ affiliations: [1]
30
+ - name: "Andrés Marafioti"
31
+ url: "https://huggingface.co/andito"
32
+ affiliations: [1]
33
  affiliations:
34
  - name: "Hugging Face"
35
  url: "https://huggingface.co"
36
+ - name: "Stanford University"
37
+ url: "https://stanford.edu"
38
+ - name: "Technical University Munich"
39
+ url: "https://tum.de"
40
  published: "Sep 4, 2025"
41
  tags:
42
+ - research-article-template
43
  - research
44
  - vision-language models
45
  - dataset
 
47
  tableOfContentsAutoCollapse: true
48
  ---
49
 
50
+ Luis Wiedmann,
51
+ Orr Zohar,
52
+ Amir Mahla,
53
+ Xiaohan Wang,
54
+ Rui Li,
55
+ Thibaud Frere,
56
+ Leandro von Werra,
57
+ Aritra Roy Gosthipaty,
58
+ Andrés Marafioti
59
+
60
  import HtmlEmbed from "../components/HtmlEmbed.astro";
61
  import Wide from "../components/Wide.astro";
62
  import FullWidth from "../components/FullWidth.astro";
 
328
  After collecting and processing the data, we run multiple experiments and ablations to provide practical recommendations on how to train small, data-centric VLMs.
329
 
330
  ---
 
331
  <Wide>
332
  <HtmlEmbed src="d3-pie.html" id="pie" desc="Figure 1: Distribution of Categories in FineVision by Answer Tokens, Number of Samples, Turns, and Images. While the distributions differ a bit with the different metrics, FineVision provides a good baseline mixture, especially when judging by the number of images in the individual categories. Samples from Chart & Table usually lend themselves well to multi-turn conversations, since multiple similar questions can be asked for a single Chart. Samples from OCR QA often have a lot of answer tokens, since they aim at detailed document understanding, which are rarely answered with a short sentence." align="center" />
333
  </Wide>
app/src/content/embeds/d3-pie.html CHANGED
@@ -1,12 +1,98 @@
1
- <div class="d3-pie" style="width:100%;margin:10px 0;"></div>
2
  <style>
3
- .d3-pie .legend { font-size: 12px; line-height: 1.35; color: var(--text-color); }
4
- .d3-pie .legend .items { display:flex; flex-wrap:wrap; gap:8px 14px; align-items:center; justify-content:center; }
5
- .d3-pie .legend .item { display:flex; align-items:center; gap:8px; white-space:nowrap; }
6
- .d3-pie .legend .swatch { width:14px; height:14px; border-radius:3px; display:inline-block; border: 1px solid var(--border-color); }
7
- .d3-pie .caption { font-size: 14px; font-weight: 800; fill: var(--text-color); }
8
- .d3-pie .nodata { font-size: 12px; fill: var(--muted-color); }
9
- .d3-pie .slice-label { font-size: 11px; font-weight: 700; fill: var(--text-color); paint-order: stroke; stroke: rgba(255,255,255,0.2); stroke-width: 3px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  </style>
11
  <script>
12
  (() => {
@@ -25,14 +111,14 @@
25
  const host = scriptEl && scriptEl.parentElement;
26
  let container = null;
27
  if (host && host.querySelector) {
28
- container = host.querySelector('.d3-pie');
29
  }
30
  if (!container) {
31
  let sib = scriptEl && scriptEl.previousElementSibling;
32
- while (sib && !(sib.classList && sib.classList.contains('d3-pie'))) {
33
  sib = sib.previousElementSibling;
34
  }
35
- container = sib || document.querySelector('.d3-pie');
36
  }
37
  if (!container) return;
38
  if (container.dataset) { if (container.dataset.mounted === 'true') return; container.dataset.mounted = 'true'; }
@@ -44,24 +130,23 @@
44
  tip = document.createElement('div'); tip.className = 'd3-tooltip';
45
  Object.assign(tip.style, {
46
  position:'absolute', top:'0px', left:'0px', transform:'translate(-9999px, -9999px)', pointerEvents:'none',
47
- padding:'8px 10px', borderRadius:'8px', fontSize:'12px', lineHeight:'1.35', border:'1px solid var(--border-color)',
48
- background:'var(--surface-bg)', color:'var(--text-color)', boxShadow:'0 4px 24px rgba(0,0,0,.18)', opacity:'0', transition:'opacity .12s ease'
 
49
  });
50
  tipInner = document.createElement('div'); tipInner.className = 'd3-tooltip__inner'; tipInner.style.textAlign='left'; tip.appendChild(tipInner); container.appendChild(tip);
51
  } else { tipInner = tip.querySelector('.d3-tooltip__inner') || tip; }
52
 
53
- // SVG scaffolding
54
- const svg = d3.select(container).append('svg').attr('width','100%').style('display','block').attr('preserveAspectRatio','xMidYMin meet');
55
- const gRoot = svg.append('g');
56
- const gLegend = gRoot.append('foreignObject').attr('class','legend');
57
- const gPlots = gRoot.append('g').attr('class','plots');
58
 
59
  // Metrics (order and labels as in the Python script)
60
  const METRICS = [
61
- { key:'answer_total_tokens', name:'Answer Tokens', title:'Weighted by Answer Tokens', letter:'a' },
62
- { key:'total_samples', name:'Number of Samples', title:'Weighted by Number of Samples', letter:'b' },
63
- { key:'total_turns', name:'Number of Turns', title:'Weighted by Number of Turns', letter:'c' },
64
- { key:'total_images', name:'Number of Images', title:'Weighted by Number of Images', letter:'d' }
65
  ];
66
 
67
  // CSV: load from public path
@@ -89,125 +174,87 @@
89
  }));
90
 
91
  // Layout
92
- let width=800; const margin = { top: 8, right: 24, bottom: 0, left: 24 };
93
- const CAPTION_GAP = 24; // espace entre titre et donut
94
- const GAP_X = 20; // espace entre colonnes
95
  const GAP_Y = 12; // espace entre lignes
96
- const BASE_LEGEND_HEIGHT = 56; // hauteur minimale de la légende (augmentée pour éviter la troncature mobile)
97
- const TOP_OFFSET = 4; // décalage vertical supplémentaire pour aérer le haut
 
 
 
98
  const updateSize = () => {
99
  width = container.clientWidth || 800;
100
- svg.attr('width', width);
101
- gRoot.attr('transform', `translate(${margin.left},${margin.top})`);
102
  return { innerWidth: width - margin.left - margin.right };
103
  };
104
 
105
- function renderLegend(categories, colorOf, innerWidth, legendY){
106
- const minHeight = BASE_LEGEND_HEIGHT;
107
- gLegend.attr('x', 0).attr('y', legendY).attr('width', innerWidth);
108
- const root = gLegend.selectAll('div').data([0]).join('xhtml:div');
109
- root
110
- .style('min-height', minHeight + 'px')
111
- .style('display', 'flex')
112
- .style('align-items', 'center')
113
- .style('justify-content', 'center');
114
- root.html(`<div class="items">${categories.map(c => `<div class="item"><span class="swatch" style="background:${colorOf(c)}"></span><span style="font-weight:500">${c}</span></div>`).join('')}</div>`);
115
-
116
- // Mesurer la hauteur réelle (contenu potentiellement sur plusieurs lignes en mobile)
117
- let measured = minHeight;
118
- try {
119
- const n = root.node();
120
- const h1 = n && n.scrollHeight ? Math.ceil(n.scrollHeight) : 0;
121
- const h2 = n ? Math.ceil(n.getBoundingClientRect().height) : 0;
122
- measured = Math.max(minHeight, h1, h2);
123
- } catch {}
124
- gLegend.attr('height', measured);
125
- root.style('height', measured + 'px');
126
- return measured;
127
  }
128
 
129
  function drawPies(rows){
130
  const { innerWidth } = updateSize();
131
 
132
- // Catégories (triées) + échelle de couleurs harmonisée avec banner.html
133
  const categories = Array.from(new Set(rows.map(r => r.eagle_cathegory || 'Unknown'))).sort();
134
- const color = d3.scaleOrdinal().domain(categories).range(d3.schemeTableau10);
 
 
 
 
135
  const colorOf = (cat) => color(cat || 'Unknown');
136
 
137
- // Clear plots
138
- gPlots.selectAll('*').remove();
139
-
140
- // Colonnes responsives: tenter 4 colonnes si possible, sinon descendre à 3/2/1
141
- const selectCols = () => {
142
- const MIN_RADIUS = 80; // garantir lisibilité
143
- const allowed = [4, 2, 1]; // seulement 4 / 2 / 1 colonnes
144
- // 1) essayer avec contrainte de rayon minimal
145
- for (const c of allowed) {
146
- const cw = (innerWidth - GAP_X * (c - 1)) / c;
147
- const r = Math.max(30, Math.min(cw * 0.42, 120));
148
- const gw = c * (r * 2) + (c - 1) * GAP_X;
149
- if (gw <= innerWidth && r >= MIN_RADIUS) {
150
- return { c, r };
151
- }
152
- }
153
- // 2) sinon, première config qui tient (même si plus petit rayon)
154
- for (const c of allowed) {
155
- const cw = (innerWidth - GAP_X * (c - 1)) / c;
156
- const r = Math.max(30, Math.min(cw * 0.42, 120));
157
- const gw = c * (r * 2) + (c - 1) * GAP_X;
158
- if (gw <= innerWidth) {
159
- return { c, r };
160
- }
161
- }
162
- // 3) fallback très petit écran
163
- const r1 = Math.max(30, Math.min(innerWidth * 0.42, 120));
164
- return { c: 1, r: r1 };
165
- };
166
- const { c: cols, r: radius } = selectCols();
167
- const rowsCount = Math.ceil(METRICS.length / cols);
168
- const innerR = Math.round(radius * 0.28);
169
- // Calculer un espacement effectif pour occuper toute la largeur disponible
170
- const baseGap = GAP_X;
171
- const effectiveGapX = cols > 1
172
- ? Math.max(baseGap, Math.floor((innerWidth - cols * (radius * 2)) / (cols - 1)))
173
- : 0;
174
- // largeur réelle de la grille avec l'espacement effectif
175
- const gridWidth = cols * (radius * 2) + (cols - 1) * effectiveGapX;
176
- const xOffset = Math.max(0, Math.floor((innerWidth - gridWidth) / 2));
177
- gPlots.attr('transform', `translate(${xOffset},${TOP_OFFSET})`);
178
- const perRowHeight = Math.ceil(radius * 2 + CAPTION_GAP + 20); // donut + caption + marge
179
- const plotsHeight = rowsCount * perRowHeight + (rowsCount - 1) * GAP_Y;
180
-
181
- const pie = d3.pie().sort(null).value(d => d.value).padAngle(0.02);
182
  const arc = d3.arc().innerRadius(innerR).outerRadius(radius).cornerRadius(3);
183
  const arcLabel = d3.arc().innerRadius((innerR + radius) / 2).outerRadius((innerR + radius) / 2);
184
 
185
- // Positionner la légende sous les graphiques
186
- const legendY = TOP_OFFSET + plotsHeight + 4;
187
- // Légende centrée globalement (pleine largeur du conteneur)
188
- gLegend.attr('x', 0).attr('width', innerWidth);
189
- const legendHeightUsed = renderLegend(categories, colorOf, innerWidth, legendY);
190
-
191
- const captions = new Map(METRICS.map(m => [m.key, `${m.title}`]));
192
 
193
  METRICS.forEach((metric, idx) => {
194
  // Aggregate by category
195
  const totals = new Map(); categories.forEach(c => totals.set(c, 0));
196
  rows.forEach(r => { totals.set(r.eagle_cathegory, totals.get(r.eagle_cathegory) + (r[metric.key] || 0)); });
197
  const values = categories.map(c => ({ category: c, value: totals.get(c) || 0 }));
198
- const totalSum = d3.sum(values, d => d.value);
199
-
200
- const rowIdx = Math.floor(idx / cols);
201
- const colIdx = idx % cols;
202
- const cx = colIdx * ((radius * 2) + effectiveGapX) + radius;
203
- const cy = TOP_OFFSET + rowIdx * (perRowHeight + GAP_Y) + CAPTION_GAP + radius;
204
-
205
- const gCell = gPlots.append('g').attr('transform', `translate(${cx},${cy})`);
206
-
207
- if (!totalSum || totalSum <= 0) {
 
 
 
 
 
 
 
 
 
208
  gCell.append('text').attr('class','nodata').attr('text-anchor','middle').attr('dy','0').text('No data for this metric');
209
  } else {
210
- const data = pie(values);
211
  const percent = (v) => (v / totalSum) * 100;
212
 
213
  // Slices
@@ -216,16 +263,32 @@
216
  .attr('fill', d => colorOf(d.data.category))
217
  .attr('stroke', 'var(--surface-bg)')
218
  .attr('stroke-width', 1.2)
 
219
  .on('mouseenter', function(ev, d){
 
 
 
 
 
220
  d3.select(this).attr('stroke', 'rgba(0,0,0,0.85)').attr('stroke-width', 1);
221
  const p = percent(d.data.value);
222
- tipInner.innerHTML = `<div><strong>${d.data.category}</strong></div><div><strong>${metric.name}</strong> ${d.data.value.toLocaleString()}</div><div><strong>Share</strong> ${p.toFixed(1)}%</div>`;
 
 
 
 
223
  tip.style.opacity = '1';
224
  })
225
  .on('mousemove', function(ev){
226
  const [mx, my] = d3.pointer(ev, container); const offsetX = 12, offsetY = 12; tip.style.transform = `translate(${Math.round(mx+offsetX)}px, ${Math.round(my+offsetY)}px)`;
227
  })
228
- .on('mouseleave', function(){ tip.style.opacity='0'; tip.style.transform='translate(-9999px, -9999px)'; d3.select(this).attr('stroke','var(--surface-bg)'); });
 
 
 
 
 
 
229
 
230
  // Percentage labels (>= 3%)
231
  gCell.selectAll('text.slice-label').data(data.filter(d => percent(d.data.value) >= 3)).enter()
@@ -235,17 +298,21 @@
235
  .text(d => `${percent(d.data.value).toFixed(1)}%`);
236
  }
237
 
238
- // Caption above donut
239
- gCell.append('text')
240
- .attr('class','caption')
241
- .attr('text-anchor','middle')
242
- .attr('y', -(radius + (CAPTION_GAP - 6)))
243
- .text(captions.get(metric.key));
244
  });
245
 
246
- // Définir la hauteur totale du SVG après avoir placé les éléments
247
- const totalHeight = Math.ceil(margin.top + TOP_OFFSET + plotsHeight + 4 + (typeof legendHeightUsed === 'number' ? legendHeightUsed : BASE_LEGEND_HEIGHT) + margin.bottom);
248
- svg.attr('height', totalHeight);
 
 
 
 
 
 
 
249
  }
250
 
251
  async function init(){
@@ -275,3 +342,5 @@
275
 
276
 
277
 
 
 
 
1
+ <div class="d3-pie-quad"></div>
2
  <style>
3
+ /* Layout piloté par container queries (par rapport au parent) */
4
+ .d3-pie-quad { container-type: inline-size; }
5
+ .d3-pie-quad .legend { width: 50%;margin: 0 auto; font-size: 12px; line-height: 1.35; color: var(--text-color); }
6
+ .d3-pie-quad .legend { margin-top: 24px; margin-bottom: 32px; }
7
+ .d3-pie-quad .legend .legend-title { display:block; text-align:center; font-weight:700; font-size:13px; margin-bottom:12px; color: var(--text-color); text-transform: uppercase; letter-spacing: 0.5px; }
8
+ .d3-pie-quad .legend .items { display:flex; flex-wrap:wrap; gap:8px 14px; align-items:center; justify-content:center; }
9
+ .d3-pie-quad .legend .item { display:flex; align-items:center; gap:8px; white-space:nowrap; }
10
+ .d3-pie-quad .legend .swatch { width:14px; height:14px; border-radius:3px; display:inline-block; border: 1px solid var(--border-color); }
11
+ .d3-pie-quad .caption { font-size: 14px; font-weight: 800; fill: var(--text-color); }
12
+ .d3-pie-quad .caption-subtitle { font-size: 11px; font-weight: 400; fill: var(--muted-color); }
13
+ .d3-pie-quad .nodata { font-size: 12px; fill: var(--muted-color); }
14
+ /* Ghost legend items when hovering slices */
15
+ .d3-pie-quad.hovering .legend .item.ghost { opacity: .35; }
16
+ .d3-pie-quad .slice-label { font-size: 11px; font-weight: 700; fill: var(--text-color); paint-order: stroke; stroke: var(--page-bg); stroke-width: 3px; }
17
+ /* Effet ghost synchronisé */
18
+ .d3-pie-quad .slice {
19
+ transition: opacity .15s ease;
20
+ }
21
+ .d3-pie-quad.hovering .slice.ghost {
22
+ opacity: .25;
23
+ }
24
+ /* HTML layout (not JS) for grid and cells */
25
+ .d3-pie-quad .plots-grid {
26
+ display: flex;
27
+ flex-wrap: wrap;
28
+ justify-content: center;
29
+ align-items: flex-start;
30
+ gap: 20px;
31
+ margin-left: auto;
32
+ margin-right: auto;
33
+ width: 100%;
34
+ }
35
+ /* Default (flow ~1280): 2 centered columns */
36
+ .content-grid .d3-pie-quad .plots-grid { width: 100%; }
37
+ .content-grid .d3-pie-quad .pie-cell { flex: 0 0 calc((100% - 20px)/2); }
38
+ /* In wide wrappers: aim for 4 columns if space allows */
39
+ .wide .d3-pie-quad .plots-grid,
40
+ .full-width .d3-pie-quad .plots-grid { width: 100%; }
41
+ .wide .d3-pie-quad .pie-cell,
42
+ .full-width .d3-pie-quad .pie-cell { flex: 0 0 calc((100% - 60px)/4); }
43
+ /* Force 2 columns in flow when parent ~1280px */
44
+ .content-grid .d3-pie-quad .plots-grid { width: 100%; }
45
+ .d3-pie-quad .pie-cell {
46
+ display: flex;
47
+ flex-direction: column;
48
+ align-items: center;
49
+ flex: 0 0 360px; /* Reduced from 360px to allow 4 columns in smaller spaces */
50
+ }
51
+ /* 4/2/1 colonnes en fonction de la largeur du parent */
52
+ /* @container (min-width: 740px) {
53
+ .d3-pie-quad .plots-grid { width: 740px; }
54
+ }
55
+ @container (max-width: 739.98px) {
56
+ .d3-pie-quad .plots-grid { width: 100%; }
57
+ } */
58
+ @media (max-width: 500px) {
59
+ .d3-pie-quad .pie-cell { flex: 0 0 100%; }
60
+ }
61
+ /* Tooltip styling aligned with filters-quad */
62
+ .d3-pie-quad .d3-tooltip {
63
+ z-index: var(--z-elevated);
64
+ backdrop-filter: saturate(1.12) blur(8px);
65
+ }
66
+ .d3-pie-quad .d3-tooltip__inner {
67
+ display: flex;
68
+ flex-direction: column;
69
+ gap: 6px;
70
+ min-width: 220px;
71
+ }
72
+ .d3-pie-quad .d3-tooltip__inner > div:first-child {
73
+ font-weight: 800;
74
+ letter-spacing: 0.1px;
75
+ margin-bottom: 0;
76
+ }
77
+ .d3-pie-quad .d3-tooltip__inner > div:nth-child(2) {
78
+ font-size: 11px;
79
+ color: var(--muted-color);
80
+ display: block;
81
+ margin-top: -4px;
82
+ margin-bottom: 2px;
83
+ letter-spacing: 0.1px;
84
+ }
85
+ .d3-pie-quad .d3-tooltip__inner > div:nth-child(n+3) {
86
+ padding-top: 6px;
87
+ border-top: 1px solid var(--border-color);
88
+ }
89
+ .d3-pie-quad .d3-tooltip__color-dot {
90
+ display: inline-block;
91
+ width: 12px;
92
+ height: 12px;
93
+ border-radius: 3px;
94
+ border: 1px solid var(--border-color);
95
+ }
96
  </style>
97
  <script>
98
  (() => {
 
111
  const host = scriptEl && scriptEl.parentElement;
112
  let container = null;
113
  if (host && host.querySelector) {
114
+ container = host.querySelector('.d3-pie-quad');
115
  }
116
  if (!container) {
117
  let sib = scriptEl && scriptEl.previousElementSibling;
118
+ while (sib && !(sib.classList && sib.classList.contains('d3-pie-quad'))) {
119
  sib = sib.previousElementSibling;
120
  }
121
+ container = sib || document.querySelector('.d3-pie-quad');
122
  }
123
  if (!container) return;
124
  if (container.dataset) { if (container.dataset.mounted === 'true') return; container.dataset.mounted = 'true'; }
 
130
  tip = document.createElement('div'); tip.className = 'd3-tooltip';
131
  Object.assign(tip.style, {
132
  position:'absolute', top:'0px', left:'0px', transform:'translate(-9999px, -9999px)', pointerEvents:'none',
133
+ padding:'10px 12px', borderRadius:'12px', fontSize:'12px', lineHeight:'1.35', border:'1px solid var(--border-color)',
134
+ background:'var(--surface-bg)', color:'var(--text-color)', boxShadow:'0 8px 32px rgba(0,0,0,.28), 0 2px 8px rgba(0,0,0,.12)', opacity:'0', transition:'opacity .12s ease',
135
+ zIndex: 'var(--z-elevated)', backdropFilter: 'saturate(1.12) blur(8px)'
136
  });
137
  tipInner = document.createElement('div'); tipInner.className = 'd3-tooltip__inner'; tipInner.style.textAlign='left'; tip.appendChild(tipInner); container.appendChild(tip);
138
  } else { tipInner = tip.querySelector('.d3-tooltip__inner') || tip; }
139
 
140
+ // HTML scaffolding: legend and plots grid as HTML; only pies are SVG
141
+ const legendHost = document.createElement('div'); legendHost.className = 'legend'; container.appendChild(legendHost);
142
+ const plotsHost = document.createElement('div'); plotsHost.className = 'plots-grid'; container.appendChild(plotsHost);
 
 
143
 
144
  // Metrics (order and labels as in the Python script)
145
  const METRICS = [
146
+ { key:'answer_total_tokens', name:'Answer Tokens', title:'Weighted by ', letter:'a' },
147
+ { key:'total_samples', name:'Number of Samples', title:'Weighted by ', letter:'b' },
148
+ { key:'total_turns', name:'Number of Turns', title:'Weighted by ', letter:'c' },
149
+ { key:'total_images', name:'Number of Images', title:'Weighted by ', letter:'d' }
150
  ];
151
 
152
  // CSV: load from public path
 
174
  }));
175
 
176
  // Layout
177
+ let width=800; const margin = { top: 8, right: 0, bottom: 0, left: 0 };
178
+ const CAPTION_GAP = 36; // espace entre titre et donut
179
+ const GAP_X = 0; // espace entre colonnes
180
  const GAP_Y = 12; // espace entre lignes
181
+ const TOP_OFFSET = 4; // additional vertical offset to air out the top
182
+ const DONUT_INNER_RATIO = 0.28; // ratio du trou central (0 = pie plein, 0.5 = moitié)
183
+ // LEGEND_GAP supprimé: l'espacement est désormais géré en CSS via .d3-pie-quad .legend { margin-bottom }
184
+ const SVG_VPAD = 16; // additional vertical padding inside SVGs to avoid cropping
185
+
186
  const updateSize = () => {
187
  width = container.clientWidth || 800;
 
 
188
  return { innerWidth: width - margin.left - margin.right };
189
  };
190
 
191
+ function renderLegend(categories, colorOf){
192
+ legendHost.style.display = 'flex';
193
+ legendHost.style.flexDirection = 'column';
194
+ legendHost.style.alignItems = 'center';
195
+ legendHost.style.justifyContent = 'center';
196
+ legendHost.innerHTML = `<div class="legend-title">Legend</div><div class="items">${categories.map(c => `<div class="item" data-category="${c}"><span class=\"swatch\" style=\"background:${colorOf(c)}\"></span><span style=\"font-weight:500\">${c}</span></div>`).join('')}</div>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  }
198
 
199
  function drawPies(rows){
200
  const { innerWidth } = updateSize();
201
 
202
+ // Categories (sorted) + color scale harmonized with banner.html
203
  const categories = Array.from(new Set(rows.map(r => r.eagle_cathegory || 'Unknown'))).sort();
204
+ const getCatColors = (n) => {
205
+ try { if (window.ColorPalettes && typeof window.ColorPalettes.getColors === 'function') return window.ColorPalettes.getColors('categorical', n); } catch(_) {}
206
+ return (d3.schemeTableau10 ? d3.schemeTableau10.slice(0, n) : ['#4e79a7','#f28e2b','#e15759','#76b7b2','#59a14f','#edc948','#b07aa1','#ff9da7','#9c755f','#bab0ab'].slice(0, n));
207
+ };
208
+ const color = d3.scaleOrdinal().domain(categories).range(getCatColors(categories.length));
209
  const colorOf = (cat) => color(cat || 'Unknown');
210
 
211
+ // Clear plots grid
212
+ plotsHost.innerHTML = '';
213
+
214
+ // Légende au-dessus, centrée
215
+ renderLegend(categories, colorOf);
216
+
217
+ // Rayon fixé selon la largeur cible d'une cellule (gérée par CSS)
218
+ const CELL_BASIS = 240; // doit correspondre à .pie-cell { flex-basis }
219
+ const radius = Math.max(80, Math.min(120, Math.floor(CELL_BASIS * 0.42)));
220
+ const innerR = Math.round(radius * DONUT_INNER_RATIO);
221
+ // Placement géré par CSS; ici on ne fait que l'espacement vertical minimal
222
+ plotsHost.style.position = 'relative';
223
+ plotsHost.style.marginTop = (TOP_OFFSET) + 'px';
224
+
225
+ const pie = d3.pie().sort(null).value(d => d.value).padAngle(0.005); // Réduit de 0.02 à 0.005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  const arc = d3.arc().innerRadius(innerR).outerRadius(radius).cornerRadius(3);
227
  const arcLabel = d3.arc().innerRadius((innerR + radius) / 2).outerRadius((innerR + radius) / 2);
228
 
229
+ // Légende déjà rendue au-dessus
 
 
 
 
 
 
230
 
231
  METRICS.forEach((metric, idx) => {
232
  // Aggregate by category
233
  const totals = new Map(); categories.forEach(c => totals.set(c, 0));
234
  rows.forEach(r => { totals.set(r.eagle_cathegory, totals.get(r.eagle_cathegory) + (r[metric.key] || 0)); });
235
  const values = categories.map(c => ({ category: c, value: totals.get(c) || 0 }));
236
+ const nonZeroValues = values.filter(v => (v.value || 0) > 0);
237
+ const totalSum = d3.sum(nonZeroValues, d => d.value);
238
+
239
+ // Create HTML cell container
240
+ const cell = document.createElement('div');
241
+ cell.className = 'pie-cell';
242
+ cell.style.width = (radius * 2) + 'px';
243
+ cell.style.height = (radius * 2 + SVG_VPAD * 2 + CAPTION_GAP + 24) + 'px';
244
+ cell.style.display = 'flex';
245
+ cell.style.flexDirection = 'column';
246
+ cell.style.alignItems = 'center';
247
+ cell.style.justifyContent = 'flex-start';
248
+ plotsHost.appendChild(cell);
249
+
250
+ // SVG pie inside cell
251
+ const svg = d3.select(cell).append('svg').attr('width', radius * 2).attr('height', radius * 2 + SVG_VPAD * 2).style('display','block');
252
+ const gCell = svg.append('g').attr('transform', `translate(${radius},${radius + SVG_VPAD})`);
253
+
254
+ if (!totalSum || totalSum <= 0 || nonZeroValues.length === 0) {
255
  gCell.append('text').attr('class','nodata').attr('text-anchor','middle').attr('dy','0').text('No data for this metric');
256
  } else {
257
+ const data = pie(nonZeroValues);
258
  const percent = (v) => (v / totalSum) * 100;
259
 
260
  // Slices
 
263
  .attr('fill', d => colorOf(d.data.category))
264
  .attr('stroke', 'var(--surface-bg)')
265
  .attr('stroke-width', 1.2)
266
+ .attr('data-category', d => d.data.category)
267
  .on('mouseenter', function(ev, d){
268
+ const hoveredCategory = d.data.category;
269
+ d3.select(container).classed('hovering', true);
270
+ d3.select(container).selectAll('path.slice').classed('ghost', s => (s.data && s.data.category) !== hoveredCategory);
271
+ // Ghost legend items that are not hovered
272
+ d3.select(legendHost).selectAll('.item').classed('ghost', function(){ return this.dataset && this.dataset.category !== hoveredCategory; });
273
  d3.select(this).attr('stroke', 'rgba(0,0,0,0.85)').attr('stroke-width', 1);
274
  const p = percent(d.data.value);
275
+ const catColor = colorOf(d.data.category);
276
+ let html = `<div style="display:flex;align-items:center;gap:8px;white-space:nowrap;"><span class=\"d3-tooltip__color-dot\" style=\"background:${catColor}\"></span><strong>${d.data.category}</strong></div>`;
277
+ html += `<div>${metric.name}</div>`;
278
+ html += `<div style="display:flex;align-items:center;gap:6px;white-space:nowrap;"><strong>Value</strong><span style="margin-left:auto;text-align:right;">${d.data.value.toLocaleString()}</span></div>`;
279
+ tipInner.innerHTML = html;
280
  tip.style.opacity = '1';
281
  })
282
  .on('mousemove', function(ev){
283
  const [mx, my] = d3.pointer(ev, container); const offsetX = 12, offsetY = 12; tip.style.transform = `translate(${Math.round(mx+offsetX)}px, ${Math.round(my+offsetY)}px)`;
284
  })
285
+ .on('mouseleave', function(){
286
+ tip.style.opacity='0'; tip.style.transform='translate(-9999px, -9999px)';
287
+ d3.select(container).classed('hovering', false);
288
+ d3.select(container).selectAll('path.slice').classed('ghost', false);
289
+ d3.select(legendHost).selectAll('.item').classed('ghost', false);
290
+ d3.select(this).attr('stroke','var(--surface-bg)');
291
+ });
292
 
293
  // Percentage labels (>= 3%)
294
  gCell.selectAll('text.slice-label').data(data.filter(d => percent(d.data.value) >= 3)).enter()
 
298
  .text(d => `${percent(d.data.value).toFixed(1)}%`);
299
  }
300
 
301
+ // HTML captions under the SVG (keep design)
302
+ const subtitleEl = document.createElement('div'); subtitleEl.className = 'caption-subtitle'; subtitleEl.textContent = metric.title; subtitleEl.style.textAlign = 'center'; cell.appendChild(subtitleEl);
303
+ const titleEl = document.createElement('div'); titleEl.className = 'caption'; titleEl.textContent = metric.name; titleEl.style.textAlign = 'center'; cell.appendChild(titleEl);
 
 
 
304
  });
305
 
306
+ // Container height flows naturally with HTML; nothing to do
307
+
308
+ // Reset global hover/ghost when leaving the plots area
309
+ plotsHost.onmouseleave = () => {
310
+ tip.style.opacity='0';
311
+ tip.style.transform='translate(-9999px, -9999px)';
312
+ d3.select(container).classed('hovering', false);
313
+ d3.select(container).selectAll('path.slice').classed('ghost', false);
314
+ d3.select(legendHost).selectAll('.item').classed('ghost', false);
315
+ };
316
  }
317
 
318
  async function init(){
 
342
 
343
 
344
 
345
+
346
+
app/src/pages/index.astro CHANGED
@@ -212,4 +212,3 @@ const licence = (articleFM as any)?.licence ?? (articleFM as any)?.license ?? (a
212
  </body>
213
  </html>
214
 
215
-
 
212
  </body>
213
  </html>
214
 
 
app/src/styles/_layout.css CHANGED
@@ -70,7 +70,7 @@
70
 
71
  .wide {
72
  /* Target up to ~1100px while staying within viewport minus page gutters */
73
- width: min(1400px, 100vw - 32px);
74
  margin-left: calc(50% + var(--content-padding-x) * 2);
75
  transform: translateX(-50%);
76
  }
 
70
 
71
  .wide {
72
  /* Target up to ~1100px while staying within viewport minus page gutters */
73
+ width: min(1200px, 100vw - 32px);
74
  margin-left: calc(50% + var(--content-padding-x) * 2);
75
  transform: translateX(-50%);
76
  }