@diagrammo/dgmo 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/advanced.cjs +2003 -466
- package/dist/advanced.d.cts +5714 -0
- package/dist/advanced.d.ts +5714 -0
- package/dist/advanced.js +1999 -466
- package/dist/auto.cjs +2048 -449
- package/dist/auto.d.cts +39 -0
- package/dist/auto.d.ts +39 -0
- package/dist/auto.js +121 -121
- package/dist/auto.mjs +2050 -450
- package/dist/cli.cjs +170 -170
- package/dist/editor.cjs +13 -16
- package/dist/editor.js +13 -16
- package/dist/highlight.cjs +15 -13
- package/dist/highlight.js +15 -13
- package/dist/index.cjs +2032 -435
- package/dist/index.d.cts +339 -0
- package/dist/index.d.ts +339 -0
- package/dist/index.js +2034 -436
- package/dist/internal.cjs +2003 -466
- package/dist/internal.d.cts +5714 -0
- package/dist/internal.d.ts +5714 -0
- package/dist/internal.js +1999 -466
- package/dist/map-data/water-bodies.json +1 -0
- package/docs/language-reference.md +20 -9
- package/gallery/fixtures/map-categorical-world.dgmo +16 -0
- package/gallery/fixtures/map-categorical.dgmo +0 -1
- package/gallery/fixtures/map-choropleth.dgmo +0 -1
- package/gallery/fixtures/map-coastline.dgmo +7 -0
- package/gallery/fixtures/map-colorize.dgmo +11 -0
- package/gallery/fixtures/map-direct-color.dgmo +0 -1
- package/gallery/fixtures/map-reference-world.dgmo +11 -0
- package/gallery/fixtures/map-region-scope.dgmo +0 -3
- package/gallery/fixtures/map-route.dgmo +0 -1
- package/package.json +1 -1
- package/src/advanced.ts +12 -1
- package/src/boxes-and-lines/renderer.ts +39 -12
- package/src/cli.ts +1 -1
- package/src/completion.ts +32 -25
- package/src/cycle/renderer.ts +14 -1
- package/src/d3.ts +8 -2
- package/src/editor/highlight-api.ts +4 -0
- package/src/editor/keywords.ts +13 -16
- package/src/infra/renderer.ts +35 -7
- package/src/map/colorize.ts +54 -0
- package/src/map/context-labels.ts +429 -0
- package/src/map/data/types.ts +34 -0
- package/src/map/data/water-bodies.json +1 -0
- package/src/map/dimensions.ts +117 -0
- package/src/map/geo-query.ts +21 -3
- package/src/map/geo.ts +47 -1
- package/src/map/layout.ts +1300 -251
- package/src/map/load-data.ts +10 -2
- package/src/map/parser.ts +42 -116
- package/src/map/renderer.ts +512 -13
- package/src/map/resolved-types.ts +16 -2
- package/src/map/resolver.ts +208 -59
- package/src/map/types.ts +30 -32
- package/src/mindmap/renderer.ts +10 -1
- package/src/palettes/atlas.ts +77 -0
- package/src/palettes/blueprint.ts +73 -0
- package/src/palettes/color-utils.ts +58 -1
- package/src/palettes/index.ts +12 -3
- package/src/palettes/slate.ts +73 -0
- package/src/palettes/tidewater.ts +73 -0
- package/src/render.ts +8 -1
- package/src/tech-radar/renderer.ts +3 -0
- package/src/tech-radar/types.ts +3 -0
- package/src/utils/d3-types.ts +5 -0
- package/src/utils/legend-layout.ts +21 -4
- package/src/utils/legend-types.ts +7 -0
- package/src/utils/reserved-key-registry.ts +3 -0
- package/src/palettes/bold.ts +0 -67
package/src/map/geo-query.ts
CHANGED
|
@@ -21,14 +21,19 @@ import type { DecodedFeature } from './geo';
|
|
|
21
21
|
import { pixelToLonLat, lonLatToPixel } from './invert';
|
|
22
22
|
import type { MapData, GeoExtent } from './resolved-types';
|
|
23
23
|
import type { Gazetteer } from './data/types';
|
|
24
|
+
import type { DgmoError } from '../diagnostics';
|
|
24
25
|
|
|
25
26
|
/** Nearest gazetteer city to a point: the real haversine distance, plus the
|
|
26
|
-
* canonical name + ISO + (US-only) subdivision for token shaping.
|
|
27
|
+
* canonical name + ISO + (US-only) subdivision for token shaping. `lon`/`lat`
|
|
28
|
+
* are the city's own gazetteer coordinates (so callers can mark it on the map,
|
|
29
|
+
* distinct from the inspected point). */
|
|
27
30
|
export interface NearestCity {
|
|
28
31
|
readonly name: string;
|
|
29
32
|
readonly iso: string;
|
|
30
33
|
readonly sub?: string;
|
|
31
34
|
readonly distanceKm: number;
|
|
35
|
+
readonly lon: number;
|
|
36
|
+
readonly lat: number;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/** A region declaration with its canonical/primary form plus bare alternates
|
|
@@ -85,6 +90,10 @@ export interface MapGeoQuery {
|
|
|
85
90
|
locate(px: number, py: number): ResultCard | null;
|
|
86
91
|
/** Culled + projected cities for the all-cities layer (population-primary). */
|
|
87
92
|
cities(extent?: GeoExtent): ProjectedCity[];
|
|
93
|
+
/** Layout-time, dimension-dependent diagnostics. They live on the geo-query
|
|
94
|
+
* (bound to the rendered layout) rather than the resolver. Callers merge them
|
|
95
|
+
* with `resolved.diagnostics`. (No producers currently — always empty.) */
|
|
96
|
+
readonly diagnostics: readonly DgmoError[];
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
export interface CreateMapGeoQueryOptions {
|
|
@@ -144,6 +153,8 @@ function nearestCity(
|
|
|
144
153
|
iso: c[2],
|
|
145
154
|
...(c[5] !== undefined && { sub: c[5] }),
|
|
146
155
|
distanceKm: best.dist,
|
|
156
|
+
lat: c[0],
|
|
157
|
+
lon: c[1],
|
|
147
158
|
};
|
|
148
159
|
}
|
|
149
160
|
|
|
@@ -206,7 +217,14 @@ const MAX_CITY_DOTS = 250;
|
|
|
206
217
|
|
|
207
218
|
/** Construct a geo-query handle bound to the layout for `(content, width,
|
|
208
219
|
* height, data, palette, isDark)`. Deterministic: identical inputs ⇒ the same
|
|
209
|
-
* fitted projection the rendered SVG used, so inverted clicks align.
|
|
220
|
+
* fitted projection the rendered SVG used, so inverted clicks align.
|
|
221
|
+
*
|
|
222
|
+
* INVARIANT: this is the PREVIEW path — it never passes `preferContain`, so its
|
|
223
|
+
* layout matches the in-app preview (stretch-fill), where geo-query is used. It is
|
|
224
|
+
* NOT valid against a content-aware EXPORT canvas (which may set `preferContain` →
|
|
225
|
+
* contain-fit): the inverted positions would not match that export's pixels. If
|
|
226
|
+
* geo-query is ever pointed at an export canvas, thread `preferContain` through
|
|
227
|
+
* `CreateMapGeoQueryOptions` to keep the projection in sync. */
|
|
210
228
|
export function createMapGeoQuery(opts: CreateMapGeoQueryOptions): MapGeoQuery {
|
|
211
229
|
const { content, width, height, data, palette, isDark } = opts;
|
|
212
230
|
const resolved = resolveMap(parseMap(content), data);
|
|
@@ -273,5 +291,5 @@ export function createMapGeoQuery(opts: CreateMapGeoQueryOptions): MapGeoQuery {
|
|
|
273
291
|
return out;
|
|
274
292
|
};
|
|
275
293
|
|
|
276
|
-
return { invert, project, locate, cities };
|
|
294
|
+
return { invert, project, locate, cities, diagnostics: layout.diagnostics };
|
|
277
295
|
}
|
package/src/map/geo.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Geometry helpers for the resolver: topology indexing + antimeridian-correct
|
|
2
2
|
// feature bounds (via d3-geo geoBounds — NOT naive min/max, which breaks on the
|
|
3
3
|
// antimeridian and on multi-part features like US Alaska/Hawaii; R5/R6).
|
|
4
|
-
import { feature } from 'topojson-client';
|
|
4
|
+
import { feature, neighbors } from 'topojson-client';
|
|
5
5
|
import { geoBounds, geoArea } from 'd3-geo';
|
|
6
6
|
import type { BoundaryTopology } from './data/types';
|
|
7
7
|
import type { GeoExtent } from './resolved-types';
|
|
@@ -47,6 +47,52 @@ export function idSet(topo: BoundaryTopology): Set<string> {
|
|
|
47
47
|
return new Set(geomObject(topo).geometries.map((g) => g.id));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// Memoize adjacency on the RAW asset object (never the per-render-mutated
|
|
51
|
+
// `worldLayer`). Keyed by topology identity — the assets are stable singletons
|
|
52
|
+
// from load-data.ts, so one build per topology lasts the process (G13).
|
|
53
|
+
const adjacencyCache = new WeakMap<BoundaryTopology, Map<string, string[]>>();
|
|
54
|
+
|
|
55
|
+
/** Per-topology arc-adjacency: ISO → neighbour ISOs, from shared TopoJSON arcs
|
|
56
|
+
* (`topojson-client.neighbors()` on the RAW topology geometries — arcs live on
|
|
57
|
+
* the topology, independent of any `feature()` decode — F2/ADR-4). Computed
|
|
58
|
+
* per-topology (a country never neighbours a state) and memoized.
|
|
59
|
+
*
|
|
60
|
+
* DATA HYGIENE (G1): the raw geometry array can carry (a) `type: null`
|
|
61
|
+
* sovereignty stubs with no arcs (e.g. "Ashmore & Cartier Is." tagged `AU`) and
|
|
62
|
+
* (b) genuine duplicate ISO ids. Null stubs are skipped (no arcs → no
|
|
63
|
+
* adjacency), and every geometry sharing one ISO is UNIONED into a single ISO
|
|
64
|
+
* node — matching the merged layer `decodeLayer` actually draws. Without this
|
|
65
|
+
* the ISO-keyed graph corrupts and the AC9 no-collision guarantee degrades. */
|
|
66
|
+
export function buildAdjacency(topo: BoundaryTopology): Map<string, string[]> {
|
|
67
|
+
const cached = adjacencyCache.get(topo);
|
|
68
|
+
if (cached) return cached;
|
|
69
|
+
const geometries = geomObject(topo).geometries as Array<{
|
|
70
|
+
id: string;
|
|
71
|
+
type?: string;
|
|
72
|
+
}>;
|
|
73
|
+
// neighbors() returns, per geometry BY ARRAY POSITION, the indices of
|
|
74
|
+
// arc-sharing geometries. Null-geometry stubs share no arcs → empty lists.
|
|
75
|
+
const nb = neighbors(geometries as never);
|
|
76
|
+
const sets = new Map<string, Set<string>>();
|
|
77
|
+
geometries.forEach((g, i) => {
|
|
78
|
+
if (!g.type || g.type === 'null') return; // skip arc-less sovereignty stubs
|
|
79
|
+
let set = sets.get(g.id);
|
|
80
|
+
if (!set) {
|
|
81
|
+
set = new Set<string>();
|
|
82
|
+
sets.set(g.id, set);
|
|
83
|
+
}
|
|
84
|
+
for (const j of nb[i] ?? []) {
|
|
85
|
+
const nid = geometries[j]?.id;
|
|
86
|
+
if (nid && nid !== g.id) set.add(nid); // union; never self
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const out = new Map<string, string[]>();
|
|
90
|
+
// Deterministic neighbour order (sorted) so downstream coloring is stable.
|
|
91
|
+
for (const [iso, set] of sets) out.set(iso, [...set].sort());
|
|
92
|
+
adjacencyCache.set(topo, out);
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
50
96
|
/** A decoded boundary feature: the GeoJSON geometry plus its ISO id and display
|
|
51
97
|
* name (carried straight from the topology's `properties.name`). Used for
|
|
52
98
|
* point-in-polygon reverse-geocoding by the geo-query. */
|