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
2026-11-26GA4 product analytics: utils/analytics.ts (createUsageTracker), hooks in MapChart (usage.*), welcome events in HomePage, tools/ga4-setup.mjs + tools/ga4-report.mjs, e2e analytics.spec.tsLearn usage before migrating to PaintMyMap.com repo

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.

Analytics (GA4, property 504930332, G-5B6MN3J4M0) โ€‹

  • All events go through utils/analytics.ts; event catalogue is its header comment. MapChart holds one usage tracker per mount; every call is wrapped in try { } catch { } and must never change UI.
  • pushHistory/undo/redo in MapChart are thin wrappers around useHistory so edits and undo/redo are counted.
  • New event parameter โ‡’ add it to tools/ga4-setup.mjs and run node tools/ga4-setup.mjs --apply BEFORE deploy (GA4 only reports params registered before the events arrive).
  • Report: node tools/ga4-report.mjs [--start YYYY-MM-DD --end YYYY-MM-DD] [--out file.md]. Auth: TrueSize repo service account (../../Enlistments/TrueSize/google-service-account/token.mjs).
  • E2E tests/e2e/analytics.spec.ts blocks real GA hits and asserts the funnel via window.dataLayer.

Updated at: