Skip to content

mapchart/ โ€” Module Map for AI Agents โ€‹

Single responsibility per file. Cross-module state lives in the orchestrator (../MapChart.vue) only. Read this before editing anything in this folder.

utils/ (pure TS, no Vue refs) โ€‹

  • color.ts โœ“ โ€” hex/RGB conversion, lerp, interpHex, choroplethRamp.
  • geometry.ts โ˜ โ€” ptSegDist, bbox helpers, safeBounds, boxesIntersectOrTouch.
  • svg-sanitize.ts โ˜ โ€” sanitizeSvgMarkup + tag/attribute allow-list + stroke override.
  • format-parsers.ts โ˜ โ€” GeoJSON / TopoJSON / Shapefile / KML(Z) / CSV โ†’ normalized GeoJSON.
  • projection-registry.ts โ˜ โ€” projection id โ†’ d3 factory + display label.
  • name-disambiguation.ts โ˜ โ€” normName, abbrev index, neighbor disambiguation.
  • state-schema.ts โ˜ โ€” FROZEN serialize/deserialize for autosave. Round-trip tested per fixture.
  • viewport-math.ts โ˜ โ€” clampZoom, wheelFactorFromDelta, viewportโ†”shape coord conversion.

composables/ (Vue Composition API) โ€‹

Rules:

  • File โ‰ค 400 lines.
  • Accept dependencies as parameters; never read other composables' module-level state.
  • Return { state refs, computeds, actions }.
  • Side effects (DOM, localStorage) go through injected handles, not direct globals.

Planned composables (one concern each): useHistory, useAutosave, useProjection, useMapData, useLegend, usePaint, useShapes, useLabels, useFeatureTransforms, useViewport, useKeyboard, useSvgLibrary, useDialogs, useOrientationTip.

ui/ (Vue SFCs) โ€‹

Rules:

  • Receive everything via props; emit user events. Do NOT import composables.
  • Preserve existing class names verbatim โ€” they are part of the test+CSS contract.
  • Keep ARIA attributes and keyboard hints intact.

Drift log (track what diverged from guide/) โ€‹

After Phase 0 the sync from ../guide/src/.vitepress/components/MapChart.vue is gone. Record any back-portable fix here so a future merge is tractable.

DateChangeReason
2026-04-16Decoupled from sync; added test harness; extracted utils/color.tsRefactor for AI manageability

Slice protocol (recap) โ€‹

  1. Extract โ†’ import back into MapChart.vue with // X moved to ... marker.
  2. Add unit tests for new pure modules.
  3. npm run test && npm run test:e2e โ€” both must stay green.
  4. Update the โœ“ mark above.

Updated at: