@ac-kit/model-chart 0.1.0 → 0.3.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.
Files changed (144) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/README.md +141 -1
  3. package/dist/geographic/index.d.ts +2 -0
  4. package/dist/geographic/index.d.ts.map +1 -0
  5. package/dist/geographic/index.js +2 -0
  6. package/dist/geographic/index.js.map +1 -0
  7. package/dist/geographic/project-geographic-layer.d.ts +54 -0
  8. package/dist/geographic/project-geographic-layer.d.ts.map +1 -0
  9. package/dist/geographic/project-geographic-layer.js +214 -0
  10. package/dist/geographic/project-geographic-layer.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +10 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/layout/_fit.d.ts +12 -0
  16. package/dist/layout/_fit.d.ts.map +1 -0
  17. package/dist/layout/_fit.js +52 -0
  18. package/dist/layout/_fit.js.map +1 -0
  19. package/dist/layout/index.d.ts +4 -0
  20. package/dist/layout/index.d.ts.map +1 -0
  21. package/dist/layout/index.js +4 -0
  22. package/dist/layout/index.js.map +1 -0
  23. package/dist/layout/layout-hierarchy.d.ts +35 -0
  24. package/dist/layout/layout-hierarchy.d.ts.map +1 -0
  25. package/dist/layout/layout-hierarchy.js +98 -0
  26. package/dist/layout/layout-hierarchy.js.map +1 -0
  27. package/dist/layout/layout-network.d.ts +45 -0
  28. package/dist/layout/layout-network.d.ts.map +1 -0
  29. package/dist/layout/layout-network.js +197 -0
  30. package/dist/layout/layout-network.js.map +1 -0
  31. package/dist/layout/options.d.ts +29 -0
  32. package/dist/layout/options.d.ts.map +1 -0
  33. package/dist/layout/options.js +2 -0
  34. package/dist/layout/options.js.map +1 -0
  35. package/dist/render/_fallback-chain.d.ts +13 -0
  36. package/dist/render/_fallback-chain.d.ts.map +1 -0
  37. package/dist/render/_fallback-chain.js +41 -0
  38. package/dist/render/_fallback-chain.js.map +1 -0
  39. package/dist/render/capabilities.d.ts +23 -1
  40. package/dist/render/capabilities.d.ts.map +1 -1
  41. package/dist/render/capabilities.js +56 -10
  42. package/dist/render/capabilities.js.map +1 -1
  43. package/dist/resolve/_calendar-interval.d.ts +10 -0
  44. package/dist/resolve/_calendar-interval.d.ts.map +1 -0
  45. package/dist/resolve/_calendar-interval.js +27 -0
  46. package/dist/resolve/_calendar-interval.js.map +1 -0
  47. package/dist/resolve/_coords.d.ts +35 -0
  48. package/dist/resolve/_coords.d.ts.map +1 -0
  49. package/dist/resolve/_coords.js +354 -0
  50. package/dist/resolve/_coords.js.map +1 -0
  51. package/dist/resolve/_grid-field.d.ts +16 -0
  52. package/dist/resolve/_grid-field.d.ts.map +1 -0
  53. package/dist/resolve/_grid-field.js +23 -0
  54. package/dist/resolve/_grid-field.js.map +1 -0
  55. package/dist/resolve/_guides.d.ts +16 -0
  56. package/dist/resolve/_guides.d.ts.map +1 -0
  57. package/dist/resolve/_guides.js +66 -0
  58. package/dist/resolve/_guides.js.map +1 -0
  59. package/dist/resolve/_options.d.ts +17 -0
  60. package/dist/resolve/_options.d.ts.map +1 -0
  61. package/dist/resolve/_options.js +38 -0
  62. package/dist/resolve/_options.js.map +1 -0
  63. package/dist/resolve/errors.d.ts +63 -0
  64. package/dist/resolve/errors.d.ts.map +1 -0
  65. package/dist/resolve/errors.js +91 -0
  66. package/dist/resolve/errors.js.map +1 -0
  67. package/dist/resolve/options.d.ts +30 -0
  68. package/dist/resolve/options.d.ts.map +1 -0
  69. package/dist/resolve/options.js +2 -0
  70. package/dist/resolve/options.js.map +1 -0
  71. package/dist/resolve/scale-ticks.d.ts +91 -0
  72. package/dist/resolve/scale-ticks.d.ts.map +1 -0
  73. package/dist/resolve/scale-ticks.js +231 -0
  74. package/dist/resolve/scale-ticks.js.map +1 -0
  75. package/dist/resolve/scale-transform.d.ts +102 -0
  76. package/dist/resolve/scale-transform.d.ts.map +1 -0
  77. package/dist/resolve/scale-transform.js +466 -0
  78. package/dist/resolve/scale-transform.js.map +1 -0
  79. package/dist/resolve/scale.d.ts +139 -0
  80. package/dist/resolve/scale.d.ts.map +1 -0
  81. package/dist/resolve/scale.js +710 -0
  82. package/dist/resolve/scale.js.map +1 -0
  83. package/dist/resolve/series.d.ts +26 -0
  84. package/dist/resolve/series.d.ts.map +1 -0
  85. package/dist/resolve/series.js +105 -0
  86. package/dist/resolve/series.js.map +1 -0
  87. package/dist/resolve/view-types.d.ts +223 -0
  88. package/dist/resolve/view-types.d.ts.map +1 -0
  89. package/dist/resolve/view-types.js +2 -0
  90. package/dist/resolve/view-types.js.map +1 -0
  91. package/dist/resolve/view.d.ts +43 -0
  92. package/dist/resolve/view.d.ts.map +1 -0
  93. package/dist/resolve/view.js +621 -0
  94. package/dist/resolve/view.js.map +1 -0
  95. package/dist/spec/channel.d.ts +3 -1
  96. package/dist/spec/channel.d.ts.map +1 -1
  97. package/dist/spec/channel.js.map +1 -1
  98. package/dist/spec/coord.d.ts +22 -0
  99. package/dist/spec/coord.d.ts.map +1 -1
  100. package/dist/spec/data-sources.d.ts +47 -0
  101. package/dist/spec/data-sources.d.ts.map +1 -0
  102. package/dist/spec/data-sources.js +112 -0
  103. package/dist/spec/data-sources.js.map +1 -0
  104. package/dist/spec/mark.d.ts +6 -1
  105. package/dist/spec/mark.d.ts.map +1 -1
  106. package/dist/spec/plot.d.ts +5 -0
  107. package/dist/spec/plot.d.ts.map +1 -1
  108. package/dist/spec/scale.d.ts +21 -2
  109. package/dist/spec/scale.d.ts.map +1 -1
  110. package/dist/spec/transform.d.ts +32 -6
  111. package/dist/spec/transform.d.ts.map +1 -1
  112. package/dist/transform/aggregate.d.ts +28 -0
  113. package/dist/transform/aggregate.d.ts.map +1 -0
  114. package/dist/transform/aggregate.js +463 -0
  115. package/dist/transform/aggregate.js.map +1 -0
  116. package/dist/transform/apply-transforms.d.ts +26 -0
  117. package/dist/transform/apply-transforms.d.ts.map +1 -0
  118. package/dist/transform/apply-transforms.js +66 -0
  119. package/dist/transform/apply-transforms.js.map +1 -0
  120. package/dist/transform/bin.d.ts +30 -0
  121. package/dist/transform/bin.d.ts.map +1 -0
  122. package/dist/transform/bin.js +169 -0
  123. package/dist/transform/bin.js.map +1 -0
  124. package/dist/transform/columns.d.ts +24 -0
  125. package/dist/transform/columns.d.ts.map +1 -0
  126. package/dist/transform/columns.js +77 -0
  127. package/dist/transform/columns.js.map +1 -0
  128. package/dist/transform/filter.d.ts +11 -0
  129. package/dist/transform/filter.d.ts.map +1 -0
  130. package/dist/transform/filter.js +64 -0
  131. package/dist/transform/filter.js.map +1 -0
  132. package/dist/transform/group-rows.d.ts +25 -0
  133. package/dist/transform/group-rows.d.ts.map +1 -0
  134. package/dist/transform/group-rows.js +52 -0
  135. package/dist/transform/group-rows.js.map +1 -0
  136. package/dist/transform/sort.d.ts +10 -0
  137. package/dist/transform/sort.d.ts.map +1 -0
  138. package/dist/transform/sort.js +63 -0
  139. package/dist/transform/sort.js.map +1 -0
  140. package/dist/transform/stack.d.ts +37 -0
  141. package/dist/transform/stack.d.ts.map +1 -0
  142. package/dist/transform/stack.js +218 -0
  143. package/dist/transform/stack.js.map +1 -0
  144. package/package.json +28 -9
@@ -0,0 +1,13 @@
1
+ import type { PlotSpec } from "../spec/plot.js";
2
+ /**
3
+ * The `rect` a `surface` falls back to: the same grid, coloured by `color ??
4
+ * z`.
5
+ */
6
+ export declare function surfaceAsRect_(spec: PlotSpec): PlotSpec;
7
+ /**
8
+ * The candidates of a fallback chain, in the order a renderer tries them: the
9
+ * spec, then its fallbacks breadth-first (each visited once, so a cyclic chain
10
+ * ends), then, for each `surface` among them, its implicit `rect`.
11
+ */
12
+ export declare function fallbackCandidates_(spec: PlotSpec): Generator<PlotSpec>;
13
+ //# sourceMappingURL=_fallback-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_fallback-chain.d.ts","sourceRoot":"","sources":["../../src/render/_fallback-chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CASvD;AAED;;;;GAIG;AACH,wBAAiB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,CAoBxE"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The `rect` a `surface` falls back to: the same grid, coloured by `color ??
3
+ * z`.
4
+ */
5
+ export function surfaceAsRect_(spec) {
6
+ const { z, ...encoding } = spec.encoding;
7
+ const color = encoding.color ?? z;
8
+ return {
9
+ ...spec,
10
+ mark: "rect",
11
+ encoding: color === undefined ? encoding : { ...encoding, color },
12
+ fallback: undefined,
13
+ };
14
+ }
15
+ /**
16
+ * The candidates of a fallback chain, in the order a renderer tries them: the
17
+ * spec, then its fallbacks breadth-first (each visited once, so a cyclic chain
18
+ * ends), then, for each `surface` among them, its implicit `rect`.
19
+ */
20
+ export function* fallbackCandidates_(spec) {
21
+ const pending = [spec];
22
+ const surfaces = [];
23
+ // A fallback chain is plain data and could be built cyclically by mistake.
24
+ const seen = new Set();
25
+ for (let index = 0; index < pending.length; index++) {
26
+ const candidate = pending[index];
27
+ if (seen.has(candidate)) {
28
+ continue;
29
+ }
30
+ seen.add(candidate);
31
+ yield candidate;
32
+ if (candidate.mark === "surface") {
33
+ surfaces.push(candidate);
34
+ }
35
+ pending.push(...(candidate.fallback ?? []));
36
+ }
37
+ for (const surface of surfaces) {
38
+ yield surfaceAsRect_(surface);
39
+ }
40
+ }
41
+ //# sourceMappingURL=_fallback-chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_fallback-chain.js","sourceRoot":"","sources":["../../src/render/_fallback-chain.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAc;IAC5C,MAAM,EAAE,CAAC,EAAE,GAAG,QAAQ,EAAE,GAAG,IAA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ord.js";
2
+ import type { CoordKind, HierarchyLayout, NetworkLayout, ProjectionKind } from "../spec/coord.js";
3
3
  import type { Mark } from "../spec/mark.js";
4
4
  import type { PlotSpec } from "../spec/plot.js";
5
5
  import type { TransformSpec } from "../spec/transform.js";
@@ -26,6 +26,15 @@ export type RendererCapabilities = {
26
26
  * absent.
27
27
  */
28
28
  maxMarks?: number;
29
+ /**
30
+ * Spatial dimensions drawn; a spec encoding `z` needs `3`, any other `2`.
31
+ * Absent: no restriction.
32
+ */
33
+ dimensions?: ReadonlySet<2 | 3>;
34
+ /** Map projections available. Absent: no restriction. */
35
+ projections?: ReadonlySet<ProjectionKind>;
36
+ /** Hierarchy and network layouts available. Absent: no restriction. */
37
+ layouts?: ReadonlySet<HierarchyLayout | NetworkLayout>;
29
38
  };
30
39
  /**
31
40
  * Everything in `spec` that `capabilities` cannot honour.
@@ -46,8 +55,21 @@ export declare function canRender(spec: PlotSpec, capabilities: RendererCapabili
46
55
  /**
47
56
  * The first spec in `spec`'s fallback chain that `capabilities` can draw.
48
57
  *
58
+ * A `surface` that nothing in its explicit chain can draw gets one implicit
59
+ * last candidate: a `rect` over the same grid, coloured by `color ?? z`.
60
+ *
49
61
  * @returns `null` when nothing in the chain is drawable, which is the signal to
50
62
  * apply the universal fallback and render the underlying frame as a table.
51
63
  */
52
64
  export declare function resolvePlot(spec: PlotSpec, capabilities: RendererCapabilities): PlotSpec | null;
65
+ /**
66
+ * What model-chart itself can resolve; a renderer's capabilities are
67
+ * intersected with it. The projections are those `projectionCreate`
68
+ * (`@ac-kit/math-map-projection`) builds, and the layouts all but `pack`.
69
+ */
70
+ export declare const RESOLVER_SUPPORT: Readonly<{
71
+ transforms: ReadonlySet<TransformSpec["kind"]>;
72
+ projections: ReadonlySet<ProjectionKind>;
73
+ layouts: ReadonlySet<HierarchyLayout | NetworkLayout>;
74
+ }>;
53
75
  //# sourceMappingURL=capabilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/render/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAClC,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC/B,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/B,UAAU,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,+EAA+E;IAC/E,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;IAC3B,+EAA+E;IAC/E,UAAU,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,oBAAoB,GAChC,MAAM,EAAE,CAyBV;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,oBAAoB,GAChC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,oBAAoB,GAChC,QAAQ,GAAG,IAAI,CAmBjB"}
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/render/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,O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WAAW,CAC1B,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,oBAAoB,GAChC,QAAQ,GAAG,IAAI,CAQjB;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC;IACvC,UAAU,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,WAAW,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACzC,OAAO,EAAE,WAAW,CAAC,eAAe,GAAG,aAAa,CAAC,CAAC;CACtD,CA6BA,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { fallbackCandidates_ } from "./_fallback-chain.js";
1
2
  /**
2
3
  * Everything in `spec` that `capabilities` cannot honour.
3
4
  *
@@ -23,6 +24,22 @@ export function unsupportedFeatures(spec, capabilities) {
23
24
  reasons.push(`transform "${transform.kind}"`);
24
25
  }
25
26
  }
27
+ const dimension = spec.encoding.z === undefined ? 2 : 3;
28
+ if (capabilities.dimensions !== undefined &&
29
+ !capabilities.dimensions.has(dimension)) {
30
+ reasons.push(`dimension ${dimension}`);
31
+ }
32
+ const coord = spec.coord;
33
+ if (coord?.kind === "geographic" &&
34
+ capabilities.projections !== undefined &&
35
+ !capabilities.projections.has(coord.projection.kind)) {
36
+ reasons.push(`projection ${coord.projection.kind}`);
37
+ }
38
+ if ((coord?.kind === "hierarchy" || coord?.kind === "network") &&
39
+ capabilities.layouts !== undefined &&
40
+ !capabilities.layouts.has(coord.layout)) {
41
+ reasons.push(`layout ${coord.layout}`);
42
+ }
26
43
  return reasons;
27
44
  }
28
45
  /**
@@ -39,24 +56,53 @@ export function canRender(spec, capabilities) {
39
56
  /**
40
57
  * The first spec in `spec`'s fallback chain that `capabilities` can draw.
41
58
  *
59
+ * A `surface` that nothing in its explicit chain can draw gets one implicit
60
+ * last candidate: a `rect` over the same grid, coloured by `color ?? z`.
61
+ *
42
62
  * @returns `null` when nothing in the chain is drawable, which is the signal to
43
63
  * apply the universal fallback and render the underlying frame as a table.
44
64
  */
45
65
  export function resolvePlot(spec, capabilities) {
46
- const pending = [spec];
47
- // A fallback chain is plain data and could be built cyclically by mistake.
48
- const seen = new Set();
49
- while (pending.length > 0) {
50
- const candidate = pending.shift();
51
- if (seen.has(candidate)) {
52
- continue;
53
- }
54
- seen.add(candidate);
66
+ for (const candidate of fallbackCandidates_(spec)) {
55
67
  if (canRender(candidate, capabilities)) {
56
68
  return candidate;
57
69
  }
58
- pending.push(...(candidate.fallback ?? []));
59
70
  }
60
71
  return null;
61
72
  }
73
+ /**
74
+ * What model-chart itself can resolve; a renderer's capabilities are
75
+ * intersected with it. The projections are those `projectionCreate`
76
+ * (`@ac-kit/math-map-projection`) builds, and the layouts all but `pack`.
77
+ */
78
+ export const RESOLVER_SUPPORT = {
79
+ transforms: new Set(["filter", "sort", "aggregate", "bin", "stack"]),
80
+ projections: new Set([
81
+ "equirectangular",
82
+ "mercator",
83
+ "transverse-mercator",
84
+ "albers",
85
+ "conic-conformal",
86
+ "conic-equal-area",
87
+ "conic-equidistant",
88
+ "azimuthal-equal-area",
89
+ "azimuthal-equidistant",
90
+ "gnomonic",
91
+ "orthographic",
92
+ "stereographic",
93
+ "natural-earth",
94
+ "equal-earth",
95
+ ]),
96
+ layouts: new Set([
97
+ "squarify",
98
+ "partition",
99
+ "tidy",
100
+ "cluster",
101
+ "force",
102
+ "layered",
103
+ "circular",
104
+ "arc",
105
+ "flow",
106
+ ]),
107
+ };
62
108
  //# sourceMappingURL=capabilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/render/capabilities.ts"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAAc,EACd,YAAkC;IAElC,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,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ED,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACxB,IAAc,EACd,YAAkC;IAElC,OAAO,mBAAmB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAC1B,IAAc,EACd,YAAkC;IAElC,KAAK,MAAM,SAAS,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,IAAI,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC;YACxC,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAIxB;IACJ,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACpE,WAAW,EAAE,IAAI,GAAG,CAAC;QACpB,iBAAiB;QACjB,UAAU;QACV,qBAAqB;QACrB,QAAQ;QACR,iBAAiB;QACjB,kBAAkB;QAClB,mBAAmB;QACnB,sBAAsB;QACtB,uBAAuB;QACvB,UAAU;QACV,cAAc;QACd,eAAe;QACf,eAAe;QACf,aAAa;KACb,CAAC;IACF,OAAO,EAAE,IAAI,GAAG,CAAC;QAChB,UAAU;QACV,WAAW;QACX,MAAM;QACN,SAAS;QACT,OAAO;QACP,SAAS;QACT,UAAU;QACV,KAAK;QACL,MAAM;KACN,CAAC;CACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { CalendarInterval } from "@ac-kit/core";
2
+ import type { CalendarIntervalSpec } from "../spec/scale.js";
3
+ /**
4
+ * The core interval a spec names; `undefined` for an unknown unit or a step
5
+ * that is not a positive safe integer.
6
+ */
7
+ export declare function calendarIntervalOf_(spec: CalendarIntervalSpec): CalendarInterval | undefined;
8
+ /** Whether a spec is a calendar interval rather than a boolean or a count. */
9
+ export declare function isCalendarIntervalSpec_(value: unknown): value is CalendarIntervalSpec;
10
+ //# sourceMappingURL=_calendar-interval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_calendar-interval.d.ts","sourceRoot":"","sources":["../../src/resolve/_calendar-interval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,cAAc,CAAC;AAEvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAa7D;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,oBAAoB,GACxB,gBAAgB,GAAG,SAAS,CAO9B;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,oBAAoB,CAI/B"}
@@ -0,0 +1,27 @@
1
+ const UNITS_ = new Set([
2
+ "millisecond",
3
+ "second",
4
+ "minute",
5
+ "hour",
6
+ "day",
7
+ "week",
8
+ "month",
9
+ "year",
10
+ ]);
11
+ /**
12
+ * The core interval a spec names; `undefined` for an unknown unit or a step
13
+ * that is not a positive safe integer.
14
+ */
15
+ export function calendarIntervalOf_(spec) {
16
+ const unit = typeof spec === "string" ? spec : spec.unit;
17
+ const step = typeof spec === "string" ? 1 : (spec.step ?? 1);
18
+ if (!UNITS_.has(unit) || !Number.isSafeInteger(step) || step < 1) {
19
+ return undefined;
20
+ }
21
+ return { unit, step };
22
+ }
23
+ /** Whether a spec is a calendar interval rather than a boolean or a count. */
24
+ export function isCalendarIntervalSpec_(value) {
25
+ return (typeof value === "string" || (typeof value === "object" && value !== null));
26
+ }
27
+ //# sourceMappingURL=_calendar-interval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_calendar-interval.js","sourceRoot":"","sources":["../../src/resolve/_calendar-interval.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,GAAyB,IAAI,GAAG,CAAmB;IAC9D,aAAa;IACb,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;CACN,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAA0B;IAE1B,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACzD,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QAClE,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,uBAAuB,CACtC,KAAc;IAEd,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAC1E,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { CoordSpec } from "../spec/coord.js";
2
+ import type { DataSources } from "../spec/data-sources.js";
3
+ import type { ResolveScaleOptions } from "./scale.js";
4
+ import type { ResolvedCoord, ResolvedLayer } from "./view-types.js";
5
+ type DefaultedCoord_<Kind extends CoordSpec["kind"]> = Required<Extract<CoordSpec, {
6
+ kind: Kind;
7
+ }>>;
8
+ /**
9
+ * `coord` with its static defaults filled in (an absent `coord` is cartesian);
10
+ * the fields whose default depends on the data (parallel `axes`, network
11
+ * `nodes`) and the optional geographic `crs` are left as given.
12
+ */
13
+ export declare function defaultedCoord_(coord: Extract<CoordSpec, {
14
+ kind: "polar";
15
+ }>): DefaultedCoord_<"polar">;
16
+ export declare function defaultedCoord_(coord: Extract<CoordSpec, {
17
+ kind: "hierarchy";
18
+ }>): DefaultedCoord_<"hierarchy">;
19
+ export declare function defaultedCoord_(coord: CoordSpec | undefined): CoordSpec;
20
+ /**
21
+ * Whether two layers' `coord` describe the same coordinate system: equal after
22
+ * defaulting, compared structurally (key order, an optional property set to
23
+ * `undefined` and `0` against `-0` do not matter).
24
+ */
25
+ export declare function isSameCoord_(first: CoordSpec | undefined, second: CoordSpec | undefined): boolean;
26
+ /**
27
+ * The resolved coordinate system of a panel's layers, whose effective `coord`
28
+ * they share.
29
+ *
30
+ * @throws {InvalidCoordError} {InvalidEncodingError} {InvalidHierarchyError}
31
+ * {InvalidNetworkError} {InvalidLayerSourceError}
32
+ */
33
+ export declare function resolveCoord_(coord: CoordSpec | undefined, layers: readonly ResolvedLayer[], sources: DataSources, options: ResolveScaleOptions): ResolvedCoord;
34
+ export {};
35
+ //# sourceMappingURL=_coords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_coords.d.ts","sourceRoot":"","sources":["../../src/resolve/_coords.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAY3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,KAAK,EACX,aAAa,EAEb,aAAa,EAGb,MAAM,iBAAiB,CAAC;AASzB,KAAK,eAAe,CAAC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,IAAI,QAAQ,CAC9D,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAClC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,GAC1C,eAAe,CAAC,OAAO,CAAC,CAAC;AAC5B,wBAAgB,eAAe,CAC9B,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,GAC9C,eAAe,CAAC,WAAW,CAAC,CAAC;AAChC,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAiCzE;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,MAAM,EAAE,SAAS,GAAG,SAAS,GAC3B,OAAO,CAOT;AA6WD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,mBAAmB,GAC1B,aAAa,CA0Bf"}
@@ -0,0 +1,354 @@
1
+ import { isDeepEqual } from "@ac-kit/core";
2
+ import { findDataFrameFieldIndexByName, getDataFrameColumnByName, getDataFrameFieldByName, isDataGrid, } from "@ac-kit/model-dataset";
3
+ import { resolveDataSource } from "../spec/data-sources.js";
4
+ import { isFieldEncoding } from "../spec/encoding.js";
5
+ import { guideOf_ } from "./_guides.js";
6
+ import { InvalidCoordError, InvalidEncodingError, InvalidHierarchyError, InvalidLayerSourceError, InvalidNetworkError, } from "./errors.js";
7
+ import { resolveScale } from "./scale.js";
8
+ const PARALLEL_KINDS_ = new Set([
9
+ "quantitative",
10
+ "temporal",
11
+ "ordinal",
12
+ "nominal",
13
+ ]);
14
+ export function defaultedCoord_(coord) {
15
+ switch (coord?.kind) {
16
+ case undefined:
17
+ case "cartesian":
18
+ return { kind: "cartesian", transpose: coord?.transpose ?? false };
19
+ case "polar":
20
+ return {
21
+ kind: "polar",
22
+ innerRadius: coord.innerRadius ?? 0,
23
+ startAngle: coord.startAngle ?? 0,
24
+ endAngle: coord.endAngle ?? 2 * Math.PI,
25
+ };
26
+ case "geographic":
27
+ return {
28
+ kind: "geographic",
29
+ projection: coord.projection,
30
+ crs: coord.crs,
31
+ };
32
+ case "parallel":
33
+ return { kind: "parallel", axes: coord.axes };
34
+ case "hierarchy":
35
+ return {
36
+ kind: "hierarchy",
37
+ layout: coord.layout,
38
+ padding: coord.padding ?? 0,
39
+ radial: coord.radial ?? false,
40
+ };
41
+ case "network":
42
+ return { kind: "network", layout: coord.layout, nodes: coord.nodes };
43
+ }
44
+ }
45
+ /**
46
+ * Whether two layers' `coord` describe the same coordinate system: equal after
47
+ * defaulting, compared structurally (key order, an optional property set to
48
+ * `undefined` and `0` against `-0` do not matter).
49
+ */
50
+ export function isSameCoord_(first, second) {
51
+ return isDeepEqual(defaultedCoord_(first), defaultedCoord_(second), "sameValueZero", { ignoreUndefinedProperties: true });
52
+ }
53
+ // Map keys: a number and the same bigint are one key, as `compareValues`
54
+ // orders them; `NaN` is one key and `0` equals `-0` (SameValueZero).
55
+ function keyOf_(value) {
56
+ return typeof value === "bigint" &&
57
+ Number.isSafeInteger(Number(value)) &&
58
+ BigInt(Number(value)) === value
59
+ ? Number(value)
60
+ : value;
61
+ }
62
+ function cell_(column, row) {
63
+ return column[row] ?? null;
64
+ }
65
+ function frameOf_(layer, index) {
66
+ if (layer.source.kind === "grid") {
67
+ throw new InvalidLayerSourceError(layer.sourceName, layer.spec.mark, `Layer ${index} reads a grid, which a ${layer.spec.coord?.kind ?? "cartesian"} coordinate system can't take`);
68
+ }
69
+ return layer.source.frame;
70
+ }
71
+ function fieldColumn_(layer, channel) {
72
+ const encoding = layer.spec.encoding[channel];
73
+ if (encoding === undefined || !isFieldEncoding(encoding)) {
74
+ return undefined;
75
+ }
76
+ return layer.source.kind === "frame"
77
+ ? getDataFrameColumnByName(layer.source.frame, encoding.field)
78
+ : undefined;
79
+ }
80
+ function polar_(coord) {
81
+ const { innerRadius, startAngle, endAngle } = defaultedCoord_(coord);
82
+ if (!(innerRadius >= 0 && innerRadius < 1)) {
83
+ throw new InvalidCoordError("polar", `innerRadius is a fraction in [0, 1), got ${innerRadius}`);
84
+ }
85
+ if (startAngle - startAngle !== 0 ||
86
+ endAngle - endAngle !== 0 ||
87
+ startAngle === endAngle) {
88
+ throw new InvalidCoordError("polar", `startAngle and endAngle are finite and distinct, got ${startAngle} and ${endAngle}`);
89
+ }
90
+ return { kind: "polar", innerRadius, startAngle, endAngle };
91
+ }
92
+ function parallel_(coord, layers, options) {
93
+ const first = frameOf_(layers[0], 0);
94
+ let axes;
95
+ if (coord.axes !== undefined) {
96
+ axes = coord.axes;
97
+ }
98
+ else {
99
+ const encoded = new Set();
100
+ for (const layer of layers) {
101
+ for (const encoding of Object.values(layer.spec.encoding)) {
102
+ if (encoding !== undefined && isFieldEncoding(encoding)) {
103
+ encoded.add(encoding.field);
104
+ }
105
+ }
106
+ }
107
+ axes = first.fields
108
+ .filter((field) => PARALLEL_KINDS_.has(field.kind) && !encoded.has(field.name))
109
+ .map((field) => ({ field: field.name }));
110
+ }
111
+ if (axes.length === 0) {
112
+ throw new InvalidEncodingError(undefined, "Parallel coordinates need at least one axis");
113
+ }
114
+ const resolved = axes.map((encoding) => {
115
+ const inputs = layers.flatMap((layer, index) => {
116
+ const frame = frameOf_(layer, index);
117
+ return findDataFrameFieldIndexByName(frame, encoding.field) < 0 &&
118
+ index > 0
119
+ ? []
120
+ : [
121
+ {
122
+ channel: "y",
123
+ encoding,
124
+ mark: layer.spec.mark,
125
+ source: frame,
126
+ },
127
+ ];
128
+ });
129
+ const scale = resolveScale(inputs, options);
130
+ return {
131
+ encoding,
132
+ field: getDataFrameFieldByName(first, encoding.field),
133
+ scale,
134
+ guide: guideOf_("y", scale, [encoding]),
135
+ };
136
+ });
137
+ return { kind: "parallel", axes: resolved };
138
+ }
139
+ function hierarchy_(coord, layers) {
140
+ const { padding, radial } = defaultedCoord_(coord);
141
+ if (!(padding >= 0 && padding - padding === 0)) {
142
+ throw new InvalidCoordError("hierarchy", `padding is finite and ≥ 0, got ${padding}`);
143
+ }
144
+ for (const layer of layers) {
145
+ if (layer.spec.mark === "arc" && !radial) {
146
+ throw new InvalidCoordError("hierarchy", "arc marks in a hierarchy need radial: true (a sunburst)");
147
+ }
148
+ }
149
+ const treeLayer = layers.findIndex((layer) => layer.spec.encoding.parent !== undefined);
150
+ if (treeLayer < 0) {
151
+ throw new InvalidEncodingError("parent", "A hierarchy needs a layer encoding parent and key");
152
+ }
153
+ const tree = layers[treeLayer];
154
+ frameOf_(tree, treeLayer);
155
+ const keys = fieldColumn_(tree, "key");
156
+ const parents = fieldColumn_(tree, "parent");
157
+ if (keys === undefined || parents === undefined) {
158
+ throw new InvalidEncodingError(keys === undefined ? "key" : "parent", "The tree layer of a hierarchy encodes key and parent as fields");
159
+ }
160
+ const rowCount = keys.length;
161
+ const rowOfKey = new Map();
162
+ for (let row = 0; row < rowCount; row++) {
163
+ const key = keyOf_(cell_(keys, row));
164
+ if (rowOfKey.has(key)) {
165
+ throw new InvalidEncodingError("key", `Hierarchy rows ${rowOfKey.get(key)} and ${row} share a key`);
166
+ }
167
+ rowOfKey.set(key, row);
168
+ }
169
+ const parentRows = new Int32Array(rowCount);
170
+ let root = -1;
171
+ for (let row = 0; row < rowCount; row++) {
172
+ const parent = cell_(parents, row);
173
+ if (parent === null) {
174
+ if (root >= 0) {
175
+ throw new InvalidHierarchyError(row, "several-roots", `Hierarchy rows ${root} and ${row} both have a null parent`);
176
+ }
177
+ root = row;
178
+ parentRows[row] = -1;
179
+ continue;
180
+ }
181
+ const parentRow = rowOfKey.get(keyOf_(parent));
182
+ if (parentRow === undefined) {
183
+ throw new InvalidHierarchyError(row, "unknown-parent", `Hierarchy row ${row} names a parent no row has`);
184
+ }
185
+ parentRows[row] = parentRow;
186
+ }
187
+ if (root < 0 && rowCount > 0) {
188
+ throw new InvalidHierarchyError(-1, "no-root", "No hierarchy row has a null parent");
189
+ }
190
+ // Every row must reach the root: walking up marks each chain once.
191
+ const state = new Uint8Array(rowCount); // 0 unseen, 1 on the walk, 2 reaches root
192
+ if (root >= 0) {
193
+ state[root] = 2;
194
+ }
195
+ const walk = [];
196
+ for (let row = 0; row < rowCount; row++) {
197
+ let current = row;
198
+ while (state[current] === 0) {
199
+ state[current] = 1;
200
+ walk.push(current);
201
+ current = parentRows[current];
202
+ }
203
+ if (state[current] === 1) {
204
+ throw new InvalidHierarchyError(row, "cycle", `Hierarchy row ${row} does not reach the root: its parents form a cycle`);
205
+ }
206
+ for (const visited of walk) {
207
+ state[visited] = 2;
208
+ }
209
+ walk.length = 0;
210
+ }
211
+ const layerNodes = layers.map((layer, index) => {
212
+ if (index === treeLayer) {
213
+ return Int32Array.from({ length: rowCount }, (_, row) => row);
214
+ }
215
+ const layerKeys = fieldColumn_(layer, "key");
216
+ if (layerKeys === undefined) {
217
+ return undefined;
218
+ }
219
+ return Int32Array.from({ length: layerKeys.length }, (_, row) => rowOfKey.get(keyOf_(cell_(layerKeys, row))) ?? -1);
220
+ });
221
+ return {
222
+ kind: "hierarchy",
223
+ layout: coord.layout,
224
+ padding,
225
+ radial,
226
+ treeLayer,
227
+ parentRows,
228
+ root: Math.max(root, 0),
229
+ layerNodes,
230
+ };
231
+ }
232
+ function network_(coord, layers, sources) {
233
+ const nodeKeys = [];
234
+ const nodeOfKey = new Map();
235
+ let nodeSource;
236
+ const nodeRows = [];
237
+ if (coord.nodes !== undefined) {
238
+ const named = resolveDataSource(coord.nodes, sources);
239
+ // `assertDataReferences` has checked it is a frame with an `id` field.
240
+ nodeSource = isDataGrid(named) ? undefined : named;
241
+ }
242
+ if (nodeSource !== undefined) {
243
+ const ids = getDataFrameColumnByName(nodeSource, "id");
244
+ for (let row = 0; row < ids.length; row++) {
245
+ const id = cell_(ids, row);
246
+ const key = keyOf_(id);
247
+ if (nodeOfKey.has(key)) {
248
+ throw new InvalidEncodingError("key", `Node rows ${nodeRows[nodeOfKey.get(key)]} and ${row} of "${coord.nodes}" share an id`);
249
+ }
250
+ nodeOfKey.set(key, nodeKeys.length);
251
+ nodeKeys.push(id);
252
+ nodeRows.push(row);
253
+ }
254
+ }
255
+ const linkEnds = layers.map((layer, index) => {
256
+ if (layer.spec.mark !== "link") {
257
+ return undefined;
258
+ }
259
+ frameOf_(layer, index);
260
+ const sourceColumn = fieldColumn_(layer, "source");
261
+ const targetColumn = fieldColumn_(layer, "target");
262
+ if (sourceColumn === undefined || targetColumn === undefined) {
263
+ throw new InvalidEncodingError(sourceColumn === undefined ? "source" : "target", "A link layer encodes source and target as fields");
264
+ }
265
+ return [sourceColumn, targetColumn];
266
+ });
267
+ const nodeOf = (value, row, endpoint) => {
268
+ if (value === null) {
269
+ return -1;
270
+ }
271
+ const key = keyOf_(value);
272
+ const node = nodeOfKey.get(key);
273
+ if (node !== undefined) {
274
+ return node;
275
+ }
276
+ if (nodeSource !== undefined) {
277
+ throw new InvalidNetworkError(row, endpoint, `Link row ${row}'s ${endpoint} is not among the ids of "${coord.nodes}"`);
278
+ }
279
+ nodeOfKey.set(key, nodeKeys.length);
280
+ nodeKeys.push(value);
281
+ nodeRows.push(-1);
282
+ return nodeKeys.length - 1;
283
+ };
284
+ const layerNodes = layers.map((layer, index) => {
285
+ const ends = linkEnds[index];
286
+ if (ends === undefined) {
287
+ return undefined;
288
+ }
289
+ const [sourceColumn, targetColumn] = ends;
290
+ const pairs = new Int32Array(sourceColumn.length * 2);
291
+ for (let row = 0; row < sourceColumn.length; row++) {
292
+ pairs[2 * row] = nodeOf(cell_(sourceColumn, row), row, "source");
293
+ pairs[2 * row + 1] = nodeOf(cell_(targetColumn, row), row, "target");
294
+ }
295
+ return pairs;
296
+ });
297
+ for (const [index, layer] of layers.entries()) {
298
+ if (linkEnds[index] !== undefined || layer.source.kind !== "frame") {
299
+ continue;
300
+ }
301
+ const frame = layer.source.frame;
302
+ const keys = fieldColumn_(layer, "key") ??
303
+ (findDataFrameFieldIndexByName(frame, "id") >= 0
304
+ ? getDataFrameColumnByName(frame, "id")
305
+ : undefined);
306
+ if (keys !== undefined) {
307
+ layerNodes[index] = Int32Array.from({ length: keys.length }, (_, row) => nodeOfKey.get(keyOf_(cell_(keys, row))) ?? -1);
308
+ }
309
+ }
310
+ nodeRows.length = nodeKeys.length;
311
+ return {
312
+ kind: "network",
313
+ layout: coord.layout,
314
+ nodeKeys,
315
+ nodeRows: Int32Array.from(nodeRows),
316
+ nodeSource,
317
+ layerNodes,
318
+ };
319
+ }
320
+ /**
321
+ * The resolved coordinate system of a panel's layers, whose effective `coord`
322
+ * they share.
323
+ *
324
+ * @throws {InvalidCoordError} {InvalidEncodingError} {InvalidHierarchyError}
325
+ * {InvalidNetworkError} {InvalidLayerSourceError}
326
+ */
327
+ export function resolveCoord_(coord, layers, sources, options) {
328
+ switch (coord?.kind) {
329
+ case undefined:
330
+ case "cartesian":
331
+ return {
332
+ kind: "cartesian",
333
+ transpose: coord?.transpose ?? false,
334
+ dimension: layers.some((layer) => layer.spec.encoding.z !== undefined)
335
+ ? 3
336
+ : 2,
337
+ };
338
+ case "polar":
339
+ return polar_(coord);
340
+ case "geographic":
341
+ return {
342
+ kind: "geographic",
343
+ projection: coord.projection,
344
+ crs: coord.crs,
345
+ };
346
+ case "parallel":
347
+ return parallel_(coord, layers, options);
348
+ case "hierarchy":
349
+ return hierarchy_(coord, layers);
350
+ case "network":
351
+ return network_(coord, layers, sources);
352
+ }
353
+ }
354
+ //# sourceMappingURL=_coords.js.map