Files
json/docs/mkdocs/docs/js/fig-charts.js
T
Niels Lohmann a47170346a docs: new design for the documentation site (#5934)
* docs: new design for the documentation site

Apply the brand to the Material for MkDocs site: Inter and JetBrains Mono
served by the site (upright and real italic), brand colours, blue header band
with the syntax pattern, wordmark in the header, new home page (hero, cards,
animated feature tour), 404 page, polish for tabs, search, footer, focus
rings, tables and code blocks, and theme features (code copy, previous/next
footer, TOC follow, search suggestions).

Draw the number railroad diagram, the parser callback events and the iterator
illustrations as inline SVGs that follow the light and dark scheme. The
generator scripts are in docs/mkdocs/scripts/figures; the feature slideshow
(json-light.svg, json-dark.svg, replacing json.gif on the home page) is built
by docs/mkdocs/scripts/slideshow. Decision nodes in five flowcharts become
hexagons, which need far less room.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: add figures, table captions and a macro chooser

- Figures with numbered captions: SAX stepper, json_view layout and edit
  stepper, exception map, JSON pointer and patch walkers, QA pipeline,
  scaling and binary size charts, roadmap lanes, release timeline,
  integration decision tree and namespace builder
- Table captions (nj-table-caption) on 9 pages
- Compile times: modules and PCH charts, filesystem section, re-measured
  Figure 1, links between features/modules.md and compile_times.md
- Interactive macro chooser for features/arbitrary_types.md
- Link check: exclude URLs that answer the plugin with 400/401/419 or are
  dead (customers.md)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: macro chooser generates adl_serializer for non-default-constructible types

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: cross-link concept pages and API pages in See also sections

Add See also links in both directions between the concept pages (features,
home, integration) and the API pages, write API links in code font, give every
entry a comment after a dash, and show the callback event figure on the parser
callbacks page.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: address review comments on the new design

- Home: add a "Latest release" button
- Sponsors: update the list and group it by tier
- Features: list all feature pages on the index page
- Releases: add highlights per release, link the 4.0 roadmap, add the first commit to the timeline
- Exceptions: prefix all example messages with the exception name
- API: no code font for format names in the See also links of the to_/from_ pages
- Merge Patch: show the document before, the patch, and the result
- Replace "--" with typographic dashes, mark external links with an icon, center Mermaid diagrams

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-27 07:41:42 +01:00

107 lines
5.0 KiB
JavaScript

/* figures: charts. Number literal explorer on features/types/number_handling.md.
The table in .nj-charts-num is the source and the no-JS fallback; its rows were verified by compiling a program
against include/ (json::parse + type() + dump()). The explorer only looks literals up in that table: it does not
parse numbers itself, so anything else is reported as "not in the verified list". */
(function () {
"use strict";
var WHY = {
"0": "No fraction, exponent, or minus sign: stored as unsigned integer.",
"-0": "Leading minus sign: stored as signed integer; the serialization does not reproduce the -.",
"-0.0": "Has a fraction: stored as double, which keeps the sign of zero.",
"1E3": "Has an exponent: always stored as double.",
"-12345678912345789123456789": "Smaller than INT64_MIN: does not fit std::int64_t, so it is stored as double.",
"18446744073709551615": "2^64-1 is the largest value std::uint64_t can store without loss.",
"18446744073709551616": "2^64 does not fit std::uint64_t, so it is stored as double.",
"-9223372036854775808": "-2^63 is the smallest value std::int64_t can store.",
"1E400": "Its rounded value is not finite as double: parsing throws out_of_range.406.",
"1E-400": "Too small for double: becomes zero, with the sign of the number.",
"3.141592653589793238462643383279": "Rounded to the nearest double, then printed with the fewest digits that read back.",
"2555.5599999999999": "The fewest digits that read back as the same double are 2555.56.",
"0.0000972439793401814": "The %g layout switches to scientific notation.",
"12345E-5": "The %g layout prints this double without exponent."
};
function init() {
var roots = document.querySelectorAll(".nj-charts-num");
Array.prototype.forEach.call(roots, setup);
}
function setup(root, idx) {
if (root.dataset.njChartsReady) return;
var table = root.querySelector("table");
if (!table) return;
root.dataset.njChartsReady = "1";
var entries = [];
Array.prototype.forEach.call(table.querySelectorAll("tbody tr"), function (tr) {
var c = tr.querySelectorAll("td");
if (c.length < 3) return;
entries.push({ lit: c[0].textContent.trim(), type: c[1].textContent.trim(), dump: c[2].textContent.trim(), row: tr });
});
if (!entries.length) return;
var id = "nj-charts-num-" + idx;
var ui = document.createElement("div");
ui.className = "nj-charts-num-ui";
ui.innerHTML =
'<ul class="nj-charts-num-chips" aria-label="Literals to show"></ul>' +
'<div id="' + id + '-out" aria-live="polite"></div>';
root.insertBefore(ui, root.firstChild);
var list = ui.querySelector("ul");
var out = ui.querySelector("#" + id + "-out");
var buttons = [];
entries.forEach(function (e) {
var li = document.createElement("li");
var b = document.createElement("button");
b.type = "button";
b.className = "nj-charts-num-chip";
b.textContent = e.lit;
b.setAttribute("aria-pressed", "false");
b.setAttribute("aria-label", "Show literal " + e.lit);
b.addEventListener("click", function () { show(e.lit); });
li.appendChild(b);
list.appendChild(li);
buttons.push(b);
});
function show(text) {
var lit = text.trim();
var hit = null;
entries.forEach(function (e, i) {
var on = e.lit === lit;
if (on) hit = e;
buttons[i].setAttribute("aria-pressed", on ? "true" : "false");
e.row.classList.toggle("nj-charts-num-hit", on);
});
out.textContent = "";
if (hit) {
var dl = document.createElement("dl");
dl.className = "nj-charts-num-out";
[["literal", hit.lit, true], ["stored as", hit.type, false], ["dump()", hit.dump, true],
["why", WHY[hit.lit] || "", false]].forEach(function (p) {
if (!p[1]) return;
var dt = document.createElement("dt"); dt.textContent = p[0];
var dd = document.createElement("dd");
if (p[2] && p[1].indexOf("(") !== 0) { var c = document.createElement("code"); c.textContent = p[1]; dd.appendChild(c); }
else dd.textContent = p[1];
dl.appendChild(dt); dl.appendChild(dd);
});
out.appendChild(dl);
}
}
show(entries[1] ? entries[1].lit : entries[0].lit);
}
if (typeof document$ !== "undefined" && document$ && typeof document$.subscribe === "function") {
document$.subscribe(init);
} else if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();