@macrostrat/column-views 3.9.0 → 3.10.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 (118) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/index.cjs +15 -42
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +1 -34
  6. package/dist/index.js.map +1 -1
  7. package/dist/units/boxes.cjs +3 -3
  8. package/dist/units/boxes.cjs.map +1 -1
  9. package/dist/units/boxes.js +3 -3
  10. package/dist/units/boxes.js.map +1 -1
  11. package/dist/units/index.cjs +7 -11
  12. package/dist/units/index.cjs.map +1 -1
  13. package/dist/units/index.d.ts +0 -1
  14. package/dist/units/index.js +4 -9
  15. package/dist/units/index.js.map +1 -1
  16. package/package.json +6 -27
  17. package/src/index.ts +3 -1
  18. package/src/units/boxes.ts +7 -4
  19. package/src/units/index.ts +9 -26
  20. package/dist/maps/column-correlation/core.cjs +0 -288
  21. package/dist/maps/column-correlation/core.cjs.map +0 -1
  22. package/dist/maps/column-correlation/core.d.ts +0 -9
  23. package/dist/maps/column-correlation/core.js +0 -286
  24. package/dist/maps/column-correlation/core.js.map +0 -1
  25. package/dist/maps/column-correlation/index.d.ts +0 -2
  26. package/dist/maps/column-correlation/state.cjs +0 -193
  27. package/dist/maps/column-correlation/state.cjs.map +0 -1
  28. package/dist/maps/column-correlation/state.d.ts +0 -62
  29. package/dist/maps/column-correlation/state.js +0 -190
  30. package/dist/maps/column-correlation/state.js.map +0 -1
  31. package/dist/maps/column-navigation/index.d.ts +0 -2
  32. package/dist/maps/column-navigation/mapbox/index.cjs +0 -215
  33. package/dist/maps/column-navigation/mapbox/index.cjs.map +0 -1
  34. package/dist/maps/column-navigation/mapbox/index.d.ts +0 -38
  35. package/dist/maps/column-navigation/mapbox/index.js +0 -213
  36. package/dist/maps/column-navigation/mapbox/index.js.map +0 -1
  37. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs +0 -105
  38. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs.map +0 -1
  39. package/dist/maps/column-navigation/mapbox/keyboard-navigation.d.ts +0 -8
  40. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js +0 -105
  41. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js.map +0 -1
  42. package/dist/maps/column-navigation/mapbox/state.cjs +0 -73
  43. package/dist/maps/column-navigation/mapbox/state.cjs.map +0 -1
  44. package/dist/maps/column-navigation/mapbox/state.d.ts +0 -23
  45. package/dist/maps/column-navigation/mapbox/state.js +0 -71
  46. package/dist/maps/column-navigation/mapbox/state.js.map +0 -1
  47. package/dist/maps/column-navigation/svg/animated.d.ts +0 -1
  48. package/dist/maps/column-navigation/svg/data-fetcher.cjs +0 -25
  49. package/dist/maps/column-navigation/svg/data-fetcher.cjs.map +0 -1
  50. package/dist/maps/column-navigation/svg/data-fetcher.d.ts +0 -6
  51. package/dist/maps/column-navigation/svg/data-fetcher.js +0 -25
  52. package/dist/maps/column-navigation/svg/data-fetcher.js.map +0 -1
  53. package/dist/maps/column-navigation/svg/index.cjs +0 -94
  54. package/dist/maps/column-navigation/svg/index.cjs.map +0 -1
  55. package/dist/maps/column-navigation/svg/index.d.ts +0 -9
  56. package/dist/maps/column-navigation/svg/index.js +0 -93
  57. package/dist/maps/column-navigation/svg/index.js.map +0 -1
  58. package/dist/maps/column-navigation/svg/layers.cjs +0 -177
  59. package/dist/maps/column-navigation/svg/layers.cjs.map +0 -1
  60. package/dist/maps/column-navigation/svg/layers.d.ts +0 -54
  61. package/dist/maps/column-navigation/svg/layers.js +0 -174
  62. package/dist/maps/column-navigation/svg/layers.js.map +0 -1
  63. package/dist/maps/column-navigation/utils/keyboard-navigation.cjs +0 -50
  64. package/dist/maps/column-navigation/utils/keyboard-navigation.cjs.map +0 -1
  65. package/dist/maps/column-navigation/utils/keyboard-navigation.d.ts +0 -10
  66. package/dist/maps/column-navigation/utils/keyboard-navigation.js +0 -50
  67. package/dist/maps/column-navigation/utils/keyboard-navigation.js.map +0 -1
  68. package/dist/maps/index.d.ts +0 -4
  69. package/dist/maps/inset-map/index.cjs +0 -71
  70. package/dist/maps/inset-map/index.cjs.map +0 -1
  71. package/dist/maps/inset-map/index.d.ts +0 -16
  72. package/dist/maps/inset-map/index.js +0 -69
  73. package/dist/maps/inset-map/index.js.map +0 -1
  74. package/dist/maps/layers/columns.cjs +0 -165
  75. package/dist/maps/layers/columns.cjs.map +0 -1
  76. package/dist/maps/layers/columns.d.ts +0 -28
  77. package/dist/maps/layers/columns.js +0 -165
  78. package/dist/maps/layers/columns.js.map +0 -1
  79. package/dist/maps/layers/index.d.ts +0 -2
  80. package/dist/maps/layers/units.cjs +0 -207
  81. package/dist/maps/layers/units.cjs.map +0 -1
  82. package/dist/maps/layers/units.d.ts +0 -14
  83. package/dist/maps/layers/units.js +0 -204
  84. package/dist/maps/layers/units.js.map +0 -1
  85. package/dist/units/colors.cjs +0 -115
  86. package/dist/units/colors.cjs.map +0 -1
  87. package/dist/units/colors.d.ts +0 -20
  88. package/dist/units/colors.js +0 -113
  89. package/dist/units/colors.js.map +0 -1
  90. package/dist/units/resolvers.cjs +0 -125
  91. package/dist/units/resolvers.cjs.map +0 -1
  92. package/dist/units/resolvers.d.ts +0 -8
  93. package/dist/units/resolvers.js +0 -125
  94. package/dist/units/resolvers.js.map +0 -1
  95. package/src/maps/column-correlation/column-correlation-map.stories.ts +0 -108
  96. package/src/maps/column-correlation/core.ts +0 -342
  97. package/src/maps/column-correlation/index.ts +0 -2
  98. package/src/maps/column-correlation/state.ts +0 -315
  99. package/src/maps/column-navigation/index.ts +0 -2
  100. package/src/maps/column-navigation/mapbox/column-navigation-map.stories.ts +0 -278
  101. package/src/maps/column-navigation/mapbox/index.ts +0 -276
  102. package/src/maps/column-navigation/mapbox/keyboard-navigation.ts +0 -133
  103. package/src/maps/column-navigation/mapbox/state.ts +0 -119
  104. package/src/maps/column-navigation/svg/animated.ts +0 -78
  105. package/src/maps/column-navigation/svg/column-navigation-svg-map.stories.ts +0 -46
  106. package/src/maps/column-navigation/svg/data-fetcher.ts +0 -34
  107. package/src/maps/column-navigation/svg/index.ts +0 -96
  108. package/src/maps/column-navigation/svg/layers.ts +0 -233
  109. package/src/maps/column-navigation/utils/keyboard-navigation.ts +0 -58
  110. package/src/maps/index.ts +0 -4
  111. package/src/maps/inset-map/index.ts +0 -87
  112. package/src/maps/inset-map/inset-map.stories.ts +0 -20
  113. package/src/maps/layers/columns.ts +0 -216
  114. package/src/maps/layers/index.ts +0 -2
  115. package/src/maps/layers/units.ts +0 -286
  116. package/src/maps/unit-map.stories.ts +0 -79
  117. package/src/units/colors.ts +0 -183
  118. package/src/units/resolvers.ts +0 -141
@@ -1,276 +0,0 @@
1
- import { useMapRef, useMapStyleOperator } from "@macrostrat/mapbox-react";
2
- import h from "@macrostrat/hyper";
3
- import { ReactNode, useCallback, useEffect, useMemo, useRef } from "react";
4
-
5
- import {
6
- ColumnNavigationProvider,
7
- NavigationProviderProps,
8
- useColumnNavigationStore,
9
- } from "./state";
10
- import { InsetMap, type InsetMapProps } from "../../inset-map";
11
- import { geoCentroid } from "d3-geo";
12
- import { BaseColumnsLayer, SelectedColumnOverlay } from "../../layers";
13
- import { ColumnKeyboardNavigation } from "./keyboard-navigation";
14
- import type { ColumnFeature } from "../../layers";
15
-
16
- export interface ColumnNavigationMapProps extends InsetMapProps {
17
- padding?: number;
18
- children?: ReactNode;
19
- accessToken?: string;
20
- selectedColumn?: number;
21
- hoveredColumn?: number;
22
- onSelectColumn?: (colID: number | null) => void;
23
- onHoverColumn?: (colID: number | null) => void;
24
- showTriangulation?: boolean;
25
- columnColor?: string;
26
- }
27
-
28
- export function ColumnNavigationMap(
29
- props: ColumnNavigationMapProps & NavigationProviderProps,
30
- ) {
31
- const {
32
- padding = 50,
33
- children,
34
- columnColor,
35
- showTriangulation,
36
- triangulationColor,
37
- keyboardNavigation = true,
38
- columns,
39
- columnIDs,
40
- onSelectColumn,
41
- onHoverColumn,
42
- selectedColumn,
43
- hoveredColumn,
44
- projectID,
45
- inProcess,
46
- ...rest
47
- } = props;
48
-
49
- return h(
50
- InsetMap,
51
- {
52
- ...rest,
53
- boxZoom: false,
54
- dragRotate: false,
55
- },
56
- [
57
- h(ColumnsNavigationLayer, {
58
- color: columnColor,
59
- columns,
60
- columnIDs,
61
- onSelectColumn,
62
- onHoverColumn,
63
- selectedColumn,
64
- hoveredColumn,
65
- projectID,
66
- inProcess,
67
- keyboardNavigation,
68
- showTriangulation,
69
- triangulationColor,
70
- }),
71
- children,
72
- ],
73
- );
74
- }
75
-
76
- interface ColumnLayerProps {
77
- enabled?: boolean;
78
- color?: string;
79
- }
80
-
81
- interface ColumnKeyboardNavigationProps {
82
- triangulationColor?: string;
83
- keyboardNavigation?: boolean;
84
- showTriangulation?: boolean;
85
- }
86
-
87
- export function ColumnsNavigationLayer(
88
- props: NavigationProviderProps &
89
- ColumnLayerProps &
90
- ColumnKeyboardNavigationProps,
91
- ) {
92
- const {
93
- enabled,
94
- color,
95
- keyboardNavigation,
96
- showTriangulation,
97
- triangulationColor,
98
- ...providerProps
99
- } = props;
100
-
101
- return h(ColumnNavigationProvider, providerProps, [
102
- h(_ColumnsNavigationLayer, { enabled, color }),
103
- h.if(keyboardNavigation)(ColumnKeyboardNavigation, {
104
- showTriangulation,
105
- triangulationColor,
106
- }),
107
- ]);
108
- }
109
-
110
- const columnLayers = ["columns-points", "columns-fill"];
111
-
112
- function _ColumnsNavigationLayer({ enabled = true, color }) {
113
- const columns = useColumnNavigationStore((state) => state.columns);
114
- const selectedColumnID = useColumnNavigationStore(
115
- (state) => state.selectedColumn,
116
- );
117
- const selectColumn = useColumnNavigationStore((state) => state.selectColumn);
118
- const setHoveredColumn = useColumnNavigationStore(
119
- (state) => state.setHoveredColumn,
120
- );
121
-
122
- const onHover = useCallback(
123
- (event) => setHoveredColumn(event.features?.[0]?.id),
124
- [setHoveredColumn],
125
- );
126
-
127
- /** Convert features into column IDs to pass to the selection manager */
128
- const onSelectColumn = useCallback(
129
- (column) => selectColumn(column.id),
130
- [selectColumn],
131
- );
132
-
133
- const selectedColumnFeature = useMemo(() => {
134
- if (columns == null || selectedColumnID == null) return null;
135
- return columns.find((d) => d.id == selectedColumnID);
136
- }, [selectedColumnID, columns]);
137
-
138
- return h([
139
- h(BaseColumnsLayer, { enabled, color, columns }),
140
- h(ColumnSelectionManager, {
141
- selectedColumn: selectedColumnFeature,
142
- onSelectColumn,
143
- }),
144
- h(ColumnHoverInteraction, { onHover }),
145
- ]);
146
- }
147
-
148
- export function ColumnSelectionManager({
149
- selectedColumn,
150
- onSelectColumn,
151
- centerOnSelect = true,
152
- }: {
153
- selectedColumn: ColumnFeature;
154
- onSelectColumn: (column: ColumnFeature) => void;
155
- centerOnSelect?: boolean;
156
- }) {
157
- const onClick = useCallback(
158
- (event) => {
159
- if (event.features.length == 0) return;
160
- const selectedColumn = event.features[0];
161
- onSelectColumn(selectedColumn);
162
- },
163
- [onSelectColumn],
164
- );
165
-
166
- return h([
167
- h.if(centerOnSelect)(SelectedColumnCenterer, {
168
- selectedColumn,
169
- }),
170
- h(SelectedColumnOverlay, { selectedColumn }),
171
- h(ClickInteraction, {
172
- onClick,
173
- layers: columnLayers,
174
- }),
175
- ]);
176
- }
177
-
178
- export function ColumnHoverInteraction({ onHover }) {
179
- return h(HoverInteraction, { onHover, layers: columnLayers });
180
- }
181
-
182
- function ClickInteraction({ onClick, layers }) {
183
- useMapStyleOperator(
184
- (map) => {
185
- // Setup hover styles on map
186
- map.on("click", layers, onClick);
187
- return () => {
188
- map.off("click", layers, onClick);
189
- };
190
- },
191
- [layers, onClick],
192
- );
193
- return null;
194
- }
195
-
196
- function HoverInteraction({ onHover, layers }) {
197
- const hoveredFeaturesRef = useRef([]);
198
- const updateFeatureState = useCallback((map, features) => {
199
- // Reset hover state for previously hovered features
200
- for (const f of hoveredFeaturesRef.current) {
201
- map.setFeatureState(
202
- { source: f.source, id: f.id, sourceLayer: f.sourceLayer },
203
- { hover: false },
204
- );
205
- }
206
- // Set hover state for new features
207
- for (const f of features) {
208
- map.setFeatureState(
209
- { source: f.source, id: f.id, sourceLayer: f.sourceLayer },
210
- { hover: true },
211
- );
212
- }
213
- hoveredFeaturesRef.current = features;
214
- }, []);
215
-
216
- useMapStyleOperator(
217
- (map) => {
218
- const mouseMove = (event) => {
219
- if (event.features.length == 0) return;
220
- onHover?.(event);
221
- updateFeatureState(map, event.features);
222
- map.getCanvas().style.cursor = "pointer";
223
- };
224
- const mouseLeave = (event) => {
225
- onHover?.(event);
226
- updateFeatureState(map, event.features ?? []);
227
- map.getCanvas().style.cursor = "";
228
- };
229
-
230
- // Setup hover styles on map
231
- map.on("mousemove", layers, mouseMove);
232
- map.on("mouseleave", layers, mouseLeave);
233
-
234
- return () => {
235
- map.off("mouseenter", layers, mouseMove);
236
- map.off("mouseleave", layers, mouseLeave);
237
- };
238
- },
239
- [layers, onHover],
240
- );
241
- return null;
242
- }
243
-
244
- function SelectedColumnCenterer({
245
- selectedColumn,
246
- easeDuration = 500,
247
- }: {
248
- selectedColumn: ColumnFeature;
249
- easeDuration?: number;
250
- }) {
251
- const columnCenter = useMemo(() => {
252
- const columnGeometry = selectedColumn?.geometry;
253
- if (columnGeometry == null) return null;
254
- return geoCentroid(columnGeometry);
255
- }, [selectedColumn]);
256
-
257
- const mapRef = useMapRef();
258
- const map = mapRef.current;
259
- const initialRenderRef = useRef(true);
260
- // Center the map on the selected column when it changes
261
- useEffect(() => {
262
- if (map == null) return;
263
- const isInitialRender = initialRenderRef.current;
264
- if (isInitialRender) initialRenderRef.current = false;
265
- // If this is the first render of the map, jump to the location. Otherwise, ease to it.
266
- if (columnCenter == null) return;
267
- if (isInitialRender) {
268
- map.setCenter(columnCenter);
269
- initialRenderRef.current = false;
270
- } else {
271
- map.easeTo({ center: columnCenter }, { duration: easeDuration });
272
- }
273
- }, [mapRef.current, columnCenter]);
274
-
275
- return null;
276
- }
@@ -1,133 +0,0 @@
1
- import { useCallback, useEffect, useMemo } from "react";
2
- import { buildGeoJSONSource, setGeoJSON } from "@macrostrat/mapbox-utils";
3
- import {
4
- useMapRef,
5
- useMapStyleOperator,
6
- useOverlayStyle,
7
- } from "@macrostrat/mapbox-react";
8
- import { useColumnNavigationStore } from "./state";
9
- import {
10
- buildTriangulation,
11
- buildKeyMapping,
12
- } from "../utils/keyboard-navigation";
13
- import { StyleSpecification } from "mapbox-gl";
14
-
15
- interface KeyboardNavProps {
16
- showTriangulation: boolean;
17
- triangulationColor?: string;
18
- }
19
-
20
- export function ColumnKeyboardNavigation(props: KeyboardNavProps) {
21
- /** Keyboard navigation of columns using a Delaunay triangulation */
22
- const { showTriangulation = false, triangulationColor } = props;
23
- const columns = useColumnNavigationStore((state) => state.columns);
24
- const col_id = useColumnNavigationStore((state) => state.selectedColumn);
25
- const selectColumn = useColumnNavigationStore((state) => state.selectColumn);
26
-
27
- const voronoi = useMemo(() => {
28
- if (!columns || columns.length == 0) return null;
29
- return buildTriangulation(columns);
30
- }, [columns]);
31
-
32
- const mapRef = useMapRef();
33
- const map = mapRef.current;
34
-
35
- // Set up overlay style for triangulation
36
- useOverlayStyle(() => {
37
- if (!showTriangulation) return null;
38
- return buildKeyboardNavigationStyle(
39
- triangulationColor,
40
- ) as Partial<StyleSpecification>;
41
- }, [triangulationColor, showTriangulation]);
42
-
43
- const keyMapping = useMemo(() => {
44
- if (columns == null || voronoi == null || map == null) return null;
45
-
46
- const projection = (d) => {
47
- const pt = map.project(d);
48
- return [pt.x, pt.y];
49
- };
50
-
51
- const currentIndex = columns.findIndex(
52
- (d) => d.properties.col_id == col_id,
53
- );
54
-
55
- const neighbors = voronoi.tri.delaunay.neighbors[currentIndex];
56
- return buildKeyMapping(
57
- neighbors,
58
- voronoi.centroids,
59
- currentIndex,
60
- projection,
61
- );
62
- }, [col_id, columns, voronoi, map]);
63
-
64
- const onKeyDown = useCallback(
65
- (event: KeyboardEvent) => {
66
- if (keyMapping == null) return;
67
- const nextColumnIx = keyMapping[event.which];
68
- if (nextColumnIx == null) return;
69
- event.preventDefault();
70
- event.stopPropagation();
71
- // @ts-ignore
72
- selectColumn(columns[nextColumnIx].id);
73
- return false;
74
- },
75
- [keyMapping, selectColumn],
76
- );
77
-
78
- useEffect(() => {
79
- if (map == null) return;
80
- const canvas = map.getCanvas();
81
- canvas.addEventListener("keydown", onKeyDown);
82
- return () => {
83
- canvas.removeEventListener("keydown", onKeyDown);
84
- };
85
- }, [map, onKeyDown]);
86
-
87
- useMapStyleOperator(
88
- (map) => {
89
- if (voronoi == null || !showTriangulation) return;
90
- const { features } = voronoi.tri.links();
91
-
92
- setGeoJSON(map, "column-links", {
93
- type: "FeatureCollection",
94
- features,
95
- });
96
- },
97
- [voronoi, showTriangulation],
98
- );
99
-
100
- //if (neighbors == null) return null;
101
- //const neighborFeatures = neighbors.map((d) => features[d]);
102
-
103
- return null;
104
- }
105
-
106
- export function buildKeyboardNavigationStyle(color: string = "purple") {
107
- return {
108
- sources: {
109
- "column-links": buildGeoJSONSource(),
110
- //neighbors: buildGeoJSONSource(),
111
- },
112
- layers: [
113
- {
114
- id: "column-links",
115
- type: "line",
116
- source: "column-links",
117
- paint: {
118
- "line-color": color,
119
- "line-width": 1.5,
120
- },
121
- },
122
- {
123
- id: "column-centers",
124
- type: "circle",
125
- source: "column-links",
126
- paint: {
127
- "circle-radius": 2,
128
- "circle-color": color,
129
- },
130
- },
131
- ],
132
- } as Partial<StyleSpecification>;
133
- }
@@ -1,119 +0,0 @@
1
- import { create, StoreApi, useStore } from "zustand";
2
- import type { ColumnGeoJSONRecordWithID } from "@macrostrat/api-types";
3
- import {
4
- createContext,
5
- useState,
6
- useContext,
7
- ReactNode,
8
- useEffect,
9
- useMemo,
10
- } from "react";
11
- import h from "@macrostrat/hyper";
12
- import {
13
- useMacrostratColumns,
14
- useMacrostratStore,
15
- } from "@macrostrat/data-provider";
16
-
17
- export interface NavigationStore {
18
- columns: ColumnGeoJSONRecordWithID[];
19
- selectedColumn: number | null;
20
- hoveredColumn: number | null;
21
- selectColumn: (columnID: number | null) => void;
22
- setHoveredColumn: (columnID: number | null) => void;
23
- }
24
-
25
- export interface NavigationProviderProps {
26
- projectID?: number;
27
- inProcess?: boolean;
28
- selectedColumn?: number | null;
29
- hoveredColumn?: number | null;
30
- columns?: ColumnGeoJSONRecordWithID[] | null;
31
- columnIDs?: number[] | null;
32
- children: ReactNode;
33
- onSelectColumn?: (col_id: number | null, column: any) => void;
34
- onHoverColumn?: (col_id: number | null, column: any) => void;
35
- }
36
-
37
- const NavigationStoreContext = createContext<StoreApi<NavigationStore> | null>(
38
- null,
39
- );
40
-
41
- export function ColumnNavigationProvider({
42
- children,
43
- columns,
44
- columnIDs,
45
- selectedColumn,
46
- projectID,
47
- inProcess,
48
- onSelectColumn,
49
- onHoverColumn,
50
- }: NavigationProviderProps) {
51
- const getColumns = useMacrostratStore((s) => s.getColumns);
52
-
53
- const [store] = useState(() => {
54
- return create<NavigationStore>((set, get): NavigationStore => {
55
- return {
56
- columns: null,
57
- selectedColumn: null,
58
- hoveredColumn: null,
59
- selectColumn(columnID: number | null) {
60
- set({ selectedColumn: columnID, hoveredColumn: null });
61
- const { columns } = get();
62
- const column = columns?.find((d) => d.id == columnID);
63
- onSelectColumn?.(columnID, column);
64
- },
65
- setHoveredColumn(columnID: number | null) {
66
- set({ hoveredColumn: columnID });
67
- const { columns } = get();
68
- const column = columns?.find((d) => d.id == columnID);
69
- onHoverColumn?.(columnID, column);
70
- },
71
- };
72
- });
73
- });
74
-
75
- // Set up the store
76
- /** TODO: unify handling of columns between parts of application */
77
- // useAsyncEffect(async () => {
78
- // let _columns = columns ?? (await getColumns(projectID, inProcess));
79
- // store.setState({ columns: _columns, selectedColumn });
80
- // }, [projectID, inProcess, columns, getColumns]);
81
-
82
- let _columns = columns ?? useMacrostratColumns(projectID, inProcess);
83
-
84
- // filter columns if specified
85
- if (columnIDs?.length > 0) {
86
- _columns = useMemo(() => {
87
- return _columns?.filter((d) => columnIDs.includes(d.properties.col_id));
88
- }, [columnIDs, _columns]);
89
- }
90
-
91
- useEffect(() => {
92
- if (_columns?.length > 0) {
93
- store.setState({ columns: _columns, selectedColumn });
94
- }
95
- }, [_columns]);
96
- // Update selected column if it is changed externally
97
-
98
- // Kind of an awkward way to do this but we need to allow the selector to run
99
- useEffect(() => {
100
- const { selectColumn, selectedColumn: _internalSelectedColumn } =
101
- store.getState();
102
- if (selectedColumn == _internalSelectedColumn) {
103
- return;
104
- }
105
- selectColumn(selectedColumn);
106
- }, [selectedColumn]);
107
-
108
- return h(NavigationStoreContext.Provider, { value: store }, children);
109
- }
110
-
111
- export function useColumnNavigationStore(
112
- selector: (state: NavigationStore) => any,
113
- ) {
114
- const storeApi = useContext(NavigationStoreContext);
115
- if (storeApi == null) {
116
- throw new Error("Missing ColumnNavigationProvider");
117
- }
118
- return useStore(storeApi, selector);
119
- }
@@ -1,78 +0,0 @@
1
- import { useState } from "react";
2
- import h from "@macrostrat/hyper";
3
- import { Globe } from "@macrostrat/svg-map-components";
4
- import { Button } from "@blueprintjs/core";
5
- import { geoCentroid } from "d3-geo";
6
- import { LandLayer } from "@macrostrat/svg-map-components";
7
- import { Columns, CurrentColumn } from "./layers";
8
- import classNames from "classnames";
9
- import { useSpring, animated } from "react-spring";
10
-
11
- const AnimatedGlobe = animated(Globe);
12
-
13
- const MapViewFrame = (props) => {
14
- const [expanded, setExpanded] = useState(false);
15
- const className = classNames({ expanded }, "context-map");
16
- const { children, center, margin = 10 } = props;
17
- const baseSize = 250;
18
- const sz = expanded ? 450 : baseSize;
19
-
20
- let scale = sz / 2 - margin;
21
- if (expanded) {
22
- scale *= 3;
23
- }
24
-
25
- const targetProps = {
26
- width: sz,
27
- height: sz,
28
- scale,
29
- };
30
-
31
- const animationProps = useSpring(targetProps);
32
-
33
- return h(
34
- "div.map-placeholder",
35
- { style: { width: baseSize, height: baseSize } },
36
- [
37
- h(animated.div, { className, style: animationProps }, [
38
- h(
39
- AnimatedGlobe,
40
- {
41
- ...targetProps,
42
- margin,
43
- center,
44
- allowDrag: expanded,
45
- allowZoom: false,
46
- keepNorthUp: true,
47
- onClick() {
48
- setExpanded(true);
49
- },
50
- },
51
- [h(LandLayer), children],
52
- ),
53
- h.if(expanded)(Button, {
54
- className: "close-button",
55
- icon: "cross",
56
- minimal: true,
57
- onClick() {
58
- setExpanded(false);
59
- },
60
- intent: "danger",
61
- }),
62
- ]),
63
- ],
64
- );
65
- };
66
-
67
- export const AnimatedMapView = (props) => {
68
- const { currentColumn, setCurrentColumn, children, ...rest } = props;
69
- const center = geoCentroid(currentColumn);
70
-
71
- return h(MapViewFrame, { center, ...rest }, [
72
- h(Columns, { onClick: setCurrentColumn, ...rest }),
73
- children,
74
- h.if(currentColumn != null)(CurrentColumn, {
75
- feature: currentColumn,
76
- }),
77
- ]);
78
- };
@@ -1,46 +0,0 @@
1
- import h from "@macrostrat/hyper";
2
-
3
- import { Meta } from "@storybook/react-vite";
4
- import { ColumnNavigationSVGMap, ColumnNavigationSVGMapProps } from ".";
5
- import { MacrostratDataProvider } from "@macrostrat/data-provider";
6
- import { useState } from "react";
7
-
8
- interface ColumnIndexMapProps extends ColumnNavigationSVGMapProps {
9
- col_id: number;
10
- }
11
-
12
- function BasicColumnNavigationSVGMap(props: ColumnIndexMapProps) {
13
- return h(
14
- MacrostratDataProvider,
15
- h(ColumnNavigationSVGMap, { style: { width: 500, height: 500 }, ...props }),
16
- );
17
- }
18
-
19
- // More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
20
- export default {
21
- title: "Column views/Maps/Column navigation (SVG)",
22
- component: BasicColumnNavigationSVGMap,
23
- } as Meta<typeof ColumnNavigationSVGMap>;
24
-
25
- export const StaticColumnView = {
26
- args: {
27
- center: [-100, 38],
28
- },
29
- };
30
-
31
- export function Interactive() {
32
- const [currentColumn, setCurrentColumn] = useState(null);
33
- return h(BasicColumnNavigationSVGMap, {
34
- currentColumn,
35
- setCurrentColumn,
36
- });
37
- }
38
-
39
- export function ShowingTriangulation() {
40
- const [currentColumn, setCurrentColumn] = useState(null);
41
- return h(BasicColumnNavigationSVGMap, {
42
- currentColumn,
43
- setCurrentColumn,
44
- showDebugLayers: true,
45
- });
46
- }
@@ -1,34 +0,0 @@
1
- import {
2
- ColumnStatusCode,
3
- fetchAllColumns,
4
- useMacrostratFetch,
5
- } from "@macrostrat/data-provider";
6
- import { useAsyncMemo } from "@macrostrat/ui-components";
7
-
8
- export function useColumnFeatures({
9
- status_code,
10
- project_id,
11
- format = "geojson",
12
- }: {
13
- apiRoute?: string;
14
- status_code?: string;
15
- project_id?: number;
16
- format?: "geojson" | "topojson" | "geojson_bare";
17
- }) {
18
- /** Legacy fetcher for column features */
19
- const fetch = useMacrostratFetch();
20
-
21
- let statusCode: ColumnStatusCode[] = ["active"];
22
- if (status_code == "in process") {
23
- statusCode.push("in process");
24
- }
25
-
26
- return useAsyncMemo(async () => {
27
- return await fetchAllColumns({
28
- projectID: project_id,
29
- statusCode: statusCode,
30
- format,
31
- fetch,
32
- });
33
- }, [project_id, status_code, format]);
34
- }