// Descriptive presentation of alteration resistance metadata. #import "@preview/primaviz:0.6.0": bar-chart, horizontal-bar-chart #import "alteration_metrics.typ": * #import "report_style.typ": chart-theme, metric-card, report-theme #import "../theme/tables.typ" as tables #let percentage(part, total) = if total == 0 { "0 %" } else { str(calc.round(100 * part / total, digits: 1)) + " %" } #let synthesis-bubble(label, value, note) = block( width: 100%, fill: report-theme.parchment, stroke: 0.7pt + report-theme.border, inset: 9pt, radius: 5pt, )[ #text( size: 6.5pt, tracking: 0.07em, weight: "bold", fill: report-theme.heading-subtle, )[#upper(label)] #v(2pt) #text(size: 11pt, weight: "bold", fill: report-theme.heading)[#value] #v(2pt) #text(size: 7.2pt, fill: report-theme.muted-ink)[#note] ] #let alteration-report() = { pagebreak() heading(level: 1)[Altérations] heading(level: 2)[Altérations — Résistances et catégories] grid( columns: (1fr,) * 4, column-gutter: 8pt, metric-card("Entrées", alterations.len()), metric-card( "Documentées", configured-alterations.len(), note: [avec résistance], ), metric-card("Méta-catégories", alteration-meta-categories.len()), metric-card( "Catégories", alteration-categories.len(), note: [classifications `custom.category`], ), ) [Cette section restitue uniquement les métadonnées du glossaire : méta-catégorie (`group`), catégorie (`custom.category`), caractéristique de résistance et difficulté. Elle ne produit ni score de puissance, ni pondération d’équilibrage.] heading(level: 3)[Caractéristiques représentées] grid( columns: (1fr, 1fr), column-gutter: 12pt, horizontal-bar-chart( ( labels: characteristic-counts.map(item => item.label), values: characteristic-counts.map(item => item.count), ), width: 100%, height: 175pt, title: [Résistances par caractéristique], show-values: true, theme: chart-theme, ), horizontal-bar-chart( ( labels: meta-category-counts.map(item => item.label), values: meta-category-counts.map(item => item.count), ), width: 100%, height: 175pt, title: [Altérations par méta-catégorie], show-values: true, theme: chart-theme, ), ) heading(level: 3)[Composition des méta-catégories] let matrix = () for meta-category in alteration-meta-categories { matrix.push(meta-category) for characteristic in resisting-characteristics { let count = characteristic-count( characteristic, meta-category: meta-category, ) let shade = if count == 0 { report-theme.parchment-light } else { report-theme.chart-2.transparentize(calc.max(18%, 82% - count * 7%)) } matrix.push(table.cell(fill: shade)[#count]) } } tables.set-table-style( table( columns: (1.45fr,) + (0.72fr,) * resisting-characteristics.len(), align: (left,) + (center,) * resisting-characteristics.len(), table.header([Méta-catégorie], ..resisting-characteristics), ..matrix, ), table-theme: "steingrund", text-size: 7pt, ) heading(level: 3)[Synthèse descriptive] grid( columns: (1fr, 1fr, 1fr), column-gutter: 10pt, row-gutter: 10pt, synthesis-bubble( "Caractéristique dominante", characteristic-leader.label + " · " + str(characteristic-leader.count), [plus grand nombre d’altérations résistées], ), synthesis-bubble( "Méta-catégorie dominante", meta-category-leader.label + " · " + str(meta-category-leader.count), [plus grand nombre d’entrées du glossaire], ), synthesis-bubble( "Couples représentés", str(represented-pairs), [combinaisons méta-catégorie × caractéristique présentes], ), synthesis-bubble( "Difficultés présentes", alteration-difficulties.map(str).join(" · "), [valeurs distinctes déclarées], ), synthesis-bubble( "Métadonnées manquantes", str(unconfigured-alterations.len()), if unconfigured-alterations.len() == 0 { [aucune entrée] } else { let names = unconfigured-alterations.map(item => item.name) [#names.slice(0, calc.min(4, names.len())).join(", ")#if ( names.len() > 4 ) { [ +#(names.len() - 4)] }] }, ), synthesis-bubble( "Difficulté la plus fréquente", difficulty-counts.sorted(key: item => -item.count).first().label, [#difficulty-counts.sorted(key: item => -item.count).first().count altérations], ), ) pagebreak(weak: true) heading(level: 3)[Répartition par catégorie] if category-counts.len() == 0 { [Aucune catégorie `custom.category` n’est encore déclarée.] } else { let category-summary = category-counts .sorted(key: item => item.label) .map(item => ( item.label, str(item.count), percentage(item.count, alterations.len()), )) if uncategorized-alterations.len() > 0 { category-summary.push(( [Sans catégorie], str(uncategorized-alterations.len()), percentage(uncategorized-alterations.len(), alterations.len()), )) } [Le pourcentage indique la part des #alterations.len() altérations appartenant à chaque catégorie. Une altération multi-catégorie est comptée dans chacune de ses catégories.] tables.set-table-style( table( columns: (1fr, 0.35fr, 0.4fr), align: (left, right, right), table.header([Catégorie], [Nombre], [Part]), ..category-summary.flatten(), ), table-theme: "steingrund", text-size: 8pt, ) v(8pt) grid( columns: (1.2fr, 0.8fr), column-gutter: 12pt, horizontal-bar-chart( ( labels: category-counts.map(item => item.label), values: category-counts.map(item => item.count), ), width: 100%, height: calc.max(145pt, category-counts.len() * 13pt), show-values: true, theme: chart-theme, ), synthesis-bubble( "Couverture catégorielle", str(categorized-alterations.len()) + " / " + str(alterations.len()), [#uncategorized-alterations.len() altérations restent sans `custom.category`; une entrée multi-catégorie compte dans chaque barre], ), ) } heading(level: 3)[Difficultés déclarées] bar-chart( ( labels: difficulty-counts.map(item => item.label), values: difficulty-counts.map(item => item.count), ), width: 100%, height: 145pt, show-values: true, theme: chart-theme, ) heading(level: 3)[Altérations par catégorie] let inventory-categories = alteration-categories.sorted() for category in inventory-categories { let category-alterations = alterations .filter(item => category in item.categories) .sorted(key: item => item.name) heading(level: 4)[#category (#category-alterations.len())] let rows = category-alterations.map(item => ( item.name, item.meta-category, if item.resisted-by == none { [—] } else { item.resisted-by }, if item.difficulty == none { [—] } else { str(item.difficulty) }, )) tables.set-table-style( table( columns: (1.2fr, 1fr, 0.85fr, 0.5fr), align: (left, left, left, right), table.header( [Altération], [Méta-catégorie], [Résistée par], [Difficulté], ), ..rows.flatten(), ), table-theme: "steingrund", text-size: 7.5pt, ) } if uncategorized-alterations.len() > 0 { heading(level: 4)[Sans catégorie (#uncategorized-alterations.len())] let rows = uncategorized-alterations .sorted(key: item => item.name) .map(item => ( item.name, item.meta-category, if item.resisted-by == none { [—] } else { item.resisted-by }, if item.difficulty == none { [—] } else { str(item.difficulty) }, )) tables.set-table-style( table( columns: (1.2fr, 1fr, 0.85fr, 0.5fr), align: (left, left, left, right), table.header( [Altération], [Méta-catégorie], [Résistée par], [Difficulté], ), ..rows.flatten(), ), table-theme: "steingrund", text-size: 7.5pt, ) } }