@diagrammo/dgmo 0.20.0 → 0.20.2
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/dist/advanced.cjs +106 -74
- package/dist/advanced.js +104 -72
- package/dist/auto.cjs +104 -72
- package/dist/auto.js +111 -111
- package/dist/auto.mjs +103 -71
- package/dist/cli.cjs +153 -153
- package/dist/index.cjs +103 -71
- package/dist/index.js +102 -70
- package/dist/internal.cjs +106 -74
- package/dist/internal.js +104 -72
- package/docs/language-reference.md +4 -4
- package/package.json +1 -1
- package/src/advanced.ts +1 -4
- package/src/map/layout.ts +134 -72
- package/src/map/load-data.ts +48 -19
- package/src/map/resolver.ts +8 -1
package/dist/auto.cjs
CHANGED
|
@@ -45835,7 +45835,7 @@ function resolveMap(parsed, data) {
|
|
|
45835
45835
|
const lonSpan = extent2[1][0] - extent2[0][0];
|
|
45836
45836
|
const latSpan = extent2[1][1] - extent2[0][1];
|
|
45837
45837
|
const span = Math.max(lonSpan, latSpan);
|
|
45838
|
-
const usDominant = (
|
|
45838
|
+
const usDominant = (subdivisions.includes("us-states") || regions.some((r) => r.layer === "us-state")) && !regions.some((r) => r.layer === "country" && r.iso !== "US") && !anyNonUsPoi;
|
|
45839
45839
|
let projection;
|
|
45840
45840
|
const override = parsed.directives.projection;
|
|
45841
45841
|
if (override === "equirectangular" || override === "natural-earth" || override === "albers-usa" || override === "mercator") {
|
|
@@ -45941,14 +45941,22 @@ var load_data_exports = {};
|
|
|
45941
45941
|
__export(load_data_exports, {
|
|
45942
45942
|
loadMapData: () => loadMapData
|
|
45943
45943
|
});
|
|
45944
|
-
async function
|
|
45945
|
-
|
|
45944
|
+
async function loadNodeBuiltins() {
|
|
45945
|
+
const [{ readFile }, { fileURLToPath }, { dirname, resolve }] = await Promise.all([
|
|
45946
|
+
import("fs/promises"),
|
|
45947
|
+
import("url"),
|
|
45948
|
+
import("path")
|
|
45949
|
+
]);
|
|
45950
|
+
return { readFile, fileURLToPath, dirname, resolve };
|
|
45951
|
+
}
|
|
45952
|
+
async function readJson(nb, dir, name) {
|
|
45953
|
+
return JSON.parse(await nb.readFile(nb.resolve(dir, name), "utf8"));
|
|
45946
45954
|
}
|
|
45947
|
-
async function firstExistingDir(baseDir) {
|
|
45955
|
+
async function firstExistingDir(nb, baseDir) {
|
|
45948
45956
|
for (const rel of CANDIDATE_DIRS) {
|
|
45949
|
-
const dir =
|
|
45957
|
+
const dir = nb.resolve(baseDir, rel);
|
|
45950
45958
|
try {
|
|
45951
|
-
await
|
|
45959
|
+
await nb.readFile(nb.resolve(dir, FILES.gazetteer), "utf8");
|
|
45952
45960
|
return dir;
|
|
45953
45961
|
} catch {
|
|
45954
45962
|
}
|
|
@@ -45964,10 +45972,10 @@ function validate(data) {
|
|
|
45964
45972
|
}
|
|
45965
45973
|
return data;
|
|
45966
45974
|
}
|
|
45967
|
-
function moduleBaseDir() {
|
|
45975
|
+
function moduleBaseDir(nb) {
|
|
45968
45976
|
try {
|
|
45969
45977
|
const url = import_meta.url;
|
|
45970
|
-
if (url) return
|
|
45978
|
+
if (url) return nb.dirname(nb.fileURLToPath(url));
|
|
45971
45979
|
} catch {
|
|
45972
45980
|
}
|
|
45973
45981
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
@@ -45975,7 +45983,8 @@ function moduleBaseDir() {
|
|
|
45975
45983
|
}
|
|
45976
45984
|
function loadMapData() {
|
|
45977
45985
|
cache ??= (async () => {
|
|
45978
|
-
const
|
|
45986
|
+
const nb = await loadNodeBuiltins();
|
|
45987
|
+
const dir = await firstExistingDir(nb, moduleBaseDir(nb));
|
|
45979
45988
|
const [
|
|
45980
45989
|
worldCoarse,
|
|
45981
45990
|
worldDetail,
|
|
@@ -45986,15 +45995,15 @@ function loadMapData() {
|
|
|
45986
45995
|
naLakes,
|
|
45987
45996
|
gazetteer
|
|
45988
45997
|
] = await Promise.all([
|
|
45989
|
-
readJson(dir, FILES.worldCoarse),
|
|
45990
|
-
readJson(dir, FILES.worldDetail),
|
|
45991
|
-
readJson(dir, FILES.usStates),
|
|
45998
|
+
readJson(nb, dir, FILES.worldCoarse),
|
|
45999
|
+
readJson(nb, dir, FILES.worldDetail),
|
|
46000
|
+
readJson(nb, dir, FILES.usStates),
|
|
45992
46001
|
// Lakes/rivers/NA assets are optional — older bundles may predate them.
|
|
45993
|
-
readJson(dir, FILES.lakes).catch(() => void 0),
|
|
45994
|
-
readJson(dir, FILES.rivers).catch(() => void 0),
|
|
45995
|
-
readJson(dir, FILES.naLand).catch(() => void 0),
|
|
45996
|
-
readJson(dir, FILES.naLakes).catch(() => void 0),
|
|
45997
|
-
readJson(dir, FILES.gazetteer)
|
|
46002
|
+
readJson(nb, dir, FILES.lakes).catch(() => void 0),
|
|
46003
|
+
readJson(nb, dir, FILES.rivers).catch(() => void 0),
|
|
46004
|
+
readJson(nb, dir, FILES.naLand).catch(() => void 0),
|
|
46005
|
+
readJson(nb, dir, FILES.naLakes).catch(() => void 0),
|
|
46006
|
+
readJson(nb, dir, FILES.gazetteer)
|
|
45998
46007
|
]);
|
|
45999
46008
|
return validate({
|
|
46000
46009
|
worldCoarse,
|
|
@@ -46012,13 +46021,10 @@ function loadMapData() {
|
|
|
46012
46021
|
});
|
|
46013
46022
|
return cache;
|
|
46014
46023
|
}
|
|
46015
|
-
var
|
|
46024
|
+
var import_meta, FILES, CANDIDATE_DIRS, cache;
|
|
46016
46025
|
var init_load_data = __esm({
|
|
46017
46026
|
"src/map/load-data.ts"() {
|
|
46018
46027
|
"use strict";
|
|
46019
|
-
import_promises = require("fs/promises");
|
|
46020
|
-
import_node_url = require("url");
|
|
46021
|
-
import_node_path = require("path");
|
|
46022
46028
|
import_meta = {};
|
|
46023
46029
|
FILES = {
|
|
46024
46030
|
worldCoarse: "world-coarse.json",
|
|
@@ -46073,8 +46079,19 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46073
46079
|
const { width, height } = size;
|
|
46074
46080
|
const wantsUsStates = resolved.basemaps.subdivisions.includes("us-states");
|
|
46075
46081
|
const usCrisp = resolved.projection === "albers-usa" && wantsUsStates && !!data.naLand;
|
|
46076
|
-
const worldTopo = usCrisp ? data.
|
|
46082
|
+
const worldTopo = usCrisp ? data.worldDetail : resolved.basemaps.world === "detail" ? data.worldDetail : data.worldCoarse;
|
|
46077
46083
|
const worldLayer = decodeLayer(worldTopo);
|
|
46084
|
+
if (usCrisp && data.naLand) {
|
|
46085
|
+
const [nbW, nbS, nbE, nbN] = [-140, 10, -52, 66];
|
|
46086
|
+
const crisp = decodeLayer(data.naLand);
|
|
46087
|
+
for (const [iso, cf] of crisp) {
|
|
46088
|
+
const base = worldLayer.get(iso);
|
|
46089
|
+
if (!base) continue;
|
|
46090
|
+
const [[bw, bs], [be, bn]] = (0, import_d3_geo2.geoBounds)(base);
|
|
46091
|
+
if (bw >= nbW && be <= nbE && bs >= nbS && bn <= nbN)
|
|
46092
|
+
worldLayer.set(iso, cf);
|
|
46093
|
+
}
|
|
46094
|
+
}
|
|
46078
46095
|
const usLayer = wantsUsStates ? decodeLayer(data.usStates) : null;
|
|
46079
46096
|
const landTint = isDark ? LAND_TINT_DARK : LAND_TINT_LIGHT;
|
|
46080
46097
|
const neutralFill = mix(palette.colors.green, palette.bg, landTint);
|
|
@@ -46220,6 +46237,10 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46220
46237
|
return p ? stretch(p[0], p[1]) : null;
|
|
46221
46238
|
};
|
|
46222
46239
|
} else {
|
|
46240
|
+
projection.clipExtent([
|
|
46241
|
+
[0, 0],
|
|
46242
|
+
[width, height]
|
|
46243
|
+
]);
|
|
46223
46244
|
path = (0, import_d3_geo2.geoPath)(projection);
|
|
46224
46245
|
project = (lon, lat) => projection([lon, lat]) ?? null;
|
|
46225
46246
|
}
|
|
@@ -46364,18 +46385,11 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46364
46385
|
placeInset("US-HI", hawaiiProjection(), akRight + 24, width * 0.1);
|
|
46365
46386
|
}
|
|
46366
46387
|
const conusFit = resolved.projection === "albers-usa" && !!usLayer;
|
|
46367
|
-
const
|
|
46368
|
-
const [[
|
|
46369
|
-
const
|
|
46370
|
-
const
|
|
46371
|
-
const
|
|
46372
|
-
const padLon = Math.max(8, lonSpan * 0.35);
|
|
46373
|
-
const padLat = Math.max(8, latSpan * 0.35);
|
|
46374
|
-
const vW = exW - padLon;
|
|
46375
|
-
const vE = exE + padLon;
|
|
46376
|
-
const vS = exS - padLat;
|
|
46377
|
-
const vN = exN + padLat;
|
|
46378
|
-
const vLonCenter = (exW + exE) / 2;
|
|
46388
|
+
const classifyExtent = conusFit ? (0, import_d3_geo2.geoBounds)(fitTarget) : resolved.extent;
|
|
46389
|
+
const dLonSpan = classifyExtent[1][0] - classifyExtent[0][0];
|
|
46390
|
+
const dLatSpan = classifyExtent[1][1] - classifyExtent[0][1];
|
|
46391
|
+
const isGlobalView = dLonSpan >= 270 || dLatSpan >= 130;
|
|
46392
|
+
const vLonCenter = (classifyExtent[0][0] + classifyExtent[1][0]) / 2;
|
|
46379
46393
|
const normLon = (lon) => {
|
|
46380
46394
|
let L = lon;
|
|
46381
46395
|
while (L < vLonCenter - 180) L += 360;
|
|
@@ -46383,23 +46397,28 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46383
46397
|
return L;
|
|
46384
46398
|
};
|
|
46385
46399
|
const ringOverlapsView = (ring) => {
|
|
46386
|
-
let
|
|
46387
|
-
|
|
46388
|
-
for (const [rawLon, lat] of ring) {
|
|
46400
|
+
let loMin = Infinity, loMax = -Infinity, rawMin = Infinity, rawMax = -Infinity;
|
|
46401
|
+
for (const [rawLon] of ring) {
|
|
46389
46402
|
const lon = normLon(rawLon);
|
|
46390
|
-
if (lon >= vW && lon <= vE && lat >= vS && lat <= vN) anyIn = true;
|
|
46391
46403
|
if (lon < loMin) loMin = lon;
|
|
46392
46404
|
if (lon > loMax) loMax = lon;
|
|
46393
46405
|
if (rawLon < rawMin) rawMin = rawLon;
|
|
46394
46406
|
if (rawLon > rawMax) rawMax = rawLon;
|
|
46395
|
-
if (lat < laMin) laMin = lat;
|
|
46396
|
-
if (lat > laMax) laMax = lat;
|
|
46397
46407
|
}
|
|
46398
46408
|
if (loMax - loMin > 270) return false;
|
|
46399
46409
|
if (rawMax - rawMin > 180 && loMax - loMin < 90) return false;
|
|
46400
|
-
|
|
46401
|
-
|
|
46402
|
-
|
|
46410
|
+
let px0 = Infinity, py0 = Infinity, px1 = -Infinity, py1 = -Infinity, anyFinite = false;
|
|
46411
|
+
for (const [lon, lat] of ring) {
|
|
46412
|
+
const p = project(lon, lat);
|
|
46413
|
+
if (!p || !Number.isFinite(p[0]) || !Number.isFinite(p[1])) continue;
|
|
46414
|
+
anyFinite = true;
|
|
46415
|
+
if (p[0] < px0) px0 = p[0];
|
|
46416
|
+
if (p[0] > px1) px1 = p[0];
|
|
46417
|
+
if (p[1] < py0) py0 = p[1];
|
|
46418
|
+
if (p[1] > py1) py1 = p[1];
|
|
46419
|
+
}
|
|
46420
|
+
if (!anyFinite) return false;
|
|
46421
|
+
return !(px1 < 0 || px0 > width || py1 < 0 || py0 > height);
|
|
46403
46422
|
};
|
|
46404
46423
|
const cullFeatureToView = (f) => {
|
|
46405
46424
|
if (isGlobalView) return f;
|
|
@@ -46790,19 +46809,39 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46790
46809
|
const text = labelText(p);
|
|
46791
46810
|
return { text, w: measureLegendText(text, FONT) };
|
|
46792
46811
|
};
|
|
46812
|
+
const GAP = 3;
|
|
46813
|
+
const inlineRect = (p, w, side) => {
|
|
46814
|
+
switch (side) {
|
|
46815
|
+
case "right":
|
|
46816
|
+
return { x: p.cx + p.r + GAP, y: p.cy - poiLabH / 2, w, h: poiLabH };
|
|
46817
|
+
case "left":
|
|
46818
|
+
return {
|
|
46819
|
+
x: p.cx - p.r - GAP - w,
|
|
46820
|
+
y: p.cy - poiLabH / 2,
|
|
46821
|
+
w,
|
|
46822
|
+
h: poiLabH
|
|
46823
|
+
};
|
|
46824
|
+
case "above":
|
|
46825
|
+
return {
|
|
46826
|
+
x: p.cx - w / 2,
|
|
46827
|
+
y: p.cy - p.r - GAP - poiLabH,
|
|
46828
|
+
w,
|
|
46829
|
+
h: poiLabH
|
|
46830
|
+
};
|
|
46831
|
+
case "below":
|
|
46832
|
+
return { x: p.cx - w / 2, y: p.cy + p.r + GAP, w, h: poiLabH };
|
|
46833
|
+
}
|
|
46834
|
+
};
|
|
46793
46835
|
const pushInline = (p, text, w, side) => {
|
|
46794
|
-
const
|
|
46795
|
-
obstacles.push(
|
|
46796
|
-
|
|
46797
|
-
|
|
46798
|
-
w,
|
|
46799
|
-
h: poiLabH
|
|
46800
|
-
});
|
|
46836
|
+
const rect = inlineRect(p, w, side);
|
|
46837
|
+
obstacles.push(rect);
|
|
46838
|
+
const anchor = side === "right" ? "start" : side === "left" ? "end" : "middle";
|
|
46839
|
+
const x = side === "right" ? rect.x : side === "left" ? rect.x + w : p.cx;
|
|
46801
46840
|
labels.push({
|
|
46802
|
-
x
|
|
46803
|
-
y:
|
|
46841
|
+
x,
|
|
46842
|
+
y: rect.y + poiLabH / 2 + FONT / 3,
|
|
46804
46843
|
text,
|
|
46805
|
-
anchor
|
|
46844
|
+
anchor,
|
|
46806
46845
|
color: palette.text,
|
|
46807
46846
|
halo: true,
|
|
46808
46847
|
haloColor: palette.bg,
|
|
@@ -46811,14 +46850,8 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46811
46850
|
});
|
|
46812
46851
|
};
|
|
46813
46852
|
const inlineFits = (p, w, side) => {
|
|
46814
|
-
const
|
|
46815
|
-
|
|
46816
|
-
x: side === "right" ? tx : tx - w,
|
|
46817
|
-
y: p.cy - poiLabH / 2,
|
|
46818
|
-
w,
|
|
46819
|
-
h: poiLabH
|
|
46820
|
-
};
|
|
46821
|
-
return rect.x >= 0 && rect.x + rect.w <= width && !collides(rect);
|
|
46853
|
+
const rect = inlineRect(p, w, side);
|
|
46854
|
+
return rect.x >= 0 && rect.x + rect.w <= width && rect.y >= 0 && rect.y + rect.h <= height && !collides(rect);
|
|
46822
46855
|
};
|
|
46823
46856
|
const GROUP_R = 30;
|
|
46824
46857
|
const groups = [];
|
|
@@ -46875,12 +46908,11 @@ function layoutMap(resolved, data, size, opts) {
|
|
|
46875
46908
|
if (g.length === 1) {
|
|
46876
46909
|
const p = g[0];
|
|
46877
46910
|
const { text, w } = labelInfo(p);
|
|
46878
|
-
|
|
46879
|
-
|
|
46880
|
-
|
|
46881
|
-
|
|
46882
|
-
|
|
46883
|
-
pushInline(p, text, w, "left");
|
|
46911
|
+
const side = ["right", "left", "above", "below"].find(
|
|
46912
|
+
(s) => inlineFits(p, w, s)
|
|
46913
|
+
);
|
|
46914
|
+
if (side) {
|
|
46915
|
+
pushInline(p, text, w, side);
|
|
46884
46916
|
continue;
|
|
46885
46917
|
}
|
|
46886
46918
|
}
|
|
@@ -53630,18 +53662,18 @@ function getRotateFn(mode) {
|
|
|
53630
53662
|
return () => 0;
|
|
53631
53663
|
}
|
|
53632
53664
|
function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
53633
|
-
return new Promise((
|
|
53665
|
+
return new Promise((resolve) => {
|
|
53634
53666
|
d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
53635
53667
|
const { words, cloudOptions } = parsed;
|
|
53636
53668
|
const title = parsed.noTitle ? null : parsed.title;
|
|
53637
53669
|
if (words.length === 0) {
|
|
53638
|
-
|
|
53670
|
+
resolve();
|
|
53639
53671
|
return;
|
|
53640
53672
|
}
|
|
53641
53673
|
const width = exportDims?.width ?? container.clientWidth;
|
|
53642
53674
|
const height = exportDims?.height ?? container.clientHeight;
|
|
53643
53675
|
if (width <= 0 || height <= 0) {
|
|
53644
|
-
|
|
53676
|
+
resolve();
|
|
53645
53677
|
return;
|
|
53646
53678
|
}
|
|
53647
53679
|
const titleHeight = title ? 40 : 0;
|
|
@@ -53670,7 +53702,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
|
53670
53702
|
"transform",
|
|
53671
53703
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
53672
53704
|
).text((d) => d.text);
|
|
53673
|
-
|
|
53705
|
+
resolve();
|
|
53674
53706
|
}).start();
|
|
53675
53707
|
});
|
|
53676
53708
|
}
|
|
@@ -57036,7 +57068,7 @@ pre.dgmo, code.language-dgmo, pre > code.language-dgmo,
|
|
|
57036
57068
|
|
|
57037
57069
|
// src/auto/index.ts
|
|
57038
57070
|
init_safe_href();
|
|
57039
|
-
var VERSION = "0.20.
|
|
57071
|
+
var VERSION = "0.20.2";
|
|
57040
57072
|
var DEFAULTS = {
|
|
57041
57073
|
theme: "auto",
|
|
57042
57074
|
palette: "nord",
|