@macrostrat/column-views 3.9.0 → 3.11.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 (138) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/column-views.css +10 -0
  3. package/dist/correlation-chart/main.cjs +11 -3
  4. package/dist/correlation-chart/main.cjs.map +1 -1
  5. package/dist/correlation-chart/main.d.ts +1 -1
  6. package/dist/correlation-chart/main.js +11 -3
  7. package/dist/correlation-chart/main.js.map +1 -1
  8. package/dist/index.cjs +18 -42
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +2 -1
  11. package/dist/index.js +4 -34
  12. package/dist/index.js.map +1 -1
  13. package/dist/unit-details/age-window-tag.cjs +68 -0
  14. package/dist/unit-details/age-window-tag.cjs.map +1 -0
  15. package/dist/unit-details/age-window-tag.d.ts +26 -0
  16. package/dist/unit-details/age-window-tag.js +66 -0
  17. package/dist/unit-details/age-window-tag.js.map +1 -0
  18. package/dist/unit-details/age-window-tag.module.sass.cjs +12 -0
  19. package/dist/unit-details/age-window-tag.module.sass.cjs.map +1 -0
  20. package/dist/unit-details/age-window-tag.module.sass.js +11 -0
  21. package/dist/unit-details/age-window-tag.module.sass.js.map +1 -0
  22. package/dist/unit-details/index.d.ts +1 -0
  23. package/dist/units/boxes.cjs +3 -3
  24. package/dist/units/boxes.cjs.map +1 -1
  25. package/dist/units/boxes.js +3 -3
  26. package/dist/units/boxes.js.map +1 -1
  27. package/dist/units/index.cjs +7 -11
  28. package/dist/units/index.cjs.map +1 -1
  29. package/dist/units/index.d.ts +0 -1
  30. package/dist/units/index.js +4 -9
  31. package/dist/units/index.js.map +1 -1
  32. package/package.json +6 -27
  33. package/src/correlation-chart/main.ts +14 -2
  34. package/src/index.ts +3 -1
  35. package/src/unit-details/age-window-tag.module.sass +10 -0
  36. package/src/unit-details/age-window-tag.ts +102 -0
  37. package/src/unit-details/index.ts +1 -0
  38. package/src/units/boxes.ts +7 -4
  39. package/src/units/index.ts +9 -26
  40. package/dist/maps/column-correlation/core.cjs +0 -288
  41. package/dist/maps/column-correlation/core.cjs.map +0 -1
  42. package/dist/maps/column-correlation/core.d.ts +0 -9
  43. package/dist/maps/column-correlation/core.js +0 -286
  44. package/dist/maps/column-correlation/core.js.map +0 -1
  45. package/dist/maps/column-correlation/index.d.ts +0 -2
  46. package/dist/maps/column-correlation/state.cjs +0 -193
  47. package/dist/maps/column-correlation/state.cjs.map +0 -1
  48. package/dist/maps/column-correlation/state.d.ts +0 -62
  49. package/dist/maps/column-correlation/state.js +0 -190
  50. package/dist/maps/column-correlation/state.js.map +0 -1
  51. package/dist/maps/column-navigation/index.d.ts +0 -2
  52. package/dist/maps/column-navigation/mapbox/index.cjs +0 -215
  53. package/dist/maps/column-navigation/mapbox/index.cjs.map +0 -1
  54. package/dist/maps/column-navigation/mapbox/index.d.ts +0 -38
  55. package/dist/maps/column-navigation/mapbox/index.js +0 -213
  56. package/dist/maps/column-navigation/mapbox/index.js.map +0 -1
  57. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs +0 -105
  58. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs.map +0 -1
  59. package/dist/maps/column-navigation/mapbox/keyboard-navigation.d.ts +0 -8
  60. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js +0 -105
  61. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js.map +0 -1
  62. package/dist/maps/column-navigation/mapbox/state.cjs +0 -73
  63. package/dist/maps/column-navigation/mapbox/state.cjs.map +0 -1
  64. package/dist/maps/column-navigation/mapbox/state.d.ts +0 -23
  65. package/dist/maps/column-navigation/mapbox/state.js +0 -71
  66. package/dist/maps/column-navigation/mapbox/state.js.map +0 -1
  67. package/dist/maps/column-navigation/svg/animated.d.ts +0 -1
  68. package/dist/maps/column-navigation/svg/data-fetcher.cjs +0 -25
  69. package/dist/maps/column-navigation/svg/data-fetcher.cjs.map +0 -1
  70. package/dist/maps/column-navigation/svg/data-fetcher.d.ts +0 -6
  71. package/dist/maps/column-navigation/svg/data-fetcher.js +0 -25
  72. package/dist/maps/column-navigation/svg/data-fetcher.js.map +0 -1
  73. package/dist/maps/column-navigation/svg/index.cjs +0 -94
  74. package/dist/maps/column-navigation/svg/index.cjs.map +0 -1
  75. package/dist/maps/column-navigation/svg/index.d.ts +0 -9
  76. package/dist/maps/column-navigation/svg/index.js +0 -93
  77. package/dist/maps/column-navigation/svg/index.js.map +0 -1
  78. package/dist/maps/column-navigation/svg/layers.cjs +0 -177
  79. package/dist/maps/column-navigation/svg/layers.cjs.map +0 -1
  80. package/dist/maps/column-navigation/svg/layers.d.ts +0 -54
  81. package/dist/maps/column-navigation/svg/layers.js +0 -174
  82. package/dist/maps/column-navigation/svg/layers.js.map +0 -1
  83. package/dist/maps/column-navigation/utils/keyboard-navigation.cjs +0 -50
  84. package/dist/maps/column-navigation/utils/keyboard-navigation.cjs.map +0 -1
  85. package/dist/maps/column-navigation/utils/keyboard-navigation.d.ts +0 -10
  86. package/dist/maps/column-navigation/utils/keyboard-navigation.js +0 -50
  87. package/dist/maps/column-navigation/utils/keyboard-navigation.js.map +0 -1
  88. package/dist/maps/index.d.ts +0 -4
  89. package/dist/maps/inset-map/index.cjs +0 -71
  90. package/dist/maps/inset-map/index.cjs.map +0 -1
  91. package/dist/maps/inset-map/index.d.ts +0 -16
  92. package/dist/maps/inset-map/index.js +0 -69
  93. package/dist/maps/inset-map/index.js.map +0 -1
  94. package/dist/maps/layers/columns.cjs +0 -165
  95. package/dist/maps/layers/columns.cjs.map +0 -1
  96. package/dist/maps/layers/columns.d.ts +0 -28
  97. package/dist/maps/layers/columns.js +0 -165
  98. package/dist/maps/layers/columns.js.map +0 -1
  99. package/dist/maps/layers/index.d.ts +0 -2
  100. package/dist/maps/layers/units.cjs +0 -207
  101. package/dist/maps/layers/units.cjs.map +0 -1
  102. package/dist/maps/layers/units.d.ts +0 -14
  103. package/dist/maps/layers/units.js +0 -204
  104. package/dist/maps/layers/units.js.map +0 -1
  105. package/dist/units/colors.cjs +0 -115
  106. package/dist/units/colors.cjs.map +0 -1
  107. package/dist/units/colors.d.ts +0 -20
  108. package/dist/units/colors.js +0 -113
  109. package/dist/units/colors.js.map +0 -1
  110. package/dist/units/resolvers.cjs +0 -125
  111. package/dist/units/resolvers.cjs.map +0 -1
  112. package/dist/units/resolvers.d.ts +0 -8
  113. package/dist/units/resolvers.js +0 -125
  114. package/dist/units/resolvers.js.map +0 -1
  115. package/src/maps/column-correlation/column-correlation-map.stories.ts +0 -108
  116. package/src/maps/column-correlation/core.ts +0 -342
  117. package/src/maps/column-correlation/index.ts +0 -2
  118. package/src/maps/column-correlation/state.ts +0 -315
  119. package/src/maps/column-navigation/index.ts +0 -2
  120. package/src/maps/column-navigation/mapbox/column-navigation-map.stories.ts +0 -278
  121. package/src/maps/column-navigation/mapbox/index.ts +0 -276
  122. package/src/maps/column-navigation/mapbox/keyboard-navigation.ts +0 -133
  123. package/src/maps/column-navigation/mapbox/state.ts +0 -119
  124. package/src/maps/column-navigation/svg/animated.ts +0 -78
  125. package/src/maps/column-navigation/svg/column-navigation-svg-map.stories.ts +0 -46
  126. package/src/maps/column-navigation/svg/data-fetcher.ts +0 -34
  127. package/src/maps/column-navigation/svg/index.ts +0 -96
  128. package/src/maps/column-navigation/svg/layers.ts +0 -233
  129. package/src/maps/column-navigation/utils/keyboard-navigation.ts +0 -58
  130. package/src/maps/index.ts +0 -4
  131. package/src/maps/inset-map/index.ts +0 -87
  132. package/src/maps/inset-map/inset-map.stories.ts +0 -20
  133. package/src/maps/layers/columns.ts +0 -216
  134. package/src/maps/layers/index.ts +0 -2
  135. package/src/maps/layers/units.ts +0 -286
  136. package/src/maps/unit-map.stories.ts +0 -79
  137. package/src/units/colors.ts +0 -183
  138. package/src/units/resolvers.ts +0 -141
@@ -1,193 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const zustand = require("zustand");
4
- const lineIntersect = require("@turf/line-intersect");
5
- const distance = require("@turf/distance");
6
- const nearestPointOnLine = require("@turf/nearest-point-on-line");
7
- const centroid = require("@turf/centroid");
8
- const React = require("react");
9
- const h = require("@macrostrat/hyper");
10
- const zustandComputed = require("zustand-computed");
11
- const dataProvider = require("@macrostrat/data-provider");
12
- const buffer = require("@turf/buffer");
13
- const booleanPointInPolygon = require("@turf/boolean-point-in-polygon");
14
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
15
- const distance__default = /* @__PURE__ */ _interopDefault(distance);
16
- const h__default = /* @__PURE__ */ _interopDefault(h);
17
- const CorrelationStoreContext = React.createContext(null);
18
- const computed = zustandComputed.createComputed((state) => {
19
- const manual = state.manualColumns != null;
20
- return {
21
- selectionMode: manual ? "manual" : "line",
22
- // Focused columns are derived either from an explicit manual selection or
23
- // from the columns intersecting the line of section.
24
- focusedColumns: manual ? buildManualColumns(state.columns, state.manualColumns) : buildCorrelationColumns(state.columns, state.focusedLine)
25
- };
26
- });
27
- function ColumnCorrelationProvider({
28
- children,
29
- columns,
30
- projectID,
31
- inProcess,
32
- focusedLine,
33
- manualColumns = null,
34
- onSelectColumns
35
- }) {
36
- const [store] = React.useState(() => {
37
- return zustand.create(
38
- computed((set, get) => {
39
- return {
40
- focusedLine,
41
- manualColumns,
42
- hoveredColumn: null,
43
- zoomColumn: null,
44
- zoomNonce: 0,
45
- projectID,
46
- columns: null,
47
- onClickMap(event, point) {
48
- const state = get();
49
- if (state.manualColumns != null) return;
50
- const shiftKeyPressed = event.originalEvent.shiftKey;
51
- let existingCoords = state.focusedLine?.coordinates ?? [];
52
- if (existingCoords.length >= 2 && !shiftKeyPressed) {
53
- existingCoords = [];
54
- }
55
- set({
56
- focusedLine: {
57
- type: "LineString",
58
- coordinates: [...existingCoords, point.coordinates]
59
- }
60
- });
61
- },
62
- toggleColumn(colID) {
63
- const state = get();
64
- const current = state.manualColumns ?? state.focusedColumns.map((d) => d.properties.col_id);
65
- const next = current.includes(colID) ? current.filter((d) => d !== colID) : [...current, colID];
66
- set({ manualColumns: next, focusedLine: null });
67
- },
68
- removeColumn(colID) {
69
- const state = get();
70
- const current = state.manualColumns ?? state.focusedColumns.map((d) => d.properties.col_id);
71
- set({
72
- manualColumns: current.filter((d) => d !== colID),
73
- focusedLine: null
74
- });
75
- },
76
- setManualColumns(colIDs) {
77
- set({ manualColumns: colIDs, focusedLine: null });
78
- },
79
- setHoveredColumn(colID) {
80
- set({ hoveredColumn: colID });
81
- },
82
- zoomToColumn(colID) {
83
- set({ zoomColumn: colID, zoomNonce: get().zoomNonce + 1 });
84
- }
85
- };
86
- })
87
- );
88
- });
89
- const _columns = dataProvider.useMacrostratColumns(projectID, inProcess);
90
- React.useEffect(() => {
91
- if (_columns != null) {
92
- store.setState({ columns: _columns });
93
- }
94
- }, [_columns]);
95
- const focusedColumns = zustand.useStore(store, (state) => state.focusedColumns);
96
- const _focusedLine = zustand.useStore(store, (state) => state.focusedLine);
97
- React.useEffect(() => {
98
- onSelectColumns?.(focusedColumns, _focusedLine);
99
- }, [focusedColumns, _focusedLine]);
100
- return h__default.default(CorrelationStoreContext.Provider, { value: store }, children);
101
- }
102
- function useCorrelationMapStore(selector) {
103
- const storeApi = React.useContext(CorrelationStoreContext);
104
- if (storeApi == null) {
105
- throw new Error("Missing CorrelationMapProvider");
106
- }
107
- return zustand.useStore(storeApi, selector);
108
- }
109
- function useColumnMapLink() {
110
- const setHoveredColumn = useCorrelationMapStore((s) => s.setHoveredColumn);
111
- const zoomToColumn = useCorrelationMapStore((s) => s.zoomToColumn);
112
- return {
113
- onColumnMouseOver: setHoveredColumn,
114
- onColumnClick: zoomToColumn
115
- };
116
- }
117
- function buildCorrelationColumns(columns, line) {
118
- if (columns == null || line == null || line.coordinates.length < 2) {
119
- return [];
120
- }
121
- return orderColumnsByDistance(
122
- computeIntersectingColumns(columns, line),
123
- line
124
- );
125
- }
126
- function buildManualColumns(columns, ids) {
127
- if (columns == null || ids == null) return [];
128
- const byID = new Map(columns.map((c) => [c.properties.col_id, c]));
129
- const result = [];
130
- ids.forEach((id, i) => {
131
- const col = byID.get(id);
132
- if (col == null) return;
133
- const c = centroid.centroid(col.geometry);
134
- result.push({
135
- ...col,
136
- properties: {
137
- ...col.properties,
138
- centroid: c,
139
- nearestPointOnLine: c,
140
- distanceAlongLine: i
141
- }
142
- });
143
- });
144
- return result;
145
- }
146
- function computeIntersectingColumns(columns, line) {
147
- if (columns == null || line == null) {
148
- return [];
149
- }
150
- const bufferedLine = buffer.buffer(line, 1, { units: "degrees" });
151
- const nearbyPoints = columns.filter((col) => {
152
- if (col.geometry?.type != "Point") {
153
- return false;
154
- }
155
- return booleanPointInPolygon.booleanPointInPolygon(col.geometry, bufferedLine);
156
- });
157
- const intersectingPolygons = columns.filter((col) => {
158
- const poly = col.geometry;
159
- if (poly == null) return false;
160
- if (poly.type != "Polygon" && poly.type != "MultiPolygon") return false;
161
- const intersection = lineIntersect.lineIntersect(line, poly);
162
- return intersection.features.length > 0;
163
- });
164
- return [...intersectingPolygons, ...nearbyPoints];
165
- }
166
- function orderColumnsByDistance(columns, line) {
167
- const centroids = columns.map((col) => centroid.centroid(col.geometry));
168
- const projectedPoints = centroids.map(
169
- (point) => nearestPointOnLine.nearestPointOnLine(line, point)
170
- );
171
- const distances = projectedPoints.map(
172
- (point) => distance__default.default(point.geometry.coordinates, line.coordinates[0])
173
- );
174
- let newColumns = columns.map((col, i) => {
175
- return {
176
- ...col,
177
- properties: {
178
- ...col.properties,
179
- centroid: centroids[i],
180
- nearestPointOnLine: projectedPoints[i],
181
- distanceAlongLine: distances[i]
182
- }
183
- };
184
- });
185
- return sorted(newColumns, (d) => d.properties.distanceAlongLine);
186
- }
187
- function sorted(data, accessor) {
188
- return data.sort((a, b) => accessor(a) - accessor(b));
189
- }
190
- exports.ColumnCorrelationProvider = ColumnCorrelationProvider;
191
- exports.useColumnMapLink = useColumnMapLink;
192
- exports.useCorrelationMapStore = useCorrelationMapStore;
193
- //# sourceMappingURL=state.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.cjs","sources":["../../../src/maps/column-correlation/state.ts"],"sourcesContent":["import { LineString, Point } from \"geojson\";\nimport { create, StoreApi, useStore } from \"zustand\";\nimport type { ColumnGeoJSONRecord } from \"@macrostrat/api-types\";\n// Turf intersection\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport distance from \"@turf/distance\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { centroid } from \"@turf/centroid\";\nimport {\n createContext,\n useState,\n useContext,\n ReactNode,\n useEffect,\n} from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { createComputed } from \"zustand-computed\";\nimport { useMacrostratColumns } from \"@macrostrat/data-provider\";\nimport { buffer } from \"@turf/buffer\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\n\nexport type CorrelationSelectionMode = \"line\" | \"manual\";\n\nexport interface CorrelationMapInput {\n columns: ColumnGeoJSONRecord[];\n focusedLine: LineString | null;\n /** When set, columns are selected manually (by clicking) in this order,\n * rather than derived from a line of section. */\n manualColumns?: number[] | null;\n}\n\nexport interface CorrelationMapStore extends CorrelationMapInput {\n onClickMap: (event: mapboxgl.MapMouseEvent, point: Point) => void;\n /** Toggle a column in/out of the manual selection (used in \"manual\" mode) */\n toggleColumn: (colID: number) => void;\n /** Remove a column from the selection. In \"line\" mode this converts the\n * current selection to a manual one (a line can't represent an arbitrary\n * subset), so removing a column switches modes. */\n removeColumn: (colID: number) => void;\n /** Replace the manual column selection with an explicit ordered list (used\n * e.g. for drag-and-drop reordering). Switches to manual mode. */\n setManualColumns: (colIDs: number[]) => void;\n setHoveredColumn: (colID: number | null) => void;\n hoveredColumn: number | null;\n /** Request the map to frame a particular column (e.g. on header click). */\n zoomToColumn: (colID: number | null) => void;\n zoomColumn: number | null;\n /** Incremented on each zoom request so repeat clicks re-frame the column. */\n zoomNonce: number;\n projectID?: number;\n}\n\nexport interface CorrelationProviderProps extends CorrelationMapInput {\n projectID?: number;\n inProcess?: boolean;\n columns: ColumnGeoJSONRecord[] | null;\n children: ReactNode;\n onSelectColumns?: (\n columns: FocusedColumnGeoJSONRecord[],\n line: LineString | null,\n ) => void;\n}\n\nconst CorrelationStoreContext =\n createContext<StoreApi<CorrelationMapStore> | null>(null);\n\ntype ComputedStore = {\n focusedColumns: FocusedColumnGeoJSONRecord[];\n selectionMode: CorrelationSelectionMode;\n};\n\n/** A computed store that will automatically update when the state changes */\nconst computed = createComputed((state: CorrelationMapStore): ComputedStore => {\n const manual = state.manualColumns != null;\n return {\n selectionMode: manual ? \"manual\" : \"line\",\n // Focused columns are derived either from an explicit manual selection or\n // from the columns intersecting the line of section.\n focusedColumns: manual\n ? buildManualColumns(state.columns, state.manualColumns)\n : buildCorrelationColumns(state.columns, state.focusedLine),\n };\n}) as any;\n\nexport function ColumnCorrelationProvider({\n children,\n columns,\n projectID,\n inProcess,\n focusedLine,\n manualColumns = null,\n onSelectColumns,\n}: CorrelationProviderProps) {\n const [store] = useState(() => {\n return create<CorrelationMapStore & ComputedStore>(\n computed((set, get): CorrelationMapStore => {\n return {\n focusedLine,\n manualColumns,\n hoveredColumn: null,\n zoomColumn: null,\n zoomNonce: 0,\n projectID,\n columns: null,\n onClickMap(event: mapboxgl.MapMouseEvent, point: Point) {\n const state = get();\n // In manual-selection mode the map click is handled per-column\n if (state.manualColumns != null) return;\n // Check if shift key is pressed\n const shiftKeyPressed = event.originalEvent.shiftKey;\n let existingCoords = state.focusedLine?.coordinates ?? [];\n\n if (existingCoords.length >= 2 && !shiftKeyPressed) {\n // Reset the line to zero length\n existingCoords = [];\n }\n set({\n focusedLine: {\n type: \"LineString\",\n coordinates: [...existingCoords, point.coordinates],\n },\n });\n },\n toggleColumn(colID: number) {\n const state = get();\n const current =\n state.manualColumns ??\n state.focusedColumns.map((d) => d.properties.col_id);\n const next = current.includes(colID)\n ? current.filter((d) => d !== colID)\n : [...current, colID];\n set({ manualColumns: next, focusedLine: null });\n },\n removeColumn(colID: number) {\n const state = get();\n // Seed from the current selection (line-derived or manual)\n const current =\n state.manualColumns ??\n state.focusedColumns.map((d) => d.properties.col_id);\n set({\n manualColumns: current.filter((d) => d !== colID),\n focusedLine: null,\n });\n },\n setManualColumns(colIDs: number[]) {\n set({ manualColumns: colIDs, focusedLine: null });\n },\n setHoveredColumn(colID: number | null) {\n set({ hoveredColumn: colID });\n },\n zoomToColumn(colID: number | null) {\n set({ zoomColumn: colID, zoomNonce: get().zoomNonce + 1 });\n },\n };\n }),\n );\n });\n\n // Set up the store\n /** TODO: move the fetching of all columns to within the map */\n const _columns = useMacrostratColumns(projectID, inProcess);\n useEffect(() => {\n if (_columns != null) {\n store.setState({ columns: _columns });\n }\n }, [_columns]);\n\n // Kind of an awkward way to do this but we need to allow the selector to run\n const focusedColumns = useStore(store, (state) => state.focusedColumns);\n const _focusedLine = useStore(store, (state) => state.focusedLine);\n\n useEffect(() => {\n onSelectColumns?.(focusedColumns, _focusedLine);\n }, [focusedColumns, _focusedLine]);\n\n return h(CorrelationStoreContext.Provider, { value: store }, children);\n}\n\nexport function useCorrelationMapStore(\n selector: (state: CorrelationMapStore & ComputedStore) => any,\n) {\n const storeApi = useContext(CorrelationStoreContext);\n if (storeApi == null) {\n throw new Error(\"Missing CorrelationMapProvider\");\n }\n return useStore(storeApi, selector);\n}\n\nexport interface ColumnMapLink {\n onColumnMouseOver: (colID: number | null) => void;\n onColumnClick: (colID: number) => void;\n}\n\n/** Wire a correlation chart's column-level events to the correlation map:\n * hovering a column highlights it on the map, and clicking a column header\n * frames it. Spread the result into `CorrelationChart`. Must be used within a\n * `ColumnCorrelationProvider`. */\nexport function useColumnMapLink(): ColumnMapLink {\n const setHoveredColumn = useCorrelationMapStore((s) => s.setHoveredColumn);\n const zoomToColumn = useCorrelationMapStore((s) => s.zoomToColumn);\n return {\n onColumnMouseOver: setHoveredColumn,\n onColumnClick: zoomToColumn,\n };\n}\n\nfunction buildCorrelationColumns(\n columns: ColumnGeoJSONRecord[],\n line: LineString,\n): FocusedColumnGeoJSONRecord[] {\n if (columns == null || line == null || line.coordinates.length < 2) {\n return [];\n }\n return orderColumnsByDistance(\n computeIntersectingColumns(columns, line),\n line,\n );\n}\n\nfunction buildManualColumns(\n columns: ColumnGeoJSONRecord[],\n ids: number[],\n): FocusedColumnGeoJSONRecord[] {\n /** Build focused columns from an explicit, ordered list of column IDs. The\n * ordering line simply connects them in the order they were selected. */\n if (columns == null || ids == null) return [];\n const byID = new Map(columns.map((c) => [c.properties.col_id, c]));\n const result: FocusedColumnGeoJSONRecord[] = [];\n ids.forEach((id, i) => {\n const col = byID.get(id);\n if (col == null) return;\n const c = centroid(col.geometry);\n result.push({\n ...col,\n properties: {\n ...col.properties,\n centroid: c,\n nearestPointOnLine: c,\n distanceAlongLine: i,\n },\n });\n });\n return result;\n}\n\nfunction computeIntersectingColumns(\n columns: ColumnGeoJSONRecord[],\n line: LineString,\n): ColumnGeoJSONRecord[] {\n if (columns == null || line == null) {\n return [];\n }\n\n /** eODP-focused process. Find buffers around line and then find columns intersecting that buffer */\n const bufferedLine = buffer(line, 1, { units: \"degrees\" });\n\n const nearbyPoints = columns.filter((col) => {\n if (col.geometry?.type != \"Point\") {\n return false;\n }\n return booleanPointInPolygon(col.geometry, bufferedLine);\n });\n\n const intersectingPolygons = columns.filter((col) => {\n const poly = col.geometry;\n\n // Some in-process datasets seem to have null geometries\n if (poly == null) return false;\n if (poly.type != \"Polygon\" && poly.type != \"MultiPolygon\") return false;\n\n const intersection = lineIntersect(line, poly);\n return intersection.features.length > 0;\n });\n\n return [...intersectingPolygons, ...nearbyPoints];\n}\n\ninterface FocusedColumnGeoJSONRecord extends ColumnGeoJSONRecord {\n properties: {\n centroid: Point;\n nearestPointOnLine: Point;\n distanceAlongLine: number;\n } & ColumnGeoJSONRecord[\"properties\"];\n}\n\nfunction orderColumnsByDistance(\n columns: ColumnGeoJSONRecord[],\n line: LineString,\n): FocusedColumnGeoJSONRecord[] {\n const centroids = columns.map((col) => centroid(col.geometry));\n const projectedPoints = centroids.map((point) =>\n nearestPointOnLine(line, point),\n );\n const distances = projectedPoints.map((point) =>\n distance(point.geometry.coordinates, line.coordinates[0]),\n );\n\n let newColumns = columns.map((col, i) => {\n return {\n ...col,\n properties: {\n ...col.properties,\n centroid: centroids[i],\n nearestPointOnLine: projectedPoints[i],\n distanceAlongLine: distances[i],\n },\n };\n });\n\n return sorted(newColumns, (d) => d.properties.distanceAlongLine);\n}\n\nfunction sorted(data, accessor: (d) => number) {\n return data.sort((a, b) => accessor(a) - accessor(b));\n}\n"],"names":["createContext","createComputed","useState","create","useMacrostratColumns","useEffect","useStore","h","useContext","centroid","buffer","booleanPointInPolygon","lineIntersect","nearestPointOnLine","distance"],"mappings":";;;;;;;;;;;;;;;;AA+DA,MAAM,0BACJA,MAAAA,cAAoD,IAAI;AAQ1D,MAAM,WAAWC,gBAAAA,eAAe,CAAC,UAA8C;AAC7E,QAAM,SAAS,MAAM,iBAAiB;AACtC,SAAO;AAAA,IACL,eAAe,SAAS,WAAW;AAAA;AAAA;AAAA,IAGnC,gBAAgB,SACZ,mBAAmB,MAAM,SAAS,MAAM,aAAa,IACrD,wBAAwB,MAAM,SAAS,MAAM,WAAW;AAAA,EAAA;AAEhE,CAAC;AAEM,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AACF,GAA6B;AAC3B,QAAM,CAAC,KAAK,IAAIC,MAAAA,SAAS,MAAM;AAC7B,WAAOC,QAAAA;AAAAA,MACL,SAAS,CAAC,KAAK,QAA6B;AAC1C,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA,eAAe;AAAA,UACf,YAAY;AAAA,UACZ,WAAW;AAAA,UACX;AAAA,UACA,SAAS;AAAA,UACT,WAAW,OAA+B,OAAc;AACtD,kBAAM,QAAQ,IAAA;AAEd,gBAAI,MAAM,iBAAiB,KAAM;AAEjC,kBAAM,kBAAkB,MA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K,MAAM;AACvC,WAAO;AAAA,MACL,GAAG;AAAA,MACH,YAAY;AAAA,QACV,GAAG,IAAI;AAAA,QACP,UAAU,UAAU,CAAC;AAAA,QACrB,oBAAoB,gBAAgB,CAAC;AAAA,QACrC,mBAAmB,UAAU,CAAC;AAAA,MAAA;AAAA,IAChC;AAAA,EAEJ,CAAC;AAED,SAAO,OAAO,YAAY,CAAC,MAAM,EAAE,WAAW,iBAAiB;AACjE;AAEA,SAAS,OAAO,MAAM,UAAyB;AAC7C,SAAO,KAAK,KAAK,CAAC,GAAG,MAAM,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC;AACtD;;;;"}
@@ -1,62 +0,0 @@
1
- import { LineString, Point } from 'geojson';
2
- import { StoreApi } from 'zustand';
3
- import { ColumnGeoJSONRecord } from '@macrostrat/api-types';
4
- import { ReactNode } from 'react';
5
- export type CorrelationSelectionMode = "line" | "manual";
6
- export interface CorrelationMapInput {
7
- columns: ColumnGeoJSONRecord[];
8
- focusedLine: LineString | null;
9
- /** When set, columns are selected manually (by clicking) in this order,
10
- * rather than derived from a line of section. */
11
- manualColumns?: number[] | null;
12
- }
13
- export interface CorrelationMapStore extends CorrelationMapInput {
14
- onClickMap: (event: mapboxgl.MapMouseEvent, point: Point) => void;
15
- /** Toggle a column in/out of the manual selection (used in "manual" mode) */
16
- toggleColumn: (colID: number) => void;
17
- /** Remove a column from the selection. In "line" mode this converts the
18
- * current selection to a manual one (a line can't represent an arbitrary
19
- * subset), so removing a column switches modes. */
20
- removeColumn: (colID: number) => void;
21
- /** Replace the manual column selection with an explicit ordered list (used
22
- * e.g. for drag-and-drop reordering). Switches to manual mode. */
23
- setManualColumns: (colIDs: number[]) => void;
24
- setHoveredColumn: (colID: number | null) => void;
25
- hoveredColumn: number | null;
26
- /** Request the map to frame a particular column (e.g. on header click). */
27
- zoomToColumn: (colID: number | null) => void;
28
- zoomColumn: number | null;
29
- /** Incremented on each zoom request so repeat clicks re-frame the column. */
30
- zoomNonce: number;
31
- projectID?: number;
32
- }
33
- export interface CorrelationProviderProps extends CorrelationMapInput {
34
- projectID?: number;
35
- inProcess?: boolean;
36
- columns: ColumnGeoJSONRecord[] | null;
37
- children: ReactNode;
38
- onSelectColumns?: (columns: FocusedColumnGeoJSONRecord[], line: LineString | null) => void;
39
- }
40
- type ComputedStore = {
41
- focusedColumns: FocusedColumnGeoJSONRecord[];
42
- selectionMode: CorrelationSelectionMode;
43
- };
44
- export declare function ColumnCorrelationProvider({ children, columns, projectID, inProcess, focusedLine, manualColumns, onSelectColumns, }: CorrelationProviderProps): import('react').FunctionComponentElement<import('react').ProviderProps<StoreApi<CorrelationMapStore> | null>>;
45
- export declare function useCorrelationMapStore(selector: (state: CorrelationMapStore & ComputedStore) => any): any;
46
- export interface ColumnMapLink {
47
- onColumnMouseOver: (colID: number | null) => void;
48
- onColumnClick: (colID: number) => void;
49
- }
50
- /** Wire a correlation chart's column-level events to the correlation map:
51
- * hovering a column highlights it on the map, and clicking a column header
52
- * frames it. Spread the result into `CorrelationChart`. Must be used within a
53
- * `ColumnCorrelationProvider`. */
54
- export declare function useColumnMapLink(): ColumnMapLink;
55
- interface FocusedColumnGeoJSONRecord extends ColumnGeoJSONRecord {
56
- properties: {
57
- centroid: Point;
58
- nearestPointOnLine: Point;
59
- distanceAlongLine: number;
60
- } & ColumnGeoJSONRecord["properties"];
61
- }
62
- export {};
@@ -1,190 +0,0 @@
1
- import { create, useStore } from "zustand";
2
- import { lineIntersect } from "@turf/line-intersect";
3
- import distance from "@turf/distance";
4
- import { nearestPointOnLine } from "@turf/nearest-point-on-line";
5
- import { centroid } from "@turf/centroid";
6
- import { useState, useEffect, useContext, createContext } from "react";
7
- import h from "@macrostrat/hyper";
8
- import { createComputed } from "zustand-computed";
9
- import { useMacrostratColumns } from "@macrostrat/data-provider";
10
- import { buffer } from "@turf/buffer";
11
- import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
12
- const CorrelationStoreContext = createContext(null);
13
- const computed = createComputed((state) => {
14
- const manual = state.manualColumns != null;
15
- return {
16
- selectionMode: manual ? "manual" : "line",
17
- // Focused columns are derived either from an explicit manual selection or
18
- // from the columns intersecting the line of section.
19
- focusedColumns: manual ? buildManualColumns(state.columns, state.manualColumns) : buildCorrelationColumns(state.columns, state.focusedLine)
20
- };
21
- });
22
- function ColumnCorrelationProvider({
23
- children,
24
- columns,
25
- projectID,
26
- inProcess,
27
- focusedLine,
28
- manualColumns = null,
29
- onSelectColumns
30
- }) {
31
- const [store] = useState(() => {
32
- return create(
33
- computed((set, get) => {
34
- return {
35
- focusedLine,
36
- manualColumns,
37
- hoveredColumn: null,
38
- zoomColumn: null,
39
- zoomNonce: 0,
40
- projectID,
41
- columns: null,
42
- onClickMap(event, point) {
43
- const state = get();
44
- if (state.manualColumns != null) return;
45
- const shiftKeyPressed = event.originalEvent.shiftKey;
46
- let existingCoords = state.focusedLine?.coordinates ?? [];
47
- if (existingCoords.length >= 2 && !shiftKeyPressed) {
48
- existingCoords = [];
49
- }
50
- set({
51
- focusedLine: {
52
- type: "LineString",
53
- coordinates: [...existingCoords, point.coordinates]
54
- }
55
- });
56
- },
57
- toggleColumn(colID) {
58
- const state = get();
59
- const current = state.manualColumns ?? state.focusedColumns.map((d) => d.properties.col_id);
60
- const next = current.includes(colID) ? current.filter((d) => d !== colID) : [...current, colID];
61
- set({ manualColumns: next, focusedLine: null });
62
- },
63
- removeColumn(colID) {
64
- const state = get();
65
- const current = state.manualColumns ?? state.focusedColumns.map((d) => d.properties.col_id);
66
- set({
67
- manualColumns: current.filter((d) => d !== colID),
68
- focusedLine: null
69
- });
70
- },
71
- setManualColumns(colIDs) {
72
- set({ manualColumns: colIDs, focusedLine: null });
73
- },
74
- setHoveredColumn(colID) {
75
- set({ hoveredColumn: colID });
76
- },
77
- zoomToColumn(colID) {
78
- set({ zoomColumn: colID, zoomNonce: get().zoomNonce + 1 });
79
- }
80
- };
81
- })
82
- );
83
- });
84
- const _columns = useMacrostratColumns(projectID, inProcess);
85
- useEffect(() => {
86
- if (_columns != null) {
87
- store.setState({ columns: _columns });
88
- }
89
- }, [_columns]);
90
- const focusedColumns = useStore(store, (state) => state.focusedColumns);
91
- const _focusedLine = useStore(store, (state) => state.focusedLine);
92
- useEffect(() => {
93
- onSelectColumns?.(focusedColumns, _focusedLine);
94
- }, [focusedColumns, _focusedLine]);
95
- return h(CorrelationStoreContext.Provider, { value: store }, children);
96
- }
97
- function useCorrelationMapStore(selector) {
98
- const storeApi = useContext(CorrelationStoreContext);
99
- if (storeApi == null) {
100
- throw new Error("Missing CorrelationMapProvider");
101
- }
102
- return useStore(storeApi, selector);
103
- }
104
- function useColumnMapLink() {
105
- const setHoveredColumn = useCorrelationMapStore((s) => s.setHoveredColumn);
106
- const zoomToColumn = useCorrelationMapStore((s) => s.zoomToColumn);
107
- return {
108
- onColumnMouseOver: setHoveredColumn,
109
- onColumnClick: zoomToColumn
110
- };
111
- }
112
- function buildCorrelationColumns(columns, line) {
113
- if (columns == null || line == null || line.coordinates.length < 2) {
114
- return [];
115
- }
116
- return orderColumnsByDistance(
117
- computeIntersectingColumns(columns, line),
118
- line
119
- );
120
- }
121
- function buildManualColumns(columns, ids) {
122
- if (columns == null || ids == null) return [];
123
- const byID = new Map(columns.map((c) => [c.properties.col_id, c]));
124
- const result = [];
125
- ids.forEach((id, i) => {
126
- const col = byID.get(id);
127
- if (col == null) return;
128
- const c = centroid(col.geometry);
129
- result.push({
130
- ...col,
131
- properties: {
132
- ...col.properties,
133
- centroid: c,
134
- nearestPointOnLine: c,
135
- distanceAlongLine: i
136
- }
137
- });
138
- });
139
- return result;
140
- }
141
- function computeIntersectingColumns(columns, line) {
142
- if (columns == null || line == null) {
143
- return [];
144
- }
145
- const bufferedLine = buffer(line, 1, { units: "degrees" });
146
- const nearbyPoints = columns.filter((col) => {
147
- if (col.geometry?.type != "Point") {
148
- return false;
149
- }
150
- return booleanPointInPolygon(col.geometry, bufferedLine);
151
- });
152
- const intersectingPolygons = columns.filter((col) => {
153
- const poly = col.geometry;
154
- if (poly == null) return false;
155
- if (poly.type != "Polygon" && poly.type != "MultiPolygon") return false;
156
- const intersection = lineIntersect(line, poly);
157
- return intersection.features.length > 0;
158
- });
159
- return [...intersectingPolygons, ...nearbyPoints];
160
- }
161
- function orderColumnsByDistance(columns, line) {
162
- const centroids = columns.map((col) => centroid(col.geometry));
163
- const projectedPoints = centroids.map(
164
- (point) => nearestPointOnLine(line, point)
165
- );
166
- const distances = projectedPoints.map(
167
- (point) => distance(point.geometry.coordinates, line.coordinates[0])
168
- );
169
- let newColumns = columns.map((col, i) => {
170
- return {
171
- ...col,
172
- properties: {
173
- ...col.properties,
174
- centroid: centroids[i],
175
- nearestPointOnLine: projectedPoints[i],
176
- distanceAlongLine: distances[i]
177
- }
178
- };
179
- });
180
- return sorted(newColumns, (d) => d.properties.distanceAlongLine);
181
- }
182
- function sorted(data, accessor) {
183
- return data.sort((a, b) => accessor(a) - accessor(b));
184
- }
185
- export {
186
- ColumnCorrelationProvider,
187
- useColumnMapLink,
188
- useCorrelationMapStore
189
- };
190
- //# sourceMappingURL=state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.js","sources":["../../../src/maps/column-correlation/state.ts"],"sourcesContent":["import { LineString, Point } from \"geojson\";\nimport { create, StoreApi, useStore } from \"zustand\";\nimport type { ColumnGeoJSONRecord } from \"@macrostrat/api-types\";\n// Turf intersection\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport distance from \"@turf/distance\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { centroid } from \"@turf/centroid\";\nimport {\n createContext,\n useState,\n useContext,\n ReactNode,\n useEffect,\n} from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { createComputed } from \"zustand-computed\";\nimport { useMacrostratColumns } from \"@macrostrat/data-provider\";\nimport { buffer } from \"@turf/buffer\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\n\nexport type CorrelationSelectionMode = \"line\" | \"manual\";\n\nexport interface CorrelationMapInput {\n columns: ColumnGeoJSONRecord[];\n focusedLine: LineString | null;\n /** When set, columns are selected manually (by clicking) in this order,\n * rather than derived from a line of section. */\n manualColumns?: number[] | null;\n}\n\nexport interface CorrelationMapStore extends CorrelationMapInput {\n onClickMap: (event: mapboxgl.MapMouseEvent, point: Point) => void;\n /** Toggle a column in/out of the manual selection (used in \"manual\" mode) */\n toggleColumn: (colID: number) => void;\n /** Remove a column from the selection. In \"line\" mode this converts the\n * current selection to a manual one (a line can't represent an arbitrary\n * subset), so removing a column switches modes. */\n removeColumn: (colID: number) => void;\n /** Replace the manual column selection with an explicit ordered list (used\n * e.g. for drag-and-drop reordering). Switches to manual mode. */\n setManualColumns: (colIDs: number[]) => void;\n setHoveredColumn: (colID: number | null) => void;\n hoveredColumn: number | null;\n /** Request the map to frame a particular column (e.g. on header click). */\n zoomToColumn: (colID: number | null) => void;\n zoomColumn: number | null;\n /** Incremented on each zoom request so repeat clicks re-frame the column. */\n zoomNonce: number;\n projectID?: number;\n}\n\nexport interface CorrelationProviderProps extends CorrelationMapInput {\n projectID?: number;\n inProcess?: boolean;\n columns: ColumnGeoJSONRecord[] | null;\n children: ReactNode;\n onSelectColumns?: (\n columns: FocusedColumnGeoJSONRecord[],\n line: LineString | null,\n ) => void;\n}\n\nconst CorrelationStoreContext =\n createContext<StoreApi<CorrelationMapStore> | null>(null);\n\ntype ComputedStore = {\n focusedColumns: FocusedColumnGeoJSONRecord[];\n selectionMode: CorrelationSelectionMode;\n};\n\n/** A computed store that will automatically update when the state changes */\nconst computed = createComputed((state: CorrelationMapStore): ComputedStore => {\n const manual = state.manualColumns != null;\n return {\n selectionMode: manual ? \"manual\" : \"line\",\n // Focused columns are derived either from an explicit manual selection or\n // from the columns intersecting the line of section.\n focusedColumns: manual\n ? buildManualColumns(state.columns, state.manualColumns)\n : buildCorrelationColumns(state.columns, state.focusedLine),\n };\n}) as any;\n\nexport function ColumnCorrelationProvider({\n children,\n columns,\n projectID,\n inProcess,\n focusedLine,\n manualColumns = null,\n onSelectColumns,\n}: CorrelationProviderProps) {\n const [store] = useState(() => {\n return create<CorrelationMapStore & ComputedStore>(\n computed((set, get): CorrelationMapStore => {\n return {\n focusedLine,\n manualColumns,\n hoveredColumn: null,\n zoomColumn: null,\n zoomNonce: 0,\n projectID,\n columns: null,\n onClickMap(event: mapboxgl.MapMouseEvent, point: Point) {\n const state = get();\n // In manual-selection mode the map click is handled per-column\n if (state.manualColumns != null) return;\n // Check if shift key is pressed\n const shiftKeyPressed = event.originalEvent.shiftKey;\n let existingCoords = state.focusedLine?.coordinates ?? [];\n\n if (existingCoords.length >= 2 && !shiftKeyPressed) {\n // Reset the line to zero length\n existingCoords = [];\n }\n set({\n focusedLine: {\n type: \"LineString\",\n coordinates: [...existingCoords, point.coordinates],\n },\n });\n },\n toggleColumn(colID: number) {\n const state = get();\n const current =\n state.manualColumns ??\n state.focusedColumns.map((d) => d.properties.col_id);\n const next = current.includes(colID)\n ? current.filter((d) => d !== colID)\n : [...current, colID];\n set({ manualColumns: next, focusedLine: null });\n },\n removeColumn(colID: number) {\n const state = get();\n // Seed from the current selection (line-derived or manual)\n const current =\n state.manualColumns ??\n state.focusedColumns.map((d) => d.properties.col_id);\n set({\n manualColumns: current.filter((d) => d !== colID),\n focusedLine: null,\n });\n },\n setManualColumns(colIDs: number[]) {\n set({ manualColumns: colIDs, focusedLine: null });\n },\n setHoveredColumn(colID: number | null) {\n set({ hoveredColumn: colID });\n },\n zoomToColumn(colID: number | null) {\n set({ zoomColumn: colID, zoomNonce: get().zoomNonce + 1 });\n },\n };\n }),\n );\n });\n\n // Set up the store\n /** TODO: move the fetching of all columns to within the map */\n const _columns = useMacrostratColumns(projectID, inProcess);\n useEffect(() => {\n if (_columns != null) {\n store.setState({ columns: _columns });\n }\n }, [_columns]);\n\n // Kind of an awkward way to do this but we need to allow the selector to run\n const focusedColumns = useStore(store, (state) => state.focusedColumns);\n const _focusedLine = useStore(store, (state) => state.focusedLine);\n\n useEffect(() => {\n onSelectColumns?.(focusedColumns, _focusedLine);\n }, [focusedColumns, _focusedLine]);\n\n return h(CorrelationStoreContext.Provider, { value: store }, children);\n}\n\nexport function useCorrelationMapStore(\n selector: (state: CorrelationMapStore & ComputedStore) => any,\n) {\n const storeApi = useContext(CorrelationStoreContext);\n if (storeApi == null) {\n throw new Error(\"Missing CorrelationMapProvider\");\n }\n return useStore(storeApi, selector);\n}\n\nexport interface ColumnMapLink {\n onColumnMouseOver: (colID: number | null) => void;\n onColumnClick: (colID: number) => void;\n}\n\n/** Wire a correlation chart's column-level events to the correlation map:\n * hovering a column highlights it on the map, and clicking a column header\n * frames it. Spread the result into `CorrelationChart`. Must be used within a\n * `ColumnCorrelationProvider`. */\nexport function useColumnMapLink(): ColumnMapLink {\n const setHoveredColumn = useCorrelationMapStore((s) => s.setHoveredColumn);\n const zoomToColumn = useCorrelationMapStore((s) => s.zoomToColumn);\n return {\n onColumnMouseOver: setHoveredColumn,\n onColumnClick: zoomToColumn,\n };\n}\n\nfunction buildCorrelationColumns(\n columns: ColumnGeoJSONRecord[],\n line: LineString,\n): FocusedColumnGeoJSONRecord[] {\n if (columns == null || line == null || line.coordinates.length < 2) {\n return [];\n }\n return orderColumnsByDistance(\n computeIntersectingColumns(columns, line),\n line,\n );\n}\n\nfunction buildManualColumns(\n columns: ColumnGeoJSONRecord[],\n ids: number[],\n): FocusedColumnGeoJSONRecord[] {\n /** Build focused columns from an explicit, ordered list of column IDs. The\n * ordering line simply connects them in the order they were selected. */\n if (columns == null || ids == null) return [];\n const byID = new Map(columns.map((c) => [c.properties.col_id, c]));\n const result: FocusedColumnGeoJSONRecord[] = [];\n ids.forEach((id, i) => {\n const col = byID.get(id);\n if (col == null) return;\n const c = centroid(col.geometry);\n result.push({\n ...col,\n properties: {\n ...col.properties,\n centroid: c,\n nearestPointOnLine: c,\n distanceAlongLine: i,\n },\n });\n });\n return result;\n}\n\nfunction computeIntersectingColumns(\n columns: ColumnGeoJSONRecord[],\n line: LineString,\n): ColumnGeoJSONRecord[] {\n if (columns == null || line == null) {\n return [];\n }\n\n /** eODP-focused process. Find buffers around line and then find columns intersecting that buffer */\n const bufferedLine = buffer(line, 1, { units: \"degrees\" });\n\n const nearbyPoints = columns.filter((col) => {\n if (col.geometry?.type != \"Point\") {\n return false;\n }\n return booleanPointInPolygon(col.geometry, bufferedLine);\n });\n\n const intersectingPolygons = columns.filter((col) => {\n const poly = col.geometry;\n\n // Some in-process datasets seem to have null geometries\n if (poly == null) return false;\n if (poly.type != \"Polygon\" && poly.type != \"MultiPolygon\") return false;\n\n const intersection = lineIntersect(line, poly);\n return intersection.features.length > 0;\n });\n\n return [...intersectingPolygons, ...nearbyPoints];\n}\n\ninterface FocusedColumnGeoJSONRecord extends ColumnGeoJSONRecord {\n properties: {\n centroid: Point;\n nearestPointOnLine: Point;\n distanceAlongLine: number;\n } & ColumnGeoJSONRecord[\"properties\"];\n}\n\nfunction orderColumnsByDistance(\n columns: ColumnGeoJSONRecord[],\n line: LineString,\n): FocusedColumnGeoJSONRecord[] {\n const centroids = columns.map((col) => centroid(col.geometry));\n const projectedPoints = centroids.map((point) =>\n nearestPointOnLine(line, point),\n );\n const distances = projectedPoints.map((point) =>\n distance(point.geometry.coordinates, line.coordinates[0]),\n );\n\n let newColumns = columns.map((col, i) => {\n return {\n ...col,\n properties: {\n ...col.properties,\n centroid: centroids[i],\n nearestPointOnLine: projectedPoints[i],\n distanceAlongLine: distances[i],\n },\n };\n });\n\n return sorted(newColumns, (d) => d.properties.distanceAlongLine);\n}\n\nfunction sorted(data, accessor: (d) => number) {\n return data.sort((a, b) => accessor(a) - accessor(b));\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA+DA,MAAM,0BACJ,cAAoD,IAAI;AAQ1D,MAAM,WAAW,eAAe,CAAC,UAA8C;AAC7E,QAAM,SAAS,MAAM,iBAAiB;AACtC,SAAO;AAAA,IACL,eAAe,SAAS,WAAW;AAAA;AAAA;AAAA,IAGnC,gBAAgB,SACZ,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