@macrostrat/column-views 3.0.2 → 3.1.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 (84) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/data-provider/column-nav.js +1 -1
  3. package/dist/data-provider/index.d.ts +0 -2
  4. package/dist/data-provider/store.cjs +49 -6
  5. package/dist/data-provider/store.cjs.map +1 -1
  6. package/dist/data-provider/store.js +46 -3
  7. package/dist/data-provider/store.js.map +1 -1
  8. package/dist/data-provider/unit-selection.cjs +9 -9
  9. package/dist/data-provider/unit-selection.cjs.map +1 -1
  10. package/dist/data-provider/unit-selection.d.ts +1 -1
  11. package/dist/data-provider/unit-selection.js +2 -2
  12. package/dist/data-provider/unit-selection.js.map +1 -1
  13. package/dist/index.cjs +5 -24
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.js +4 -23
  16. package/dist/index.js.map +1 -1
  17. package/dist/maps/column-correlation/state.cjs +2 -2
  18. package/dist/maps/column-correlation/state.cjs.map +1 -1
  19. package/dist/maps/column-correlation/state.d.ts +1 -0
  20. package/dist/maps/column-correlation/state.js +1 -1
  21. package/dist/maps/column-correlation/state.js.map +1 -1
  22. package/dist/maps/column-navigation/mapbox/state.cjs +3 -3
  23. package/dist/maps/column-navigation/mapbox/state.cjs.map +1 -1
  24. package/dist/maps/column-navigation/mapbox/state.js +1 -1
  25. package/dist/maps/column-navigation/mapbox/state.js.map +1 -1
  26. package/dist/maps/column-navigation/svg/data-fetcher.cjs +25 -0
  27. package/dist/maps/column-navigation/svg/data-fetcher.cjs.map +1 -0
  28. package/dist/maps/column-navigation/svg/data-fetcher.d.ts +6 -0
  29. package/dist/maps/column-navigation/svg/data-fetcher.js +25 -0
  30. package/dist/maps/column-navigation/svg/data-fetcher.js.map +1 -0
  31. package/dist/maps/column-navigation/svg/layers.cjs +2 -3
  32. package/dist/maps/column-navigation/svg/layers.cjs.map +1 -1
  33. package/dist/maps/column-navigation/svg/layers.js +1 -2
  34. package/dist/maps/column-navigation/svg/layers.js.map +1 -1
  35. package/dist/section.cjs +3 -3
  36. package/dist/section.cjs.map +1 -1
  37. package/dist/section.js +2 -2
  38. package/dist/section.js.map +1 -1
  39. package/dist/unit-details/panel.cjs +76 -57
  40. package/dist/unit-details/panel.cjs.map +1 -1
  41. package/dist/unit-details/panel.js +72 -53
  42. package/dist/unit-details/panel.js.map +1 -1
  43. package/dist/units/boxes.cjs +1 -0
  44. package/dist/units/boxes.cjs.map +1 -1
  45. package/dist/units/boxes.js +1 -0
  46. package/dist/units/boxes.js.map +1 -1
  47. package/dist/units/index.cjs +4 -4
  48. package/dist/units/index.cjs.map +1 -1
  49. package/dist/units/index.js +1 -1
  50. package/dist/units/index.js.map +1 -1
  51. package/package.json +23 -17
  52. package/src/correlation-chart/stories/correlation-chart.stories.ts +29 -22
  53. package/src/data-provider/index.ts +0 -2
  54. package/src/data-provider/store.ts +51 -10
  55. package/src/data-provider/unit-selection.ts +4 -4
  56. package/src/maps/column-correlation/state.ts +2 -1
  57. package/src/maps/column-navigation/mapbox/state.ts +1 -1
  58. package/src/maps/column-navigation/svg/column-navigation-svg-map.stories.ts +1 -1
  59. package/src/maps/column-navigation/svg/data-fetcher.ts +34 -0
  60. package/src/maps/column-navigation/svg/layers.ts +1 -1
  61. package/src/section.ts +1 -1
  62. package/src/unit-details/panel.ts +97 -60
  63. package/src/units/boxes.ts +2 -1
  64. package/src/units/index.ts +1 -1
  65. package/dist/data-provider/base.cjs +0 -352
  66. package/dist/data-provider/base.cjs.map +0 -1
  67. package/dist/data-provider/base.d.ts +0 -65
  68. package/dist/data-provider/base.js +0 -349
  69. package/dist/data-provider/base.js.map +0 -1
  70. package/dist/data-provider/core.cjs +0 -58
  71. package/dist/data-provider/core.cjs.map +0 -1
  72. package/dist/data-provider/core.d.ts +0 -31
  73. package/dist/data-provider/core.js +0 -56
  74. package/dist/data-provider/core.js.map +0 -1
  75. package/dist/data-provider/fetch.cjs +0 -212
  76. package/dist/data-provider/fetch.cjs.map +0 -1
  77. package/dist/data-provider/fetch.d.ts +0 -27
  78. package/dist/data-provider/fetch.js +0 -210
  79. package/dist/data-provider/fetch.js.map +0 -1
  80. package/dist/data-provider/store.d.ts +0 -34
  81. package/dist/unit-details/panel.d.ts +0 -87
  82. package/src/data-provider/base.ts +0 -475
  83. package/src/data-provider/core.ts +0 -89
  84. package/src/data-provider/fetch.ts +0 -278
@@ -1,278 +0,0 @@
1
- import {
2
- ColumnGeoJSONRecord,
3
- ColumnGeoJSONRecordWithID,
4
- MacrostratRef,
5
- StratName,
6
- UnitLong,
7
- } from "@macrostrat/api-types";
8
- import {
9
- addQueryString,
10
- joinURL,
11
- useAPIResult,
12
- } from "@macrostrat/ui-components";
13
- import crossFetch from "cross-fetch";
14
- import { feature } from "topojson-client";
15
- import { geoArea } from "d3-geo";
16
-
17
- function createScopedFetch(baseURL: string) {
18
- return function (url: string, options: RequestInit | undefined = undefined) {
19
- return crossFetch(baseURL + url, options);
20
- };
21
- }
22
-
23
- const defaultFetch = createScopedFetch("https://macrostrat.org/api/v2");
24
-
25
- export type ColumnStatusCode = "in process" | "active" | "obsolete";
26
-
27
- export interface ColumnFetchOptions {
28
- apiBaseURL?: string;
29
- projectID?: number;
30
- statusCode?: ColumnStatusCode | ColumnStatusCode[];
31
- format?: "geojson" | "topojson" | "geojson_bare";
32
- fetch?: any;
33
- }
34
-
35
- export async function fetchAllColumns(
36
- options: ColumnFetchOptions = {},
37
- ): Promise<ColumnGeoJSONRecord[]> {
38
- const {
39
- apiBaseURL,
40
- projectID,
41
- format = "topojson",
42
- statusCode,
43
- fetch = crossFetch,
44
- } = options;
45
-
46
- let args: any = { format };
47
- if (projectID != null) {
48
- args = { ...args, project_id: projectID };
49
- }
50
- let _statusCode: string | undefined = undefined;
51
- if (Array.isArray(statusCode)) {
52
- _statusCode = statusCode.join(",");
53
- } else if (statusCode != null) {
54
- _statusCode = statusCode;
55
- }
56
- args.statusCode = _statusCode;
57
-
58
- if (projectID == null) {
59
- args = { ...args, all: true };
60
- }
61
-
62
- let url = "/columns";
63
- if (apiBaseURL != null) {
64
- url = joinURL(apiBaseURL, url);
65
- }
66
-
67
- // Try with fetch
68
- url = addQueryString(url, args);
69
-
70
- const res = await fetch(url, {
71
- method: "GET",
72
- headers: {
73
- "Content-Type": "application/json",
74
- },
75
- });
76
-
77
- if (res == null) {
78
- return null;
79
- }
80
-
81
- // Get JSON
82
- const data = await res.json();
83
- return postProcessColumns(columnProcessors[format](data));
84
- }
85
-
86
- export function useColumnFeatures({
87
- apiRoute = "/columns",
88
- status_code,
89
- project_id,
90
- format = "geojson",
91
- }) {
92
- let all: boolean = undefined;
93
- if (status_code == null && project_id == null) {
94
- all = true;
95
- }
96
-
97
- const processor = columnProcessors[format];
98
-
99
- return useAPIResult(
100
- apiRoute,
101
- { format, all, status_code, project_id },
102
- processor,
103
- );
104
- }
105
-
106
- function processGeoJSON(res) {
107
- return processGeoJSONBare(res?.success?.data);
108
- }
109
-
110
- function processGeoJSONBare(res) {
111
- return res?.features;
112
- }
113
-
114
- function processTopoJSON(res) {
115
- try {
116
- const { data } = res.success;
117
- const { features: f } = feature(data, data.objects.output) as any;
118
- return f;
119
- } catch (err) {
120
- console.error(err);
121
- return [];
122
- }
123
- }
124
-
125
- function postProcessColumns(columns) {
126
- return promoteColumnIDs(
127
- convertSmallAreasToPoints(removeFeaturesWithoutGeometry(columns)),
128
- );
129
- }
130
-
131
- function promoteColumnIDs(
132
- features: ColumnGeoJSONRecord[],
133
- ): ColumnGeoJSONRecordWithID[] {
134
- return features.map((f, i) => {
135
- return {
136
- id: f.properties?.col_id,
137
- ...f,
138
- };
139
- });
140
- }
141
-
142
- function removeFeaturesWithoutGeometry(features) {
143
- return features.filter((f) => f.geometry != null);
144
- }
145
-
146
- function convertSmallAreasToPoints(features) {
147
- return features.map((f) => {
148
- // GeoArea takes a long time to run. We are really more worried about points that are zero-area
149
- if (geoArea(f.geometry) < 1e-8) {
150
- const centroid = f.geometry.coordinates[0][0];
151
- f.geometry = {
152
- type: "Point",
153
- coordinates: centroid,
154
- };
155
- }
156
- return f;
157
- });
158
- }
159
-
160
- const columnProcessors = {
161
- topojson: processTopoJSON,
162
- geojson: processGeoJSON,
163
- geojson_bare: processGeoJSONBare,
164
- };
165
-
166
- async function unwrapResponse(res) {
167
- if (res == null) {
168
- return null;
169
- }
170
- const resData = await res.json();
171
- return resData["success"]["data"];
172
- }
173
-
174
- export async function fetchLithologies(fetch = defaultFetch) {
175
- const res = await fetch("/defs/lithologies?all");
176
- return await unwrapResponse(res);
177
- }
178
-
179
- export async function fetchIntervals(
180
- timescaleID: number | null,
181
- fetch = defaultFetch,
182
- ) {
183
- let url = `/defs/intervals`;
184
- if (timescaleID != null) {
185
- url += `?timescale_id=${timescaleID}`;
186
- } else {
187
- url += "?all";
188
- }
189
- const res = await fetch(url);
190
- return await unwrapResponse(res);
191
- }
192
-
193
- export async function fetchEnvironments(fetch = defaultFetch) {
194
- const res = await fetch("/defs/environments?all");
195
- return await unwrapResponse(res);
196
- }
197
-
198
- export async function fetchRefs(
199
- refs: number[],
200
- fetch = defaultFetch,
201
- ): Promise<MacrostratRef[]> {
202
- let url = `/defs/refs`;
203
- if (refs.length == 0) {
204
- return [];
205
- }
206
- url += "?ref_id=" + refs.join(",");
207
- const res = await fetch(url);
208
- return await unwrapResponse(res);
209
- }
210
-
211
- export async function fetchStratNames(
212
- names: number[],
213
- fetch = defaultFetch,
214
- ): Promise<StratName[]> {
215
- let url = `/defs/strat_names`;
216
- if (names.length == 0) {
217
- return [];
218
- }
219
- url += "?strat_name_id=" + names.join(",");
220
- const res = await fetch(url);
221
- return await unwrapResponse(res);
222
- }
223
-
224
- export type ColumnData = {
225
- units: UnitLong[];
226
- columnID: number;
227
- };
228
-
229
- export async function fetchUnits(
230
- columns: number[],
231
- fetch = defaultFetch,
232
- ): Promise<ColumnData[]> {
233
- const params = new URLSearchParams();
234
- params.append("response", "long");
235
-
236
- if (columns.length == 0) {
237
- return [];
238
- }
239
-
240
- const col_string = columns.map((column) => column.toString()).join(",");
241
- params.append("col_id", col_string);
242
-
243
- const res = await fetch("/units" + "?" + params.toString());
244
- const data = await res.json();
245
- if (!data.success) {
246
- throw new Error("Failed to fetch column units");
247
- }
248
- const units = data.success.data;
249
- const unitsMap = new Map<number, UnitLong[]>();
250
- for (const unit of units) {
251
- const colID = unit.col_id;
252
- if (!unitsMap.has(colID)) {
253
- unitsMap.set(colID, []);
254
- }
255
- unitsMap.get(colID).push(unit);
256
- }
257
- const result: ColumnData[] = [];
258
- for (const colID of columns) {
259
- result.push({ columnID: colID, units: unitsMap.get(colID) || [] });
260
- }
261
- return result;
262
- }
263
-
264
- export async function fetchColumnUnits(
265
- col_id: number,
266
- fetch = defaultFetch,
267
- ): Promise<ColumnData> {
268
- const params = new URLSearchParams();
269
- params.append("response", "long");
270
- params.append("col_id", col_id.toString());
271
- const res = await fetch("/units" + "?" + params.toString());
272
- const data = await res.json();
273
- if (!data.success) {
274
- throw new Error("Failed to fetch column units");
275
- }
276
- const units = data.success.data;
277
- return { columnID: col_id, units };
278
- }