This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build # compile src/ → dist/ (Rollup, all formats)
npm run watch # rebuild on file changes
node test/assets.js # verify dist output files exist (run after build)There is no automated test suite beyond the asset presence check in test/assets.js. The prepublishOnly script runs npm run build && node test/assets.js.
svgMap is a single-class JavaScript library (src/js/core/svg-map.js) that renders an interactive SVG world map with per-country data visualisation.
src/js/index.js— re-exports the class and imports the SCSS entry pointrollup.config.js— compiles to six formats indist/:index.js(ESM),index.cjs(CommonJS)svg-map.umd.js/svg-map.umd.min.js(UMD, global namesvgMap)svgMap.js/svgMap.min.js— legacy UMD aliases kept for backwards compatibility with pre-2.18 userssvg-map.css/svg-map.min.css(extracted from SCSS); legacysvgMap.csscopies created after each build
The svgMap class is instantiated directly by consumers (new svgMap({ targetElementID, data, ... })). Constructor calls init() which:
- Validates
targetElementIDanddataoptions - Builds the DOM structure:
.svgMap-wrapper→.svgMap-container→.svgMap-map-container→.svgMap-map-wrapper→<svg viewBox="0 0 2000 1001"> - Creates zoom controls and optional continent selector
- Calls
createMap()thenapplyData()—applyDatacomputes per-country colors usingcalculateColorRatioand writes them as the CSS custom property--svg-map-country-fillon each country<path>element - The floating tooltip is appended to
<body>and positioned withshowTooltip(e)/moveTooltip(e) - Persistent tooltips (pinned labels on the map) are handled separately in
createPersistentTooltips()
Pan and zoom are delegated entirely to the svg-pan-zoom library (the only runtime dependency).
Country paths are inlined inside the class as SVG d strings, keyed by ISO 3166-1 alpha-2 code. The countries property holds the name map; emojiFlags holds emoji representations. EH (Western Sahara) can be merged with MA (Morocco) via options.countries.EH = false.
Color interpolation (getColor) works by linearly blending two hex colors. calculateColorRatio supports 'linear', 'log', or an arbitrary (value, min, max) => ratio function.
svg-map.scss— entry point,@usesmapandtooltippartialsvariables.scss— all!defaultSCSS variables; consumers can override by importing with their own values before the library SCSS- Country fill is driven by the
--svg-map-country-fillCSS custom property set at runtime, not by a static class
| Path | Description |
|---|---|
demo/html/ |
Plain-HTML CDN demo, no bundler |
demo/es6/ |
ES module demo (requires npm install inside the folder) |
demo/react/ |
Create React App demo (requires npm install) |
Localization files (country name translations) live in demo/*/local/.
create-map-paths.html— browser tool: paste SVG<path>elements into the embedded<svg>to visualize them and generate country path data; used when adding or editing country shapeslocalize.html— browser tool for generatingcountryNamestranslation objectscountries.js— country code → name map used by the above tools
These files are shipped in the npm package but are not part of the library bundle.
Run npm publish from the repo root — prepublishOnly rebuilds and validates assets automatically. The assets/ and src/ directories are included in the published package alongside dist/.