@diagrammo/dgmo 0.20.1 → 0.20.3

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/auto.mjs CHANGED
@@ -45851,7 +45851,7 @@ function resolveMap(parsed, data) {
45851
45851
  const lonSpan = extent2[1][0] - extent2[0][0];
45852
45852
  const latSpan = extent2[1][1] - extent2[0][1];
45853
45853
  const span = Math.max(lonSpan, latSpan);
45854
- const usDominant = (inferredCountry === "US" || subdivisions.includes("us-states")) && !regions.some((r) => r.layer === "country" && r.iso !== "US") && !anyNonUsPoi;
45854
+ const usDominant = (subdivisions.includes("us-states") || regions.some((r) => r.layer === "us-state")) && !regions.some((r) => r.layer === "country" && r.iso !== "US") && !anyNonUsPoi;
45855
45855
  let projection;
45856
45856
  const override = parsed.directives.projection;
45857
45857
  if (override === "equirectangular" || override === "natural-earth" || override === "albers-usa" || override === "mercator") {
@@ -46104,8 +46104,19 @@ function layoutMap(resolved, data, size, opts) {
46104
46104
  const { width, height } = size;
46105
46105
  const wantsUsStates = resolved.basemaps.subdivisions.includes("us-states");
46106
46106
  const usCrisp = resolved.projection === "albers-usa" && wantsUsStates && !!data.naLand;
46107
- const worldTopo = usCrisp ? data.naLand : resolved.basemaps.world === "detail" ? data.worldDetail : data.worldCoarse;
46107
+ const worldTopo = usCrisp ? data.worldDetail : resolved.basemaps.world === "detail" ? data.worldDetail : data.worldCoarse;
46108
46108
  const worldLayer = decodeLayer(worldTopo);
46109
+ if (usCrisp && data.naLand) {
46110
+ const [nbW, nbS, nbE, nbN] = [-140, 10, -52, 66];
46111
+ const crisp = decodeLayer(data.naLand);
46112
+ for (const [iso, cf] of crisp) {
46113
+ const base = worldLayer.get(iso);
46114
+ if (!base) continue;
46115
+ const [[bw, bs], [be, bn]] = geoBounds2(base);
46116
+ if (bw >= nbW && be <= nbE && bs >= nbS && bn <= nbN)
46117
+ worldLayer.set(iso, cf);
46118
+ }
46119
+ }
46109
46120
  const usLayer = wantsUsStates ? decodeLayer(data.usStates) : null;
46110
46121
  const landTint = isDark ? LAND_TINT_DARK : LAND_TINT_LIGHT;
46111
46122
  const neutralFill = mix(palette.colors.green, palette.bg, landTint);
@@ -46251,6 +46262,10 @@ function layoutMap(resolved, data, size, opts) {
46251
46262
  return p ? stretch(p[0], p[1]) : null;
46252
46263
  };
46253
46264
  } else {
46265
+ projection.clipExtent([
46266
+ [0, 0],
46267
+ [width, height]
46268
+ ]);
46254
46269
  path = geoPath(projection);
46255
46270
  project = (lon, lat) => projection([lon, lat]) ?? null;
46256
46271
  }
@@ -46395,18 +46410,11 @@ function layoutMap(resolved, data, size, opts) {
46395
46410
  placeInset("US-HI", hawaiiProjection(), akRight + 24, width * 0.1);
46396
46411
  }
46397
46412
  const conusFit = resolved.projection === "albers-usa" && !!usLayer;
46398
- const cullExtent = conusFit ? geoBounds2(fitTarget) : resolved.extent;
46399
- const [[exW, exS], [exE, exN]] = cullExtent;
46400
- const lonSpan = exE - exW;
46401
- const latSpan = exN - exS;
46402
- const isGlobalView = lonSpan >= 270 || latSpan >= 130;
46403
- const padLon = Math.max(8, lonSpan * 0.35);
46404
- const padLat = Math.max(8, latSpan * 0.35);
46405
- const vW = exW - padLon;
46406
- const vE = exE + padLon;
46407
- const vS = exS - padLat;
46408
- const vN = exN + padLat;
46409
- const vLonCenter = (exW + exE) / 2;
46413
+ const classifyExtent = conusFit ? geoBounds2(fitTarget) : resolved.extent;
46414
+ const dLonSpan = classifyExtent[1][0] - classifyExtent[0][0];
46415
+ const dLatSpan = classifyExtent[1][1] - classifyExtent[0][1];
46416
+ const isGlobalView = dLonSpan >= 270 || dLatSpan >= 130;
46417
+ const vLonCenter = (classifyExtent[0][0] + classifyExtent[1][0]) / 2;
46410
46418
  const normLon = (lon) => {
46411
46419
  let L = lon;
46412
46420
  while (L < vLonCenter - 180) L += 360;
@@ -46414,23 +46422,28 @@ function layoutMap(resolved, data, size, opts) {
46414
46422
  return L;
46415
46423
  };
46416
46424
  const ringOverlapsView = (ring) => {
46417
- let anyIn = false;
46418
- let loMin = Infinity, loMax = -Infinity, laMin = Infinity, laMax = -Infinity, rawMin = Infinity, rawMax = -Infinity;
46419
- for (const [rawLon, lat] of ring) {
46425
+ let loMin = Infinity, loMax = -Infinity, rawMin = Infinity, rawMax = -Infinity;
46426
+ for (const [rawLon] of ring) {
46420
46427
  const lon = normLon(rawLon);
46421
- if (lon >= vW && lon <= vE && lat >= vS && lat <= vN) anyIn = true;
46422
46428
  if (lon < loMin) loMin = lon;
46423
46429
  if (lon > loMax) loMax = lon;
46424
46430
  if (rawLon < rawMin) rawMin = rawLon;
46425
46431
  if (rawLon > rawMax) rawMax = rawLon;
46426
- if (lat < laMin) laMin = lat;
46427
- if (lat > laMax) laMax = lat;
46428
46432
  }
46429
46433
  if (loMax - loMin > 270) return false;
46430
46434
  if (rawMax - rawMin > 180 && loMax - loMin < 90) return false;
46431
- if (anyIn) return true;
46432
- if (loMax - loMin > 180) return false;
46433
- return !(loMax < vW || loMin > vE || laMax < vS || laMin > vN);
46435
+ let px0 = Infinity, py0 = Infinity, px1 = -Infinity, py1 = -Infinity, anyFinite = false;
46436
+ for (const [lon, lat] of ring) {
46437
+ const p = project(lon, lat);
46438
+ if (!p || !Number.isFinite(p[0]) || !Number.isFinite(p[1])) continue;
46439
+ anyFinite = true;
46440
+ if (p[0] < px0) px0 = p[0];
46441
+ if (p[0] > px1) px1 = p[0];
46442
+ if (p[1] < py0) py0 = p[1];
46443
+ if (p[1] > py1) py1 = p[1];
46444
+ }
46445
+ if (!anyFinite) return false;
46446
+ return !(px1 < 0 || px0 > width || py1 < 0 || py0 > height);
46434
46447
  };
46435
46448
  const cullFeatureToView = (f) => {
46436
46449
  if (isGlobalView) return f;
@@ -46494,6 +46507,8 @@ function layoutMap(resolved, data, size, opts) {
46494
46507
  if (layerKind === "us-state" && usContext && INSET_STATES.has(iso))
46495
46508
  continue;
46496
46509
  if (layerKind === "country" && usContext && iso === "US") continue;
46510
+ if (layerKind === "country" && iso === "AQ" && !regionById.has("AQ"))
46511
+ continue;
46497
46512
  const r = regionById.get(iso);
46498
46513
  const viewF = shouldCull ? cullFeatureToView(f) : dropFrameFillers(f);
46499
46514
  if (!viewF) continue;
@@ -46821,19 +46836,39 @@ function layoutMap(resolved, data, size, opts) {
46821
46836
  const text = labelText(p);
46822
46837
  return { text, w: measureLegendText(text, FONT) };
46823
46838
  };
46839
+ const GAP = 3;
46840
+ const inlineRect = (p, w, side) => {
46841
+ switch (side) {
46842
+ case "right":
46843
+ return { x: p.cx + p.r + GAP, y: p.cy - poiLabH / 2, w, h: poiLabH };
46844
+ case "left":
46845
+ return {
46846
+ x: p.cx - p.r - GAP - w,
46847
+ y: p.cy - poiLabH / 2,
46848
+ w,
46849
+ h: poiLabH
46850
+ };
46851
+ case "above":
46852
+ return {
46853
+ x: p.cx - w / 2,
46854
+ y: p.cy - p.r - GAP - poiLabH,
46855
+ w,
46856
+ h: poiLabH
46857
+ };
46858
+ case "below":
46859
+ return { x: p.cx - w / 2, y: p.cy + p.r + GAP, w, h: poiLabH };
46860
+ }
46861
+ };
46824
46862
  const pushInline = (p, text, w, side) => {
46825
- const tx = side === "right" ? p.cx + p.r + 3 : p.cx - p.r - 3;
46826
- obstacles.push({
46827
- x: side === "right" ? tx : tx - w,
46828
- y: p.cy - poiLabH / 2,
46829
- w,
46830
- h: poiLabH
46831
- });
46863
+ const rect = inlineRect(p, w, side);
46864
+ obstacles.push(rect);
46865
+ const anchor = side === "right" ? "start" : side === "left" ? "end" : "middle";
46866
+ const x = side === "right" ? rect.x : side === "left" ? rect.x + w : p.cx;
46832
46867
  labels.push({
46833
- x: tx,
46834
- y: p.cy + FONT / 3,
46868
+ x,
46869
+ y: rect.y + poiLabH / 2 + FONT / 3,
46835
46870
  text,
46836
- anchor: side === "right" ? "start" : "end",
46871
+ anchor,
46837
46872
  color: palette.text,
46838
46873
  halo: true,
46839
46874
  haloColor: palette.bg,
@@ -46842,14 +46877,8 @@ function layoutMap(resolved, data, size, opts) {
46842
46877
  });
46843
46878
  };
46844
46879
  const inlineFits = (p, w, side) => {
46845
- const tx = side === "right" ? p.cx + p.r + 3 : p.cx - p.r - 3;
46846
- const rect = {
46847
- x: side === "right" ? tx : tx - w,
46848
- y: p.cy - poiLabH / 2,
46849
- w,
46850
- h: poiLabH
46851
- };
46852
- return rect.x >= 0 && rect.x + rect.w <= width && !collides(rect);
46880
+ const rect = inlineRect(p, w, side);
46881
+ return rect.x >= 0 && rect.x + rect.w <= width && rect.y >= 0 && rect.y + rect.h <= height && !collides(rect);
46853
46882
  };
46854
46883
  const GROUP_R = 30;
46855
46884
  const groups = [];
@@ -46906,12 +46935,11 @@ function layoutMap(resolved, data, size, opts) {
46906
46935
  if (g.length === 1) {
46907
46936
  const p = g[0];
46908
46937
  const { text, w } = labelInfo(p);
46909
- if (inlineFits(p, w, "right")) {
46910
- pushInline(p, text, w, "right");
46911
- continue;
46912
- }
46913
- if (inlineFits(p, w, "left")) {
46914
- pushInline(p, text, w, "left");
46938
+ const side = ["right", "left", "above", "below"].find(
46939
+ (s) => inlineFits(p, w, s)
46940
+ );
46941
+ if (side) {
46942
+ pushInline(p, text, w, side);
46915
46943
  continue;
46916
46944
  }
46917
46945
  }
@@ -57051,7 +57079,7 @@ pre.dgmo, code.language-dgmo, pre > code.language-dgmo,
57051
57079
 
57052
57080
  // src/auto/index.ts
57053
57081
  init_safe_href();
57054
- var VERSION = "0.20.1";
57082
+ var VERSION = "0.20.3";
57055
57083
  var DEFAULTS = {
57056
57084
  theme: "auto",
57057
57085
  palette: "nord",