@macrostrat/column-views 3.11.0 → 3.12.1

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 (138) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/dist/age-axis.cjs +1 -2
  3. package/dist/age-axis.cjs.map +1 -1
  4. package/dist/age-axis.js +1 -2
  5. package/dist/age-axis.js.map +1 -1
  6. package/dist/age-model/data.cjs +57 -0
  7. package/dist/age-model/data.cjs.map +1 -0
  8. package/dist/age-model/data.d.ts +29 -0
  9. package/dist/age-model/data.js +57 -0
  10. package/dist/age-model/data.js.map +1 -0
  11. package/dist/age-model/details.cjs +260 -0
  12. package/dist/age-model/details.cjs.map +1 -0
  13. package/dist/age-model/details.d.ts +39 -0
  14. package/dist/age-model/details.js +257 -0
  15. package/dist/age-model/details.js.map +1 -0
  16. package/dist/age-model/details.module.sass.cjs +42 -0
  17. package/dist/age-model/details.module.sass.cjs.map +1 -0
  18. package/dist/age-model/details.module.sass.js +40 -0
  19. package/dist/age-model/details.module.sass.js.map +1 -0
  20. package/dist/age-model/index.d.ts +5 -0
  21. package/dist/age-model/legacy.cjs +28 -0
  22. package/dist/age-model/legacy.cjs.map +1 -0
  23. package/dist/age-model/legacy.d.ts +6 -0
  24. package/dist/age-model/legacy.js +26 -0
  25. package/dist/age-model/legacy.js.map +1 -0
  26. package/dist/age-model/surfaces.cjs +354 -0
  27. package/dist/age-model/surfaces.cjs.map +1 -0
  28. package/dist/age-model/surfaces.d.ts +68 -0
  29. package/dist/age-model/surfaces.js +351 -0
  30. package/dist/age-model/surfaces.js.map +1 -0
  31. package/dist/age-model/surfaces.module.sass.cjs +45 -0
  32. package/dist/age-model/surfaces.module.sass.cjs.map +1 -0
  33. package/dist/age-model/surfaces.module.sass.js +43 -0
  34. package/dist/age-model/surfaces.module.sass.js.map +1 -0
  35. package/dist/age-model/types.cjs +229 -0
  36. package/dist/age-model/types.cjs.map +1 -0
  37. package/dist/age-model/types.d.ts +112 -0
  38. package/dist/age-model/types.js +229 -0
  39. package/dist/age-model/types.js.map +1 -0
  40. package/dist/column-views.css +406 -74
  41. package/dist/column.cjs +20 -13
  42. package/dist/column.cjs.map +1 -1
  43. package/dist/column.d.ts +21 -6
  44. package/dist/column.js +21 -14
  45. package/dist/column.js.map +1 -1
  46. package/dist/column.module.sass.cjs +19 -15
  47. package/dist/column.module.sass.cjs.map +1 -1
  48. package/dist/column.module.sass.js +19 -15
  49. package/dist/column.module.sass.js.map +1 -1
  50. package/dist/data-provider/store.cjs +34 -1
  51. package/dist/data-provider/store.cjs.map +1 -1
  52. package/dist/data-provider/store.d.ts +5 -0
  53. package/dist/data-provider/store.js +35 -2
  54. package/dist/data-provider/store.js.map +1 -1
  55. package/dist/index.cjs +78 -18
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.ts +3 -1
  58. package/dist/index.js +55 -4
  59. package/dist/index.js.map +1 -1
  60. package/dist/notes.cjs +11 -2
  61. package/dist/notes.cjs.map +1 -1
  62. package/dist/notes.d.ts +11 -1
  63. package/dist/notes.js +11 -2
  64. package/dist/notes.js.map +1 -1
  65. package/dist/prepare-units/composite-scale.cjs +18 -16
  66. package/dist/prepare-units/composite-scale.cjs.map +1 -1
  67. package/dist/prepare-units/composite-scale.js +18 -16
  68. package/dist/prepare-units/composite-scale.js.map +1 -1
  69. package/dist/prepare-units/density.cjs +83 -0
  70. package/dist/prepare-units/density.cjs.map +1 -0
  71. package/dist/prepare-units/density.d.ts +92 -0
  72. package/dist/prepare-units/density.js +83 -0
  73. package/dist/prepare-units/density.js.map +1 -0
  74. package/dist/prepare-units/index.cjs +15 -7
  75. package/dist/prepare-units/index.cjs.map +1 -1
  76. package/dist/prepare-units/index.d.ts +1 -0
  77. package/dist/prepare-units/index.js +15 -7
  78. package/dist/prepare-units/index.js.map +1 -1
  79. package/dist/prepare-units/types.cjs.map +1 -1
  80. package/dist/prepare-units/types.d.ts +34 -13
  81. package/dist/prepare-units/types.js.map +1 -1
  82. package/dist/section.cjs +108 -24
  83. package/dist/section.cjs.map +1 -1
  84. package/dist/section.d.ts +66 -6
  85. package/dist/section.js +109 -25
  86. package/dist/section.js.map +1 -1
  87. package/dist/timescale-zoom.cjs +191 -0
  88. package/dist/timescale-zoom.cjs.map +1 -0
  89. package/dist/timescale-zoom.d.ts +74 -0
  90. package/dist/timescale-zoom.js +191 -0
  91. package/dist/timescale-zoom.js.map +1 -0
  92. package/dist/unit-details/age-range.cjs +14 -43
  93. package/dist/unit-details/age-range.cjs.map +1 -1
  94. package/dist/unit-details/age-range.d.ts +1 -13
  95. package/dist/unit-details/age-range.js +6 -43
  96. package/dist/unit-details/age-range.js.map +1 -1
  97. package/dist/unit-details/utils.cjs +0 -5
  98. package/dist/unit-details/utils.cjs.map +1 -1
  99. package/dist/unit-details/utils.js +0 -5
  100. package/dist/unit-details/utils.js.map +1 -1
  101. package/dist/units/composite.cjs +4 -1
  102. package/dist/units/composite.cjs.map +1 -1
  103. package/dist/units/composite.d.ts +2 -0
  104. package/dist/units/composite.js +4 -1
  105. package/dist/units/composite.js.map +1 -1
  106. package/package.json +8 -8
  107. package/src/age-model/data.ts +98 -0
  108. package/src/age-model/details.module.sass +108 -0
  109. package/src/age-model/details.ts +333 -0
  110. package/src/age-model/index.ts +5 -0
  111. package/src/age-model/legacy.ts +30 -0
  112. package/src/age-model/surfaces.module.sass +168 -0
  113. package/src/age-model/surfaces.ts +568 -0
  114. package/src/age-model/types.ts +392 -0
  115. package/src/column.module.sass +59 -8
  116. package/src/column.ts +49 -23
  117. package/src/data-provider/store.ts +50 -1
  118. package/src/index.ts +5 -1
  119. package/src/notes.ts +20 -2
  120. package/src/prepare-units/composite-scale.ts +34 -31
  121. package/src/prepare-units/density.ts +197 -0
  122. package/src/prepare-units/index.ts +25 -6
  123. package/src/prepare-units/types.ts +34 -13
  124. package/src/section.ts +219 -33
  125. package/src/timescale-zoom.ts +341 -0
  126. package/src/unit-details/age-range.ts +12 -58
  127. package/src/units/composite.ts +11 -0
  128. package/dist/age-model-overlay.cjs +0 -50
  129. package/dist/age-model-overlay.cjs.map +0 -1
  130. package/dist/age-model-overlay.d.ts +0 -24
  131. package/dist/age-model-overlay.js +0 -48
  132. package/dist/age-model-overlay.js.map +0 -1
  133. package/dist/age-model-overlay.module.sass.cjs +0 -12
  134. package/dist/age-model-overlay.module.sass.cjs.map +0 -1
  135. package/dist/age-model-overlay.module.sass.js +0 -11
  136. package/dist/age-model-overlay.module.sass.js.map +0 -1
  137. package/src/age-model-overlay.module.sass +0 -11
  138. package/src/age-model-overlay.ts +0 -96
package/CHANGELOG.md CHANGED
@@ -1,5 +1,189 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.12.1] - 2026-09-25 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/column-views-v3.12.0...@macrostrat/column-views-v3.12.1)
4
+
5
+ ### Patch Changes
6
+
7
+ - - `Proportion`, `AgeLabel` and `getAge` are re-exported from
8
+ `@macrostrat/data-components`; surface calibration tags use `IntervalTag`'s
9
+ `proportion`
10
+ [5be3d4c9](https://github.com/UW-Macrostrat/web-components/commit/5be3d4c9f3fcf4442720a7ed3bdb72abca4db4ab)
11
+ - Updated dependencies
12
+ [5be3d4c9](https://github.com/UW-Macrostrat/web-components/commit/5be3d4c9f3fcf4442720a7ed3bdb72abca4db4ab)
13
+ - Updated dependencies
14
+ [dc1feb79](https://github.com/UW-Macrostrat/web-components/commit/dc1feb7961e6f901fe6a3dbb2d3f3bdba03cc32c)
15
+ - @macrostrat/data-provider@1.4.0
16
+ - @macrostrat/data-components@1.7.0
17
+
18
+ ## [3.12.0] - 2026-09-21 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/column-views-v3.11.0...@macrostrat/column-views-v3.12.0)
19
+
20
+ ### Minor Changes
21
+
22
+ - Reduce the options that set how tall a column draws to the few that say
23
+ [0614432f](https://github.com/UW-Macrostrat/web-components/commit/0614432fe94bfd2c222375b9add8f7ac100e33c3)
24
+ different things. They all resolve to one quantity — density, the pixels given
25
+ to one unit of the axis.
26
+
27
+ `targetUnitHeight` is the usual knob: room for a typical unit, now the
28
+ geometric mean of the visible units' extents rather than their arithmetic
29
+ mean, which a few long units skew far above anything on screen.
30
+ `minSectionHeight` and `minPixelScale` floor it for legibility. `pixelScale`
31
+ is the alternative: a density stated outright, which is then the density — the
32
+ floors no longer apply to it, since they would undo the scale you stated, and
33
+ `Column` no longer adjusts them behind the scenes. It is quoted in whatever
34
+ the axis measures, so `pixelsPerMyr` and `pixelsPerMeter` spell it per axis,
35
+ the way `t_age` and `t_pos` already do for the window: both can be held at
36
+ once and the axis picks, since useful values for the two differ by orders of
37
+ magnitude. `sectionOptions` decides any of these per section, given what the
38
+ section holds.
39
+
40
+ `heightMultiplier` is gone — asking for more room per unit is the same
41
+ control, and leaves the legibility floors where they belong — as is the
42
+ internal `visibleWindow`, which only restated `t_age`/`b_age`.
43
+
44
+ - Add a surfaces view for a column's age model. `ColumnSurfaces`, dropped into a
45
+ [ea700ff1](https://github.com/UW-Macrostrat/web-components/commit/ea700ff1e7725703d971e3cac440fad0f7540a65)
46
+ `Column` as a child, draws the column's calibration surfaces from the
47
+ `/age_model` route as lines across the units (`ColumnSurfaceLines`) and as a
48
+ collision-avoiding notes column of labels beside them (`ColumnSurfaceLabels`),
49
+ styled by `boundary_status` and `boundary_type`, with hover and selection.
50
+ Labels use the standard `IntervalTag` for the calibration interval (with the
51
+ position within it) over the modeled age, are drawn by default only for the
52
+ tie points where the age model was constrained (absolute, relative, spike,
53
+ imposed — `labelStatuses` widens this), and take the label column over from
54
+ the unit labels while mounted (`useClaimLabelColumn`, a new way for a column's
55
+ children to claim that space). `SurfaceDetailsPanel` inspects a selected
56
+ surface — model age, calibration interval and position within it, the units it
57
+ separates, provenance — and `SurfaceStatusLegend` explains the line styles.
58
+
59
+ The view is data-agnostic: `useColumnAgeModel` fetches boundaries through the
60
+ `MacrostratDataProvider` base URL (the old overlay hardcoded the dev server),
61
+ `surfacesFromBoundaries` maps them to `ColumnSurface` records, and
62
+ `surfacesFromUnits` derives surfaces from unit tops and bottoms as the
63
+ fallback for columns without `unit_boundaries` (or for an editor's own state).
64
+ `BoundaryAgeModelOverlay` and `ComputedSurfacesOverlay` remain as deprecated
65
+ wrappers. `ColumnNotes` gains `onClickNote` and `className` passthroughs.
66
+
67
+ `@macrostrat/api-types` gains `AgeModelBoundary` and the `BoundaryStatus` /
68
+ `BoundaryType` vocabularies, mirroring the database enums.
69
+
70
+ - Draw several timescales beside a column. A new `timescales` prop takes them in
71
+ [1b694ccf](https://github.com/UW-Macrostrat/web-components/commit/1b694ccfcc40321a6edc609b8c07106a87164a3b)
72
+ order, each a Macrostrat timescale ID or a timescale carrying its own
73
+ intervals, levels and label — the international timescale is one of these
74
+ rather than a special case. Clicks and per-interval styles report which
75
+ timescale they came from, so the same interval drawn in two of them can be
76
+ told apart, and `useTimescaleZoom` treats a click in another timescale as
77
+ moving the selection rather than zooming out. Timescales are fetched in one
78
+ place rather than once per section.
79
+ - Suppress unit labels below a pixel height, rather than labeling units too thin
80
+ [0614432f](https://github.com/UW-Macrostrat/web-components/commit/0614432fe94bfd2c222375b9add8f7ac100e33c3)
81
+ to see: `labelSuppressHeight` on `Column`, 2px by default. A gap between
82
+ sections is also labeled in the units of the axis, so a drill core reads
83
+ metres rather than Myr.
84
+ - One selection color across a column: `--column-selection-color` (the accent
85
+ [1b694ccf](https://github.com/UW-Macrostrat/web-components/commit/1b694ccfcc40321a6edc609b8c07106a87164a3b)
86
+ color, purple) drives both the unit selection overlay — now a box with an
87
+ outline and a light wash, rather than a heavy red fill — and the surface
88
+ selection.
89
+
90
+ Surface lines are drawn at a constant weight; status shows in the dash pattern
91
+ and color. A selected surface is outlined as a box, keeping its interval color
92
+ inside, and a selected label bolds its interval tag rather than sitting in a
93
+ card.
94
+
95
+ `useTimescaleZoom`: shift-clicking a timescale interval widens the window to
96
+ take it in, instead of moving the window to it. `selectedIntervals` reports
97
+ everything in the selection; all of them are styled as selected.
98
+
99
+ `CompositeTimescale` takes a `timescaleID` (which timescale the leveled column
100
+ draws) and `additionalTimescales` (further timescales drawn as extra level
101
+ columns beside it, against the same section scales), and is exported. `Column`
102
+ passes `additionalTimescales` through: narrow `timescaleLevels` by as many to
103
+ swap the finest international level for a regional one rather than widen the
104
+ timescale.
105
+
106
+ `heightMultiplier` on `Column` multiplies the heights the layout works out by
107
+ a fixed factor. The scaling approach is unchanged — density still comes from
108
+ `targetUnitHeight` and the section floors — so sections keep their proportions
109
+ and only the size changes; unconformity gaps and `windowPadding`, being chrome
110
+ rather than scale, stay put.
111
+
112
+ - Infer `relative` status for age-model surfaces that cannot have been
113
+ [c17e6379](https://github.com/UW-Macrostrat/web-components/commit/c17e637909bbff76f7bbf4366134b0ba5c5f59ef)
114
+ interpolated: those sitting on the base or top of their calibration interval,
115
+ and the edges of gap-bound packages (the youngest surface in a section with no
116
+ unit above, or the oldest with none below). `boundary_status` records many of
117
+ these as `modeled`, so filtering to the tie-point statuses was hiding real tie
118
+ points. `inferTiePointStatuses` promotes them client-side and marks the result
119
+ `statusInferred`, which `SurfaceStatusTag` shows. On by default;
120
+ `inferTiePoints: false` on `ColumnSurfaces`, `useColumnSurfaces` or
121
+ `surfacesFromBoundaries` takes the data as recorded.
122
+
123
+ Fix surface lines drifting out of alignment with the units column: the overlay
124
+ measured its position once and only re-measured on its own resize, so a
125
+ sibling changing width — the timescale, once its intervals load — left it
126
+ stale.
127
+
128
+ - Color age-model surfaces by the interval they are calibrated against: the
129
+ [acc9f478](https://github.com/UW-Macrostrat/web-components/commit/acc9f4782cbae65bfe017aa195e1b51456871822)
130
+ surface line and its label's leader line both take the interval's color, and
131
+ the lines are drawn a little heavier. The label's endpoint marker is gone —
132
+ the leader now runs into the surface line itself.
133
+
134
+ `SurfaceDetailsPanel` accepts a `null` surface and renders an empty state, so
135
+ a panel bound to a selection doesn't have to be guarded by its caller.
136
+
137
+ - Add `useTimescaleZoom`: click-to-zoom navigation over geologic time, extracted
138
+ [af6d14e1](https://github.com/UW-Macrostrat/web-components/commit/af6d14e1da59af8d09712ed5cb750b1b6bca7cc8)
139
+ from the Interval zoom story. Clicking a timescale interval animates the
140
+ rendered age window to it, clicking the interval you are in zooms back out a
141
+ level, and the timescale's level window slides with the selection so finer
142
+ intervals come into reach as you drill. `columnProps` spreads the window, the
143
+ levels, the click handler and the selected-interval styling onto a `Column`.
144
+ `unitsAgeExtent` derives the full extent from a set of units.
145
+
146
+ ### Patch Changes
147
+
148
+ - Notes columns re-run their force layout once the notes' rendered heights have
149
+ [7252f222](https://github.com/UW-Macrostrat/web-components/commit/7252f22207f63d57ef91172cf898f6b27c38725a)
150
+ been measured. The first layout ran on a 10px guess per note and was never
151
+ revisited, so notes taller than that (interval tags, two-line labels)
152
+ overlapped their neighbors. `ColumnNotes` also passes `forceOptions` through
153
+ to the layout.
154
+ - Treat an unset age or depth bound as unbounded rather than as a real one. A
155
+ [0614432f](https://github.com/UW-Macrostrat/web-components/commit/0614432fe94bfd2c222375b9add8f7ac100e33c3)
156
+ `null` `t_age` is the ordinary way to say "no window" — it is what clearing a
157
+ window leaves behind — and columns laid out with a hybrid scale, which clip
158
+ before laying out, were dropping every unit when they saw one.
159
+ - Judge an unconformity against the finer of the two scales it falls between,
160
+ [aa4fda55](https://github.com/UW-Macrostrat/web-components/commit/aa4fda557137cdb652cb3ddce98d1b5dae8109ef)
161
+ rather than the coarser one. A gap has no density of its own, and taking the
162
+ smaller estimate let a sparse neighbor speak for one the other neighbor would
163
+ have drawn many times larger — a 16 Myr hiatus read as 26px against one
164
+ section and 166px against the other, and collapsed.
165
+ - Updated dependencies
166
+ [ea700ff1](https://github.com/UW-Macrostrat/web-components/commit/ea700ff1e7725703d971e3cac440fad0f7540a65)
167
+ - Updated dependencies
168
+ [1b694ccf](https://github.com/UW-Macrostrat/web-components/commit/1b694ccfcc40321a6edc609b8c07106a87164a3b)
169
+ - Updated dependencies
170
+ [1b694ccf](https://github.com/UW-Macrostrat/web-components/commit/1b694ccfcc40321a6edc609b8c07106a87164a3b)
171
+ - Updated dependencies
172
+ [acc9f478](https://github.com/UW-Macrostrat/web-components/commit/acc9f4782cbae65bfe017aa195e1b51456871822)
173
+ - Updated dependencies
174
+ [aa4fda55](https://github.com/UW-Macrostrat/web-components/commit/aa4fda557137cdb652cb3ddce98d1b5dae8109ef)
175
+ - Updated dependencies
176
+ [af6d14e1](https://github.com/UW-Macrostrat/web-components/commit/af6d14e1da59af8d09712ed5cb750b1b6bca7cc8)
177
+ - Updated dependencies
178
+ [7252f222](https://github.com/UW-Macrostrat/web-components/commit/7252f22207f63d57ef91172cf898f6b27c38725a)
179
+ - Updated dependencies
180
+ [1b694ccf](https://github.com/UW-Macrostrat/web-components/commit/1b694ccfcc40321a6edc609b8c07106a87164a3b)
181
+ - @macrostrat/api-types@1.4.0
182
+ - @macrostrat/data-provider@1.3.1
183
+ - @macrostrat/timescale@3.3.0
184
+ - @macrostrat/column-components@2.2.0
185
+ - @macrostrat/stratigraphy-utils@1.4.2
186
+
3
187
  ## [3.11.0] - 2026-09-04 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/column-views-v3.10.0...@macrostrat/column-views-v3.11.0)
4
188
 
5
189
  ### Minor Changes
package/dist/age-axis.cjs CHANGED
@@ -5,7 +5,6 @@ const columnComponents = require("@macrostrat/column-components");
5
5
  require("react");
6
6
  const ageAxis_module = require("./age-axis.module.sass.cjs");
7
7
  const dataComponents = require("@macrostrat/data-components");
8
- const ageRange = require("./unit-details/age-range.cjs");
9
8
  const store = require("./data-provider/store.cjs");
10
9
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
11
10
  const h__default = /* @__PURE__ */ _interopDefault(h$1);
@@ -114,7 +113,7 @@ function AgeCursor({ age }) {
114
113
  top: heightPx
115
114
  }
116
115
  },
117
- [h("div.line"), h(ageRange.AgeLabel, { age, className: "label" })]
116
+ [h("div.line"), h(dataComponents.AgeLabel, { age, className: "label" })]
118
117
  );
119
118
  }
120
119
  exports.AgeCursor = AgeCursor;
@@ -1 +1 @@
1
- {"version":3,"file":"age-axis.cjs","sources":["../src/age-axis.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n SVG,\n ColumnAxis,\n ColumnContext,\n ColumnAxisType,\n AgeAxis,\n} from \"@macrostrat/column-components\";\nimport { useContext } from \"react\";\nimport styles from \"./age-axis.module.sass\";\nimport { useCompositeScale, useMacrostratColumnData } from \"./data-provider\";\nimport { Parenthetical } from \"@macrostrat/data-components\";\nimport { AgeLabel } from \"./unit-details\";\nimport { PackageScaleLayoutData } from \"./prepare-units\";\n\nconst h = hyper.styled(styles);\n\nconst AgeAxisCore = ({ ticks, tickSpacing = 40, showDomain = false }) => {\n const { pixelHeight } = useContext(ColumnContext);\n // A tick roughly every 40 pixels\n let v = Math.max(Math.round(pixelHeight / tickSpacing), 1);\n\n return h(\"g.axis\", { transform: \"translate(20 0)\" }, [\n h(ColumnAxis, {\n ticks: v,\n showDomain,\n }),\n ]);\n};\n\nexport function VerticalAxisLabel(props) {\n const { label = \"Age\", unit = \"Ma\", className, height } = props;\n return h(\n \"div.column-axis-label.age-axis-label\",\n { className, style: { height } },\n [\n label,\n \" \",\n h.if(unit)(Parenthetical, { className: \"age-axis-unit\" }, unit),\n ],\n );\n}\n\ninterface CompositeAgeAxisProps {\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function CompositeAgeAxis(rest: CompositeAgeAxisProps) {\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n return {\n key: `section-${section.section_id}`,\n ...section.scaleInfo,\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport function ApproximateHeightAxis(rest: CompositeAgeAxisProps) {\n /** Axis to show approximate height based on dynamic column scales */\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n const { scaleInfo } = section;\n if (scaleInfo.heightScale == null) {\n throw new Error(\"No height scale available for section\");\n }\n return {\n key: `section-${section.section_id}`,\n ...scaleInfo,\n scale: scaleInfo.heightScale, // Use height scale instead of age scale\n // This only works with dynamic columns\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n axisLabel: \"Approx. height\",\n axisUnit: \"m\",\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport interface CompositeStratigraphicScaleInfo extends CompositeAgeAxisProps {\n axisType: ColumnAxisType;\n axisLabel?: string;\n axisUnit?: string;\n totalHeight: number;\n packages: PackageScaleLayoutData[];\n}\n\nexport function CompositeAgeAxisCore(props: CompositeStratigraphicScaleInfo) {\n const { axisType, axisLabel, axisUnit, totalHeight, packages, ...rest } =\n props;\n\n if (axisType == ColumnAxisType.ORDINAL) {\n return null;\n }\n\n let _axisLabel: string = axisLabel ?? \"Age\";\n let _axisUnit = axisUnit ?? \"Ma\";\n if (axisType == ColumnAxisType.DEPTH) {\n _axisLabel = \"Depth\";\n _axisUnit = \"m\";\n } else if (axisType == ColumnAxisType.HEIGHT) {\n _axisLabel = \"Height\";\n _axisUnit = \"m\";\n }\n\n return h(\"div.composite-age-axis\", rest, [\n h(VerticalAxisLabel, {\n label: _axisLabel,\n unit: _axisUnit,\n height: totalHeight,\n }),\n h(\n SVG,\n {\n className: \"age-axis-column\",\n style: { width: `22px`, height: `${totalHeight}px` },\n width: 22,\n height: totalHeight,\n },\n packages.map((group, i) => {\n const { key, scale } = group;\n\n return h(AgeAxis, {\n key,\n className: \"age-axis\",\n scale,\n tickSizeOuter: 3,\n });\n }),\n ),\n ]);\n}\n\nexport function AgeCursor({ age }) {\n /** A cursor that shows the age at a specific point on the age axis. */\n const scale = useCompositeScale();\n const heightPx = scale(age);\n\n if (age == null || heightPx == null) {\n return null;\n }\n\n return h(\n \"div.age-cursor\",\n {\n style: {\n top: heightPx,\n },\n },\n [h(\"div.line\"), h(AgeLabel, { age, className: \"label\" })],\n );\n}\n"],"names":["hyper","styles","Parenthetical","useMacrostratCol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EAAA;AAE5D;;;;;;"}
1
+ {"version":3,"file":"age-axis.cjs","sources":["../src/age-axis.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n SVG,\n ColumnAxis,\n ColumnContext,\n ColumnAxisType,\n AgeAxis,\n} from \"@macrostrat/column-components\";\nimport { useContext } from \"react\";\nimport styles from \"./age-axis.module.sass\";\nimport { useCompositeScale, useMacrostratColumnData } from \"./data-provider\";\nimport { Parenthetical } from \"@macrostrat/data-components\";\nimport { AgeLabel } from \"./unit-details\";\nimport { PackageScaleLayoutData } from \"./prepare-units\";\n\nconst h = hyper.styled(styles);\n\nconst AgeAxisCore = ({ ticks, tickSpacing = 40, showDomain = false }) => {\n const { pixelHeight } = useContext(ColumnContext);\n // A tick roughly every 40 pixels\n let v = Math.max(Math.round(pixelHeight / tickSpacing), 1);\n\n return h(\"g.axis\", { transform: \"translate(20 0)\" }, [\n h(ColumnAxis, {\n ticks: v,\n showDomain,\n }),\n ]);\n};\n\nexport function VerticalAxisLabel(props) {\n const { label = \"Age\", unit = \"Ma\", className, height } = props;\n return h(\n \"div.column-axis-label.age-axis-label\",\n { className, style: { height } },\n [\n label,\n \" \",\n h.if(unit)(Parenthetical, { className: \"age-axis-unit\" }, unit),\n ],\n );\n}\n\ninterface CompositeAgeAxisProps {\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function CompositeAgeAxis(rest: CompositeAgeAxisProps) {\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n return {\n key: `section-${section.section_id}`,\n ...section.scaleInfo,\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport function ApproximateHeightAxis(rest: CompositeAgeAxisProps) {\n /** Axis to show approximate height based on dynamic column scales */\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n const { scaleInfo } = section;\n if (scaleInfo.heightScale == null) {\n throw new Error(\"No height scale available for section\");\n }\n return {\n key: `section-${section.section_id}`,\n ...scaleInfo,\n scale: scaleInfo.heightScale, // Use height scale instead of age scale\n // This only works with dynamic columns\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n axisLabel: \"Approx. height\",\n axisUnit: \"m\",\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport interface CompositeStratigraphicScaleInfo extends CompositeAgeAxisProps {\n axisType: ColumnAxisType;\n axisLabel?: string;\n axisUnit?: string;\n totalHeight: number;\n packages: PackageScaleLayoutData[];\n}\n\nexport function CompositeAgeAxisCore(props: CompositeStratigraphicScaleInfo) {\n const { axisType, axisLabel, axisUnit, totalHeight, packages, ...rest } =\n props;\n\n if (axisType == ColumnAxisType.ORDINAL) {\n return null;\n }\n\n let _axisLabel: string = axisLabel ?? \"Age\";\n let _axisUnit = axisUnit ?? \"Ma\";\n if (axisType == ColumnAxisType.DEPTH) {\n _axisLabel = \"Depth\";\n _axisUnit = \"m\";\n } else if (axisType == ColumnAxisType.HEIGHT) {\n _axisLabel = \"Height\";\n _axisUnit = \"m\";\n }\n\n return h(\"div.composite-age-axis\", rest, [\n h(VerticalAxisLabel, {\n label: _axisLabel,\n unit: _axisUnit,\n height: totalHeight,\n }),\n h(\n SVG,\n {\n className: \"age-axis-column\",\n style: { width: `22px`, height: `${totalHeight}px` },\n width: 22,\n height: totalHeight,\n },\n packages.map((group, i) => {\n const { key, scale } = group;\n\n return h(AgeAxis, {\n key,\n className: \"age-axis\",\n scale,\n tickSizeOuter: 3,\n });\n }),\n ),\n ]);\n}\n\nexport function AgeCursor({ age }) {\n /** A cursor that shows the age at a specific point on the age axis. */\n const scale = useCompositeScale();\n const heightPx = scale(age);\n\n if (age == null || heightPx == null) {\n return null;\n }\n\n return h(\n \"div.age-cursor\",\n {\n style: {\n top: heightPx,\n },\n },\n [h(\"div.line\"), h(AgeLabel, { age, className: \"label\" })],\n );\n}\n"],"names":["hyper","styles","Parenthetical","useMacrostratColumnData","ColumnAxisType","SVG","Ag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/dist/age-axis.js CHANGED
@@ -2,8 +2,7 @@ import h$1 from "@macrostrat/hyper";
2
2
  import { ColumnAxisType, SVG, AgeAxis } from "@macrostrat/column-components";
3
3
  import "react";
4
4
  import h$2 from "./age-axis.module.sass.js";
5
- import { Parenthetical } from "@macrostrat/data-components";
6
- import { AgeLabel } from "./unit-details/age-range.js";
5
+ import { AgeLabel, Parenthetical } from "@macrostrat/data-components";
7
6
  import { useCompositeScale, useMacrostratColumnData } from "./data-provider/store.js";
8
7
  const h = h$1.styled(h$2);
9
8
  function VerticalAxisLabel(props) {
@@ -1 +1 @@
1
- {"version":3,"file":"age-axis.js","sources":["../src/age-axis.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n SVG,\n ColumnAxis,\n ColumnContext,\n ColumnAxisType,\n AgeAxis,\n} from \"@macrostrat/column-components\";\nimport { useContext } from \"react\";\nimport styles from \"./age-axis.module.sass\";\nimport { useCompositeScale, useMacrostratColumnData } from \"./data-provider\";\nimport { Parenthetical } from \"@macrostrat/data-components\";\nimport { AgeLabel } from \"./unit-details\";\nimport { PackageScaleLayoutData } from \"./prepare-units\";\n\nconst h = hyper.styled(styles);\n\nconst AgeAxisCore = ({ ticks, tickSpacing = 40, showDomain = false }) => {\n const { pixelHeight } = useContext(ColumnContext);\n // A tick roughly every 40 pixels\n let v = Math.max(Math.round(pixelHeight / tickSpacing), 1);\n\n return h(\"g.axis\", { transform: \"translate(20 0)\" }, [\n h(ColumnAxis, {\n ticks: v,\n showDomain,\n }),\n ]);\n};\n\nexport function VerticalAxisLabel(props) {\n const { label = \"Age\", unit = \"Ma\", className, height } = props;\n return h(\n \"div.column-axis-label.age-axis-label\",\n { className, style: { height } },\n [\n label,\n \" \",\n h.if(unit)(Parenthetical, { className: \"age-axis-unit\" }, unit),\n ],\n );\n}\n\ninterface CompositeAgeAxisProps {\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function CompositeAgeAxis(rest: CompositeAgeAxisProps) {\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n return {\n key: `section-${section.section_id}`,\n ...section.scaleInfo,\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport function ApproximateHeightAxis(rest: CompositeAgeAxisProps) {\n /** Axis to show approximate height based on dynamic column scales */\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n const { scaleInfo } = section;\n if (scaleInfo.heightScale == null) {\n throw new Error(\"No height scale available for section\");\n }\n return {\n key: `section-${section.section_id}`,\n ...scaleInfo,\n scale: scaleInfo.heightScale, // Use height scale instead of age scale\n // This only works with dynamic columns\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n axisLabel: \"Approx. height\",\n axisUnit: \"m\",\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport interface CompositeStratigraphicScaleInfo extends CompositeAgeAxisProps {\n axisType: ColumnAxisType;\n axisLabel?: string;\n axisUnit?: string;\n totalHeight: number;\n packages: PackageScaleLayoutData[];\n}\n\nexport function CompositeAgeAxisCore(props: CompositeStratigraphicScaleInfo) {\n const { axisType, axisLabel, axisUnit, totalHeight, packages, ...rest } =\n props;\n\n if (axisType == ColumnAxisType.ORDINAL) {\n return null;\n }\n\n let _axisLabel: string = axisLabel ?? \"Age\";\n let _axisUnit = axisUnit ?? \"Ma\";\n if (axisType == ColumnAxisType.DEPTH) {\n _axisLabel = \"Depth\";\n _axisUnit = \"m\";\n } else if (axisType == ColumnAxisType.HEIGHT) {\n _axisLabel = \"Height\";\n _axisUnit = \"m\";\n }\n\n return h(\"div.composite-age-axis\", rest, [\n h(VerticalAxisLabel, {\n label: _axisLabel,\n unit: _axisUnit,\n height: totalHeight,\n }),\n h(\n SVG,\n {\n className: \"age-axis-column\",\n style: { width: `22px`, height: `${totalHeight}px` },\n width: 22,\n height: totalHeight,\n },\n packages.map((group, i) => {\n const { key, scale } = group;\n\n return h(AgeAxis, {\n key,\n className: \"age-axis\",\n scale,\n tickSizeOuter: 3,\n });\n }),\n ),\n ]);\n}\n\nexport function AgeCursor({ age }) {\n /** A cursor that shows the age at a specific point on the age axis. */\n const scale = useCompositeScale();\n const heightPx = scale(age);\n\n if (age == null || heightPx == null) {\n return null;\n }\n\n return h(\n \"div.age-cursor\",\n {\n style: {\n top: heightPx,\n },\n },\n [h(\"div.line\"), h(AgeLabel, { age, className: \"label\" })],\n );\n}\n"],"names":["hyper","styles"],"mappings":";;;;;;;AAeA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AAetB,SAAS,kBAAkB,OAAO;AACvC,QAAM,EAAE,QAAQ,OAAO,OAAO,MAAM,WAAW,WAAW;AAC1D,SAAO;AAAA,IACL;AAAA,IACA,EAAE,WAAW,OAAO,EAAE,SAAO;AAAA,IAC7B;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,GAAG,IAAI,EAAE,eAAe,EAAE,WAAW,gBAAA,GAAmB,IAAI;AAAA,IAAA;AAAA,EAChE;AAEJ;AAOO,SAAS,iBAAiB,MAA6B;AAC5D,QAAM,EAAE,UAAU,UAAU,YAAA,IAAgB,wBAAA;AAE5C,QAAM,WAAW,SAAS,IAAI,CAAC,YAAY;AACzC,WAAO;AAAA,MACL,KAAK,WAAW,QAAQ,UAAU;AAAA,MAClC,GAAG,QAAQ;AAAA,IAAA;AAAA,EAEf,CAAC;AAED,SAAO,EAAE,sBAAsB;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,sBAAsB,MAA6B;AAEjE,QAAM,EAAE,UAAU,UAAU,YAAA,IAAgB,wBAAA;AAE5C,QAAM,WAAW,SAAS,IAAI,CAAC,YAAY;AACzC,UAAM,EAAE,cAAc;AACtB,QAAI,UAAU,eAAe,MAAM;AACjC,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AACA,WAAO;AAAA,MACL,KAAK,WAAW,QAAQ,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;AAAA,IACA;AAAA,MACE,OAAO;AAAA,QACL,KAAK;AAAA,MAAA;AAAA,IACP;AAAA,IAEF,CAAC,EAAE,UAAU,GAAG,EAAE,UAAU,EAAE,KAAK,WAAW,SAAS,CAAC;AAAA,EAAA;AAE5D;"}
1
+ {"version":3,"file":"age-axis.js","sources":["../src/age-axis.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n SVG,\n ColumnAxis,\n ColumnContext,\n ColumnAxisType,\n AgeAxis,\n} from \"@macrostrat/column-components\";\nimport { useContext } from \"react\";\nimport styles from \"./age-axis.module.sass\";\nimport { useCompositeScale, useMacrostratColumnData } from \"./data-provider\";\nimport { Parenthetical } from \"@macrostrat/data-components\";\nimport { AgeLabel } from \"./unit-details\";\nimport { PackageScaleLayoutData } from \"./prepare-units\";\n\nconst h = hyper.styled(styles);\n\nconst AgeAxisCore = ({ ticks, tickSpacing = 40, showDomain = false }) => {\n const { pixelHeight } = useContext(ColumnContext);\n // A tick roughly every 40 pixels\n let v = Math.max(Math.round(pixelHeight / tickSpacing), 1);\n\n return h(\"g.axis\", { transform: \"translate(20 0)\" }, [\n h(ColumnAxis, {\n ticks: v,\n showDomain,\n }),\n ]);\n};\n\nexport function VerticalAxisLabel(props) {\n const { label = \"Age\", unit = \"Ma\", className, height } = props;\n return h(\n \"div.column-axis-label.age-axis-label\",\n { className, style: { height } },\n [\n label,\n \" \",\n h.if(unit)(Parenthetical, { className: \"age-axis-unit\" }, unit),\n ],\n );\n}\n\ninterface CompositeAgeAxisProps {\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function CompositeAgeAxis(rest: CompositeAgeAxisProps) {\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n return {\n key: `section-${section.section_id}`,\n ...section.scaleInfo,\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport function ApproximateHeightAxis(rest: CompositeAgeAxisProps) {\n /** Axis to show approximate height based on dynamic column scales */\n const { axisType, sections, totalHeight } = useMacrostratColumnData();\n\n const packages = sections.map((section) => {\n const { scaleInfo } = section;\n if (scaleInfo.heightScale == null) {\n throw new Error(\"No height scale available for section\");\n }\n return {\n key: `section-${section.section_id}`,\n ...scaleInfo,\n scale: scaleInfo.heightScale, // Use height scale instead of age scale\n // This only works with dynamic columns\n };\n });\n\n return h(CompositeAgeAxisCore, {\n axisType,\n axisLabel: \"Approx. height\",\n axisUnit: \"m\",\n packages,\n totalHeight,\n ...rest,\n });\n}\n\nexport interface CompositeStratigraphicScaleInfo extends CompositeAgeAxisProps {\n axisType: ColumnAxisType;\n axisLabel?: string;\n axisUnit?: string;\n totalHeight: number;\n packages: PackageScaleLayoutData[];\n}\n\nexport function CompositeAgeAxisCore(props: CompositeStratigraphicScaleInfo) {\n const { axisType, axisLabel, axisUnit, totalHeight, packages, ...rest } =\n props;\n\n if (axisType == ColumnAxisType.ORDINAL) {\n return null;\n }\n\n let _axisLabel: string = axisLabel ?? \"Age\";\n let _axisUnit = axisUnit ?? \"Ma\";\n if (axisType == ColumnAxisType.DEPTH) {\n _axisLabel = \"Depth\";\n _axisUnit = \"m\";\n } else if (axisType == ColumnAxisType.HEIGHT) {\n _axisLabel = \"Height\";\n _axisUnit = \"m\";\n }\n\n return h(\"div.composite-age-axis\", rest, [\n h(VerticalAxisLabel, {\n label: _axisLabel,\n unit: _axisUnit,\n height: totalHeight,\n }),\n h(\n SVG,\n {\n className: \"age-axis-column\",\n style: { width: `22px`, height: `${totalHeight}px` },\n width: 22,\n height: totalHeight,\n },\n packages.map((group, i) => {\n const { key, scale } = group;\n\n return h(AgeAxis, {\n key,\n className: \"age-axis\",\n scale,\n tickSizeOuter: 3,\n });\n }),\n ),\n ]);\n}\n\nexport function AgeCursor({ age }) {\n /** A cursor that shows the age at a specific point on the age axis. */\n const scale = useCompositeScale();\n const heightPx = scale(age);\n\n if (age == null || heightPx == null) {\n return null;\n }\n\n return h(\n \"div.age-cursor\",\n {\n style: {\n top: heightPx,\n },\n },\n [h(\"div.line\"), h(AgeLabel, { age, className: \"label\" })],\n );\n}\n"],"names":["hyper","styles"],"mappings":";;;;;;AAeA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AAetB,SAAS,kBAAkB,OAAO;AACvC,QAAM,EAAE,QAAQ,OAAO,OAAO,MAAM,WAAW,WAAW;AAC1D,SAAO;AAAA,IACL;AAAA,IACA,EAAE,WAAW,OAAO,EAAE,SAAO;AAAA,IAC7B;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,GAAG,IAAI,EAAE,eAAe,EAAE,WAAW,gBAAA,GAAmB,IAAI;AAAA,IAAA;AAAA,EAChE;AAEJ;AAOO,SAAS,iBAAiB,MAA6B;AAC5D,QAAM,EAAE,UAAU,UAAU,YAAA,IAAgB,wBAAA;AAE5C,QAAM,WAAW,SAAS,IAAI,CAAC,YAAY;AACzC,WAAO;AAAA,MACL,KAAK,WAAW,QAAQ,UAAU;AAAA,MAClC,GAAG,QAAQ;AAAA,IAAA;AAAA,EAEf,CAAC;AAED,SAAO,EAAE,sBAAsB;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,sBAAsB,MAA6B;AAEjE,QAAM,EAAE,UAAU,UAAU,YAAA,IAAgB,wBAAA;AAE5C,QAAM,WAAW,SAAS,IAAI,CAAC,YAAY;AACzC,UAAM,EAAE,cAAc;AACtB,QAAI,UAAU,eAAe,MAAM;AACjC,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AACA,WAAO;AAAA,MACL,KAAK,WAAW,QAAQ,UAAU;AAAA,MAClC,GAAG;AAAA,MACH,OAAO,UAAU;AAAA;AAAA;AAAA,IAAA;AAAA,EAGrB,CAAC;AAED,SAAO,EAAE,sBAAsB;AAAA,IAC7B;AAAA,IACA,WAAW;AAAA,IACX,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,GAAG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
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const uiComponents = require("@macrostrat/ui-components");
5
+ const dataProvider = require("@macrostrat/data-provider");
6
+ const types = require("./types.cjs");
7
+ const store = require("../data-provider/store.cjs");
8
+ const AGE_MODEL_ROUTE = "/age_model";
9
+ function useColumnAgeModel(col_id) {
10
+ const baseURL = dataProvider.useMacrostratBaseURL();
11
+ const params = React.useMemo(() => ({ col_id }), [col_id]);
12
+ let route = null;
13
+ if (col_id != null) {
14
+ route = baseURL + AGE_MODEL_ROUTE;
15
+ }
16
+ return uiComponents.useAPIResult(route, params, unwrapAgeModel) ?? null;
17
+ }
18
+ function unwrapAgeModel(res) {
19
+ return res?.success?.data ?? [];
20
+ }
21
+ function useColumnSurfaces(options = {}) {
22
+ const {
23
+ surfaces: provided,
24
+ col_id,
25
+ fallbackToUnits = true,
26
+ inferTiePoints = true
27
+ } = options;
28
+ const units = store.useMacrostratUnits();
29
+ const { axisType } = store.useMacrostratColumnData();
30
+ let fetchID = null;
31
+ if (provided == null) {
32
+ fetchID = col_id ?? units?.[0]?.col_id ?? null;
33
+ }
34
+ const boundaries = useColumnAgeModel(fetchID);
35
+ const fromAgeModel = React.useMemo(
36
+ () => types.surfacesFromBoundaries(boundaries, { inferTiePoints }),
37
+ [boundaries, inferTiePoints]
38
+ );
39
+ const derived = React.useMemo(() => {
40
+ if (!fallbackToUnits) return [];
41
+ return types.surfacesFromUnits(units, { axisType });
42
+ }, [units, axisType, fallbackToUnits]);
43
+ if (provided != null) {
44
+ return { surfaces: provided, source: "provided" };
45
+ }
46
+ if (fetchID != null && boundaries == null) {
47
+ return { surfaces: [], source: "loading" };
48
+ }
49
+ if (fromAgeModel.length > 0) {
50
+ return { surfaces: fromAgeModel, source: "age-model" };
51
+ }
52
+ return { surfaces: derived, source: "derived" };
53
+ }
54
+ exports.AGE_MODEL_ROUTE = AGE_MODEL_ROUTE;
55
+ exports.useColumnAgeModel = useColumnAgeModel;
56
+ exports.useColumnSurfaces = useColumnSurfaces;
57
+ //# sourceMappingURL=data.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.cjs","sources":["../../src/age-model/data.ts"],"sourcesContent":["/** Data hooks for a column's age model. */\nimport { useMemo } from \"react\";\nimport { useAPIResult } from \"@macrostrat/ui-components\";\nimport { useMacrostratBaseURL } from \"@macrostrat/data-provider\";\nimport type { UnitLong } from \"@macrostrat/api-types\";\nimport { useMacrostratColumnData, useMacrostratUnits } from \"../data-provider\";\nimport {\n type AgeModelBoundary,\n type ColumnSurface,\n surfacesFromBoundaries,\n surfacesFromUnits,\n} from \"./types\";\n\nexport const AGE_MODEL_ROUTE = \"/age_model\";\n\n/** The age-model boundaries of a column, from `/age_model?col_id=` on the\n * API the enclosing `MacrostratDataProvider` points at (production when there\n * is none). `null` while loading or when `col_id` is not set. */\nexport function useColumnAgeModel(\n col_id: number | null | undefined,\n): AgeModelBoundary[] | null {\n const baseURL = useMacrostratBaseURL();\n const params = useMemo(() => ({ col_id }), [col_id]);\n let route: string | null = null;\n if (col_id != null) {\n route = baseURL + AGE_MODEL_ROUTE;\n }\n return useAPIResult(route, params, unwrapAgeModel) ?? null;\n}\n\nfunction unwrapAgeModel(res: any): AgeModelBoundary[] {\n return res?.success?.data ?? [];\n}\n\n/** Where a column's surfaces came from */\nexport type SurfacesSource = \"provided\" | \"age-model\" | \"derived\" | \"loading\";\n\nexport interface UseColumnSurfacesOptions {\n /** Surfaces to show. When given, nothing is fetched. */\n surfaces?: ColumnSurface[] | null;\n /** The column whose age model to fetch. Defaults to the column being\n * rendered (read from its units). */\n col_id?: number | null;\n /** When the age model has no boundaries, derive surfaces from the units\n * instead (default `true`). */\n fallbackToUnits?: boolean;\n /** Promote `modeled` surfaces that must in fact constrain the age model to\n * `relative` (default `true`) — see `inferTiePointStatuses`. */\n inferTiePoints?: boolean;\n}\n\nexport interface ColumnSurfacesData {\n surfaces: ColumnSurface[];\n source: SurfacesSource;\n}\n\n/** Resolve the surfaces to show for the enclosing `Column`: the ones passed\n * in, else the column's age model, else (optionally) surfaces derived from\n * its units. Must be used inside a `Column`. */\nexport function useColumnSurfaces(\n options: UseColumnSurfacesOptions = {},\n): ColumnSurfacesData {\n const {\n surfaces: provided,\n col_id,\n fallbackToUnits = true,\n inferTiePoints = true,\n } = options;\n const units = useMacrostratUnits() as UnitLong[] | undefined;\n const { axisType } = useMacrostratColumnData();\n\n let fetchID: number | null = null;\n if (provided == null) {\n fetchID = col_id ?? units?.[0]?.col_id ?? null;\n }\n const boundaries = useColumnAgeModel(fetchID);\n\n const fromAgeModel = useMemo(\n () => surfacesFromBoundaries(boundaries, { inferTiePoints }),\n [boundaries, inferTiePoints],\n );\n\n const derived = useMemo(() => {\n if (!fallbackToUnits) return [];\n return surfacesFromUnits(units, { axisType });\n }, [units, axisType, fallbackToUnits]);\n\n if (provided != null) {\n return { surfaces: provided, source: \"provided\" };\n }\n if (fetchID != null && boundaries == null) {\n return { surfaces: [], source: \"loading\" };\n }\n if (fromAgeModel.length > 0) {\n return { surfaces: fromAgeModel, source: \"age-model\" };\n }\n return { surfaces: derived, source: \"derived\" };\n}\n"],"names":["useMacrostratBaseURL","useMemo","useAPIResult","useMacrostratUnits","useMacrostratColumnData","surfacesFromBoundaries","surfacesFromUnits"],"mappings":";;;;;;;AAaO,MAAM,kBAAkB;AAKxB,SAAS,kBACd,QAC2B;AAC3B,QAAM,UAAUA,aAAAA,qBAAA;AAChB,QAAM,SAASC,MAAAA,QAAQ,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;AACnD,MAAI,QAAuB;AAC3B,MAAI,UAAU,MAAM;AAClB,YAAQ,UAAU;AAAA,EACpB;AACA,SAAOC,aAAAA,aAAa,OAAO,QAAQ,cAAc,KAAK;AACxD;AAEA,SAAS,eAAe,KAA8B;AACpD,SAAO,KAAK,SAAS,QAAQ,CAAA;AAC/B;AA2BO,SAAS,kBACd,UAAoC,IAChB;AACpB,QAAM;AAAA,IACJ,UAAU;AAAA,IACV;AAAA,IACA,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,EAAA,IACf;AACJ,QAAM,QAAQC,MAAAA,mBAAA;AACd,QAAM,EAAE,SAAA,IAAaC,8BAAA;AAErB,MAAI,UAAyB;AAC7B,MAAI,YAAY,MAAM;AACpB,cAAU,UAAU,QAAQ,CAAC,GAAG,UAAU;AAAA,EAC5C;AACA,QAAM,aAAa,kBAAkB,OAAO;AAE5C,QAAM,eAAeH,MAAAA;AAAAA,IACnB,MAAMI,6BAAuB,YAAY,EAAE,gBAAgB;AAAA,IAC3D,CAAC,YAAY,cAAc;AAAA,EAAA;AAG7B,QAAM,UAAUJ,MAAAA,QAAQ,MAAM;AAC5B,QAAI,CAAC,gBAAiB,QAAO,CAAA;AAC7B,WAAOK,wBAAkB,OAAO,EAAE,UAAU;AAAA,EAC9C,GAAG,CAAC,OAAO,UAAU,eAAe,CAAC;AAErC,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE,UAAU,UAAU,QAAQ,WAAA;AAAA,EACvC;AACA,MAAI,WAAW,QAAQ,cAAc,MAAM;AACzC,WAAO,EAAE,UAAU,IAAI,QAAQ,UAAA;AAAA,EACjC;AACA,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,EAAE,UAAU,cAAc,QAAQ,YAAA;AAAA,EAC3C;AACA,SAAO,EAAE,UAAU,SAAS,QAAQ,UAAA;AACtC;;;;"}
@@ -0,0 +1,29 @@
1
+ import { AgeModelBoundary, ColumnSurface } from './types';
2
+ export declare const AGE_MODEL_ROUTE = "/age_model";
3
+ /** The age-model boundaries of a column, from `/age_model?col_id=` on the
4
+ * API the enclosing `MacrostratDataProvider` points at (production when there
5
+ * is none). `null` while loading or when `col_id` is not set. */
6
+ export declare function useColumnAgeModel(col_id: number | null | undefined): AgeModelBoundary[] | null;
7
+ /** Where a column's surfaces came from */
8
+ export type SurfacesSource = "provided" | "age-model" | "derived" | "loading";
9
+ export interface UseColumnSurfacesOptions {
10
+ /** Surfaces to show. When given, nothing is fetched. */
11
+ surfaces?: ColumnSurface[] | null;
12
+ /** The column whose age model to fetch. Defaults to the column being
13
+ * rendered (read from its units). */
14
+ col_id?: number | null;
15
+ /** When the age model has no boundaries, derive surfaces from the units
16
+ * instead (default `true`). */
17
+ fallbackToUnits?: boolean;
18
+ /** Promote `modeled` surfaces that must in fact constrain the age model to
19
+ * `relative` (default `true`) — see `inferTiePointStatuses`. */
20
+ inferTiePoints?: boolean;
21
+ }
22
+ export interface ColumnSurfacesData {
23
+ surfaces: ColumnSurface[];
24
+ source: SurfacesSource;
25
+ }
26
+ /** Resolve the surfaces to show for the enclosing `Column`: the ones passed
27
+ * in, else the column's age model, else (optionally) surfaces derived from
28
+ * its units. Must be used inside a `Column`. */
29
+ export declare function useColumnSurfaces(options?: UseColumnSurfacesOptions): ColumnSurfacesData;
@@ -0,0 +1,57 @@
1
+ import { useMemo } from "react";
2
+ import { useAPIResult } from "@macrostrat/ui-components";
3
+ import { useMacrostratBaseURL } from "@macrostrat/data-provider";
4
+ import { surfacesFromBoundaries, surfacesFromUnits } from "./types.js";
5
+ import { useMacrostratUnits, useMacrostratColumnData } from "../data-provider/store.js";
6
+ const AGE_MODEL_ROUTE = "/age_model";
7
+ function useColumnAgeModel(col_id) {
8
+ const baseURL = useMacrostratBaseURL();
9
+ const params = useMemo(() => ({ col_id }), [col_id]);
10
+ let route = null;
11
+ if (col_id != null) {
12
+ route = baseURL + AGE_MODEL_ROUTE;
13
+ }
14
+ return useAPIResult(route, params, unwrapAgeModel) ?? null;
15
+ }
16
+ function unwrapAgeModel(res) {
17
+ return res?.success?.data ?? [];
18
+ }
19
+ function useColumnSurfaces(options = {}) {
20
+ const {
21
+ surfaces: provided,
22
+ col_id,
23
+ fallbackToUnits = true,
24
+ inferTiePoints = true
25
+ } = options;
26
+ const units = useMacrostratUnits();
27
+ const { axisType } = useMacrostratColumnData();
28
+ let fetchID = null;
29
+ if (provided == null) {
30
+ fetchID = col_id ?? units?.[0]?.col_id ?? null;
31
+ }
32
+ const boundaries = useColumnAgeModel(fetchID);
33
+ const fromAgeModel = useMemo(
34
+ () => surfacesFromBoundaries(boundaries, { inferTiePoints }),
35
+ [boundaries, inferTiePoints]
36
+ );
37
+ const derived = useMemo(() => {
38
+ if (!fallbackToUnits) return [];
39
+ return surfacesFromUnits(units, { axisType });
40
+ }, [units, axisType, fallbackToUnits]);
41
+ if (provided != null) {
42
+ return { surfaces: provided, source: "provided" };
43
+ }
44
+ if (fetchID != null && boundaries == null) {
45
+ return { surfaces: [], source: "loading" };
46
+ }
47
+ if (fromAgeModel.length > 0) {
48
+ return { surfaces: fromAgeModel, source: "age-model" };
49
+ }
50
+ return { surfaces: derived, source: "derived" };
51
+ }
52
+ export {
53
+ AGE_MODEL_ROUTE,
54
+ useColumnAgeModel,
55
+ useColumnSurfaces
56
+ };
57
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.js","sources":["../../src/age-model/data.ts"],"sourcesContent":["/** Data hooks for a column's age model. */\nimport { useMemo } from \"react\";\nimport { useAPIResult } from \"@macrostrat/ui-components\";\nimport { useMacrostratBaseURL } from \"@macrostrat/data-provider\";\nimport type { UnitLong } from \"@macrostrat/api-types\";\nimport { useMacrostratColumnData, useMacrostratUnits } from \"../data-provider\";\nimport {\n type AgeModelBoundary,\n type ColumnSurface,\n surfacesFromBoundaries,\n surfacesFromUnits,\n} from \"./types\";\n\nexport const AGE_MODEL_ROUTE = \"/age_model\";\n\n/** The age-model boundaries of a column, from `/age_model?col_id=` on the\n * API the enclosing `MacrostratDataProvider` points at (production when there\n * is none). `null` while loading or when `col_id` is not set. */\nexport function useColumnAgeModel(\n col_id: number | null | undefined,\n): AgeModelBoundary[] | null {\n const baseURL = useMacrostratBaseURL();\n const params = useMemo(() => ({ col_id }), [col_id]);\n let route: string | null = null;\n if (col_id != null) {\n route = baseURL + AGE_MODEL_ROUTE;\n }\n return useAPIResult(route, params, unwrapAgeModel) ?? null;\n}\n\nfunction unwrapAgeModel(res: any): AgeModelBoundary[] {\n return res?.success?.data ?? [];\n}\n\n/** Where a column's surfaces came from */\nexport type SurfacesSource = \"provided\" | \"age-model\" | \"derived\" | \"loading\";\n\nexport interface UseColumnSurfacesOptions {\n /** Surfaces to show. When given, nothing is fetched. */\n surfaces?: ColumnSurface[] | null;\n /** The column whose age model to fetch. Defaults to the column being\n * rendered (read from its units). */\n col_id?: number | null;\n /** When the age model has no boundaries, derive surfaces from the units\n * instead (default `true`). */\n fallbackToUnits?: boolean;\n /** Promote `modeled` surfaces that must in fact constrain the age model to\n * `relative` (default `true`) — see `inferTiePointStatuses`. */\n inferTiePoints?: boolean;\n}\n\nexport interface ColumnSurfacesData {\n surfaces: ColumnSurface[];\n source: SurfacesSource;\n}\n\n/** Resolve the surfaces to show for the enclosing `Column`: the ones passed\n * in, else the column's age model, else (optionally) surfaces derived from\n * its units. Must be used inside a `Column`. */\nexport function useColumnSurfaces(\n options: UseColumnSurfacesOptions = {},\n): ColumnSurfacesData {\n const {\n surfaces: provided,\n col_id,\n fallbackToUnits = true,\n inferTiePoints = true,\n } = options;\n const units = useMacrostratUnits() as UnitLong[] | undefined;\n const { axisType } = useMacrostratColumnData();\n\n let fetchID: number | null = null;\n if (provided == null) {\n fetchID = col_id ?? units?.[0]?.col_id ?? null;\n }\n const boundaries = useColumnAgeModel(fetchID);\n\n const fromAgeModel = useMemo(\n () => surfacesFromBoundaries(boundaries, { inferTiePoints }),\n [boundaries, inferTiePoints],\n );\n\n const derived = useMemo(() => {\n if (!fallbackToUnits) return [];\n return surfacesFromUnits(units, { axisType });\n }, [units, axisType, fallbackToUnits]);\n\n if (provided != null) {\n return { surfaces: provided, source: \"provided\" };\n }\n if (fetchID != null && boundaries == null) {\n return { surfaces: [], source: \"loading\" };\n }\n if (fromAgeModel.length > 0) {\n return { surfaces: fromAgeModel, source: \"age-model\" };\n }\n return { surfaces: derived, source: \"derived\" };\n}\n"],"names":[],"mappings":";;;;;AAaO,MA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