@macrostrat/column-views 1.0.2 → 2.0.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.
- package/CHANGELOG.md +21 -0
- package/dist/esm/_shared.f7eec55a.js +9 -0
- package/dist/esm/_shared.f7eec55a.js.map +1 -0
- package/dist/esm/age-axis.4a8cf5e6.js +98 -0
- package/dist/esm/age-axis.4a8cf5e6.js.map +1 -0
- package/dist/esm/age-axis.module.03773a80.css +33 -0
- package/dist/esm/age-axis.module.03773a80.css.map +1 -0
- package/dist/esm/age-axis.module.3cc91335.js +22 -0
- package/dist/esm/age-axis.module.3cc91335.js.map +1 -0
- package/dist/esm/age-model-overlay.c7226855.js +57 -0
- package/dist/esm/age-model-overlay.c7226855.js.map +1 -0
- package/dist/esm/age-model-overlay.module.5d9e78fb.css +14 -0
- package/dist/esm/age-model-overlay.module.5d9e78fb.css.map +1 -0
- package/dist/esm/age-model-overlay.module.cd985dcb.js +16 -0
- package/dist/esm/age-model-overlay.module.cd985dcb.js.map +1 -0
- package/dist/esm/base.910b80b4.js +288 -0
- package/dist/esm/base.910b80b4.js.map +1 -0
- package/dist/esm/boxes.8292cff2.js +258 -0
- package/dist/esm/boxes.8292cff2.js.map +1 -0
- package/dist/esm/boxes.module.2b5fb18e.css +26 -0
- package/dist/esm/boxes.module.2b5fb18e.css.map +1 -0
- package/dist/esm/boxes.module.4ebc7796.js +19 -0
- package/dist/esm/boxes.module.4ebc7796.js.map +1 -0
- package/dist/esm/{carbon-isotopes.3b502a9e.js → carbon-isotopes.10db8285.js} +2 -2
- package/dist/esm/{carbon-isotopes.3b502a9e.js.map → carbon-isotopes.10db8285.js.map} +1 -1
- package/dist/esm/colors.395c6db5.js +40 -0
- package/dist/esm/colors.395c6db5.js.map +1 -0
- package/dist/esm/column-correlation.c8dcfe98.js +9 -0
- package/dist/esm/column-correlation.c8dcfe98.js.map +1 -0
- package/dist/esm/column-nav.5414677c.js +55 -0
- package/dist/esm/column-nav.5414677c.js.map +1 -0
- package/dist/esm/column-navigation.37cd3245.js +9 -0
- package/dist/esm/column-navigation.37cd3245.js.map +1 -0
- package/dist/esm/column.01d68dd8.js +127 -0
- package/dist/esm/column.01d68dd8.js.map +1 -0
- package/dist/esm/{column.db058031.js → column.a25f8ebd.js} +4 -4
- package/dist/esm/column.a25f8ebd.js.map +1 -0
- package/dist/esm/column.module.1b776e15.js +46 -0
- package/dist/esm/column.module.1b776e15.js.map +1 -0
- package/dist/esm/column.module.a67a6b4c.css +159 -0
- package/dist/esm/column.module.a67a6b4c.css.map +1 -0
- package/dist/esm/composite-scale.577bf64a.js +222 -0
- package/dist/esm/composite-scale.577bf64a.js.map +1 -0
- package/dist/esm/composite.039e4798.js +163 -0
- package/dist/esm/composite.039e4798.js.map +1 -0
- package/dist/esm/{core.4db8e452.js → core.843310d3.js} +11 -12
- package/dist/esm/core.843310d3.js.map +1 -0
- package/dist/esm/core.91ede078.js +206 -0
- package/dist/esm/core.91ede078.js.map +1 -0
- package/dist/esm/correlation-chart.abd8b346.js +9 -0
- package/dist/esm/correlation-chart.abd8b346.js.map +1 -0
- package/dist/esm/data-provider.1506eb64.js.map +1 -1
- package/dist/esm/data-provider.f10c6d0b.js +13 -0
- package/dist/esm/data-provider.f10c6d0b.js.map +1 -0
- package/dist/esm/fetch.99aec438.js +152 -0
- package/dist/esm/fetch.99aec438.js.map +1 -0
- package/dist/esm/hash-string.285b37fb.js +39 -0
- package/dist/esm/hash-string.285b37fb.js.map +1 -0
- package/dist/esm/helpers.2f0a0cb7.js +141 -0
- package/dist/esm/helpers.2f0a0cb7.js.map +1 -0
- package/dist/esm/index.d.ts +797 -120
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +14 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/inset-map.3c18106d.js +66 -0
- package/dist/esm/inset-map.3c18106d.js.map +1 -0
- package/dist/esm/keyboard-navigation.6713401b.js +48 -0
- package/dist/esm/keyboard-navigation.6713401b.js.map +1 -0
- package/dist/esm/keyboard-navigation.a9fc80dd.js +112 -0
- package/dist/esm/keyboard-navigation.a9fc80dd.js.map +1 -0
- package/dist/esm/layers.033d3fb0.js +170 -0
- package/dist/esm/layers.033d3fb0.js.map +1 -0
- package/dist/esm/main.2e0375a5.js +221 -0
- package/dist/esm/main.2e0375a5.js.map +1 -0
- package/dist/esm/main.module.3dd9500b.css +134 -0
- package/dist/esm/main.module.3dd9500b.css.map +1 -0
- package/dist/esm/main.module.c09154b1.js +70 -0
- package/dist/esm/main.module.c09154b1.js.map +1 -0
- package/dist/esm/mapbox.cac42eed.js +167 -0
- package/dist/esm/mapbox.cac42eed.js.map +1 -0
- package/dist/esm/maps.bcdea9c1.js +11 -0
- package/dist/esm/maps.bcdea9c1.js.map +1 -0
- package/dist/esm/{names.f6a4e9a4.js → names.a8f2b452.js} +5 -5
- package/dist/esm/names.a8f2b452.js.map +1 -0
- package/dist/esm/panel.598f76a5.js +420 -0
- package/dist/esm/panel.598f76a5.js.map +1 -0
- package/dist/esm/panel.module.386166cc.js +58 -0
- package/dist/esm/panel.module.386166cc.js.map +1 -0
- package/dist/esm/panel.module.3d2ea3c6.css +111 -0
- package/dist/esm/panel.module.3d2ea3c6.css.map +1 -0
- package/dist/esm/popover.a810b7bc.js +66 -0
- package/dist/esm/popover.a810b7bc.js.map +1 -0
- package/dist/esm/popover.module.c4ba4189.js +22 -0
- package/dist/esm/popover.module.c4ba4189.js.map +1 -0
- package/dist/esm/{selection-popover.module.0a701258.css → popover.module.c4d6bfb0.css} +11 -8
- package/dist/esm/popover.module.c4d6bfb0.css.map +1 -0
- package/dist/esm/prepare-data.d4284b4a.js +125 -0
- package/dist/esm/prepare-data.d4284b4a.js.map +1 -0
- package/dist/esm/prepare-units.6c890a96.js +104 -0
- package/dist/esm/prepare-units.6c890a96.js.map +1 -0
- package/dist/esm/{resolvers.b5c82b78.js → resolvers.36013b49.js} +13 -2
- package/dist/esm/resolvers.36013b49.js.map +1 -0
- package/dist/esm/section.a34d379a.js +215 -0
- package/dist/esm/section.a34d379a.js.map +1 -0
- package/dist/esm/selection.f5b0297e.js +143 -0
- package/dist/esm/selection.f5b0297e.js.map +1 -0
- package/dist/esm/state.178ef364.js +75 -0
- package/dist/esm/state.178ef364.js.map +1 -0
- package/dist/esm/state.2952cbca.js +118 -0
- package/dist/esm/state.2952cbca.js.map +1 -0
- package/dist/esm/store.c4d7a8a4.js +52 -0
- package/dist/esm/store.c4d7a8a4.js.map +1 -0
- package/dist/esm/styles.7bc776d1.js +95 -0
- package/dist/esm/styles.7bc776d1.js.map +1 -0
- package/dist/esm/svg.4b9a96c1.js +89 -0
- package/dist/esm/svg.4b9a96c1.js.map +1 -0
- package/dist/esm/types.0f0b57c9.js +3 -0
- package/dist/esm/types.0f0b57c9.js.map +1 -0
- package/dist/esm/unit-details.071cefed.js +9 -0
- package/dist/esm/unit-details.071cefed.js.map +1 -0
- package/dist/esm/units.5a4fc058.js +98 -0
- package/dist/esm/units.5a4fc058.js.map +1 -0
- package/dist/esm/utils.d7a43a2a.js +55 -0
- package/dist/esm/utils.d7a43a2a.js.map +1 -0
- package/dist/node/index.js.map +1 -1
- package/package.json +24 -7
- package/src/age-axis.module.sass +27 -0
- package/src/age-axis.ts +82 -19
- package/src/age-model-overlay.module.sass +11 -0
- package/src/age-model-overlay.ts +73 -0
- package/src/carbon-isotopes/column.ts +4 -2
- package/src/carbon-isotopes/core.ts +9 -6
- package/src/carbon-isotopes/data-provider.ts +3 -3
- package/src/column.module.sass +58 -49
- package/src/column.ts +149 -135
- package/src/correlation-chart/hash-string.ts +57 -0
- package/src/correlation-chart/index.ts +2 -0
- package/src/correlation-chart/main.module.sass +122 -0
- package/src/correlation-chart/main.ts +305 -0
- package/src/correlation-chart/prepare-data.ts +217 -0
- package/src/correlation-chart/stories/correlation-chart.stories.ts +192 -0
- package/src/correlation-chart/stories/stories.module.sass +18 -0
- package/src/correlation-chart/unconformity-line.module.sass +8 -0
- package/src/correlation-chart/unconformity-line.ts +25 -0
- package/src/data-provider/base.ts +388 -0
- package/src/data-provider/column-nav.ts +53 -0
- package/src/data-provider/fetch.ts +231 -0
- package/src/data-provider/index.ts +4 -0
- package/src/data-provider/store.ts +72 -0
- package/src/index.ts +6 -3
- package/src/maps/_shared/index.ts +2 -0
- package/src/maps/_shared/inset-map.stories.ts +20 -0
- package/src/maps/_shared/inset-map.ts +87 -0
- package/src/maps/_shared/styles.ts +57 -0
- package/src/maps/column-correlation/column-correlation-map.stories.ts +96 -0
- package/src/maps/column-correlation/core.ts +225 -0
- package/src/maps/column-correlation/index.ts +2 -0
- package/src/maps/column-correlation/state.ts +192 -0
- package/src/maps/column-navigation/index.ts +2 -0
- package/src/maps/column-navigation/mapbox/column-navigation-map.stories.ts +102 -0
- package/src/maps/column-navigation/mapbox/index.ts +219 -0
- package/src/maps/column-navigation/mapbox/keyboard-navigation.ts +119 -0
- package/src/maps/column-navigation/mapbox/state.ts +109 -0
- package/src/maps/column-navigation/svg/column-navigation-svg-map.stories.ts +46 -0
- package/src/{map → maps/column-navigation/svg}/index.ts +18 -6
- package/src/{map → maps/column-navigation/svg}/layers.ts +28 -109
- package/src/maps/column-navigation/utils/keyboard-navigation.ts +58 -0
- package/src/maps/index.ts +3 -0
- package/src/prepare-units/composite-scale.ts +353 -0
- package/src/prepare-units/helpers.ts +226 -0
- package/src/prepare-units/index.ts +177 -0
- package/src/prepare-units/utils.ts +98 -0
- package/src/section.ts +264 -84
- package/src/unit-details/index.ts +2 -215
- package/src/unit-details/{index.module.sass → panel.module.sass} +39 -8
- package/src/unit-details/panel.ts +523 -0
- package/src/{selection-popover.module.sass → unit-details/popover.module.sass} +4 -2
- package/src/unit-details/popover.ts +82 -0
- package/src/units/boxes.module.sass +16 -0
- package/src/units/boxes.ts +243 -90
- package/src/units/colors.ts +64 -0
- package/src/units/composite.ts +157 -152
- package/src/units/index.ts +76 -9
- package/src/units/names.ts +8 -4
- package/src/units/resolvers.ts +11 -0
- package/src/units/selection.ts +115 -101
- package/src/units/types.ts +5 -16
- package/dist/esm/age-axis.64c509ee.js +0 -41
- package/dist/esm/age-axis.64c509ee.js.map +0 -1
- package/dist/esm/boxes.13968b76.js +0 -164
- package/dist/esm/boxes.13968b76.js.map +0 -1
- package/dist/esm/boxes.module.28873d08.css +0 -4
- package/dist/esm/boxes.module.28873d08.css.map +0 -1
- package/dist/esm/boxes.module.605bdcd6.js +0 -13
- package/dist/esm/boxes.module.605bdcd6.js.map +0 -1
- package/dist/esm/column.8dd26e1a.js +0 -149
- package/dist/esm/column.8dd26e1a.js.map +0 -1
- package/dist/esm/column.db058031.js.map +0 -1
- package/dist/esm/column.module.039d872c.css +0 -151
- package/dist/esm/column.module.039d872c.css.map +0 -1
- package/dist/esm/column.module.e632868a.js +0 -19
- package/dist/esm/column.module.e632868a.js.map +0 -1
- package/dist/esm/composite.608a4ca2.js +0 -153
- package/dist/esm/composite.608a4ca2.js.map +0 -1
- package/dist/esm/core.4db8e452.js.map +0 -1
- package/dist/esm/helpers.8a03cfc7.js +0 -94
- package/dist/esm/helpers.8a03cfc7.js.map +0 -1
- package/dist/esm/index.module.0844afd8.css +0 -65
- package/dist/esm/index.module.0844afd8.css.map +0 -1
- package/dist/esm/index.module.24fe3a2e.js +0 -37
- package/dist/esm/index.module.24fe3a2e.js.map +0 -1
- package/dist/esm/layers.ad5fd25d.js +0 -231
- package/dist/esm/layers.ad5fd25d.js.map +0 -1
- package/dist/esm/map.7aa26f17.js +0 -82
- package/dist/esm/map.7aa26f17.js.map +0 -1
- package/dist/esm/names.f6a4e9a4.js.map +0 -1
- package/dist/esm/providers.cd1e652f.js +0 -25
- package/dist/esm/providers.cd1e652f.js.map +0 -1
- package/dist/esm/resolvers.b5c82b78.js.map +0 -1
- package/dist/esm/section.cc1b1100.js +0 -118
- package/dist/esm/section.cc1b1100.js.map +0 -1
- package/dist/esm/selection-popover.17d1bd55.js +0 -60
- package/dist/esm/selection-popover.17d1bd55.js.map +0 -1
- package/dist/esm/selection-popover.module.0a701258.css.map +0 -1
- package/dist/esm/selection-popover.module.e22f5183.js +0 -22
- package/dist/esm/selection-popover.module.e22f5183.js.map +0 -1
- package/dist/esm/selection.bbf26d0e.js +0 -117
- package/dist/esm/selection.bbf26d0e.js.map +0 -1
- package/dist/esm/store.25eaa168.js +0 -18
- package/dist/esm/store.25eaa168.js.map +0 -1
- package/dist/esm/types.f016e032.js +0 -18
- package/dist/esm/types.f016e032.js.map +0 -1
- package/dist/esm/unit-details.56ff8b70.js +0 -209
- package/dist/esm/unit-details.56ff8b70.js.map +0 -1
- package/dist/esm/units.361088d4.js +0 -42
- package/dist/esm/units.361088d4.js.map +0 -1
- package/src/helpers.ts +0 -133
- package/src/providers.ts +0 -34
- package/src/selection-popover.ts +0 -71
- package/src/store.ts +0 -12
- package/src/units/units.scss +0 -16
- /package/src/{map → maps/column-navigation/svg}/animated.ts +0 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ColumnGeoJSONRecord,
|
|
3
|
+
ColumnGeoJSONRecordWithID,
|
|
4
|
+
MacrostratRef,
|
|
5
|
+
UnitLong,
|
|
6
|
+
} from "@macrostrat/api-types";
|
|
7
|
+
import {
|
|
8
|
+
addQueryString,
|
|
9
|
+
joinURL,
|
|
10
|
+
useAPIResult,
|
|
11
|
+
} from "@macrostrat/ui-components";
|
|
12
|
+
import crossFetch from "cross-fetch";
|
|
13
|
+
import { feature } from "topojson-client";
|
|
14
|
+
import { geoArea } from "d3-geo";
|
|
15
|
+
|
|
16
|
+
function defaultFetch(
|
|
17
|
+
url: string,
|
|
18
|
+
options: RequestInit | undefined = undefined
|
|
19
|
+
) {
|
|
20
|
+
const baseURL = "https://macrostrat.org/api/v2";
|
|
21
|
+
return crossFetch(baseURL + url, options);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ColumnFetchOptions {
|
|
25
|
+
apiBaseURL?: string;
|
|
26
|
+
projectID?: number;
|
|
27
|
+
statusCode?: "in process";
|
|
28
|
+
format?: "geojson" | "topojson" | "geojson_bare";
|
|
29
|
+
fetch?: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function fetchAllColumns(
|
|
33
|
+
options: ColumnFetchOptions = {}
|
|
34
|
+
): Promise<ColumnGeoJSONRecord[]> {
|
|
35
|
+
const {
|
|
36
|
+
apiBaseURL,
|
|
37
|
+
projectID,
|
|
38
|
+
format = "topojson",
|
|
39
|
+
statusCode,
|
|
40
|
+
fetch = crossFetch,
|
|
41
|
+
} = options;
|
|
42
|
+
|
|
43
|
+
let args: any = { format };
|
|
44
|
+
if (projectID != null) {
|
|
45
|
+
args = { ...args, project_id: projectID };
|
|
46
|
+
}
|
|
47
|
+
if (statusCode != null) {
|
|
48
|
+
args = { ...args, status_code: statusCode };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (projectID == null) {
|
|
52
|
+
args = { ...args, all: true };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let url = "/columns";
|
|
56
|
+
if (apiBaseURL != null) {
|
|
57
|
+
url = joinURL(apiBaseURL, url);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Try with fetch
|
|
61
|
+
url = addQueryString(url, args);
|
|
62
|
+
|
|
63
|
+
const res = await fetch(url, {
|
|
64
|
+
method: "GET",
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (res == null) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Get JSON
|
|
75
|
+
const data = await res.json();
|
|
76
|
+
return postProcessColumns(columnProcessors[format](data));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function useColumnFeatures({
|
|
80
|
+
apiRoute = "/columns",
|
|
81
|
+
status_code,
|
|
82
|
+
project_id,
|
|
83
|
+
format = "geojson",
|
|
84
|
+
}) {
|
|
85
|
+
let all: boolean = undefined;
|
|
86
|
+
if (status_code == null && project_id == null) {
|
|
87
|
+
all = true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const processor = columnProcessors[format];
|
|
91
|
+
|
|
92
|
+
return useAPIResult(
|
|
93
|
+
apiRoute,
|
|
94
|
+
{ format, all, status_code, project_id },
|
|
95
|
+
processor
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function processGeoJSON(res) {
|
|
100
|
+
return processGeoJSONBare(res?.success?.data);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function processGeoJSONBare(res) {
|
|
104
|
+
return res?.features;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function processTopoJSON(res) {
|
|
108
|
+
try {
|
|
109
|
+
const { data } = res.success;
|
|
110
|
+
const { features: f } = feature(data, data.objects.output) as any;
|
|
111
|
+
return f;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.error(err);
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function postProcessColumns(columns) {
|
|
119
|
+
return promoteColumnIDs(
|
|
120
|
+
convertSmallAreasToPoints(removeFeaturesWithoutGeometry(columns))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function promoteColumnIDs(
|
|
125
|
+
features: ColumnGeoJSONRecord[]
|
|
126
|
+
): ColumnGeoJSONRecordWithID[] {
|
|
127
|
+
return features.map((f, i) => {
|
|
128
|
+
return {
|
|
129
|
+
id: f.properties?.col_id,
|
|
130
|
+
...f,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function removeFeaturesWithoutGeometry(features) {
|
|
136
|
+
return features.filter((f) => f.geometry != null);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function convertSmallAreasToPoints(features) {
|
|
140
|
+
return features.map((f) => {
|
|
141
|
+
// GeoArea takes a long time to run. We are really more worried about points that are zero-area
|
|
142
|
+
if (geoArea(f.geometry) < 1e-8) {
|
|
143
|
+
const centroid = f.geometry.coordinates[0][0];
|
|
144
|
+
f.geometry = {
|
|
145
|
+
type: "Point",
|
|
146
|
+
coordinates: centroid,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return f;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const columnProcessors = {
|
|
154
|
+
topojson: processTopoJSON,
|
|
155
|
+
geojson: processGeoJSON,
|
|
156
|
+
geojson_bare: processGeoJSONBare,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
async function unwrapResponse(res) {
|
|
160
|
+
if (res == null) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const resData = await res.json();
|
|
164
|
+
return resData["success"]["data"];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function fetchLithologies(fetch = defaultFetch) {
|
|
168
|
+
const res = await fetch("/defs/lithologies?all");
|
|
169
|
+
return await unwrapResponse(res);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function fetchIntervals(
|
|
173
|
+
timescaleID: number | null,
|
|
174
|
+
fetch = defaultFetch
|
|
175
|
+
) {
|
|
176
|
+
let url = `/defs/intervals`;
|
|
177
|
+
if (timescaleID != null) {
|
|
178
|
+
url += `?timescale_id=${timescaleID}`;
|
|
179
|
+
} else {
|
|
180
|
+
url += "?all";
|
|
181
|
+
}
|
|
182
|
+
const res = await fetch(url);
|
|
183
|
+
return await unwrapResponse(res);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function fetchEnvironments(fetch = defaultFetch) {
|
|
187
|
+
const res = await fetch("/defs/environments?all");
|
|
188
|
+
return await unwrapResponse(res);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function fetchRefs(
|
|
192
|
+
refs: number[],
|
|
193
|
+
fetch = defaultFetch
|
|
194
|
+
): Promise<MacrostratRef[]> {
|
|
195
|
+
let url = `/defs/refs`;
|
|
196
|
+
if (refs.length == 0) {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
url += "?ref_id=" + refs.join(",");
|
|
200
|
+
const res = await fetch(url);
|
|
201
|
+
return await unwrapResponse(res);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export type ColumnData = {
|
|
205
|
+
units: UnitLong[];
|
|
206
|
+
columnID: number;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export async function fetchUnits(
|
|
210
|
+
columns: number[],
|
|
211
|
+
fetch = defaultFetch
|
|
212
|
+
): Promise<ColumnData[]> {
|
|
213
|
+
const promises = columns.map((col_id) => fetchColumnUnits(col_id, fetch));
|
|
214
|
+
return await Promise.all(promises);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function fetchColumnUnits(
|
|
218
|
+
col_id: number,
|
|
219
|
+
fetch = defaultFetch
|
|
220
|
+
): Promise<ColumnData> {
|
|
221
|
+
const params = new URLSearchParams();
|
|
222
|
+
params.append("response", "long");
|
|
223
|
+
params.append("col_id", col_id.toString());
|
|
224
|
+
const res = await fetch("/units" + "?" + params.toString());
|
|
225
|
+
const data = await res.json();
|
|
226
|
+
if (!data.success) {
|
|
227
|
+
throw new Error("Failed to fetch column units");
|
|
228
|
+
}
|
|
229
|
+
const units = data.success.data;
|
|
230
|
+
return { columnID: col_id, units };
|
|
231
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createContext, useContext, ReactNode, useMemo } from "react";
|
|
2
|
+
import h from "@macrostrat/hyper";
|
|
3
|
+
import {
|
|
4
|
+
createCompositeScale,
|
|
5
|
+
PackageLayoutData,
|
|
6
|
+
} from "../prepare-units/composite-scale";
|
|
7
|
+
import { ExtUnit } from "../prepare-units/helpers";
|
|
8
|
+
import { ColumnAxisType } from "@macrostrat/column-components";
|
|
9
|
+
|
|
10
|
+
export interface MacrostratColumnDataContext {
|
|
11
|
+
units: ExtUnit[];
|
|
12
|
+
sections: PackageLayoutData[];
|
|
13
|
+
totalHeight?: number;
|
|
14
|
+
axisType?: ColumnAxisType;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const MacrostratColumnDataContext =
|
|
18
|
+
createContext<MacrostratColumnDataContext>(null);
|
|
19
|
+
|
|
20
|
+
export function MacrostratColumnDataProvider({
|
|
21
|
+
children,
|
|
22
|
+
units,
|
|
23
|
+
sections,
|
|
24
|
+
totalHeight,
|
|
25
|
+
axisType,
|
|
26
|
+
}: MacrostratColumnDataContext & { children: ReactNode }) {
|
|
27
|
+
/** Provider for Macrostrat column data.
|
|
28
|
+
* As a general rule, we want to provide data and column-axis
|
|
29
|
+
* height calculations through the context, since these need to
|
|
30
|
+
* be accessed by any component that lays out information on the
|
|
31
|
+
* column.
|
|
32
|
+
*
|
|
33
|
+
* Cross-axis layout and view configuration (e.g., showing and hiding
|
|
34
|
+
* of different components or labels) should be handled through passing
|
|
35
|
+
* props to the components themselves.
|
|
36
|
+
* */
|
|
37
|
+
|
|
38
|
+
const value = useMemo(() => {
|
|
39
|
+
return {
|
|
40
|
+
units,
|
|
41
|
+
sections,
|
|
42
|
+
totalHeight,
|
|
43
|
+
axisType,
|
|
44
|
+
};
|
|
45
|
+
}, [units, sections, totalHeight, axisType]);
|
|
46
|
+
|
|
47
|
+
return h(MacrostratColumnDataContext.Provider, { value }, children);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function useMacrostratColumnData() {
|
|
51
|
+
const ctx = useContext(MacrostratColumnDataContext);
|
|
52
|
+
if (!ctx) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"useMacrostratColumnData must be used within a MacrostratColumnDataProvider"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return ctx;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useMacrostratUnits() {
|
|
61
|
+
return useMacrostratColumnData().units;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useCompositeScale() {
|
|
65
|
+
const ctx = useContext(MacrostratColumnDataContext);
|
|
66
|
+
if (!ctx) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"useCompositeScale must be used within a MacrostratUnitsProvider"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return createCompositeScale(ctx.sections, true);
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from "./units";
|
|
2
|
+
export * from "./data-provider";
|
|
2
3
|
export * from "./age-axis";
|
|
3
4
|
export * from "./carbon-isotopes";
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./helpers";
|
|
6
|
-
export * from "./map";
|
|
5
|
+
export * from "./prepare-units";
|
|
7
6
|
export * from "./column";
|
|
7
|
+
export * from "./unit-details";
|
|
8
|
+
export * from "./maps";
|
|
9
|
+
export * from "./age-model-overlay";
|
|
10
|
+
export * from "./correlation-chart";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import h from "@macrostrat/hyper";
|
|
2
|
+
|
|
3
|
+
const mapboxToken = import.meta.env.VITE_MAPBOX_API_TOKEN;
|
|
4
|
+
|
|
5
|
+
import { Meta } from "@storybook/react";
|
|
6
|
+
import { InsetMap } from ".";
|
|
7
|
+
|
|
8
|
+
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
|
9
|
+
export default {
|
|
10
|
+
title: "Column views/Maps/Inset map",
|
|
11
|
+
component: InsetMap,
|
|
12
|
+
description: "A basic inset map",
|
|
13
|
+
} as Meta<typeof InsetMap>;
|
|
14
|
+
|
|
15
|
+
export function BasicInsetMap() {
|
|
16
|
+
return h(InsetMap, {
|
|
17
|
+
style: { width: "800px", height: "600px" },
|
|
18
|
+
accessToken: mapboxToken,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
MapView,
|
|
4
|
+
getBasicMapStyle,
|
|
5
|
+
MapViewProps,
|
|
6
|
+
} from "@macrostrat/map-interface";
|
|
7
|
+
import h from "@macrostrat/hyper";
|
|
8
|
+
import { MapboxMapProvider } from "@macrostrat/mapbox-react";
|
|
9
|
+
import { useInDarkMode } from "@macrostrat/ui-components";
|
|
10
|
+
import {
|
|
11
|
+
removeMapLabels,
|
|
12
|
+
removeSourceFromStyle,
|
|
13
|
+
} from "@macrostrat/mapbox-utils";
|
|
14
|
+
import type { ReactNode, CSSProperties } from "react";
|
|
15
|
+
|
|
16
|
+
export interface InsetMapProps extends Omit<MapViewProps, "style"> {
|
|
17
|
+
controls?: ReactNode;
|
|
18
|
+
className?: string;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
style?: CSSProperties;
|
|
21
|
+
mapStyle?: mapboxgl.Style | string;
|
|
22
|
+
showLabels?: boolean;
|
|
23
|
+
showAdmin?: boolean;
|
|
24
|
+
showRoads?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function InsetMap({
|
|
28
|
+
controls,
|
|
29
|
+
className,
|
|
30
|
+
children,
|
|
31
|
+
style,
|
|
32
|
+
mapStyle,
|
|
33
|
+
accessToken,
|
|
34
|
+
showLabels = false,
|
|
35
|
+
showAdmin = false,
|
|
36
|
+
showRoads = false,
|
|
37
|
+
...rest
|
|
38
|
+
}: InsetMapProps) {
|
|
39
|
+
const inDarkMode = useInDarkMode();
|
|
40
|
+
const _style = useMemo((): mapboxgl.Style | string => {
|
|
41
|
+
return mapStyle ?? getBasicMapStyle({ inDarkMode });
|
|
42
|
+
}, [mapStyle, inDarkMode]);
|
|
43
|
+
|
|
44
|
+
const transformStyle = useCallback(
|
|
45
|
+
(style) => {
|
|
46
|
+
let newStyle = style;
|
|
47
|
+
if (!showLabels) {
|
|
48
|
+
newStyle = removeMapLabels(newStyle);
|
|
49
|
+
}
|
|
50
|
+
if (!showAdmin) {
|
|
51
|
+
newStyle = removeSourceFromStyle(newStyle, null, "admin");
|
|
52
|
+
}
|
|
53
|
+
if (!showRoads) {
|
|
54
|
+
newStyle = removeSourceFromStyle(newStyle, null, "road");
|
|
55
|
+
newStyle = removeSourceFromStyle(newStyle, null, "aeroway");
|
|
56
|
+
}
|
|
57
|
+
return newStyle;
|
|
58
|
+
},
|
|
59
|
+
[mapStyle, showLabels, showRoads, showAdmin]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return h("div.inset-map", { className, style }, [
|
|
63
|
+
h(MapboxMapProvider, [
|
|
64
|
+
controls,
|
|
65
|
+
h(
|
|
66
|
+
MapView,
|
|
67
|
+
{
|
|
68
|
+
style: _style,
|
|
69
|
+
accessToken,
|
|
70
|
+
standalone: true,
|
|
71
|
+
/* Default map position that centers on the bulk of Macrostrat columns
|
|
72
|
+
*/
|
|
73
|
+
mapPosition: {
|
|
74
|
+
camera: {
|
|
75
|
+
lng: -100,
|
|
76
|
+
lat: 38,
|
|
77
|
+
altitude: 5000000,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
transformStyle,
|
|
81
|
+
...rest,
|
|
82
|
+
},
|
|
83
|
+
children
|
|
84
|
+
),
|
|
85
|
+
]),
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getCSSVariable } from "@macrostrat/color-utils";
|
|
2
|
+
import { buildGeoJSONSource } from "@macrostrat/mapbox-utils";
|
|
3
|
+
|
|
4
|
+
export function buildColumnsStyle(color: string) {
|
|
5
|
+
const columnColor = color ?? getCSSVariable("--text-subtle-color", "black");
|
|
6
|
+
return {
|
|
7
|
+
sources: {
|
|
8
|
+
columns: buildGeoJSONSource(),
|
|
9
|
+
},
|
|
10
|
+
layers: [
|
|
11
|
+
{
|
|
12
|
+
id: "columns-fill",
|
|
13
|
+
type: "fill",
|
|
14
|
+
source: "columns",
|
|
15
|
+
paint: {
|
|
16
|
+
"fill-color": columnColor,
|
|
17
|
+
"fill-opacity": [
|
|
18
|
+
"case",
|
|
19
|
+
["boolean", ["feature-state", "selected"], false],
|
|
20
|
+
0.5,
|
|
21
|
+
["boolean", ["feature-state", "hover"], false],
|
|
22
|
+
0.3,
|
|
23
|
+
0.1,
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "columns-line",
|
|
29
|
+
type: "line",
|
|
30
|
+
source: "columns",
|
|
31
|
+
paint: {
|
|
32
|
+
"line-color": columnColor,
|
|
33
|
+
"line-width": 2,
|
|
34
|
+
"line-opacity": 0.5,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "columns-points",
|
|
39
|
+
type: "circle",
|
|
40
|
+
source: "columns",
|
|
41
|
+
paint: {
|
|
42
|
+
"circle-radius": 4,
|
|
43
|
+
"circle-color": columnColor,
|
|
44
|
+
"circle-opacity": [
|
|
45
|
+
"case",
|
|
46
|
+
["boolean", ["feature-state", "selected"], false],
|
|
47
|
+
1,
|
|
48
|
+
["boolean", ["feature-state", "hover"], false],
|
|
49
|
+
0.7,
|
|
50
|
+
0.5,
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
filter: ["==", "$type", "Point"],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import h from "@macrostrat/hyper";
|
|
2
|
+
|
|
3
|
+
const mapboxToken = import.meta.env.VITE_MAPBOX_API_TOKEN;
|
|
4
|
+
|
|
5
|
+
import { Meta } from "@storybook/react";
|
|
6
|
+
import {
|
|
7
|
+
ColumnCorrelationMap,
|
|
8
|
+
ColumnCorrelationProvider,
|
|
9
|
+
CorrelationMapProps,
|
|
10
|
+
CorrelationProviderProps,
|
|
11
|
+
} from ".";
|
|
12
|
+
|
|
13
|
+
function ColumnCorrelationMapExt(
|
|
14
|
+
props: CorrelationMapProps & CorrelationProviderProps
|
|
15
|
+
) {
|
|
16
|
+
const {
|
|
17
|
+
focusedLine,
|
|
18
|
+
columns,
|
|
19
|
+
onSelectColumns,
|
|
20
|
+
projectID,
|
|
21
|
+
inProcess,
|
|
22
|
+
...rest
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
return h(
|
|
26
|
+
ColumnCorrelationProvider,
|
|
27
|
+
{
|
|
28
|
+
focusedLine,
|
|
29
|
+
columns,
|
|
30
|
+
onSelectColumns,
|
|
31
|
+
projectID,
|
|
32
|
+
inProcess,
|
|
33
|
+
},
|
|
34
|
+
h(ColumnCorrelationMap, { accessToken: mapboxToken, ...rest })
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
|
39
|
+
export default {
|
|
40
|
+
title: "Column views/Maps/Column correlation",
|
|
41
|
+
component: ColumnCorrelationMapExt,
|
|
42
|
+
description: "Cross section creation map",
|
|
43
|
+
} as Meta<typeof ColumnCorrelationMapExt>;
|
|
44
|
+
|
|
45
|
+
export const ColumnCorrelation = {
|
|
46
|
+
args: {
|
|
47
|
+
style: { width: "800px", height: "600px" },
|
|
48
|
+
padding: 100,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const withPreloadedCrossSection = {
|
|
53
|
+
args: {
|
|
54
|
+
style: { width: "800px", height: "600px" },
|
|
55
|
+
padding: 100,
|
|
56
|
+
focusedLine: {
|
|
57
|
+
type: "LineString",
|
|
58
|
+
coordinates: [
|
|
59
|
+
[-122.399, 37.791],
|
|
60
|
+
[-100, 45],
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const nonStandardProject = {
|
|
67
|
+
args: {
|
|
68
|
+
style: { width: "800px", height: "600px" },
|
|
69
|
+
padding: 100,
|
|
70
|
+
projectID: 10,
|
|
71
|
+
inProcess: true,
|
|
72
|
+
mapPosition: {
|
|
73
|
+
camera: {
|
|
74
|
+
lng: -100,
|
|
75
|
+
lat: 38,
|
|
76
|
+
altitude: 5000000,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const eODP = {
|
|
83
|
+
args: {
|
|
84
|
+
style: { width: "800px", height: "600px" },
|
|
85
|
+
padding: 100,
|
|
86
|
+
projectID: 3,
|
|
87
|
+
inProcess: true,
|
|
88
|
+
mapPosition: {
|
|
89
|
+
camera: {
|
|
90
|
+
lng: -100,
|
|
91
|
+
lat: 38,
|
|
92
|
+
altitude: 5000000,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|