@ac-kit/model-chart 0.2.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 (139) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +106 -0
  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 +9 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +9 -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 +13 -0
  40. package/dist/render/capabilities.d.ts.map +1 -1
  41. package/dist/render/capabilities.js +40 -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 +17 -0
  99. package/dist/spec/coord.d.ts.map +1 -1
  100. package/dist/spec/data-sources.js.map +1 -1
  101. package/dist/spec/mark.d.ts +6 -1
  102. package/dist/spec/mark.d.ts.map +1 -1
  103. package/dist/spec/scale.d.ts +21 -2
  104. package/dist/spec/scale.d.ts.map +1 -1
  105. package/dist/spec/transform.d.ts +32 -6
  106. package/dist/spec/transform.d.ts.map +1 -1
  107. package/dist/transform/aggregate.d.ts +28 -0
  108. package/dist/transform/aggregate.d.ts.map +1 -0
  109. package/dist/transform/aggregate.js +463 -0
  110. package/dist/transform/aggregate.js.map +1 -0
  111. package/dist/transform/apply-transforms.d.ts +26 -0
  112. package/dist/transform/apply-transforms.d.ts.map +1 -0
  113. package/dist/transform/apply-transforms.js +66 -0
  114. package/dist/transform/apply-transforms.js.map +1 -0
  115. package/dist/transform/bin.d.ts +30 -0
  116. package/dist/transform/bin.d.ts.map +1 -0
  117. package/dist/transform/bin.js +169 -0
  118. package/dist/transform/bin.js.map +1 -0
  119. package/dist/transform/columns.d.ts +24 -0
  120. package/dist/transform/columns.d.ts.map +1 -0
  121. package/dist/transform/columns.js +77 -0
  122. package/dist/transform/columns.js.map +1 -0
  123. package/dist/transform/filter.d.ts +11 -0
  124. package/dist/transform/filter.d.ts.map +1 -0
  125. package/dist/transform/filter.js +64 -0
  126. package/dist/transform/filter.js.map +1 -0
  127. package/dist/transform/group-rows.d.ts +25 -0
  128. package/dist/transform/group-rows.d.ts.map +1 -0
  129. package/dist/transform/group-rows.js +52 -0
  130. package/dist/transform/group-rows.js.map +1 -0
  131. package/dist/transform/sort.d.ts +10 -0
  132. package/dist/transform/sort.d.ts.map +1 -0
  133. package/dist/transform/sort.js +63 -0
  134. package/dist/transform/sort.js.map +1 -0
  135. package/dist/transform/stack.d.ts +37 -0
  136. package/dist/transform/stack.d.ts.map +1 -0
  137. package/dist/transform/stack.js +218 -0
  138. package/dist/transform/stack.js.map +1 -0
  139. package/package.json +22 -4
package/dist/index.js CHANGED
@@ -1,4 +1,12 @@
1
1
  export * from "./render/capabilities.js";
2
+ export * from "./resolve/errors.js";
3
+ export * from "./resolve/options.js";
4
+ export * from "./resolve/scale.js";
5
+ export * from "./resolve/scale-ticks.js";
6
+ export * from "./resolve/scale-transform.js";
7
+ export * from "./resolve/series.js";
8
+ export * from "./resolve/view-types.js";
9
+ export * from "./resolve/view.js";
2
10
  export * from "./spec/annotation.js";
3
11
  export * from "./spec/channel.js";
4
12
  export * from "./spec/coord.js";
@@ -8,4 +16,5 @@ export * from "./spec/mark.js";
8
16
  export * from "./spec/plot.js";
9
17
  export * from "./spec/scale.js";
10
18
  export * from "./spec/transform.js";
19
+ export * from "./transform/apply-transforms.js";
11
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ChartLayoutOptions } from "./options.js";
2
+ /** The aspect ratio, checked. */
3
+ export declare function aspectRatioOf_(options: ChartLayoutOptions): number;
4
+ /**
5
+ * Pairs of a layout laid out in arbitrary units, fitted uniformly (keeping
6
+ * their shape) and centred in a plot of width `aspectRatio` and height 1, then
7
+ * divided by the width: positions in the unit square of the plot. A layout with
8
+ * no extent sits at the centre. `extra` pairs (bends) follow the same map. In
9
+ * place.
10
+ */
11
+ export declare function fitPairs_(pairs: Float64Array, aspectRatio: number, extra?: Float64Array): void;
12
+ //# sourceMappingURL=_fit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_fit.d.ts","sourceRoot":"","sources":["../../src/layout/_fit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,iCAAiC;AACjC,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAMlE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACxB,KAAK,EAAE,YAAY,EACnB,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,YAAY,GAClB,IAAI,CAuCN"}
@@ -0,0 +1,52 @@
1
+ /** The aspect ratio, checked. */
2
+ export function aspectRatioOf_(options) {
3
+ const aspectRatio = options.aspectRatio ?? 1;
4
+ if (!(aspectRatio > 0 && aspectRatio - aspectRatio === 0)) {
5
+ throw new RangeError(`aspectRatio is finite and > 0, got ${aspectRatio}`);
6
+ }
7
+ return aspectRatio;
8
+ }
9
+ /**
10
+ * Pairs of a layout laid out in arbitrary units, fitted uniformly (keeping
11
+ * their shape) and centred in a plot of width `aspectRatio` and height 1, then
12
+ * divided by the width: positions in the unit square of the plot. A layout with
13
+ * no extent sits at the centre. `extra` pairs (bends) follow the same map. In
14
+ * place.
15
+ */
16
+ export function fitPairs_(pairs, aspectRatio, extra) {
17
+ let minX = Infinity;
18
+ let minY = Infinity;
19
+ let maxX = -Infinity;
20
+ let maxY = -Infinity;
21
+ for (let index = 0; index + 1 < pairs.length; index += 2) {
22
+ const x = pairs[index];
23
+ const y = pairs[index + 1];
24
+ if (x - x === 0 && y - y === 0) {
25
+ minX = Math.min(minX, x);
26
+ maxX = Math.max(maxX, x);
27
+ minY = Math.min(minY, y);
28
+ maxY = Math.max(maxY, y);
29
+ }
30
+ }
31
+ const width = maxX - minX;
32
+ const height = maxY - minY;
33
+ const scale = width > 0 || height > 0
34
+ ? Math.min(width > 0 ? aspectRatio / width : Infinity, height > 0 ? 1 / height : Infinity)
35
+ : 0;
36
+ const offsetX = (aspectRatio - (width > 0 ? width * scale : 0)) / 2;
37
+ const offsetY = (1 - (height > 0 ? height * scale : 0)) / 2;
38
+ const map = (values) => {
39
+ for (let index = 0; index + 1 < values.length; index += 2) {
40
+ values[index] = ((values[index] - minX) * scale + offsetX) / aspectRatio;
41
+ values[index + 1] = (values[index + 1] - minY) * scale + offsetY;
42
+ }
43
+ };
44
+ if (minX > maxX) {
45
+ return;
46
+ }
47
+ map(pairs);
48
+ if (extra !== undefined) {
49
+ map(extra);
50
+ }
51
+ }
52
+ //# sourceMappingURL=_fit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_fit.js","sourceRoot":"","sources":["../../src/layout/_fit.ts"],"names":[],"mappings":"AAEA,iCAAiC;AACjC,MAAM,UAAU,cAAc,CAAC,OAA2B;IACzD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;IAC7C,IAAI,CAAC,CAAC,WAAW,GAAG,CAAC,IAAI,WAAW,GAAG,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,UAAU,CAAC,sCAAsC,WAAW,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,WAAW,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACxB,KAAmB,EACnB,WAAmB,EACnB,KAAoB;IAEpB,IAAI,IAAI,GAAG,QAAQ,CAAC;IACpB,IAAI,IAAI,GAAG,QAAQ,CAAC;IACpB,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC;IACrB,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC;IACrB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC1D,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;QACxB,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG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AC3D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAE,GAAG,IAAI,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC,GAAG,WAAW,CAAC;YAC1E,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAE,GAAG,IAAI,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC;QACnE,CAAC;IACF,CAAC,CAAC;IACF,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;QACjB,OAAO;IACR,CAAC;IACD,GAAG,CAAC,KAAK,CAAC,CAAC;IACX,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,GAAG,CAAC,KAAK,CAAC,CAAC;IACZ,CAAC;AACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./layout-hierarchy.js";
2
+ export * from "./layout-network.js";
3
+ export * from "./options.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./layout-hierarchy.js";
2
+ export * from "./layout-network.js";
3
+ export * from "./options.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type HierarchyBoxLayout, type HierarchyPointLayout } from "@ac-kit/math-graph";
2
+ import type { ResolvedPanel } from "../resolve/view-types.js";
3
+ import type { ChartLayoutOptions } from "./options.js";
4
+ /**
5
+ * A laid-out hierarchy: a node-link layout (`tidy`, `cluster`: `positions`, 2
6
+ * per node) or a space-filling one (`squarify`, `partition`: `boxes`, 4 per
7
+ * node, and summed `values`). Rows are in pre-order; `nodes[i]` is the tree row
8
+ * (of the panel's tree layer) of row i. Coordinates are in the unit square of
9
+ * the plot (x across, y down with depth); in a radial hierarchy x is the
10
+ * fraction of the turn and y of the radius.
11
+ */
12
+ export type ChartHierarchyLayout = {
13
+ readonly kind: "point";
14
+ readonly layout: HierarchyPointLayout<number>;
15
+ } | {
16
+ readonly kind: "box";
17
+ readonly layout: HierarchyBoxLayout<number>;
18
+ };
19
+ /**
20
+ * Lays out a hierarchy panel with the math-graph layout its coordinate system
21
+ * names: `tidy` → `tidyTreeLayout`, `cluster` → `dendrogramLayout`, `squarify`
22
+ * → `treemapLayout` (squarified), `partition` → `partitionLayout`. The
23
+ * space-filling layouts weigh each node by its tree row's `size` (missing or
24
+ * negative counts as 0; without `size`, 1 per leaf) and use the panel's padding
25
+ * as a fraction of the height. A plot `aspectRatio` wide and 1 high is laid
26
+ * out, then divided by its width; a radial tree is laid out over a unit turn
27
+ * with the separation divided by depth.
28
+ *
29
+ * Complexity: that of the math-graph layout, O(n) or O(n log n).
30
+ *
31
+ * @throws {RangeError} A panel that is not a hierarchy, a bad `aspectRatio`, or
32
+ * what the layout throws; what `budget` throws propagates.
33
+ */
34
+ export declare function layoutHierarchy(panel: ResolvedPanel, options?: ChartLayoutOptions): ChartHierarchyLayout;
35
+ //# sourceMappingURL=layout-hierarchy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-hierarchy.d.ts","sourceRoot":"","sources":["../../src/layout/layout-hierarchy.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAIzB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAEX,aAAa,EACb,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAC7B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAA;CAAE,GACzE;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAqBzE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,kBAAuB,GAC9B,oBAAoB,CA4EtB"}
@@ -0,0 +1,98 @@
1
+ import { groupIndices } from "@ac-kit/algo";
2
+ import { dendrogramLayout, partitionLayout, tidyTreeLayout, treemapLayout, } from "@ac-kit/math-graph";
3
+ import { columnToFloat64Array } from "@ac-kit/model-dataset";
4
+ import { aspectRatioOf_ } from "./_fit.js";
5
+ function hierarchyOf_(panel) {
6
+ if (panel.coord.kind !== "hierarchy") {
7
+ throw new RangeError(`layoutHierarchy lays out a hierarchy panel, not a ${panel.coord.kind} one`);
8
+ }
9
+ return panel.coord;
10
+ }
11
+ // Children per tree row in row order, as compressed sparse rows.
12
+ function childrenOf_(parentRows) {
13
+ const { offsets, indices } = groupIndices(parentRows, (parent) => parent, parentRows.length);
14
+ return (node) => indices.subarray(offsets[node], offsets[node + 1]);
15
+ }
16
+ /**
17
+ * Lays out a hierarchy panel with the math-graph layout its coordinate system
18
+ * names: `tidy` → `tidyTreeLayout`, `cluster` → `dendrogramLayout`, `squarify`
19
+ * → `treemapLayout` (squarified), `partition` → `partitionLayout`. The
20
+ * space-filling layouts weigh each node by its tree row's `size` (missing or
21
+ * negative counts as 0; without `size`, 1 per leaf) and use the panel's padding
22
+ * as a fraction of the height. A plot `aspectRatio` wide and 1 high is laid
23
+ * out, then divided by its width; a radial tree is laid out over a unit turn
24
+ * with the separation divided by depth.
25
+ *
26
+ * Complexity: that of the math-graph layout, O(n) or O(n log n).
27
+ *
28
+ * @throws {RangeError} A panel that is not a hierarchy, a bad `aspectRatio`, or
29
+ * what the layout throws; what `budget` throws propagates.
30
+ */
31
+ export function layoutHierarchy(panel, options = {}) {
32
+ const coord = hierarchyOf_(panel);
33
+ const aspectRatio = aspectRatioOf_(options);
34
+ const width = coord.radial ? 1 : aspectRatio;
35
+ const childrenOf = childrenOf_(coord.parentRows);
36
+ const layer = panel.layers[coord.treeLayer];
37
+ const size = layer.channels.get("size");
38
+ const sizes = size?.kind === "field"
39
+ ? columnToFloat64Array(new Float64Array(size.column.length), size.column)
40
+ : undefined;
41
+ const leafCount = (node) => (childrenOf(node).length === 0 ? 1 : 0);
42
+ const ownValueOf = (node) => {
43
+ if (sizes === undefined) {
44
+ return leafCount(node);
45
+ }
46
+ const value = sizes[node];
47
+ return value > 0 && value - value === 0 ? value : 0;
48
+ };
49
+ const budget = options.budget;
50
+ switch (coord.layout) {
51
+ case "tidy":
52
+ case "cluster": {
53
+ const traits = {
54
+ childrenOf,
55
+ ...(coord.radial
56
+ ? {
57
+ separationOf: (a, b, table) => (table.parentIndices[a] === table.parentIndices[b] ? 1 : 2) /
58
+ Math.max(1, table.depths[a]),
59
+ }
60
+ : {}),
61
+ };
62
+ const layout = coord.layout === "tidy"
63
+ ? tidyTreeLayout(coord.root, traits, { width, height: 1, budget })
64
+ : dendrogramLayout(coord.root, traits, { width, height: 1, budget });
65
+ const positions = layout.positions.slice();
66
+ for (let index = 0; index < positions.length; index += 2) {
67
+ positions[index] = positions[index] / width;
68
+ }
69
+ return { kind: "point", layout: { ...layout, positions } };
70
+ }
71
+ case "squarify":
72
+ case "partition": {
73
+ const traits = { childrenOf, ownValueOf };
74
+ const layout = coord.layout === "squarify"
75
+ ? treemapLayout(coord.root, traits, {
76
+ width,
77
+ height: 1,
78
+ tiling: "squarify",
79
+ paddingInner: coord.padding,
80
+ budget,
81
+ })
82
+ : partitionLayout(coord.root, traits, {
83
+ width,
84
+ height: 1,
85
+ padding: coord.padding,
86
+ budget,
87
+ });
88
+ const boxes = layout.boxes.slice();
89
+ for (let index = 0; index < boxes.length; index += 2) {
90
+ boxes[index] = boxes[index] / width;
91
+ }
92
+ return { kind: "box", layout: { ...layout, boxes } };
93
+ }
94
+ case "pack":
95
+ throw new RangeError("layoutHierarchy can't lay out pack (resolveView declines it)");
96
+ }
97
+ }
98
+ //# sourceMappingURL=layout-hierarchy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-hierarchy.js","sourceRoot":"","sources":["../../src/layout/layout-hierarchy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACN,gBAAgB,EAGhB,eAAe,EACf,cAAc,EACd,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAM7D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAe3C,SAAS,YAAY,CAAC,KAAoB;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CACnB,qDAAqD,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAC3E,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC;AACpB,CAAC;AAED,iEAAiE;AACjE,SAAS,WAAW,CAAC,UAAsB;IAC1C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,YAAY,CACxC,UAAU,EACV,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAClB,UAAU,CAAC,MAAM,CACjB,CAAC;IACF,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;;;;GAcG;A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QAC5D,CAAC;QACD,KAAK,UAAU,CAAC;QAChB,KAAK,WAAW,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;YAC1C,MAAM,MAAM,GACX,KAAK,CAAC,MAAM,KAAK,UAAU;gBAC1B,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE;oBAClC,KAAK;oBACL,MAAM,EAAE,CAAC;oBACT,MAAM,EAAE,UAAU;oBAClB,YAAY,EAAE,KAAK,CAAC,OAAO;oBAC3B,MAAM;iBACN,CAAC;gBACH,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE;oBACpC,KAAK;oBACL,MAAM,EAAE,CAAC;oBACT,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,MAAM;iBACN,CAAC,CAAC;YACN,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;gBACtD,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAE,GAAG,KAAK,CAAC;YACtC,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,CAAC;QACD,KAAK,MAAM;YACV,MAAM,IAAI,UAAU,CACnB,8DAA8D,CAC9D,CAAC;IACJ,CAAC;AACF,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { AsyncLayoutOptions, SankeyLayout } from "@ac-kit/math-graph";
2
+ import type { ResolvedPanel } from "../resolve/view-types.js";
3
+ import type { ChartLayoutOptions } from "./options.js";
4
+ /**
5
+ * A laid-out network, in the unit square of the plot (x across, y down).
6
+ * `routes` are a layered layout's link polylines (link i is vertices
7
+ * `[starts[i], starts[i + 1])` of `points`, 2 numbers each), from the source
8
+ * box through each bend to the target; `flow` is a flow layout's bands, its x
9
+ * coordinates divided by the width like the rest.
10
+ */
11
+ export type ChartNetworkLayout = {
12
+ /** 2 per node, in `nodeKeys` order. */
13
+ readonly positions: Float64Array;
14
+ readonly routes: {
15
+ readonly points: Float64Array;
16
+ readonly starts: Uint32Array;
17
+ } | undefined;
18
+ readonly flow: SankeyLayout | undefined;
19
+ };
20
+ /**
21
+ * Lays out a network panel with the math-graph layout its coordinate system
22
+ * names: `force` → `forceDirectedLayout`, `layered` → `layeredLayout` (with the
23
+ * link routes), `circular` → `circularLayout` (node 0 at the top), `flow` →
24
+ * `sankeyLayout` (link value = the link row's `size`, 1 without it; node
25
+ * centres as positions), `arc` → nodes evenly on y = ½ in node order. Links
26
+ * come from the panel's `link` layers; one with a missing endpoint is left out.
27
+ * Force and layered positions are fitted uniformly into a plot `aspectRatio`
28
+ * wide and 1 high, centred, then divided by its width; the others are laid out
29
+ * in it.
30
+ *
31
+ * Complexity: that of the math-graph layout (force: O(iterations · (n log n +
32
+ * m))).
33
+ *
34
+ * @throws {RangeError} A panel that is not a network, a bad option, or what the
35
+ * layout throws; what `budget` throws propagates.
36
+ */
37
+ export declare function layoutNetwork(panel: ResolvedPanel, options?: ChartLayoutOptions): ChartNetworkLayout;
38
+ /**
39
+ * {@link layoutNetwork} in time slices: the force, layered and flow layouts
40
+ * yield to the event loop between their steps (math-graph's `…Async` twins);
41
+ * the result equals the sync form's. Rejects with `signal.reason` once aborted,
42
+ * before any work when it already is.
43
+ */
44
+ export declare function layoutNetworkAsync(panel: ResolvedPanel, options?: ChartLayoutOptions & AsyncLayoutOptions): Promise<ChartNetworkLayout>;
45
+ //# sourceMappingURL=layout-network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-network.d.ts","sourceRoot":"","sources":["../../src/layout/layout-network.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAY3E,OAAO,KAAK,EAEX,aAAa,EACb,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,uCAAuC;IACvC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,MAAM,EACZ;QAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;KAAE,GAC/D,SAAS,CAAC;IACb,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;CACxC,CAAC;AAyKF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,kBAAuB,GAC9B,kBAAkB,CAyCpB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACvC,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,kBAAkB,GAAG,kBAAuB,GACnD,OAAO,CAAC,kBAAkB,CAAC,CA2C7B"}
@@ -0,0 +1,197 @@
1
+ import { circularLayout, forceDirectedLayout, forceDirectedLayoutAsync, layeredLayout, layeredLayoutAsync, sankeyLayout, sankeyLayoutAsync, } from "@ac-kit/math-graph";
2
+ import { columnToFloat64Array } from "@ac-kit/model-dataset";
3
+ import { aspectRatioOf_, fitPairs_ } from "./_fit.js";
4
+ const DEFAULT_FLOW_FRACTION_ = 0.02;
5
+ function networkOf_(panel) {
6
+ if (panel.coord.kind !== "network") {
7
+ throw new RangeError(`layoutNetwork lays out a network panel, not a ${panel.coord.kind} one`);
8
+ }
9
+ return panel.coord;
10
+ }
11
+ // Every complete link of the panel's link layers, in layer then row order.
12
+ function linksOf_(panel, coord) {
13
+ const ends = [];
14
+ const values = [];
15
+ for (const [index, layer] of panel.layers.entries()) {
16
+ const pairs = coord.layerNodes[index];
17
+ if (layer.spec.mark !== "link" || pairs === undefined) {
18
+ continue;
19
+ }
20
+ const size = layer.channels.get("size");
21
+ const sizes = size?.kind === "field"
22
+ ? columnToFloat64Array(new Float64Array(size.column.length), size.column)
23
+ : undefined;
24
+ for (let row = 0; 2 * row < pairs.length; row++) {
25
+ const source = pairs[2 * row];
26
+ const target = pairs[2 * row + 1];
27
+ if (source < 0 || target < 0) {
28
+ continue;
29
+ }
30
+ ends.push(source, target);
31
+ const value = sizes?.[row] ?? 1;
32
+ values.push(value > 0 && value - value === 0 ? value : 0);
33
+ }
34
+ }
35
+ return {
36
+ nodeCount: coord.nodeKeys.length,
37
+ ends: Int32Array.from(ends),
38
+ values: Float64Array.from(values),
39
+ };
40
+ }
41
+ function linkIndices_(links) {
42
+ return Array.from({ length: links.ends.length / 2 }, (_, index) => index);
43
+ }
44
+ function nodeIndices_(links) {
45
+ return Array.from({ length: links.nodeCount }, (_, index) => index);
46
+ }
47
+ function traits_(links) {
48
+ return {
49
+ sourceOf: (link) => links.ends[2 * link],
50
+ targetOf: (link) => links.ends[2 * link + 1],
51
+ };
52
+ }
53
+ function forceOptions_(options) {
54
+ if (options.force === undefined) {
55
+ throw new RangeError("A force layout needs options.force.random, a random generator");
56
+ }
57
+ return { ...options.force, budget: options.budget };
58
+ }
59
+ function flowOptions_(options, aspectRatio) {
60
+ const nodeWidth = options.flow?.nodeWidth ?? DEFAULT_FLOW_FRACTION_;
61
+ const nodePadding = options.flow?.nodePadding ?? DEFAULT_FLOW_FRACTION_;
62
+ for (const [name, value] of [
63
+ ["flow.nodeWidth", nodeWidth],
64
+ ["flow.nodePadding", nodePadding],
65
+ ]) {
66
+ if (!(value >= 0 && value <= 1)) {
67
+ throw new RangeError(`${name} is a fraction in [0, 1], got ${value}`);
68
+ }
69
+ }
70
+ return {
71
+ width: aspectRatio,
72
+ height: 1,
73
+ nodeWidth: nodeWidth * aspectRatio,
74
+ nodePadding,
75
+ budget: options.budget,
76
+ };
77
+ }
78
+ function fromFlow_(flow, aspectRatio) {
79
+ const nodeBoxes = flow.nodeBoxes.slice();
80
+ const positions = new Float64Array((nodeBoxes.length / 4) * 2);
81
+ for (let node = 0; 4 * node < nodeBoxes.length; node++) {
82
+ nodeBoxes[4 * node] = nodeBoxes[4 * node] / aspectRatio;
83
+ nodeBoxes[4 * node + 2] = nodeBoxes[4 * node + 2] / aspectRatio;
84
+ positions[2 * node] = (nodeBoxes[4 * node] + nodeBoxes[4 * node + 2]) / 2;
85
+ positions[2 * node + 1] =
86
+ (nodeBoxes[4 * node + 1] + nodeBoxes[4 * node + 3]) / 2;
87
+ }
88
+ const linkEnds = flow.linkEnds.slice();
89
+ for (let index = 0; index < linkEnds.length; index += 2) {
90
+ linkEnds[index] = linkEnds[index] / aspectRatio;
91
+ }
92
+ return {
93
+ positions,
94
+ routes: undefined,
95
+ flow: { ...flow, nodeBoxes, linkEnds },
96
+ };
97
+ }
98
+ function fromPositions_(positions, aspectRatio, routes) {
99
+ const fitted = positions.slice();
100
+ const points = routes?.points.slice();
101
+ fitPairs_(fitted, aspectRatio, points);
102
+ return {
103
+ positions: fitted,
104
+ routes: routes === undefined
105
+ ? undefined
106
+ : { points: points, starts: routes.starts },
107
+ flow: undefined,
108
+ };
109
+ }
110
+ // Nodes on a circle (top first, clockwise) or on the line y = ½.
111
+ function placed_(layout, count, aspectRatio) {
112
+ if (layout === "arc") {
113
+ return {
114
+ positions: Float64Array.from({ length: 2 * count }, (_, index) => index % 2 === 0 ? (Math.floor(index / 2) + 0.5) / count : 0.5),
115
+ routes: undefined,
116
+ flow: undefined,
117
+ };
118
+ }
119
+ const radius = Math.min(aspectRatio, 1) / 2;
120
+ const positions = circularLayout(count, {
121
+ centerX: aspectRatio / 2,
122
+ centerY: 0.5,
123
+ radius,
124
+ });
125
+ for (let index = 0; index < positions.length; index += 2) {
126
+ positions[index] = positions[index] / aspectRatio;
127
+ }
128
+ return { positions, routes: undefined, flow: undefined };
129
+ }
130
+ /**
131
+ * Lays out a network panel with the math-graph layout its coordinate system
132
+ * names: `force` → `forceDirectedLayout`, `layered` → `layeredLayout` (with the
133
+ * link routes), `circular` → `circularLayout` (node 0 at the top), `flow` →
134
+ * `sankeyLayout` (link value = the link row's `size`, 1 without it; node
135
+ * centres as positions), `arc` → nodes evenly on y = ½ in node order. Links
136
+ * come from the panel's `link` layers; one with a missing endpoint is left out.
137
+ * Force and layered positions are fitted uniformly into a plot `aspectRatio`
138
+ * wide and 1 high, centred, then divided by its width; the others are laid out
139
+ * in it.
140
+ *
141
+ * Complexity: that of the math-graph layout (force: O(iterations · (n log n +
142
+ * m))).
143
+ *
144
+ * @throws {RangeError} A panel that is not a network, a bad option, or what the
145
+ * layout throws; what `budget` throws propagates.
146
+ */
147
+ export function layoutNetwork(panel, options = {}) {
148
+ const coord = networkOf_(panel);
149
+ const aspectRatio = aspectRatioOf_(options);
150
+ const links = linksOf_(panel, coord);
151
+ switch (coord.layout) {
152
+ case "force":
153
+ return fromPositions_(forceDirectedLayout(nodeIndices_(links), linkIndices_(links), traits_(links), forceOptions_(options)), aspectRatio);
154
+ case "layered": {
155
+ const layout = layeredLayout(nodeIndices_(links), linkIndices_(links), traits_(links), { budget: options.budget });
156
+ return fromPositions_(layout.positions, aspectRatio, {
157
+ points: layout.edgePoints,
158
+ starts: layout.edgeStarts,
159
+ });
160
+ }
161
+ case "flow":
162
+ return fromFlow_(sankeyLayout(nodeIndices_(links), linkIndices_(links), { ...traits_(links), linkValueOf: (link) => links.values[link] }, flowOptions_(options, aspectRatio)), aspectRatio);
163
+ case "circular":
164
+ case "arc":
165
+ return placed_(coord.layout, links.nodeCount, aspectRatio);
166
+ }
167
+ }
168
+ /**
169
+ * {@link layoutNetwork} in time slices: the force, layered and flow layouts
170
+ * yield to the event loop between their steps (math-graph's `…Async` twins);
171
+ * the result equals the sync form's. Rejects with `signal.reason` once aborted,
172
+ * before any work when it already is.
173
+ */
174
+ export async function layoutNetworkAsync(panel, options = {}) {
175
+ const { signal, sliceMs } = options;
176
+ signal?.throwIfAborted();
177
+ const coord = networkOf_(panel);
178
+ const aspectRatio = aspectRatioOf_(options);
179
+ const links = linksOf_(panel, coord);
180
+ switch (coord.layout) {
181
+ case "force":
182
+ return fromPositions_(await forceDirectedLayoutAsync(nodeIndices_(links), linkIndices_(links), traits_(links), { ...forceOptions_(options), signal, sliceMs }), aspectRatio);
183
+ case "layered": {
184
+ const layout = await layeredLayoutAsync(nodeIndices_(links), linkIndices_(links), traits_(links), { budget: options.budget, signal, sliceMs });
185
+ return fromPositions_(layout.positions, aspectRatio, {
186
+ points: layout.edgePoints,
187
+ starts: layout.edgeStarts,
188
+ });
189
+ }
190
+ case "flow":
191
+ return fromFlow_(await sankeyLayoutAsync(nodeIndices_(links), linkIndices_(links), { ...traits_(links), linkValueOf: (link) => links.values[link] }, { ...flowOptions_(options, aspectRatio), signal, sliceMs }), aspectRatio);
192
+ case "circular":
193
+ case "arc":
194
+ return placed_(coord.layout, links.nodeCount, aspectRatio);
195
+ }
196
+ }
197
+ //# sourceMappingURL=layout-network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-network.js","sourceRoot":"","sources":["../../src/layout/layout-network.ts"],"names":[],"mappings":"AACA,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAM7D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAmBtD,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAUpC,SAAS,UAAU,CAAC,KAAoB;IACvC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,UAAU,CACnB,iDAAiD,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CACvE,CAAC;IACH,C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AM,CAAC,IAAI,CAAE,EAAE,EACjE,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAC1D,EACD,WAAW,CACX,CAAC;QACH,KAAK,UAAU,CAAC;QAChB,KAAK,KAAK;YACT,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC7D,CAAC;AACF,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { WorkBudget } from "@ac-kit/core";
2
+ import type { ForceDirectedLayoutOptions } from "@ac-kit/math-graph";
3
+ /** What a renderer knows that a layout depends on. */
4
+ export type ChartLayoutOptions = {
5
+ /**
6
+ * Plot width over height; default 1, finite and > 0. Squarify, partition,
7
+ * force, layered, circular and flow layouts depend on it.
8
+ */
9
+ readonly aspectRatio?: number;
10
+ /**
11
+ * Flow (Sankey) node width as a fraction of the plot's width (default 0.02),
12
+ * and the gap between the nodes of a column as a fraction of its height
13
+ * (default 0.02).
14
+ */
15
+ readonly flow?: {
16
+ readonly nodeWidth?: number;
17
+ readonly nodePadding?: number;
18
+ };
19
+ /**
20
+ * Force layout knobs. `random` is required by a force layout (math-graph's
21
+ * jitter of coincident nodes; pass a seeded generator for a reproducible
22
+ * layout); `initialPositions` and `fixedPositions` are 2 per node, in
23
+ * math-graph's force units (a previous result's raw positions).
24
+ */
25
+ readonly force?: Pick<ForceDirectedLayoutOptions, "random" | "iterations" | "initialPositions" | "fixedPositions">;
26
+ /** Charged as the math-graph layout charges it; what it throws propagates. */
27
+ readonly budget?: WorkBudget;
28
+ };
29
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/layout/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAErE,sDAAsD;AACtD,MAAM,MAAM,kBAAkB,GAAG;IAChC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE;QACf,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CACpB,0BAA0B,EAC1B,QAAQ,GAAG,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,CAC/D,CAAC;IACF,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;CAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/layout/options.ts"],"names":[],"mappings":""}
@@ -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,IAAI,CAAC,QAAQ,CAAC;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;IAClC,OAAO;QACN,GAAG,IAA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