CodeVetter · Repo Unpack · Data flow
d3/d3
Library data never touches this repo at runtime. An application import resolves to src/index.js, which re-exports the installed d3-* packages. The UMD/CDN path is different: Rollup freezes those same exports into dist, and prebuild.sh copies them into docs/public. The docs site reads markdown, a local volcano JSON, the GitHub API, the Observable gallery module, and jsDelivr atlases, then VitePress writes a static tree.
- For npm consumers, Node/bundler resolution hits exports.default ./src/index.js. Each export * from "d3-<module>" is resolved from node_modules at install time, so the published package ships the barrel and not a frozen copy of the algorithms. The UMD path is separate: jsDelivr/unpkg serve dist/d3.min.js.
- Rollup's data path is bundle.js, which pulls the version string out of package.json via @rollup/plugin-json and the live exports through node-resolve, then writes the banner from LICENSE copyright lines onto dist/d3.js, dist/d3.mjs, and dist/d3.min.js.
- During docs build, Vite aliases every import of "d3" to path.resolve("./dist/d3.mjs"), so Vue examples and markdown scripts execute the bundled ESM rather than src/index.js. __APP_VERSION__ is inlined from process.env.npm_package_version for VersionAndStars.
- prebuild.sh is the asset ingress for the static site. Historical files move from build/d3.github.com to docs/public. Current bundles move from dist/ and node_modules/<pkg>/dist/ to versioned names under docs/public. VitePress then emits the site to docs/.vitepress/dist, which deploy.yml uploads as the Pages artifact.
- gallery.data.js runs at VitePress data-loader time. It constructs an @observablehq/runtime Runtime, dynamically imports https://api.observablehq.com/@d3/gallery.js?v=4, defines md as String.raw, redefines previews to push chunks into an array, awaits every named output of the previews variable, and returns that array to ExamplesGrid.
- stargazers.data.ts load() GETs https://api.github.com/repos/d3/d3 with Accept application/vnd.github.v3+json and, when GITHUB_TOKEN is set, Authorization token <token>. It returns stargazers_count. On failure it rethrows only if process.env.CI is set; otherwise it returns NaN.
- docs/data/volcano.data.js is a VitePress loader. It watches ../public/data/volcano.json and returns JSON.parse(fs.readFileSync(file)). That is the only in-repo filesystem read of a dataset.
- WorldMap.vue, on mount, fetches https://cdn.jsdelivr.net/npm/world-atlas@2.0.2/land-${resolution}.json (default resolution 110m), converts world.objects.land with topojson.feature, and writes SVG path d attributes through d3.geoPath. Pointer drag mutates projection.rotate. UsMap.vue similarly fetches us-atlas@3.0.1/counties-10m.json and builds nation, statemesh, and countymesh.
- PlotRender chooses a document implementation by environment. On the server (document undefined) it renders Plot[method] against a fake Document/Element tree and converts it with toHyperScript into Vue vnodes. In the browser it renders with the real DOM and, on mount, replaces the vnode with the live plot node. method defaults to "plot"; options are shallow-merged and className is forced to "plot".
- what-is-d3.md reads the live sidebar via useData(), walks themeConfig.sidebar into path strings, stratifies them with d3.stratify().path, lays them out with d3.tree, and passes the result to Plot.tree through PlotRender. The diagram is therefore derived from config.ts, not hand-authored coordinates.
- docs-test.js is a read-only crawl: it recursively lists docs/**/*.md, skips dot-directories such as .vitepress, strips HTML comments, extracts links and anchors, and never writes. ExampleBlankChart writes only into its own mounted DOM node: d3.create("svg"), axisBottom, axisLeft, then this.$el.append(svg.node()).
- ExamplesGrid seeds its shuffle with d3.randomLcg(d3.utcDay()), so the sample of gallery rows changes on UTC day boundaries but is deterministic within a day. ResizeObserver then slices that shuffled list to yn * xn cells.