@macrostrat/column-views 3.6.0 → 3.8.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 +50 -0
- package/dist/column-views.css +118 -89
- package/dist/column.cjs +1 -2
- package/dist/column.cjs.map +1 -1
- package/dist/column.js +1 -2
- package/dist/column.js.map +1 -1
- package/dist/column.module.sass.cjs +15 -15
- package/dist/column.module.sass.js +15 -15
- package/dist/correlation-chart/main.cjs +136 -34
- package/dist/correlation-chart/main.cjs.map +1 -1
- package/dist/correlation-chart/main.d.ts +33 -2
- package/dist/correlation-chart/main.js +118 -15
- package/dist/correlation-chart/main.js.map +1 -1
- package/dist/correlation-chart/main.module.sass.cjs +23 -20
- package/dist/correlation-chart/main.module.sass.cjs.map +1 -1
- package/dist/correlation-chart/main.module.sass.js +23 -20
- package/dist/correlation-chart/main.module.sass.js.map +1 -1
- package/dist/correlation-chart/prepare-data.cjs +0 -1
- package/dist/correlation-chart/prepare-data.cjs.map +1 -1
- package/dist/correlation-chart/prepare-data.js +0 -1
- package/dist/correlation-chart/prepare-data.js.map +1 -1
- package/dist/data-provider/store.cjs +10 -2
- package/dist/data-provider/store.cjs.map +1 -1
- package/dist/data-provider/store.d.ts +2 -2
- package/dist/data-provider/store.js +10 -2
- package/dist/data-provider/store.js.map +1 -1
- package/dist/data-provider/unit-selection.cjs +4 -1
- package/dist/data-provider/unit-selection.cjs.map +1 -1
- package/dist/data-provider/unit-selection.d.ts +1 -1
- package/dist/data-provider/unit-selection.js +4 -1
- package/dist/data-provider/unit-selection.js.map +1 -1
- package/dist/index.cjs +14 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/maps/column-correlation/core.cjs +127 -6
- package/dist/maps/column-correlation/core.cjs.map +1 -1
- package/dist/maps/column-correlation/core.js +128 -7
- package/dist/maps/column-correlation/core.js.map +1 -1
- package/dist/maps/column-correlation/state.cjs +63 -2
- package/dist/maps/column-correlation/state.cjs.map +1 -1
- package/dist/maps/column-correlation/state.d.ts +31 -1
- package/dist/maps/column-correlation/state.js +63 -2
- package/dist/maps/column-correlation/state.js.map +1 -1
- package/dist/maps/layers/columns.cjs +5 -1
- package/dist/maps/layers/columns.cjs.map +1 -1
- package/dist/maps/layers/columns.js +5 -1
- package/dist/maps/layers/columns.js.map +1 -1
- package/dist/prepare-units/helpers.cjs +4 -2
- package/dist/prepare-units/helpers.cjs.map +1 -1
- package/dist/prepare-units/helpers.js +4 -2
- package/dist/prepare-units/helpers.js.map +1 -1
- package/dist/section.cjs +8 -2
- package/dist/section.cjs.map +1 -1
- package/dist/section.d.ts +2 -0
- package/dist/section.js +8 -2
- package/dist/section.js.map +1 -1
- package/dist/unit-details/age-range.cjs +2 -1
- package/dist/unit-details/age-range.cjs.map +1 -1
- package/dist/unit-details/age-range.js +2 -1
- package/dist/unit-details/age-range.js.map +1 -1
- package/dist/unit-details/index.d.ts +1 -1
- package/dist/unit-details/panel.cjs +2 -3
- package/dist/unit-details/panel.cjs.map +1 -1
- package/dist/unit-details/panel.js +1 -2
- package/dist/unit-details/panel.js.map +1 -1
- package/dist/unit-details/panel.module.sass.cjs +18 -22
- package/dist/unit-details/panel.module.sass.cjs.map +1 -1
- package/dist/unit-details/panel.module.sass.js +18 -22
- package/dist/unit-details/panel.module.sass.js.map +1 -1
- package/dist/unit-details/strat-names.cjs +1 -2
- package/dist/unit-details/strat-names.cjs.map +1 -1
- package/dist/unit-details/strat-names.js +1 -2
- package/dist/unit-details/strat-names.js.map +1 -1
- package/dist/units/boxes.cjs +2 -1
- package/dist/units/boxes.cjs.map +1 -1
- package/dist/units/boxes.js +2 -1
- package/dist/units/boxes.js.map +1 -1
- package/package.json +7 -7
- package/src/column.module.sass +6 -0
- package/src/correlation-chart/main.module.sass +46 -2
- package/src/correlation-chart/main.ts +180 -9
- package/src/correlation-chart/prepare-data.ts +0 -1
- package/src/data-provider/store.ts +11 -1
- package/src/data-provider/unit-selection.ts +13 -2
- package/src/maps/column-correlation/column-correlation-map.stories.ts +12 -0
- package/src/maps/column-correlation/core.ts +155 -9
- package/src/maps/column-correlation/state.ts +110 -2
- package/src/maps/layers/columns.ts +7 -1
- package/src/prepare-units/helpers.ts +4 -3
- package/src/section.ts +9 -1
- package/src/unit-details/age-range.ts +3 -1
- package/src/unit-details/index.ts +7 -1
- package/src/unit-details/panel.module.sass +0 -8
- package/src/unit-details/panel.ts +6 -6
- package/src/unit-details/strat-names.ts +1 -1
- package/src/units/boxes.ts +4 -2
- package/dist/correlation-chart/stories/utils.d.ts +0 -6
- package/dist/unit-details/identifiers.cjs +0 -56
- package/dist/unit-details/identifiers.cjs.map +0 -1
- package/dist/unit-details/identifiers.d.ts +0 -31
- package/dist/unit-details/identifiers.js +0 -54
- package/dist/unit-details/identifiers.js.map +0 -1
- package/src/correlation-chart/stories/correlation-chart.stories.ts +0 -228
- package/src/correlation-chart/stories/namibia-correlation.stories.ts +0 -151
- package/src/correlation-chart/stories/stories.module.sass +0 -18
- package/src/correlation-chart/stories/utils.ts +0 -24
- package/src/unit-details/identifiers.ts +0 -67
|
@@ -11,9 +11,12 @@ import { buffer } from "@turf/buffer";
|
|
|
11
11
|
import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
|
|
12
12
|
const CorrelationStoreContext = createContext(null);
|
|
13
13
|
const computed = createComputed((state) => {
|
|
14
|
+
const manual = state.manualColumns != null;
|
|
14
15
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
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)
|
|
17
20
|
};
|
|
18
21
|
});
|
|
19
22
|
function ColumnCorrelationProvider({
|
|
@@ -22,6 +25,7 @@ function ColumnCorrelationProvider({
|
|
|
22
25
|
projectID,
|
|
23
26
|
inProcess,
|
|
24
27
|
focusedLine,
|
|
28
|
+
manualColumns = null,
|
|
25
29
|
onSelectColumns
|
|
26
30
|
}) {
|
|
27
31
|
const [store] = useState(() => {
|
|
@@ -29,10 +33,15 @@ function ColumnCorrelationProvider({
|
|
|
29
33
|
computed((set, get) => {
|
|
30
34
|
return {
|
|
31
35
|
focusedLine,
|
|
36
|
+
manualColumns,
|
|
37
|
+
hoveredColumn: null,
|
|
38
|
+
zoomColumn: null,
|
|
39
|
+
zoomNonce: 0,
|
|
32
40
|
projectID,
|
|
33
41
|
columns: null,
|
|
34
42
|
onClickMap(event, point) {
|
|
35
43
|
const state = get();
|
|
44
|
+
if (state.manualColumns != null) return;
|
|
36
45
|
const shiftKeyPressed = event.originalEvent.shiftKey;
|
|
37
46
|
let existingCoords = state.focusedLine?.coordinates ?? [];
|
|
38
47
|
if (existingCoords.length >= 2 && !shiftKeyPressed) {
|
|
@@ -44,6 +53,29 @@ function ColumnCorrelationProvider({
|
|
|
44
53
|
coordinates: [...existingCoords, point.coordinates]
|
|
45
54
|
}
|
|
46
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 });
|
|
47
79
|
}
|
|
48
80
|
};
|
|
49
81
|
})
|
|
@@ -69,6 +101,14 @@ function useCorrelationMapStore(selector) {
|
|
|
69
101
|
}
|
|
70
102
|
return useStore(storeApi, selector);
|
|
71
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
|
+
}
|
|
72
112
|
function buildCorrelationColumns(columns, line) {
|
|
73
113
|
if (columns == null || line == null || line.coordinates.length < 2) {
|
|
74
114
|
return [];
|
|
@@ -78,6 +118,26 @@ function buildCorrelationColumns(columns, line) {
|
|
|
78
118
|
line
|
|
79
119
|
);
|
|
80
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
|
+
}
|
|
81
141
|
function computeIntersectingColumns(columns, line) {
|
|
82
142
|
if (columns == null || line == null) {
|
|
83
143
|
return [];
|
|
@@ -124,6 +184,7 @@ function sorted(data, accessor) {
|
|
|
124
184
|
}
|
|
125
185
|
export {
|
|
126
186
|
ColumnCorrelationProvider,
|
|
187
|
+
useColumnMapLink,
|
|
127
188
|
useCorrelationMapStore
|
|
128
189
|
};
|
|
129
190
|
//# sourceMappingURL=state.js.map
|
|
@@ -1 +1 @@
|
|
|
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 interface CorrelationMapInput {\n columns: ColumnGeoJSONRecord[];\n focusedLine: LineString | null;\n}\n\nexport interface CorrelationMapStore extends CorrelationMapInput {\n onClickMap: (event: mapboxgl.MapMouseEvent, point: Point) => void;\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};\n\n/** A computed store that will automatically update when the state changes */\nconst computed = createComputed((state: CorrelationMapStore): ComputedStore => {\n return {\n // We compute the focused columns based on columns and focusedLine\n focusedColumns: buildCorrelationColumns(state.columns, state.focusedLine),\n };\n}) as any;\n\nexport function ColumnCorrelationProvider({\n children,\n columns,\n projectID,\n inProcess,\n focusedLine,\n onSelectColumns,\n}: CorrelationProviderProps) {\n const [store] = useState(() => {\n return create<CorrelationMapStore & ComputedStore>(\n computed((set, get): CorrelationMapStore => {\n return {\n focusedLine,\n projectID,\n columns: null,\n onClickMap(event: mapboxgl.MapMouseEvent, point: Point) {\n const state = get();\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 };\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\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 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":";;;;;;;;;;;AA0CA,MAAM,0BACJ,cAAoD,IAAI;AAO1D,MAAM,WAAW,eAAe,CAAC,UAA8C;AAC7E,SAAO;AAAA;AAAA,IAEL,gBAAgB,wBAAwB,MAAM,SAAS,MAAM,WAAW;AAAA,EAAA;AAE5E,CAAC;AAEM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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
|
+
{"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,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,IAAI,SAAS,MAAM;AAC7B,WAAO;AAAA,MACL,SAAS,CAAC,KAAK,QAA6B;AAC1C,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA,e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KAAK,YAAY,CAAC,CAAC;AAAA,EAAA;AAG1D,MAAI,aAAa,QAAQ,IAAI,CAAC,KAAK,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;"}
|
|
@@ -42,7 +42,11 @@ function buildColumnsStyle(opts = {}) {
|
|
|
42
42
|
let columnColor = columnBaseColor;
|
|
43
43
|
const columnSelectedColor = opts.selectedColor ?? colorUtils.getCSSVariable("--selection-color", "purple");
|
|
44
44
|
const lineColor = opts.lineColor ?? columnBaseColor;
|
|
45
|
-
const isHovered = [
|
|
45
|
+
const isHovered = [
|
|
46
|
+
"any",
|
|
47
|
+
["boolean", ["feature-state", "hover"], false],
|
|
48
|
+
["boolean", ["feature-state", "highlighted"], false]
|
|
49
|
+
];
|
|
46
50
|
if (typeof columnColor === "string") {
|
|
47
51
|
columnColor = [
|
|
48
52
|
"coalesce",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns.cjs","sources":["../../../src/maps/layers/columns.ts"],"sourcesContent":["import { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport GeoJSON, { FeatureCollection } from \"geojson\";\nimport { GeoJSONFeature } from \"mapbox-gl\";\nimport { getCSSVariable } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport { StyleFragment } from \"@macrostrat/mapbox-react\";\n\nexport interface ColumnsStyleOptions {\n color?: string | any[];\n selectedColor?: string | any[];\n opacity?: number | any[];\n circleRadius?: number | any[];\n lineOpacity?: number | any[];\n lineWidth?: number | any[];\n lineColor?: string | any[];\n}\n\ninterface ColumnLayerOptions extends ColumnsStyleOptions {\n enabled: boolean;\n columns: FeatureCollection | GeoJSONFeature[];\n}\n\nexport function BaseColumnsLayer({\n enabled = true,\n columns,\n ...rest\n}: ColumnLayerOptions) {\n useOverlayStyle(() => (enabled ? buildColumnsStyle(rest) : null), [enabled]);\n\n useMapStyleOperator(\n (map) => {\n if (columns == null) {\n return;\n }\n\n setGeoJSON(map, \"columns\", promoteToFeatureCollection(columns));\n },\n [columns, enabled],\n );\n return null;\n}\n\nfunction promoteToFeatureCollection(\n data: FeatureCollection | GeoJSONFeature | GeoJSONFeature[] | null,\n): FeatureCollection | null {\n if (data == null) return null;\n if (\"type\" in data && data.type == \"Feature\") {\n return {\n type: \"FeatureCollection\",\n features: [data],\n };\n }\n if (\n \"type\" in data &&\n data.type == \"FeatureCollection\" &&\n \"features\" in data\n ) {\n return data;\n }\n return {\n type: \"FeatureCollection\",\n features: data,\n };\n}\n\nexport function buildColumnsStyle(\n opts: ColumnsStyleOptions = {},\n): StyleFragment {\n const { color } = opts;\n const columnBaseColor =\n color ?? getCSSVariable(\"--text-subtle-color\", \"black\");\n let columnColor: any = columnBaseColor;\n const columnSelectedColor =\n opts.selectedColor ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n const lineColor = opts.lineColor ?? columnBaseColor;\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n // If color is in the feature state or geojson properties, use that as second choice\n if (typeof columnColor === \"string\") {\n columnColor = [\n \"coalesce\",\n [\"feature-state\", \"color\"],\n [\"get\", \"color\"],\n columnColor,\n ];\n }\n\n const fillOpacity = opts.opacity ?? 0.1;\n\n const lineOpacity = opts.lineOpacity ?? 0.5;\n const lineWidth = opts.lineWidth ?? 2;\n\n const circleRadius = opts.circleRadius ?? 4;\n\n return {\n sources: {\n columns: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"columns-fill\",\n type: \"fill\",\n source: \"columns\",\n paint: {\n \"fill-color\": columnColor,\n \"fill-opacity\": fillOpacity,\n },\n },\n {\n id: \"columns-points\",\n type: \"circle\",\n source: \"columns\",\n paint: {\n \"circle-radius\": circleRadius,\n \"circle-color\": columnColor,\n \"circle-opacity\": fillOpacity,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n {\n id: \"columns-line\",\n type: \"line\",\n source: \"columns\",\n paint: {\n \"line-color\": [\"case\", isHovered, columnSelectedColor, lineColor],\n \"line-width\": lineWidth,\n \"line-opacity\": [\"case\", isHovered, 1.0, lineOpacity],\n },\n },\n ],\n };\n}\n\nexport type ColumnFeature = GeoJSON.Feature & { id: number };\n\nconst selectedColumnSourceID = \"selectedColumn\";\n\nexport function SelectedColumnOverlay({\n selectedColumn,\n ...styleOpts\n}: { selectedColumn: ColumnFeature | null } & SelectedColumnStyleOpts) {\n useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);\n\n useMapStyleOperator(\n (map) => {\n setGeoJSON(\n map,\n selectedColumnSourceID,\n promoteToFeatureCollection(selectedColumn as GeoJSONFeature | null),\n );\n },\n [selectedColumn],\n );\n\n return null;\n}\n\ninterface SelectedColumnStyleOpts {\n color?: string | any[];\n}\n\nfunction buildSelectedColumnStyle(\n opts: SelectedColumnStyleOpts = {},\n): StyleFragment {\n const columnSelectedColor: any =\n opts.color ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n return {\n sources: {\n selectedColumn: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"selected-column-highlight\",\n type: \"fill\",\n source: selectedColumnSourceID,\n paint: {\n \"fill-color\": columnSelectedColor,\n \"fill-opacity\": 0.5,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-edge\",\n type: \"line\",\n source: selectedColumnSourceID,\n paint: {\n \"line-color\": columnSelectedColor,\n \"line-width\": 2,\n \"line-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-point\",\n type: \"circle\",\n source: selectedColumnSourceID,\n paint: {\n \"circle-radius\": 6,\n \"circle-color\": columnSelectedColor,\n \"circle-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n ],\n };\n}\n"],"names":["useOverlayStyle","useMapStyleOperator","setGeoJSON","getCSSVariable","buildGeoJSONSource"],"mappings":";;;;;AAuBO,SAAS,iBAAiB;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAuB;AACrBA,cAAAA,gBAAgB,MAAO,UAAU,kBAAkB,IAAI,IAAI,MAAO,CAAC,OAAO,CAAC;AAE3EC,cAAAA;AAAAA,IACE,CAAC,QAAQ;AACP,UAAI,WAAW,MAAM;AACnB;AAAA,MACF;AAEAC,kBAAAA,WAAW,KAAK,WAAW,2BAA2B,OAAO,CAAC;AAAA,IAChE;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EAAA;AAEnB,SAAO;AACT;AAEA,SAAS,2BACP,MAC0B;AAC1B,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI,UAAU,QAAQ,KAAK,QAAQ,WAAW;AAC5C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,CAAC,IAAI;AAAA,IAAA;AAAA,EAEnB;AACA,MACE,UAAU,QACV,KAAK,QAAQ,uBACb,cAAc,MACd;AACA,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,EAAA;AAEd;AAEO,SAAS,kBACd,OAA4B,IACb;AACf,QAAM,EAAE,UAAU;AAClB,QAAM,kBACJ,SAASC,0BAAe,uBAAuB,OAAO;AACxD,MAAI,cAAmB;AACvB,QAAM,sBACJ,KAAK,iBAAiBA,WAAAA,eAAe,qBAAqB,QAAQ;AAEpE,QAAM,YAAY,KAAK,aAAa;
|
|
1
|
+
{"version":3,"file":"columns.cjs","sources":["../../../src/maps/layers/columns.ts"],"sourcesContent":["import { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport GeoJSON, { FeatureCollection } from \"geojson\";\nimport { GeoJSONFeature } from \"mapbox-gl\";\nimport { getCSSVariable } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport { StyleFragment } from \"@macrostrat/mapbox-react\";\n\nexport interface ColumnsStyleOptions {\n color?: string | any[];\n selectedColor?: string | any[];\n opacity?: number | any[];\n circleRadius?: number | any[];\n lineOpacity?: number | any[];\n lineWidth?: number | any[];\n lineColor?: string | any[];\n}\n\ninterface ColumnLayerOptions extends ColumnsStyleOptions {\n enabled: boolean;\n columns: FeatureCollection | GeoJSONFeature[];\n}\n\nexport function BaseColumnsLayer({\n enabled = true,\n columns,\n ...rest\n}: ColumnLayerOptions) {\n useOverlayStyle(() => (enabled ? buildColumnsStyle(rest) : null), [enabled]);\n\n useMapStyleOperator(\n (map) => {\n if (columns == null) {\n return;\n }\n\n setGeoJSON(map, \"columns\", promoteToFeatureCollection(columns));\n },\n [columns, enabled],\n );\n return null;\n}\n\nfunction promoteToFeatureCollection(\n data: FeatureCollection | GeoJSONFeature | GeoJSONFeature[] | null,\n): FeatureCollection | null {\n if (data == null) return null;\n if (\"type\" in data && data.type == \"Feature\") {\n return {\n type: \"FeatureCollection\",\n features: [data],\n };\n }\n if (\n \"type\" in data &&\n data.type == \"FeatureCollection\" &&\n \"features\" in data\n ) {\n return data;\n }\n return {\n type: \"FeatureCollection\",\n features: data,\n };\n}\n\nexport function buildColumnsStyle(\n opts: ColumnsStyleOptions = {},\n): StyleFragment {\n const { color } = opts;\n const columnBaseColor =\n color ?? getCSSVariable(\"--text-subtle-color\", \"black\");\n let columnColor: any = columnBaseColor;\n const columnSelectedColor =\n opts.selectedColor ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n const lineColor = opts.lineColor ?? columnBaseColor;\n // Highlight on either direct map hover or an externally-driven highlight\n // (e.g. hovering the corresponding column header elsewhere in the UI).\n const isHovered = [\n \"any\",\n [\"boolean\", [\"feature-state\", \"hover\"], false],\n [\"boolean\", [\"feature-state\", \"highlighted\"], false],\n ];\n // If color is in the feature state or geojson properties, use that as second choice\n if (typeof columnColor === \"string\") {\n columnColor = [\n \"coalesce\",\n [\"feature-state\", \"color\"],\n [\"get\", \"color\"],\n columnColor,\n ];\n }\n\n const fillOpacity = opts.opacity ?? 0.1;\n\n const lineOpacity = opts.lineOpacity ?? 0.5;\n const lineWidth = opts.lineWidth ?? 2;\n\n const circleRadius = opts.circleRadius ?? 4;\n\n return {\n sources: {\n columns: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"columns-fill\",\n type: \"fill\",\n source: \"columns\",\n paint: {\n \"fill-color\": columnColor,\n \"fill-opacity\": fillOpacity,\n },\n },\n {\n id: \"columns-points\",\n type: \"circle\",\n source: \"columns\",\n paint: {\n \"circle-radius\": circleRadius,\n \"circle-color\": columnColor,\n \"circle-opacity\": fillOpacity,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n {\n id: \"columns-line\",\n type: \"line\",\n source: \"columns\",\n paint: {\n \"line-color\": [\"case\", isHovered, columnSelectedColor, lineColor],\n \"line-width\": lineWidth,\n \"line-opacity\": [\"case\", isHovered, 1.0, lineOpacity],\n },\n },\n ],\n };\n}\n\nexport type ColumnFeature = GeoJSON.Feature & { id: number };\n\nconst selectedColumnSourceID = \"selectedColumn\";\n\nexport function SelectedColumnOverlay({\n selectedColumn,\n ...styleOpts\n}: { selectedColumn: ColumnFeature | null } & SelectedColumnStyleOpts) {\n useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);\n\n useMapStyleOperator(\n (map) => {\n setGeoJSON(\n map,\n selectedColumnSourceID,\n promoteToFeatureCollection(selectedColumn as GeoJSONFeature | null),\n );\n },\n [selectedColumn],\n );\n\n return null;\n}\n\ninterface SelectedColumnStyleOpts {\n color?: string | any[];\n}\n\nfunction buildSelectedColumnStyle(\n opts: SelectedColumnStyleOpts = {},\n): StyleFragment {\n const columnSelectedColor: any =\n opts.color ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n return {\n sources: {\n selectedColumn: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"selected-column-highlight\",\n type: \"fill\",\n source: selectedColumnSourceID,\n paint: {\n \"fill-color\": columnSelectedColor,\n \"fill-opacity\": 0.5,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-edge\",\n type: \"line\",\n source: selectedColumnSourceID,\n paint: {\n \"line-color\": columnSelectedColor,\n \"line-width\": 2,\n \"line-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-point\",\n type: \"circle\",\n source: selectedColumnSourceID,\n paint: {\n \"circle-radius\": 6,\n \"circle-color\": columnSelectedColor,\n \"circle-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n ],\n };\n}\n"],"names":["useOverlayStyle","useMapStyleOperator","setGeoJSON","getCSSVariable","buildGeoJSONSource"],"mappings":";;;;;AAuBO,SAAS,iBAAiB;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAuB;AACrBA,cAAAA,gBAAgB,MAAO,UAAU,kBAAkB,IAAI,IAAI,MAAO,CAAC,OAAO,CAAC;AAE3EC,cAAAA;AAAAA,IACE,CAAC,QAAQ;AACP,UAAI,WAAW,MAAM;AACnB;AAAA,MACF;AAEAC,kBAAAA,WAAW,KAAK,WAAW,2BAA2B,OAAO,CAAC;AAAA,IAChE;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EAAA;AAEnB,SAAO;AACT;AAEA,SAAS,2BACP,MAC0B;AAC1B,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI,UAAU,Q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B;AAAA,QAAA;AAAA,QAElB,QAAQ,CAAC,MAAM,SAAS,SAAS;AAAA,MAAA;AAAA,MAEnC;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,gBAAgB;AAAA,UAChB,kBAAkB;AAAA,QAAA;AAAA,QAEpB,QAAQ,CAAC,MAAM,SAAS,OAAO;AAAA,MAAA;AAAA,IACjC;AAAA,EACF;AAEJ;;;;"}
|
|
@@ -40,7 +40,11 @@ function buildColumnsStyle(opts = {}) {
|
|
|
40
40
|
let columnColor = columnBaseColor;
|
|
41
41
|
const columnSelectedColor = opts.selectedColor ?? getCSSVariable("--selection-color", "purple");
|
|
42
42
|
const lineColor = opts.lineColor ?? columnBaseColor;
|
|
43
|
-
const isHovered = [
|
|
43
|
+
const isHovered = [
|
|
44
|
+
"any",
|
|
45
|
+
["boolean", ["feature-state", "hover"], false],
|
|
46
|
+
["boolean", ["feature-state", "highlighted"], false]
|
|
47
|
+
];
|
|
44
48
|
if (typeof columnColor === "string") {
|
|
45
49
|
columnColor = [
|
|
46
50
|
"coalesce",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns.js","sources":["../../../src/maps/layers/columns.ts"],"sourcesContent":["import { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport GeoJSON, { FeatureCollection } from \"geojson\";\nimport { GeoJSONFeature } from \"mapbox-gl\";\nimport { getCSSVariable } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport { StyleFragment } from \"@macrostrat/mapbox-react\";\n\nexport interface ColumnsStyleOptions {\n color?: string | any[];\n selectedColor?: string | any[];\n opacity?: number | any[];\n circleRadius?: number | any[];\n lineOpacity?: number | any[];\n lineWidth?: number | any[];\n lineColor?: string | any[];\n}\n\ninterface ColumnLayerOptions extends ColumnsStyleOptions {\n enabled: boolean;\n columns: FeatureCollection | GeoJSONFeature[];\n}\n\nexport function BaseColumnsLayer({\n enabled = true,\n columns,\n ...rest\n}: ColumnLayerOptions) {\n useOverlayStyle(() => (enabled ? buildColumnsStyle(rest) : null), [enabled]);\n\n useMapStyleOperator(\n (map) => {\n if (columns == null) {\n return;\n }\n\n setGeoJSON(map, \"columns\", promoteToFeatureCollection(columns));\n },\n [columns, enabled],\n );\n return null;\n}\n\nfunction promoteToFeatureCollection(\n data: FeatureCollection | GeoJSONFeature | GeoJSONFeature[] | null,\n): FeatureCollection | null {\n if (data == null) return null;\n if (\"type\" in data && data.type == \"Feature\") {\n return {\n type: \"FeatureCollection\",\n features: [data],\n };\n }\n if (\n \"type\" in data &&\n data.type == \"FeatureCollection\" &&\n \"features\" in data\n ) {\n return data;\n }\n return {\n type: \"FeatureCollection\",\n features: data,\n };\n}\n\nexport function buildColumnsStyle(\n opts: ColumnsStyleOptions = {},\n): StyleFragment {\n const { color } = opts;\n const columnBaseColor =\n color ?? getCSSVariable(\"--text-subtle-color\", \"black\");\n let columnColor: any = columnBaseColor;\n const columnSelectedColor =\n opts.selectedColor ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n const lineColor = opts.lineColor ?? columnBaseColor;\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n // If color is in the feature state or geojson properties, use that as second choice\n if (typeof columnColor === \"string\") {\n columnColor = [\n \"coalesce\",\n [\"feature-state\", \"color\"],\n [\"get\", \"color\"],\n columnColor,\n ];\n }\n\n const fillOpacity = opts.opacity ?? 0.1;\n\n const lineOpacity = opts.lineOpacity ?? 0.5;\n const lineWidth = opts.lineWidth ?? 2;\n\n const circleRadius = opts.circleRadius ?? 4;\n\n return {\n sources: {\n columns: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"columns-fill\",\n type: \"fill\",\n source: \"columns\",\n paint: {\n \"fill-color\": columnColor,\n \"fill-opacity\": fillOpacity,\n },\n },\n {\n id: \"columns-points\",\n type: \"circle\",\n source: \"columns\",\n paint: {\n \"circle-radius\": circleRadius,\n \"circle-color\": columnColor,\n \"circle-opacity\": fillOpacity,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n {\n id: \"columns-line\",\n type: \"line\",\n source: \"columns\",\n paint: {\n \"line-color\": [\"case\", isHovered, columnSelectedColor, lineColor],\n \"line-width\": lineWidth,\n \"line-opacity\": [\"case\", isHovered, 1.0, lineOpacity],\n },\n },\n ],\n };\n}\n\nexport type ColumnFeature = GeoJSON.Feature & { id: number };\n\nconst selectedColumnSourceID = \"selectedColumn\";\n\nexport function SelectedColumnOverlay({\n selectedColumn,\n ...styleOpts\n}: { selectedColumn: ColumnFeature | null } & SelectedColumnStyleOpts) {\n useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);\n\n useMapStyleOperator(\n (map) => {\n setGeoJSON(\n map,\n selectedColumnSourceID,\n promoteToFeatureCollection(selectedColumn as GeoJSONFeature | null),\n );\n },\n [selectedColumn],\n );\n\n return null;\n}\n\ninterface SelectedColumnStyleOpts {\n color?: string | any[];\n}\n\nfunction buildSelectedColumnStyle(\n opts: SelectedColumnStyleOpts = {},\n): StyleFragment {\n const columnSelectedColor: any =\n opts.color ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n return {\n sources: {\n selectedColumn: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"selected-column-highlight\",\n type: \"fill\",\n source: selectedColumnSourceID,\n paint: {\n \"fill-color\": columnSelectedColor,\n \"fill-opacity\": 0.5,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-edge\",\n type: \"line\",\n source: selectedColumnSourceID,\n paint: {\n \"line-color\": columnSelectedColor,\n \"line-width\": 2,\n \"line-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-point\",\n type: \"circle\",\n source: selectedColumnSourceID,\n paint: {\n \"circle-radius\": 6,\n \"circle-color\": columnSelectedColor,\n \"circle-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n ],\n };\n}\n"],"names":[],"mappings":";;;AAuBO,SAAS,iBAAiB;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,kBAAgB,MAAO,UAAU,kBAAkB,IAAI,IAAI,MAAO,CAAC,OAAO,CAAC;AAE3E;AAAA,IACE,CAAC,QAAQ;AACP,UAAI,WAAW,MAAM;AACnB;AAAA,MACF;AAEA,iBAAW,KAAK,WAAW,2BAA2B,OAAO,CAAC;AAAA,IAChE;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EAAA;AAEnB,SAAO;AACT;AAEA,SAAS,2BACP,MAC0B;AAC1B,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI,UAAU,QAAQ,KAAK,QAAQ,WAAW;AAC5C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,CAAC,IAAI;AAAA,IAAA;AAAA,EAEnB;AACA,MACE,UAAU,QACV,KAAK,QAAQ,uBACb,cAAc,MACd;AACA,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,EAAA;AAEd;AAEO,SAAS,kBACd,OAA4B,IACb;AACf,QAAM,EAAE,UAAU;AAClB,QAAM,kBACJ,SAAS,eAAe,uBAAuB,OAAO;AACxD,MAAI,cAAmB;AACvB,QAAM,sBACJ,KAAK,iBAAiB,eAAe,qBAAqB,QAAQ;AAEpE,QAAM,YAAY,KAAK,aAAa;
|
|
1
|
+
{"version":3,"file":"columns.js","sources":["../../../src/maps/layers/columns.ts"],"sourcesContent":["import { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport GeoJSON, { FeatureCollection } from \"geojson\";\nimport { GeoJSONFeature } from \"mapbox-gl\";\nimport { getCSSVariable } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport { StyleFragment } from \"@macrostrat/mapbox-react\";\n\nexport interface ColumnsStyleOptions {\n color?: string | any[];\n selectedColor?: string | any[];\n opacity?: number | any[];\n circleRadius?: number | any[];\n lineOpacity?: number | any[];\n lineWidth?: number | any[];\n lineColor?: string | any[];\n}\n\ninterface ColumnLayerOptions extends ColumnsStyleOptions {\n enabled: boolean;\n columns: FeatureCollection | GeoJSONFeature[];\n}\n\nexport function BaseColumnsLayer({\n enabled = true,\n columns,\n ...rest\n}: ColumnLayerOptions) {\n useOverlayStyle(() => (enabled ? buildColumnsStyle(rest) : null), [enabled]);\n\n useMapStyleOperator(\n (map) => {\n if (columns == null) {\n return;\n }\n\n setGeoJSON(map, \"columns\", promoteToFeatureCollection(columns));\n },\n [columns, enabled],\n );\n return null;\n}\n\nfunction promoteToFeatureCollection(\n data: FeatureCollection | GeoJSONFeature | GeoJSONFeature[] | null,\n): FeatureCollection | null {\n if (data == null) return null;\n if (\"type\" in data && data.type == \"Feature\") {\n return {\n type: \"FeatureCollection\",\n features: [data],\n };\n }\n if (\n \"type\" in data &&\n data.type == \"FeatureCollection\" &&\n \"features\" in data\n ) {\n return data;\n }\n return {\n type: \"FeatureCollection\",\n features: data,\n };\n}\n\nexport function buildColumnsStyle(\n opts: ColumnsStyleOptions = {},\n): StyleFragment {\n const { color } = opts;\n const columnBaseColor =\n color ?? getCSSVariable(\"--text-subtle-color\", \"black\");\n let columnColor: any = columnBaseColor;\n const columnSelectedColor =\n opts.selectedColor ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n const lineColor = opts.lineColor ?? columnBaseColor;\n // Highlight on either direct map hover or an externally-driven highlight\n // (e.g. hovering the corresponding column header elsewhere in the UI).\n const isHovered = [\n \"any\",\n [\"boolean\", [\"feature-state\", \"hover\"], false],\n [\"boolean\", [\"feature-state\", \"highlighted\"], false],\n ];\n // If color is in the feature state or geojson properties, use that as second choice\n if (typeof columnColor === \"string\") {\n columnColor = [\n \"coalesce\",\n [\"feature-state\", \"color\"],\n [\"get\", \"color\"],\n columnColor,\n ];\n }\n\n const fillOpacity = opts.opacity ?? 0.1;\n\n const lineOpacity = opts.lineOpacity ?? 0.5;\n const lineWidth = opts.lineWidth ?? 2;\n\n const circleRadius = opts.circleRadius ?? 4;\n\n return {\n sources: {\n columns: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"columns-fill\",\n type: \"fill\",\n source: \"columns\",\n paint: {\n \"fill-color\": columnColor,\n \"fill-opacity\": fillOpacity,\n },\n },\n {\n id: \"columns-points\",\n type: \"circle\",\n source: \"columns\",\n paint: {\n \"circle-radius\": circleRadius,\n \"circle-color\": columnColor,\n \"circle-opacity\": fillOpacity,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n {\n id: \"columns-line\",\n type: \"line\",\n source: \"columns\",\n paint: {\n \"line-color\": [\"case\", isHovered, columnSelectedColor, lineColor],\n \"line-width\": lineWidth,\n \"line-opacity\": [\"case\", isHovered, 1.0, lineOpacity],\n },\n },\n ],\n };\n}\n\nexport type ColumnFeature = GeoJSON.Feature & { id: number };\n\nconst selectedColumnSourceID = \"selectedColumn\";\n\nexport function SelectedColumnOverlay({\n selectedColumn,\n ...styleOpts\n}: { selectedColumn: ColumnFeature | null } & SelectedColumnStyleOpts) {\n useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);\n\n useMapStyleOperator(\n (map) => {\n setGeoJSON(\n map,\n selectedColumnSourceID,\n promoteToFeatureCollection(selectedColumn as GeoJSONFeature | null),\n );\n },\n [selectedColumn],\n );\n\n return null;\n}\n\ninterface SelectedColumnStyleOpts {\n color?: string | any[];\n}\n\nfunction buildSelectedColumnStyle(\n opts: SelectedColumnStyleOpts = {},\n): StyleFragment {\n const columnSelectedColor: any =\n opts.color ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n return {\n sources: {\n selectedColumn: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"selected-column-highlight\",\n type: \"fill\",\n source: selectedColumnSourceID,\n paint: {\n \"fill-color\": columnSelectedColor,\n \"fill-opacity\": 0.5,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-edge\",\n type: \"line\",\n source: selectedColumnSourceID,\n paint: {\n \"line-color\": columnSelectedColor,\n \"line-width\": 2,\n \"line-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-point\",\n type: \"circle\",\n source: selectedColumnSourceID,\n paint: {\n \"circle-radius\": 6,\n \"circle-color\": columnSelectedColor,\n \"circle-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n ],\n };\n}\n"],"names":[],"mappings":";;;AAuBO,SAAS,iBAAiB;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,kBAAgB,MAAO,UAAU,kBAAkB,IAAI,IAAI,MAAO,CAAC,OAAO,CAAC;AAE3E;AAAA,IACE,CAAC,QAAQ;AACP,UAAI,WAAW,MAAM;AACnB;AAAA,MACF;AAEA,iBAAW,KAAK,WAAW,2BAA2B,OAAO,CAAC;AAAA,IAChE;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EAAA;AAEnB,SAAO;AACT;AAEA,SAAS,2BACP,MAC0B;AAC1B,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI,UAAU,QAAQ,KAAK,QAAQ,WAAW;AAC5C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,CAAC,IAAI;AAAA,IAAA;AAAA,EAEnB;AACA,MACE,UAAU,QACV,KAAK,QAAQ,uBACb,cAAc,MACd;AACA,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,EAAA;AAEd;AAEO,SAAS,kBACd,OAA4B,IACb;AACf,QAAM,EAAE,UAAU;AAClB,QAAM,kBACJ,SAAS,eAAe,uBAAuB,OAAO;AACxD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|
}
|
|
55
55
|
}
|
|
56
|
-
console.log(columns);
|
|
57
56
|
const units = columns.flatMap(
|
|
58
57
|
(column, columnIndex) => column.map((unit) => {
|
|
59
58
|
return {
|
|
@@ -147,7 +146,10 @@ function groupUnitsIntoSectionsByOverlap(units, axisType = columnComponents.Colu
|
|
|
147
146
|
} else {
|
|
148
147
|
const lastSection = nextSections[nextSections.length - 1];
|
|
149
148
|
if (isOverlapping(section, lastSection)) {
|
|
150
|
-
nextSections[nextSections.length - 1] = mergeSections(
|
|
149
|
+
nextSections[nextSections.length - 1] = mergeSections(
|
|
150
|
+
lastSection,
|
|
151
|
+
section
|
|
152
|
+
);
|
|
151
153
|
merged = true;
|
|
152
154
|
} else {
|
|
153
155
|
nextSections.push(section);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sources":["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n mergeAgeRanges,\n MergeMode,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\n\nexport type UnitWithLayoutParameters<T extends BaseUnit> = T & {\n layout: UnitLayoutData<T>;\n};\n\nexport type UnitWithLayoutHints<T extends BaseUnit> = T & {\n layoutHints?: UnitLayoutHints;\n};\n\ninterface UnitLayoutInfo {\n column: number;\n nColumns: number;\n}\n\ntype UnitLayoutHints = Partial<UnitLayoutInfo>;\n\ntype UnitLayoutData<T extends BaseUnit> = UnitLayoutInfo & {\n totalColumns: number;\n unitGroup: UnitGroup<T>;\n};\n\nclass UnitGroup<T extends BaseUnit> implements StratigraphicPackage {\n units: T[];\n axisType: ColumnAxisType;\n\n constructor(units: T[], axisType: ColumnAxisType = ColumnAxisType.AGE) {\n this.units = units;\n this.axisType = axisType;\n }\n\n get t_age(): number {\n return Math.min(...this.units.map((d) => d.t_age));\n }\n\n get b_age(): number {\n return Math.max(...this.units.map((d) => d.b_age));\n }\n\n getUnits(): UnitWithLayoutParameters<T>[] {\n return assignColumnsToUnitsWithinOverlappingGroup(this);\n }\n}\n\nfunction groupUnitsByMutualOverlap<T extends BaseUnit>(\n units: T[],\n tolerance: number = dt,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): UnitGroup<T>[] {\n /** Group units within a section that have mutual overlap. */\n\n const sections = groupUnitsIntoSectionsByOverlap(units, axisType, tolerance);\n\n console.log(\"Grouped sections\", sections);\n\n return sections.map((d) => {\n return new UnitGroup(d.units, axisType);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<UnitWithLayoutHints<T>>,\n): UnitWithLayoutParameters<T>[] {\n /** A relatively naïve function to assign columns to units within a mutually overlapping group.\n * This gets the number of columns that would be needed to accommodate the units in the group.\n * It then assigns columns to units in the group based on the number of columns needed, with\n * lower units further to the left.\n */\n\n const sortedUnits = [...group.units].sort(createUnitSorter(group.axisType));\n\n const columns: T[][] = [];\n\n let nColumns = 1;\n\n for (const unit of sortedUnits) {\n let startIndex = 0;\n let endIndex = 0;\n // Find a column that is not already occupied by an overlapping unit\n const colHint = unit.layoutHints?.column;\n if (colHint != null) {\n columns[colHint] ??= [];\n columns[colHint].push(unit);\n continue;\n }\n let didAddToExistingColumn = false;\n\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, group.axisType, dt)) {\n column.push(unit);\n didAddToExistingColumn = true;\n break;\n }\n }\n if (!didAddToExistingColumn) {\n columns.push([unit]);\n }\n }\n\n console.log(columns);\n\n const units: UnitWithLayoutParameters<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n layout: {\n column: columnIndex,\n nColumns: 1,\n totalColumns: columns.length,\n unitGroup: group,\n },\n };\n }),\n );\n\n return units.toSorted(sortByAge);\n}\n\nexport function preprocessUnits<T extends UnitLong = UnitLong>(\n section: SectionInfo<T>,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit[] {\n /** Preprocess units to add overlapping units and columns. */\n let units = section.units;\n\n let tolerance = 0.001; // 1 kyr tolerance for age columns\n if (axisType != ColumnAxisType.AGE) {\n tolerance = 0.01; // 1cm tolerance for height/depth columns\n }\n\n const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);\n\n const divisions: any[] = [];\n // Serialize all groups' units to a single array\n for (const group of unitGroups) {\n divisions.push(...group.getUnits());\n }\n\n return divisions.map((d) =>\n enhanceUnitWithClippingPosition(section, d, axisType),\n );\n}\n\nexport function enhanceUnitWithClippingPosition(section, d, axisType) {\n const [b_pos, t_pos] = getUnitHeightRange(d, axisType);\n if (axisType == ColumnAxisType.AGE) {\n if (b_pos > section.b_age) {\n d.b_clip_pos = section.b_age;\n }\n if (t_pos < section.t_age) {\n d.t_clip_pos = section.t_age;\n }\n }\n if (axisType == ColumnAxisType.DEPTH) {\n if (b_pos > section.b_pos) {\n d.b_clip_pos = section.b_pos;\n }\n if (t_pos < section.t_pos) {\n d.t_clip_pos = section.t_pos;\n }\n }\n return d;\n}\n\nexport function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): SectionInfo<T>[] {\n /** Group units into sections by section_id.\n * This works for large-scale Macrostrat columns, where units are grouped by section_id.\n * */\n let groups = Array.from(group(units, (d) => d.section_id));\n const unitComparator = createUnitSorter(axisType);\n\n const groups1 = groups.map(([section_id, sectionUnits]) => {\n const [b_age, t_age] = getSectionAgeRange(sectionUnits);\n const [b_pos, t_pos] = getSectionPosRange(sectionUnits, axisType);\n\n // sort units by position\n sectionUnits.sort(unitComparator);\n return { section_id, t_age, b_age, b_pos, t_pos, units: sectionUnits };\n });\n // Sort sections by increasing top age, then increasing bottom age.\n // Sections have no relative ordinal position other than age...\n const compareSections = createUnitSorter(axisType) as (\n a: StratigraphicPackage,\n b: StratigraphicPackage,\n ) => number;\n groups1.sort(compareSections);\n return groups1;\n}\n\ninterface WorkingSection {\n units: UnitLong[];\n // Position or age\n heightRange: [number, number];\n}\n\nexport function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n tolerance: number = dt,\n): SectionInfo<T>[] {\n /** Group units into sections by overlap.\n * This creates \"synthetic\" sections that correspond to packages bound by scale gaps.\n * This is most useful in the height and depth domains, where gaps (e.g., missing core) are\n * common.\n * */\n // Start with each unit as its own \"section\", and progressively merge...\n const sectionList: WorkingSection[] = [];\n\n const initialSections: WorkingSection[] = units.map((unit) => {\n return {\n units: [unit],\n heightRange: getUnitHeightRange(unit, axisType),\n };\n });\n\n const isOverlapping = (a: WorkingSection, b: WorkingSection) => {\n const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);\n return res !== AgeRangeRelationship.Disjoint;\n };\n\n const mergeSections = (a: WorkingSection, b: WorkingSection) => {\n return {\n units: [...a.units, ...b.units],\n heightRange: mergeAgeRanges(\n [a.heightRange, b.heightRange],\n MergeMode.Outer,\n ),\n };\n };\n\n // Merge overlapping sections progressively until no more merges are possible\n let finalSectionList = initialSections;\n\n while (true) {\n let merged = false;\n const nextSections: WorkingSection[] = [];\n\n for (const section of finalSectionList) {\n if (nextSections.length === 0) {\n nextSections.push(section);\n } else {\n const lastSection = nextSections[nextSections.length - 1];\n if (isOverlapping(section, lastSection)) {\n // Merge with the last section\n nextSections[nextSections.length - 1] = mergeSections(lastSection, section);\n merged = true;\n } else {\n nextSections.push(section);\n }\n }\n }\n\n finalSectionList = nextSections;\n\n // Stop when no more merges occurred in this pass\n if (!merged) {\n break;\n }\n }\n\n return finalSectionList.map((section, i) => {\n const [b_age, t_age] = getSectionAgeRange(section.units);\n const [b_pos, t_pos] = getSectionPosRange(section.units, axisType);\n return {\n // Negative section IDs are used to indicate that these are synthetic sections\n section_id: -i,\n t_age,\n b_age,\n t_pos,\n b_pos,\n units: section.units as T[],\n };\n });\n}\n\nexport function getSectionPosRange(\n units: BaseUnit[],\n axisType: ColumnAxisType,\n): [number, number] {\n /** Get the overall position range of a set of units. */\n const t_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.t_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.t_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n const b_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.b_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.b_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n if (axisType == ColumnAxisType.AGE || axisType == ColumnAxisType.DEPTH) {\n return [Math.max(...b_positions), Math.min(...t_positions)];\n } else {\n return [Math.min(...b_positions), Math.max(...t_positions)];\n }\n}\n\nexport function getSectionAgeRange(units: BaseUnit[]): [number, number] {\n /** Get the overall age range of a set of units. */\n return getSectionPosRange(units, ColumnAxisType.AGE);\n}\n\nexport function mergeOverlappingSections<T extends UnitLong>(\n sections: SectionInfo<T>[],\n): SectionInfo<T>[] {\n /** Columns can have sections that overlap in time. Here, we merge overlapping\n * sections into a single section to correctly render gap-bound packages.\n */\n const [firstSection, ...rest] = sections;\n const newSections = [firstSection];\n for (const section of rest) {\n const lastSection = newSections[newSections.length - 1];\n if (\n lastSection.b_age < section.t_age ||\n lastSection.t_age > section.b_age\n ) {\n // No overlap, add the section as normal\n newSections.push(section);\n continue;\n }\n\n // Overlap, merge the sections\n lastSection.section_id = [\n ...ensureArray(lastSection.section_id),\n ...ensureArray(section.section_id),\n ];\n lastSection.units.push(...section.units);\n lastSection.b_age = Math.max(lastSection.b_age, section.b_age);\n lastSection.t_age = Math.min(lastSection.t_age, section.t_age);\n }\n return newSections;\n}\n\nexport function preprocessSectionUnit(unit: UnitLong): UnitLong {\n /** Preprocess a single unit for a \"section\" column type.\n * This mostly handles vagaries of eODP-style columns.\n * */\n\n let b_pos = unit.b_pos;\n let t_pos = unit.t_pos;\n\n let unit_name = unit.unit_name;\n\n // eODP columns sometimes have overlapping core sections, which are encoded in the name field\n // Match eODP section names\n const match = unit.unit_name.match(/^(\\d+(\\.\\d+)?)-(\\d+(\\.\\d+)?): (.+)/);\n\n if (match) {\n // These values should already be set if we've used the show_positions flag\n t_pos ??= ensureRealFloat(match[1]);\n b_pos ??= ensureRealFloat(match[3]);\n unit_name = match[5];\n }\n\n return {\n ...unit,\n b_pos: ensureRealFloat(b_pos),\n t_pos: ensureRealFloat(t_pos),\n unit_name,\n };\n}\n"],"names":["ColumnAxisType","createUnitSorter","group","unitsOverlap","getUnitHeightRange","compareAgeRanges","AgeRangeRelationship","mergeAgeRanges","MergeMode","ensureArray","ensureRealFloat"],"mappings":";;;;;;AAkBA,MAAM,KAAK;AAsBX,MAAM,UAA8D;AAAA,EAClE;AAAA,EACA;AAAA,EAEA,YAAY,OAAY,WAA2BA,iBAAAA,eAAe,KAAK;AACrE,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,WAA0C;AACxC,WAAO,2CAA2C,IAAI;AAAA,EACxD;AACF;AAEA,SAAS,0BACP,OACA,YAAoB,IACpB,WAA2B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["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n mergeAgeRanges,\n MergeMode,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\n\nexport type UnitWithLayoutParameters<T extends BaseUnit> = T & {\n layout: UnitLayoutData<T>;\n};\n\nexport type UnitWithLayoutHints<T extends BaseUnit> = T & {\n layoutHints?: UnitLayoutHints;\n};\n\ninterface UnitLayoutInfo {\n column: number;\n nColumns: number;\n}\n\ntype UnitLayoutHints = Partial<UnitLayoutInfo>;\n\ntype UnitLayoutData<T extends BaseUnit> = UnitLayoutInfo & {\n totalColumns: number;\n unitGroup: UnitGroup<T>;\n};\n\nclass UnitGroup<T extends BaseUnit> implements StratigraphicPackage {\n units: T[];\n axisType: ColumnAxisType;\n\n constructor(units: T[], axisType: ColumnAxisType = ColumnAxisType.AGE) {\n this.units = units;\n this.axisType = axisType;\n }\n\n get t_age(): number {\n return Math.min(...this.units.map((d) => d.t_age));\n }\n\n get b_age(): number {\n return Math.max(...this.units.map((d) => d.b_age));\n }\n\n getUnits(): UnitWithLayoutParameters<T>[] {\n return assignColumnsToUnitsWithinOverlappingGroup(this);\n }\n}\n\nfunction groupUnitsByMutualOverlap<T extends BaseUnit>(\n units: T[],\n tolerance: number = dt,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): UnitGroup<T>[] {\n /** Group units within a section that have mutual overlap. */\n\n const sections = groupUnitsIntoSectionsByOverlap(units, axisType, tolerance);\n\n console.log(\"Grouped sections\", sections);\n\n return sections.map((d) => {\n return new UnitGroup(d.units, axisType);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<UnitWithLayoutHints<T>>,\n): UnitWithLayoutParameters<T>[] {\n /** A relatively naïve function to assign columns to units within a mutually overlapping group.\n * This gets the number of columns that would be needed to accommodate the units in the group.\n * It then assigns columns to units in the group based on the number of columns needed, with\n * lower units further to the left.\n */\n\n const sortedUnits = [...group.units].sort(createUnitSorter(group.axisType));\n\n const columns: T[][] = [];\n\n let nColumns = 1;\n\n for (const unit of sortedUnits) {\n let startIndex = 0;\n let endIndex = 0;\n // Find a column that is not already occupied by an overlapping unit\n const colHint = unit.layoutHints?.column;\n if (colHint != null) {\n columns[colHint] ??= [];\n columns[colHint].push(unit);\n continue;\n }\n let didAddToExistingColumn = false;\n\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, group.axisType, dt)) {\n column.push(unit);\n didAddToExistingColumn = true;\n break;\n }\n }\n if (!didAddToExistingColumn) {\n columns.push([unit]);\n }\n }\n\n const units: UnitWithLayoutParameters<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n layout: {\n column: columnIndex,\n nColumns: 1,\n totalColumns: columns.length,\n unitGroup: group,\n },\n };\n }),\n );\n\n return units.toSorted(sortByAge);\n}\n\nexport function preprocessUnits<T extends UnitLong = UnitLong>(\n section: SectionInfo<T>,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit[] {\n /** Preprocess units to add overlapping units and columns. */\n let units = section.units;\n\n let tolerance = 0.001; // 1 kyr tolerance for age columns\n if (axisType != ColumnAxisType.AGE) {\n tolerance = 0.01; // 1cm tolerance for height/depth columns\n }\n\n const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);\n\n const divisions: any[] = [];\n // Serialize all groups' units to a single array\n for (const group of unitGroups) {\n divisions.push(...group.getUnits());\n }\n\n return divisions.map((d) =>\n enhanceUnitWithClippingPosition(section, d, axisType),\n );\n}\n\nexport function enhanceUnitWithClippingPosition(section, d, axisType) {\n const [b_pos, t_pos] = getUnitHeightRange(d, axisType);\n if (axisType == ColumnAxisType.AGE) {\n if (b_pos > section.b_age) {\n d.b_clip_pos = section.b_age;\n }\n if (t_pos < section.t_age) {\n d.t_clip_pos = section.t_age;\n }\n }\n if (axisType == ColumnAxisType.DEPTH) {\n if (b_pos > section.b_pos) {\n d.b_clip_pos = section.b_pos;\n }\n if (t_pos < section.t_pos) {\n d.t_clip_pos = section.t_pos;\n }\n }\n return d;\n}\n\nexport function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): SectionInfo<T>[] {\n /** Group units into sections by section_id.\n * This works for large-scale Macrostrat columns, where units are grouped by section_id.\n * */\n let groups = Array.from(group(units, (d) => d.section_id));\n const unitComparator = createUnitSorter(axisType);\n\n const groups1 = groups.map(([section_id, sectionUnits]) => {\n const [b_age, t_age] = getSectionAgeRange(sectionUnits);\n const [b_pos, t_pos] = getSectionPosRange(sectionUnits, axisType);\n\n // sort units by position\n sectionUnits.sort(unitComparator);\n return { section_id, t_age, b_age, b_pos, t_pos, units: sectionUnits };\n });\n // Sort sections by increasing top age, then increasing bottom age.\n // Sections have no relative ordinal position other than age...\n const compareSections = createUnitSorter(axisType) as (\n a: StratigraphicPackage,\n b: StratigraphicPackage,\n ) => number;\n groups1.sort(compareSections);\n return groups1;\n}\n\ninterface WorkingSection {\n units: UnitLong[];\n // Position or age\n heightRange: [number, number];\n}\n\nexport function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n tolerance: number = dt,\n): SectionInfo<T>[] {\n /** Group units into sections by overlap.\n * This creates \"synthetic\" sections that correspond to packages bound by scale gaps.\n * This is most useful in the height and depth domains, where gaps (e.g., missing core) are\n * common.\n * */\n // Start with each unit as its own \"section\", and progressively merge...\n const sectionList: WorkingSection[] = [];\n\n const initialSections: WorkingSection[] = units.map((unit) => {\n return {\n units: [unit],\n heightRange: getUnitHeightRange(unit, axisType),\n };\n });\n\n const isOverlapping = (a: WorkingSection, b: WorkingSection) => {\n const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);\n return res !== AgeRangeRelationship.Disjoint;\n };\n\n const mergeSections = (a: WorkingSection, b: WorkingSection) => {\n return {\n units: [...a.units, ...b.units],\n heightRange: mergeAgeRanges(\n [a.heightRange, b.heightRange],\n MergeMode.Outer,\n ),\n };\n };\n\n // Merge overlapping sections progressively until no more merges are possible\n let finalSectionList = initialSections;\n\n while (true) {\n let merged = false;\n const nextSections: WorkingSection[] = [];\n\n for (const section of finalSectionList) {\n if (nextSections.length === 0) {\n nextSections.push(section);\n } else {\n const lastSection = nextSections[nextSections.length - 1];\n if (isOverlapping(section, lastSection)) {\n // Merge with the last section\n nextSections[nextSections.length - 1] = mergeSections(\n lastSection,\n section,\n );\n merged = true;\n } else {\n nextSections.push(section);\n }\n }\n }\n\n finalSectionList = nextSections;\n\n // Stop when no more merges occurred in this pass\n if (!merged) {\n break;\n }\n }\n\n return finalSectionList.map((section, i) => {\n const [b_age, t_age] = getSectionAgeRange(section.units);\n const [b_pos, t_pos] = getSectionPosRange(section.units, axisType);\n return {\n // Negative section IDs are used to indicate that these are synthetic sections\n section_id: -i,\n t_age,\n b_age,\n t_pos,\n b_pos,\n units: section.units as T[],\n };\n });\n}\n\nexport function getSectionPosRange(\n units: BaseUnit[],\n axisType: ColumnAxisType,\n): [number, number] {\n /** Get the overall position range of a set of units. */\n const t_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.t_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.t_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n const b_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.b_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.b_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n if (axisType == ColumnAxisType.AGE || axisType == ColumnAxisType.DEPTH) {\n return [Math.max(...b_positions), Math.min(...t_positions)];\n } else {\n return [Math.min(...b_positions), Math.max(...t_positions)];\n }\n}\n\nexport function getSectionAgeRange(units: BaseUnit[]): [number, number] {\n /** Get the overall age range of a set of units. */\n return getSectionPosRange(units, ColumnAxisType.AGE);\n}\n\nexport function mergeOverlappingSections<T extends UnitLong>(\n sections: SectionInfo<T>[],\n): SectionInfo<T>[] {\n /** Columns can have sections that overlap in time. Here, we merge overlapping\n * sections into a single section to correctly render gap-bound packages.\n */\n const [firstSection, ...rest] = sections;\n const newSections = [firstSection];\n for (const section of rest) {\n const lastSection = newSections[newSections.length - 1];\n if (\n lastSection.b_age < section.t_age ||\n lastSection.t_age > section.b_age\n ) {\n // No overlap, add the section as normal\n newSections.push(section);\n continue;\n }\n\n // Overlap, merge the sections\n lastSection.section_id = [\n ...ensureArray(lastSection.section_id),\n ...ensureArray(section.section_id),\n ];\n lastSection.units.push(...section.units);\n lastSection.b_age = Math.max(lastSection.b_age, section.b_age);\n lastSection.t_age = Math.min(lastSection.t_age, section.t_age);\n }\n return newSections;\n}\n\nexport function preprocessSectionUnit(unit: UnitLong): UnitLong {\n /** Preprocess a single unit for a \"section\" column type.\n * This mostly handles vagaries of eODP-style columns.\n * */\n\n let b_pos = unit.b_pos;\n let t_pos = unit.t_pos;\n\n let unit_name = unit.unit_name;\n\n // eODP columns sometimes have overlapping core sections, which are encoded in the name field\n // Match eODP section names\n const match = unit.unit_name.match(/^(\\d+(\\.\\d+)?)-(\\d+(\\.\\d+)?): (.+)/);\n\n if (match) {\n // These values should already be set if we've used the show_positions flag\n t_pos ??= ensureRealFloat(match[1]);\n b_pos ??= ensureRealFloat(match[3]);\n unit_name = match[5];\n }\n\n return {\n ...unit,\n b_pos: ensureRealFloat(b_pos),\n t_pos: ensureRealFloat(t_pos),\n unit_name,\n };\n}\n"],"names":["ColumnAxisType","createUnitSorter","group","unitsOverlap","getUnitHeightRange","compareAgeRanges","AgeRangeRelationship","mergeAgeRanges","MergeMode","ensureArray","ensureRealFloat"],"mappings":";;;;;;AAkBA,MAAM,KAAK;AAsBX,MAAM,UAA8D;AAAA,EAClE;AAAA,EACA;AAAA,EAEA,YAAY,OAAY,WAA2BA,iBAAAA,eAAe,KAAK;AACrE,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,WAA0C;AACxC,WAAO,2CAA2C,IAAI;AAAA,EACxD;AACF;AAEA,SAAS,0BACP,OACA,YAAoB,IACpB,WAA2BA,iBAAAA,eAAe,KAC1B;AAGhB,QAAM,WAAW,gCAAgC,OAAO,UAAU,SAAS;AAE3E,UAAQ,IAAI,oBAAoB,QAAQ;AAExC,SAAO,SAAS,IAAI,CAAC,MAAM;AACzB,WAAO,IAAI,UAAU,EAAE,OAAO,QAAQ;AAAA,EACxC,CAAC;AACH;AAEA,MAAM,YAAYC,MAAAA,iBAAiBD,iBAAAA,eAAe,GAAG;AAErD,SAAS,2CACPE,QAC+B;AAO/B,QAAM,cAAc,CAAC,GAAGA,OAAM,KAAK,EAAE,KAAKD,MAAAA,iBAAiBC,OAAM,QAAQ,CAAC;AAE1E,QAAM,UAAiB,CAAA;AAIvB,aAAW,QAAQ,aAAa;AAI9B,UAAM,UAAU,KAAK,aAAa;AAClC,QAAI,WAAW,MAAM;AACnB,cAAQ,OAAO,MAAM,CAAA;AACrB,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AAA;AAEnC,gBAAY,MAAM,KAAK,GAAG,QAAQ,KAAK;AACvC,gBAAY,QAAQ,KAAK,IAAI,YAAY,OAAO,QAAQ,KAAK;AAC7D,gBAAY,QAAQ,KAAK,IAAI,YAAY,OAAO,QAAQ,KAAK;AAAA,EAC/D;AACA,SAAO;AACT;AAEO,SAAS,sBAAsB,MAA0B;AAK9D,MAAI,QAAQ,KAAK;AACjB,MAAI,QAAQ,KAAK;AAEjB,MAAI,YAAY,KAAK;AAIrB,QAAM,QAAQ,KAAK,UAAU,MAAM,oCAAoC;AAEvE,MAAI,OAAO;AAET,cAAUC,MAAAA,gBAAgB,MAAM,CAAC,CAAC;AAClC,cAAUA,MAAAA,gBAAgB,MAAM,CAAC,CAAC;AAClC,gBAAY,MAAM,CAAC;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAOA,MAAAA,gBAAgB,KAAK;AAAA,IAC5B,OAAOA,MAAAA,gBAAgB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAEJ;;;;;;;;;"}
|
|
@@ -51,7 +51,6 @@ function assignColumnsToUnitsWithinOverlappingGroup(group2) {
|
|
|
51
51
|
columns.push([unit]);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
console.log(columns);
|
|
55
54
|
const units = columns.flatMap(
|
|
56
55
|
(column, columnIndex) => column.map((unit) => {
|
|
57
56
|
return {
|
|
@@ -145,7 +144,10 @@ function groupUnitsIntoSectionsByOverlap(units, axisType = ColumnAxisType.AGE, t
|
|
|
145
144
|
} else {
|
|
146
145
|
const lastSection = nextSections[nextSections.length - 1];
|
|
147
146
|
if (isOverlapping(section, lastSection)) {
|
|
148
|
-
nextSections[nextSections.length - 1] = mergeSections(
|
|
147
|
+
nextSections[nextSections.length - 1] = mergeSections(
|
|
148
|
+
lastSection,
|
|
149
|
+
section
|
|
150
|
+
);
|
|
149
151
|
merged = true;
|
|
150
152
|
} else {
|
|
151
153
|
nextSections.push(section);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n mergeAgeRanges,\n MergeMode,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\n\nexport type UnitWithLayoutParameters<T extends BaseUnit> = T & {\n layout: UnitLayoutData<T>;\n};\n\nexport type UnitWithLayoutHints<T extends BaseUnit> = T & {\n layoutHints?: UnitLayoutHints;\n};\n\ninterface UnitLayoutInfo {\n column: number;\n nColumns: number;\n}\n\ntype UnitLayoutHints = Partial<UnitLayoutInfo>;\n\ntype UnitLayoutData<T extends BaseUnit> = UnitLayoutInfo & {\n totalColumns: number;\n unitGroup: UnitGroup<T>;\n};\n\nclass UnitGroup<T extends BaseUnit> implements StratigraphicPackage {\n units: T[];\n axisType: ColumnAxisType;\n\n constructor(units: T[], axisType: ColumnAxisType = ColumnAxisType.AGE) {\n this.units = units;\n this.axisType = axisType;\n }\n\n get t_age(): number {\n return Math.min(...this.units.map((d) => d.t_age));\n }\n\n get b_age(): number {\n return Math.max(...this.units.map((d) => d.b_age));\n }\n\n getUnits(): UnitWithLayoutParameters<T>[] {\n return assignColumnsToUnitsWithinOverlappingGroup(this);\n }\n}\n\nfunction groupUnitsByMutualOverlap<T extends BaseUnit>(\n units: T[],\n tolerance: number = dt,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): UnitGroup<T>[] {\n /** Group units within a section that have mutual overlap. */\n\n const sections = groupUnitsIntoSectionsByOverlap(units, axisType, tolerance);\n\n console.log(\"Grouped sections\", sections);\n\n return sections.map((d) => {\n return new UnitGroup(d.units, axisType);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<UnitWithLayoutHints<T>>,\n): UnitWithLayoutParameters<T>[] {\n /** A relatively naïve function to assign columns to units within a mutually overlapping group.\n * This gets the number of columns that would be needed to accommodate the units in the group.\n * It then assigns columns to units in the group based on the number of columns needed, with\n * lower units further to the left.\n */\n\n const sortedUnits = [...group.units].sort(createUnitSorter(group.axisType));\n\n const columns: T[][] = [];\n\n let nColumns = 1;\n\n for (const unit of sortedUnits) {\n let startIndex = 0;\n let endIndex = 0;\n // Find a column that is not already occupied by an overlapping unit\n const colHint = unit.layoutHints?.column;\n if (colHint != null) {\n columns[colHint] ??= [];\n columns[colHint].push(unit);\n continue;\n }\n let didAddToExistingColumn = false;\n\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, group.axisType, dt)) {\n column.push(unit);\n didAddToExistingColumn = true;\n break;\n }\n }\n if (!didAddToExistingColumn) {\n columns.push([unit]);\n }\n }\n\n console.log(columns);\n\n const units: UnitWithLayoutParameters<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n layout: {\n column: columnIndex,\n nColumns: 1,\n totalColumns: columns.length,\n unitGroup: group,\n },\n };\n }),\n );\n\n return units.toSorted(sortByAge);\n}\n\nexport function preprocessUnits<T extends UnitLong = UnitLong>(\n section: SectionInfo<T>,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit[] {\n /** Preprocess units to add overlapping units and columns. */\n let units = section.units;\n\n let tolerance = 0.001; // 1 kyr tolerance for age columns\n if (axisType != ColumnAxisType.AGE) {\n tolerance = 0.01; // 1cm tolerance for height/depth columns\n }\n\n const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);\n\n const divisions: any[] = [];\n // Serialize all groups' units to a single array\n for (const group of unitGroups) {\n divisions.push(...group.getUnits());\n }\n\n return divisions.map((d) =>\n enhanceUnitWithClippingPosition(section, d, axisType),\n );\n}\n\nexport function enhanceUnitWithClippingPosition(section, d, axisType) {\n const [b_pos, t_pos] = getUnitHeightRange(d, axisType);\n if (axisType == ColumnAxisType.AGE) {\n if (b_pos > section.b_age) {\n d.b_clip_pos = section.b_age;\n }\n if (t_pos < section.t_age) {\n d.t_clip_pos = section.t_age;\n }\n }\n if (axisType == ColumnAxisType.DEPTH) {\n if (b_pos > section.b_pos) {\n d.b_clip_pos = section.b_pos;\n }\n if (t_pos < section.t_pos) {\n d.t_clip_pos = section.t_pos;\n }\n }\n return d;\n}\n\nexport function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): SectionInfo<T>[] {\n /** Group units into sections by section_id.\n * This works for large-scale Macrostrat columns, where units are grouped by section_id.\n * */\n let groups = Array.from(group(units, (d) => d.section_id));\n const unitComparator = createUnitSorter(axisType);\n\n const groups1 = groups.map(([section_id, sectionUnits]) => {\n const [b_age, t_age] = getSectionAgeRange(sectionUnits);\n const [b_pos, t_pos] = getSectionPosRange(sectionUnits, axisType);\n\n // sort units by position\n sectionUnits.sort(unitComparator);\n return { section_id, t_age, b_age, b_pos, t_pos, units: sectionUnits };\n });\n // Sort sections by increasing top age, then increasing bottom age.\n // Sections have no relative ordinal position other than age...\n const compareSections = createUnitSorter(axisType) as (\n a: StratigraphicPackage,\n b: StratigraphicPackage,\n ) => number;\n groups1.sort(compareSections);\n return groups1;\n}\n\ninterface WorkingSection {\n units: UnitLong[];\n // Position or age\n heightRange: [number, number];\n}\n\nexport function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n tolerance: number = dt,\n): SectionInfo<T>[] {\n /** Group units into sections by overlap.\n * This creates \"synthetic\" sections that correspond to packages bound by scale gaps.\n * This is most useful in the height and depth domains, where gaps (e.g., missing core) are\n * common.\n * */\n // Start with each unit as its own \"section\", and progressively merge...\n const sectionList: WorkingSection[] = [];\n\n const initialSections: WorkingSection[] = units.map((unit) => {\n return {\n units: [unit],\n heightRange: getUnitHeightRange(unit, axisType),\n };\n });\n\n const isOverlapping = (a: WorkingSection, b: WorkingSection) => {\n const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);\n return res !== AgeRangeRelationship.Disjoint;\n };\n\n const mergeSections = (a: WorkingSection, b: WorkingSection) => {\n return {\n units: [...a.units, ...b.units],\n heightRange: mergeAgeRanges(\n [a.heightRange, b.heightRange],\n MergeMode.Outer,\n ),\n };\n };\n\n // Merge overlapping sections progressively until no more merges are possible\n let finalSectionList = initialSections;\n\n while (true) {\n let merged = false;\n const nextSections: WorkingSection[] = [];\n\n for (const section of finalSectionList) {\n if (nextSections.length === 0) {\n nextSections.push(section);\n } else {\n const lastSection = nextSections[nextSections.length - 1];\n if (isOverlapping(section, lastSection)) {\n // Merge with the last section\n nextSections[nextSections.length - 1] = mergeSections(lastSection, section);\n merged = true;\n } else {\n nextSections.push(section);\n }\n }\n }\n\n finalSectionList = nextSections;\n\n // Stop when no more merges occurred in this pass\n if (!merged) {\n break;\n }\n }\n\n return finalSectionList.map((section, i) => {\n const [b_age, t_age] = getSectionAgeRange(section.units);\n const [b_pos, t_pos] = getSectionPosRange(section.units, axisType);\n return {\n // Negative section IDs are used to indicate that these are synthetic sections\n section_id: -i,\n t_age,\n b_age,\n t_pos,\n b_pos,\n units: section.units as T[],\n };\n });\n}\n\nexport function getSectionPosRange(\n units: BaseUnit[],\n axisType: ColumnAxisType,\n): [number, number] {\n /** Get the overall position range of a set of units. */\n const t_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.t_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.t_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n const b_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.b_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.b_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n if (axisType == ColumnAxisType.AGE || axisType == ColumnAxisType.DEPTH) {\n return [Math.max(...b_positions), Math.min(...t_positions)];\n } else {\n return [Math.min(...b_positions), Math.max(...t_positions)];\n }\n}\n\nexport function getSectionAgeRange(units: BaseUnit[]): [number, number] {\n /** Get the overall age range of a set of units. */\n return getSectionPosRange(units, ColumnAxisType.AGE);\n}\n\nexport function mergeOverlappingSections<T extends UnitLong>(\n sections: SectionInfo<T>[],\n): SectionInfo<T>[] {\n /** Columns can have sections that overlap in time. Here, we merge overlapping\n * sections into a single section to correctly render gap-bound packages.\n */\n const [firstSection, ...rest] = sections;\n const newSections = [firstSection];\n for (const section of rest) {\n const lastSection = newSections[newSections.length - 1];\n if (\n lastSection.b_age < section.t_age ||\n lastSection.t_age > section.b_age\n ) {\n // No overlap, add the section as normal\n newSections.push(section);\n continue;\n }\n\n // Overlap, merge the sections\n lastSection.section_id = [\n ...ensureArray(lastSection.section_id),\n ...ensureArray(section.section_id),\n ];\n lastSection.units.push(...section.units);\n lastSection.b_age = Math.max(lastSection.b_age, section.b_age);\n lastSection.t_age = Math.min(lastSection.t_age, section.t_age);\n }\n return newSections;\n}\n\nexport function preprocessSectionUnit(unit: UnitLong): UnitLong {\n /** Preprocess a single unit for a \"section\" column type.\n * This mostly handles vagaries of eODP-style columns.\n * */\n\n let b_pos = unit.b_pos;\n let t_pos = unit.t_pos;\n\n let unit_name = unit.unit_name;\n\n // eODP columns sometimes have overlapping core sections, which are encoded in the name field\n // Match eODP section names\n const match = unit.unit_name.match(/^(\\d+(\\.\\d+)?)-(\\d+(\\.\\d+)?): (.+)/);\n\n if (match) {\n // These values should already be set if we've used the show_positions flag\n t_pos ??= ensureRealFloat(match[1]);\n b_pos ??= ensureRealFloat(match[3]);\n unit_name = match[5];\n }\n\n return {\n ...unit,\n b_pos: ensureRealFloat(b_pos),\n t_pos: ensureRealFloat(t_pos),\n unit_name,\n };\n}\n"],"names":["group"],"mappings":";;;;AAkBA,MAAM,KAAK;AAsBX,MAAM,UAA8D;AAAA,EAClE;AAAA,EACA;AAAA,EAEA,YAAY,OAAY,WAA2B,eAAe,KAAK;AACrE,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,WAA0C;AACxC,WAAO,2CAA2C,IAAI;AAAA,EACxD;AACF;AAEA,SAAS,0BACP,OACA,YAAoB,IACpB,WAA2B,eAAe,KAC1B;AAGhB,QAAM,WAAW,gCAAgC,OAAO,UAAU,SAAS;AAE3E,UAAQ,IAAI,oBAAoB,QAAQ;AAExC,SAAO,SAAS,IAAI,CAAC,MAAM;AACzB,WAAO,IAAI,UAAU,EAAE,OAAO,QAAQ;AAAA,EACxC,CAAC;AACH;AAEA,MAAM,YAAY,iBAAiB,eAAe,GAAG;AAErD,SAAS,2CACPA,QAC+B;AAO/B,QAAM,cAAc,CAAC,GAAGA,OAAM,KAAK,EAAE,KAAK,iBAAiBA,OAAM,QAAQ,CAAC;AAE1E,QAAM,UAAiB,CAAA;AAIvB,aAAW,QAAQ,aAAa;AAI9B,UAAM,UAAU,KAAK,aAAa;AAClC,QAAI,WAAW,MAAM;AACnB,cAAQ,OAAO,MAAM,CAAA;AACrB,cAAQ,OAAO,EAAE,KAAK,IAAI;AAC1B;AAAA,IACF;AACA,QAAI,yBAAyB;AAE7B,eAAW,UAAU,SAAS;AAC5B,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E,MAAI,OAAO;AAET,cAAU,gBAAgB,MAAM,CAAC,CAAC;AAClC,cAAU,gBAAgB,MAAM,CAAC,CAAC;AAClC,gBAAY,MAAM,CAAC;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,gBAAgB,KAAK;AAAA,IAC5B,OAAO,gBAAgB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n mergeAgeRanges,\n MergeMode,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\n\nexport type UnitWithLayoutParameters<T extends BaseUnit> = T & {\n layout: UnitLayoutData<T>;\n};\n\nexport type UnitWithLayoutHints<T extends BaseUnit> = T & {\n layoutHints?: UnitLayoutHints;\n};\n\ninterface UnitLayoutInfo {\n column: number;\n nColumns: number;\n}\n\ntype UnitLayoutHints = Partial<UnitLayoutInfo>;\n\ntype UnitLayoutData<T extends BaseUnit> = UnitLayoutInfo & {\n totalColumns: number;\n unitGroup: UnitGroup<T>;\n};\n\nclass UnitGroup<T extends BaseUnit> implements StratigraphicPackage {\n units: T[];\n axisType: ColumnAxisType;\n\n constructor(units: T[], axisType: ColumnAxisType = ColumnAxisType.AGE) {\n this.units = units;\n this.axisType = axisType;\n }\n\n get t_age(): number {\n return Math.min(...this.units.map((d) => d.t_age));\n }\n\n get b_age(): number {\n return Math.max(...this.units.map((d) => d.b_age));\n }\n\n getUnits(): UnitWithLayoutParameters<T>[] {\n return assignColumnsToUnitsWithinOverlappingGroup(this);\n }\n}\n\nfunction groupUnitsByMutualOverlap<T extends BaseUnit>(\n units: T[],\n tolerance: number = dt,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): UnitGroup<T>[] {\n /** Group units within a section that have mutual overlap. */\n\n const sections = groupUnitsIntoSectionsByOverlap(units, axisType, tolerance);\n\n console.log(\"Grouped sections\", sections);\n\n return sections.map((d) => {\n return new UnitGroup(d.units, axisType);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<UnitWithLayoutHints<T>>,\n): UnitWithLayoutParameters<T>[] {\n /** A relatively naïve function to assign columns to units within a mutually overlapping group.\n * This gets the number of columns that would be needed to accommodate the units in the group.\n * It then assigns columns to units in the group based on the number of columns needed, with\n * lower units further to the left.\n */\n\n const sortedUnits = [...group.units].sort(createUnitSorter(group.axisType));\n\n const columns: T[][] = [];\n\n let nColumns = 1;\n\n for (const unit of sortedUnits) {\n let startIndex = 0;\n let endIndex = 0;\n // Find a column that is not already occupied by an overlapping unit\n const colHint = unit.layoutHints?.column;\n if (colHint != null) {\n columns[colHint] ??= [];\n columns[colHint].push(unit);\n continue;\n }\n let didAddToExistingColumn = false;\n\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, group.axisType, dt)) {\n column.push(unit);\n didAddToExistingColumn = true;\n break;\n }\n }\n if (!didAddToExistingColumn) {\n columns.push([unit]);\n }\n }\n\n const units: UnitWithLayoutParameters<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n layout: {\n column: columnIndex,\n nColumns: 1,\n totalColumns: columns.length,\n unitGroup: group,\n },\n };\n }),\n );\n\n return units.toSorted(sortByAge);\n}\n\nexport function preprocessUnits<T extends UnitLong = UnitLong>(\n section: SectionInfo<T>,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit[] {\n /** Preprocess units to add overlapping units and columns. */\n let units = section.units;\n\n let tolerance = 0.001; // 1 kyr tolerance for age columns\n if (axisType != ColumnAxisType.AGE) {\n tolerance = 0.01; // 1cm tolerance for height/depth columns\n }\n\n const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);\n\n const divisions: any[] = [];\n // Serialize all groups' units to a single array\n for (const group of unitGroups) {\n divisions.push(...group.getUnits());\n }\n\n return divisions.map((d) =>\n enhanceUnitWithClippingPosition(section, d, axisType),\n );\n}\n\nexport function enhanceUnitWithClippingPosition(section, d, axisType) {\n const [b_pos, t_pos] = getUnitHeightRange(d, axisType);\n if (axisType == ColumnAxisType.AGE) {\n if (b_pos > section.b_age) {\n d.b_clip_pos = section.b_age;\n }\n if (t_pos < section.t_age) {\n d.t_clip_pos = section.t_age;\n }\n }\n if (axisType == ColumnAxisType.DEPTH) {\n if (b_pos > section.b_pos) {\n d.b_clip_pos = section.b_pos;\n }\n if (t_pos < section.t_pos) {\n d.t_clip_pos = section.t_pos;\n }\n }\n return d;\n}\n\nexport function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): SectionInfo<T>[] {\n /** Group units into sections by section_id.\n * This works for large-scale Macrostrat columns, where units are grouped by section_id.\n * */\n let groups = Array.from(group(units, (d) => d.section_id));\n const unitComparator = createUnitSorter(axisType);\n\n const groups1 = groups.map(([section_id, sectionUnits]) => {\n const [b_age, t_age] = getSectionAgeRange(sectionUnits);\n const [b_pos, t_pos] = getSectionPosRange(sectionUnits, axisType);\n\n // sort units by position\n sectionUnits.sort(unitComparator);\n return { section_id, t_age, b_age, b_pos, t_pos, units: sectionUnits };\n });\n // Sort sections by increasing top age, then increasing bottom age.\n // Sections have no relative ordinal position other than age...\n const compareSections = createUnitSorter(axisType) as (\n a: StratigraphicPackage,\n b: StratigraphicPackage,\n ) => number;\n groups1.sort(compareSections);\n return groups1;\n}\n\ninterface WorkingSection {\n units: UnitLong[];\n // Position or age\n heightRange: [number, number];\n}\n\nexport function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n tolerance: number = dt,\n): SectionInfo<T>[] {\n /** Group units into sections by overlap.\n * This creates \"synthetic\" sections that correspond to packages bound by scale gaps.\n * This is most useful in the height and depth domains, where gaps (e.g., missing core) are\n * common.\n * */\n // Start with each unit as its own \"section\", and progressively merge...\n const sectionList: WorkingSection[] = [];\n\n const initialSections: WorkingSection[] = units.map((unit) => {\n return {\n units: [unit],\n heightRange: getUnitHeightRange(unit, axisType),\n };\n });\n\n const isOverlapping = (a: WorkingSection, b: WorkingSection) => {\n const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);\n return res !== AgeRangeRelationship.Disjoint;\n };\n\n const mergeSections = (a: WorkingSection, b: WorkingSection) => {\n return {\n units: [...a.units, ...b.units],\n heightRange: mergeAgeRanges(\n [a.heightRange, b.heightRange],\n MergeMode.Outer,\n ),\n };\n };\n\n // Merge overlapping sections progressively until no more merges are possible\n let finalSectionList = initialSections;\n\n while (true) {\n let merged = false;\n const nextSections: WorkingSection[] = [];\n\n for (const section of finalSectionList) {\n if (nextSections.length === 0) {\n nextSections.push(section);\n } else {\n const lastSection = nextSections[nextSections.length - 1];\n if (isOverlapping(section, lastSection)) {\n // Merge with the last section\n nextSections[nextSections.length - 1] = mergeSections(\n lastSection,\n section,\n );\n merged = true;\n } else {\n nextSections.push(section);\n }\n }\n }\n\n finalSectionList = nextSections;\n\n // Stop when no more merges occurred in this pass\n if (!merged) {\n break;\n }\n }\n\n return finalSectionList.map((section, i) => {\n const [b_age, t_age] = getSectionAgeRange(section.units);\n const [b_pos, t_pos] = getSectionPosRange(section.units, axisType);\n return {\n // Negative section IDs are used to indicate that these are synthetic sections\n section_id: -i,\n t_age,\n b_age,\n t_pos,\n b_pos,\n units: section.units as T[],\n };\n });\n}\n\nexport function getSectionPosRange(\n units: BaseUnit[],\n axisType: ColumnAxisType,\n): [number, number] {\n /** Get the overall position range of a set of units. */\n const t_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.t_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.t_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n const b_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.b_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.b_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n if (axisType == ColumnAxisType.AGE || axisType == ColumnAxisType.DEPTH) {\n return [Math.max(...b_positions), Math.min(...t_positions)];\n } else {\n return [Math.min(...b_positions), Math.max(...t_positions)];\n }\n}\n\nexport function getSectionAgeRange(units: BaseUnit[]): [number, number] {\n /** Get the overall age range of a set of units. */\n return getSectionPosRange(units, ColumnAxisType.AGE);\n}\n\nexport function mergeOverlappingSections<T extends UnitLong>(\n sections: SectionInfo<T>[],\n): SectionInfo<T>[] {\n /** Columns can have sections that overlap in time. Here, we merge overlapping\n * sections into a single section to correctly render gap-bound packages.\n */\n const [firstSection, ...rest] = sections;\n const newSections = [firstSection];\n for (const section of rest) {\n const lastSection = newSections[newSections.length - 1];\n if (\n lastSection.b_age < section.t_age ||\n lastSection.t_age > section.b_age\n ) {\n // No overlap, add the section as normal\n newSections.push(section);\n continue;\n }\n\n // Overlap, merge the sections\n lastSection.section_id = [\n ...ensureArray(lastSection.section_id),\n ...ensureArray(section.section_id),\n ];\n lastSection.units.push(...section.units);\n lastSection.b_age = Math.max(lastSection.b_age, section.b_age);\n lastSection.t_age = Math.min(lastSection.t_age, section.t_age);\n }\n return newSections;\n}\n\nexport function preprocessSectionUnit(unit: UnitLong): UnitLong {\n /** Preprocess a single unit for a \"section\" column type.\n * This mostly handles vagaries of eODP-style columns.\n * */\n\n let b_pos = unit.b_pos;\n let t_pos = unit.t_pos;\n\n let unit_name = unit.unit_name;\n\n // eODP columns sometimes have overlapping core sections, which are encoded in the name field\n // Match eODP section names\n const match = unit.unit_name.match(/^(\\d+(\\.\\d+)?)-(\\d+(\\.\\d+)?): (.+)/);\n\n if (match) {\n // These values should already be set if we've used the show_positions flag\n t_pos ??= ensureRealFloat(match[1]);\n b_pos ??= ensureRealFloat(match[3]);\n unit_name = match[5];\n }\n\n return {\n ...unit,\n b_pos: ensureRealFloat(b_pos),\n t_pos: ensureRealFloat(t_pos),\n unit_name,\n };\n}\n"],"names":["group"],"mappings":";;;;AAkBA,MAAM,KAAK;AAsBX,MAAM,UAA8D;AAAA,EAClE;AAAA,EACA;AAAA,EAEA,YAAY,OAAY,WAA2B,eAAe,KAAK;AACrE,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,WAA0C;AACxC,WAAO,2CAA2C,IAAI;AAAA,EACxD;AACF;AAEA,SAAS,0BACP,OACA,YAAoB,IACpB,WAA2B,eAAe,KAC1B;AAGhB,QAAM,WAAW,gCAAgC,OAAO,UAAU,SAAS;AAE3E,UAAQ,IAAI,oBAAoB,QAAQ;AAExC,SAAO,SAAS,IAAI,CAAC,MAAM;AACzB,WAAO,IAAI,UAAU,EAAE,OAAO,QAAQ;AAAA,EACxC,CAAC;AACH;AAEA,MAAM,YAAY,iBAAiB,eAAe,GAAG;AAErD,SAAS,2CACPA,QAC+B;AAO/B,QAAM,cAAc,CAAC,GAAGA,OAAM,KAAK,EAAE,KAAK,iBAAiBA,OAAM,QAAQ,CAAC;AAE1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,QAAQ,KAAK,IAAI,YAAY,OAAO,QAAQ,KAAK;AAAA,EAC/D;AACA,SAAO;AACT;AAEO,SAAS,sBAAsB,MAA0B;AAK9D,MAAI,QAAQ,KAAK;AACjB,MAAI,QAAQ,KAAK;AAEjB,MAAI,YAAY,KAAK;AAIrB,QAAM,QAAQ,KAAK,UAAU,MAAM,oCAAoC;AAEvE,MAAI,OAAO;AAET,cAAU,gBAAgB,MAAM,CAAC,CAAC;AAClC,cAAU,gBAAgB,MAAM,CAAC,CAAC;AAClC,gBAAY,MAAM,CAAC;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,gBAAgB,KAAK;AAAA,IAC5B,OAAO,gBAAgB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
|
package/dist/section.cjs
CHANGED
|
@@ -154,7 +154,12 @@ function CompositeTimescale(props) {
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
function CompositeTimescaleCore(props) {
|
|
157
|
-
const {
|
|
157
|
+
const {
|
|
158
|
+
levels = 3,
|
|
159
|
+
packages,
|
|
160
|
+
unconformityLabels = false,
|
|
161
|
+
onClickInterval
|
|
162
|
+
} = props;
|
|
158
163
|
const baseURL = dataProvider.useMacrostratBaseURL();
|
|
159
164
|
const intervals = timescale.useMacrostratIntervals({ baseURL });
|
|
160
165
|
let _levels;
|
|
@@ -180,7 +185,8 @@ function CompositeTimescaleCore(props) {
|
|
|
180
185
|
absoluteAgeScale: true,
|
|
181
186
|
showAgeAxis: false,
|
|
182
187
|
scale,
|
|
183
|
-
intervals
|
|
188
|
+
intervals,
|
|
189
|
+
onClick: onClickInterval
|
|
184
190
|
})
|
|
185
191
|
]
|
|
186
192
|
);
|
package/dist/section.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.cjs","sources":["../src/section.ts"],"sourcesContent":["import {\n CompositeUnitsColumn,\n LabelTrackerProvider,\n SectionLabelsColumn,\n} from \"./units\";\nimport { ReactNode, FunctionComponent, useMemo } from \"react\";\nimport {\n Timescale,\n TimescaleOrientation,\n useMacrostratIntervals,\n} from \"@macrostrat/timescale\";\nimport { ColumnAxisType, SVG } from \"@macrostrat/column-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport styles from \"./column.module.sass\";\nimport {\n useMacrostratColumnData,\n useMacrostratUnits,\n MacrostratColumnProvider,\n} from \"./data-provider\";\nimport {\n useMacrostratBaseURL,\n useMacrostratData,\n} from \"@macrostrat/data-provider\";\nimport { Duration } from \"./unit-details\";\nimport { Value } from \"@macrostrat/data-components\";\nimport type { ExtUnit, PackageScaleLayoutData } from \"./prepare-units/types\";\n\nconst h = hyper.styled(styles);\n\nexport interface SectionSharedProps {\n unitComponent?: FunctionComponent<any>;\n unitComponentProps?: any;\n showLabels?: boolean;\n width?: number;\n columnWidth?: number;\n children?: ReactNode;\n showLabelColumn?: boolean;\n axisType?: ColumnAxisType;\n className?: string;\n clipUnits?: boolean;\n maxInternalColumns?: number;\n // Space between sections\n verticalSpacing?: number;\n // Whether to render unconformity labels\n unconformityLabels?: boolean;\n}\n\nexport interface SectionProps extends SectionSharedProps {\n units: ExtUnit[];\n scaleInfo: PackageScaleLayoutData;\n}\n\nexport function SectionsColumn(props: SectionSharedProps) {\n const {\n unconformityLabels = true,\n unitComponent,\n unitComponentProps,\n showLabels = true,\n width = 300,\n columnWidth = 150,\n showLabelColumn = true,\n clipUnits = true,\n maxInternalColumns,\n } = props;\n\n const units = useMacrostratUnits();\n\n // Get a unique key for the column\n const key = units[0]?.col_id;\n\n return h(LabelTrackerProvider, { units, key }, [\n h(SectionUnitsColumn, {\n width: columnWidth,\n unitComponent,\n unitComponentProps,\n showLabels,\n clipUnits,\n maxInternalColumns,\n unconformityLabels,\n }),\n h.if(showLabelColumn)(SectionLabelsColumn, {\n width: width - columnWidth,\n }),\n ]);\n}\n\nfunction SectionUnitsColumn(props: SectionSharedProps) {\n const {\n width,\n showLabels,\n unitComponent,\n unitComponentProps,\n clipUnits,\n maxInternalColumns,\n axisType,\n unconformityLabels = true,\n } = props;\n\n const { sections, totalHeight } = useMacrostratColumnData();\n\n const scaleData: PackageScaleLayoutData[] = sections.map((section) => {\n return section.scaleInfo;\n });\n\n const innerWidth = width - 2;\n\n return h(\"div.section-units-container\", { style: { width } }, [\n h(\n SVG,\n {\n className: \"sections\",\n height: totalHeight,\n innerWidth,\n paddingH: 1,\n },\n sections.map((group) => {\n const { units, scaleInfo, section_id } = group;\n\n const key = `section-${section_id}`;\n return h(\n SectionUnits,\n {\n units,\n scaleInfo,\n key,\n unitComponent,\n unitComponentProps,\n showLabels,\n width: innerWidth,\n clipUnits,\n maxInternalColumns,\n }, // This unconformity is with the section _above_\n );\n }),\n ),\n h.if(unconformityLabels)(UnconformityLabels, {\n width,\n sections: scaleData,\n verbose: false,\n }),\n ]);\n}\n\nfunction SectionUnits(props: SectionProps) {\n // Section with \"squishy\" timescale\n const {\n units,\n scaleInfo,\n unitComponent,\n showLabels = true,\n width = 300,\n unitComponentProps,\n className,\n clipUnits = true,\n maxInternalColumns,\n } = props;\n\n const { domain, pixelScale, pixelHeight, scale } = scaleInfo;\n\n /** Ensure that we can arrange units into the maximum number\n * of columns defined by unitComponentProps, but that we don't\n * use more than necessary.\n */\n const _unitComponentProps = useMemo(() => {\n return {\n ...unitComponentProps,\n nColumns: Math.min(\n maxInternalColumns ?? Math.floor(width / 10),\n unitComponentProps?.nColumns ?? Infinity,\n ),\n //axisType,\n };\n }, [units, unitComponentProps, maxInternalColumns, width]);\n\n const style = {\n \"--section-height\": `${pixelHeight}px`,\n \"--section-width\": `${width}px`,\n };\n\n return h(\n \"g.section\",\n { className, style, transform: `translate(0 ${scaleInfo.offset})` },\n h(\n MacrostratColumnProvider,\n {\n units,\n domain,\n pixelScale, // Actually pixels per myr,\n scale,\n },\n h(CompositeUnitsColumn, {\n width,\n showLabels,\n unitComponent,\n unitComponentProps: _unitComponentProps,\n clipToFrame: clipUnits,\n }),\n ),\n );\n}\n\ninterface CompositeTimescaleProps {\n levels?: [number, number] | number;\n unconformityLabels?: boolean;\n}\n\nexport function CompositeTimescale(props: CompositeTimescaleProps) {\n const { sections } = useMacrostratColumnData();\n const sectionScales = sections.map((section) => {\n return section.scaleInfo;\n });\n\n return h(CompositeTimescaleCore, {\n packages: sectionScales,\n ...props,\n });\n}\n\ntype CompositeTimescaleCoreProps = CompositeTimescaleProps & {\n packages: PackageScaleLayoutData[];\n};\n\nexport function CompositeTimescaleCore(props: CompositeTimescaleCoreProps) {\n const { levels = 3, packages, unconformityLabels = false } = props;\n\n // Use intervals from Macrostrat API\n const baseURL = useMacrostratBaseURL();\n const intervals = useMacrostratIntervals({ baseURL });\n\n let _levels: [number, number];\n if (typeof levels === \"number\") {\n // If levels is a number, use the most common starting level\n _levels = [2, Math.max(2 + Math.min(levels, 5) - 1, 1)];\n } else {\n _levels = levels;\n }\n\n const nCols = _levels[1] - _levels[0] + 1;\n\n return h(\"div.timescale-column\", [\n h(\n \"div.timescales\",\n packages.map((group) => {\n const { pixelHeight, paddingTop, key, scale } = group;\n return h(\n \"div.timescale-container\",\n { style: { paddingTop, \"--timescale-level-count\": nCols }, key },\n [\n h(Timescale, {\n orientation: TimescaleOrientation.VERTICAL,\n length: pixelHeight,\n levels: _levels,\n absoluteAgeScale: true,\n showAgeAxis: false,\n scale,\n intervals,\n }),\n ],\n );\n }),\n ),\n h.if(unconformityLabels)(UnconformityLabels, {\n width: \"100%\",\n sections: packages,\n className: \"unconformity-labels\",\n axisType: ColumnAxisType.AGE,\n }),\n ]);\n}\n\nexport function UnconformityLabels(props: {\n width: string | number;\n sections: PackageScaleLayoutData[];\n axisType?: ColumnAxisType;\n className?: string;\n verbose?: boolean;\n}) {\n const { width, sections, className, axisType, verbose } = props;\n\n return h(\n \"div.unconformity-labels\",\n {\n style: {\n width,\n },\n className,\n },\n sections.map((scaleInfo, i) => {\n const lastGroup = sections[i - 1];\n const top = scaleInfo.offset - scaleInfo.paddingTop;\n const upperAge = lastGroup?.domain[0];\n const lowerAge = scaleInfo.domain[1];\n return h(Unconformity, {\n axisType,\n upperAge,\n lowerAge,\n style: {\n width,\n height: scaleInfo.paddingTop,\n top,\n },\n verbose,\n });\n }),\n );\n}\n\nfunction Unconformity({\n upperAge,\n lowerAge,\n style,\n axisType,\n verbose = false,\n}) {\n if (upperAge == null || lowerAge == null) {\n return null;\n }\n\n const ageGap = Math.abs(upperAge - lowerAge);\n\n let maximumFractionDigits = 0;\n\n let className: string = null;\n if (ageGap > 1000) {\n className = \"giga\";\n } else if (ageGap > 100) {\n className = \"mega\";\n } else if (ageGap > 10) {\n className = \"large\";\n } else if (ageGap < 1) {\n className = \"small\";\n maximumFractionDigits = 2;\n } else {\n maximumFractionDigits = 1;\n }\n\n let val: ReactNode;\n if (axisType === ColumnAxisType.DEPTH || axisType === ColumnAxisType.HEIGHT) {\n const _txt = ageGap.toLocaleString(\"en-US\", { maximumFractionDigits });\n val = h(Value, { value: _txt, unit: \"m\" });\n } else {\n val = h(Duration, { value: ageGap, maximumFractionDigits });\n }\n\n let prefix: ReactNode = null;\n if (verbose) {\n prefix = h([\" \", h(\"span.prefix\", \" gap\")]);\n }\n\n return h(\"div.unconformity\", { style, className }, [\n h(\"div.unconformity-inner\", h(\"div.unconformity-text\", [val, prefix])),\n ]);\n}\n"],"names":["hyper","styles","useMacrostratUnits","LabelTrackerProvider","SectionLabelsColumn","useMacrostratColumnData","SVG","useMemo","MacrostratColumnProvider","CompositeUnitsColumn","useMacrostratBaseURL","useMacrostratIntervals","Timescale","TimescaleOrientation","ColumnAxisType","Value","Duration"],"mappings":";;;;;;;;;;;;;;AA2BA,MAAM,IAAIA,WAAAA,QAAM,OAAOC,qBAAM;AAyBtB,SAAS,eAAe,OAA2B;AACxD,QAAM;AAAA,IACJ,qBAAqB;AAAA,IACrB;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,kBAAkB;AAAA,IAClB,YA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EAAE,OAAO,aAAa;AAAA,IACjD,EAAE,0BAA0B,EAAE,yBAAyB,CAAC,KAAK,MAAM,CAAC,CAAC;AAAA,EAAA,CACtE;AACH;;;;;"}
|
|
1
|
+
{"version":3,"file":"section.cjs","sources":["../src/section.ts"],"sourcesContent":["import {\n CompositeUnitsColumn,\n LabelTrackerProvider,\n SectionLabelsColumn,\n} from \"./units\";\nimport { ReactNode, FunctionComponent, useMemo } from \"react\";\nimport {\n Timescale,\n TimescaleOrientation,\n TimescaleClickHandler,\n useMacrostratIntervals,\n} from \"@macrostrat/timescale\";\nimport { ColumnAxisType, SVG } from \"@macrostrat/column-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport styles from \"./column.module.sass\";\nimport {\n useMacrostratColumnData,\n useMacrostratUnits,\n MacrostratColumnProvider,\n} from \"./data-provider\";\nimport {\n useMacrostratBaseURL,\n useMacrostratData,\n} from \"@macrostrat/data-provider\";\nimport { Duration } from \"./unit-details\";\nimport { Value } from \"@macrostrat/data-components\";\nimport type { ExtUnit, PackageScaleLayoutData } from \"./prepare-units/types\";\n\nconst h = hyper.styled(styles);\n\nexport interface SectionSharedProps {\n unitComponent?: FunctionComponent<any>;\n unitComponentProps?: any;\n showLabels?: boolean;\n width?: number;\n columnWidth?: number;\n children?: ReactNode;\n showLabelColumn?: boolean;\n axisType?: ColumnAxisType;\n className?: string;\n clipUnits?: boolean;\n maxInternalColumns?: number;\n // Space between sections\n verticalSpacing?: number;\n // Whether to render unconformity labels\n unconformityLabels?: boolean;\n}\n\nexport interface SectionProps extends SectionSharedProps {\n units: ExtUnit[];\n scaleInfo: PackageScaleLayoutData;\n}\n\nexport function SectionsColumn(props: SectionSharedProps) {\n const {\n unconformityLabels = true,\n unitComponent,\n unitComponentProps,\n showLabels = true,\n width = 300,\n columnWidth = 150,\n showLabelColumn = true,\n clipUnits = true,\n maxInternalColumns,\n } = props;\n\n const units = useMacrostratUnits();\n\n // Get a unique key for the column\n const key = units[0]?.col_id;\n\n return h(LabelTrackerProvider, { units, key }, [\n h(SectionUnitsColumn, {\n width: columnWidth,\n unitComponent,\n unitComponentProps,\n showLabels,\n clipUnits,\n maxInternalColumns,\n unconformityLabels,\n }),\n h.if(showLabelColumn)(SectionLabelsColumn, {\n width: width - columnWidth,\n }),\n ]);\n}\n\nfunction SectionUnitsColumn(props: SectionSharedProps) {\n const {\n width,\n showLabels,\n unitComponent,\n unitComponentProps,\n clipUnits,\n maxInternalColumns,\n axisType,\n unconformityLabels = true,\n } = props;\n\n const { sections, totalHeight } = useMacrostratColumnData();\n\n const scaleData: PackageScaleLayoutData[] = sections.map((section) => {\n return section.scaleInfo;\n });\n\n const innerWidth = width - 2;\n\n return h(\"div.section-units-container\", { style: { width } }, [\n h(\n SVG,\n {\n className: \"sections\",\n height: totalHeight,\n innerWidth,\n paddingH: 1,\n },\n sections.map((group) => {\n const { units, scaleInfo, section_id } = group;\n\n const key = `section-${section_id}`;\n return h(\n SectionUnits,\n {\n units,\n scaleInfo,\n key,\n unitComponent,\n unitComponentProps,\n showLabels,\n width: innerWidth,\n clipUnits,\n maxInternalColumns,\n }, // This unconformity is with the section _above_\n );\n }),\n ),\n h.if(unconformityLabels)(UnconformityLabels, {\n width,\n sections: scaleData,\n verbose: false,\n }),\n ]);\n}\n\nfunction SectionUnits(props: SectionProps) {\n // Section with \"squishy\" timescale\n const {\n units,\n scaleInfo,\n unitComponent,\n showLabels = true,\n width = 300,\n unitComponentProps,\n className,\n clipUnits = true,\n maxInternalColumns,\n } = props;\n\n const { domain, pixelScale, pixelHeight, scale } = scaleInfo;\n\n /** Ensure that we can arrange units into the maximum number\n * of columns defined by unitComponentProps, but that we don't\n * use more than necessary.\n */\n const _unitComponentProps = useMemo(() => {\n return {\n ...unitComponentProps,\n nColumns: Math.min(\n maxInternalColumns ?? Math.floor(width / 10),\n unitComponentProps?.nColumns ?? Infinity,\n ),\n //axisType,\n };\n }, [units, unitComponentProps, maxInternalColumns, width]);\n\n const style = {\n \"--section-height\": `${pixelHeight}px`,\n \"--section-width\": `${width}px`,\n };\n\n return h(\n \"g.section\",\n { className, style, transform: `translate(0 ${scaleInfo.offset})` },\n h(\n MacrostratColumnProvider,\n {\n units,\n domain,\n pixelScale, // Actually pixels per myr,\n scale,\n },\n h(CompositeUnitsColumn, {\n width,\n showLabels,\n unitComponent,\n unitComponentProps: _unitComponentProps,\n clipToFrame: clipUnits,\n }),\n ),\n );\n}\n\ninterface CompositeTimescaleProps {\n levels?: [number, number] | number;\n unconformityLabels?: boolean;\n}\n\nexport function CompositeTimescale(props: CompositeTimescaleProps) {\n const { sections } = useMacrostratColumnData();\n const sectionScales = sections.map((section) => {\n return section.scaleInfo;\n });\n\n return h(CompositeTimescaleCore, {\n packages: sectionScales,\n ...props,\n });\n}\n\ntype CompositeTimescaleCoreProps = CompositeTimescaleProps & {\n packages: PackageScaleLayoutData[];\n onClickInterval?: TimescaleClickHandler;\n};\n\nexport function CompositeTimescaleCore(props: CompositeTimescaleCoreProps) {\n const {\n levels = 3,\n packages,\n unconformityLabels = false,\n onClickInterval,\n } = props;\n\n // Use intervals from Macrostrat API\n const baseURL = useMacrostratBaseURL();\n const intervals = useMacrostratIntervals({ baseURL });\n\n let _levels: [number, number];\n if (typeof levels === \"number\") {\n // If levels is a number, use the most common starting level\n _levels = [2, Math.max(2 + Math.min(levels, 5) - 1, 1)];\n } else {\n _levels = levels;\n }\n\n const nCols = _levels[1] - _levels[0] + 1;\n\n return h(\"div.timescale-column\", [\n h(\n \"div.timescales\",\n packages.map((group) => {\n const { pixelHeight, paddingTop, key, scale } = group;\n return h(\n \"div.timescale-container\",\n { style: { paddingTop, \"--timescale-level-count\": nCols }, key },\n [\n h(Timescale, {\n orientation: TimescaleOrientation.VERTICAL,\n length: pixelHeight,\n levels: _levels,\n absoluteAgeScale: true,\n showAgeAxis: false,\n scale,\n intervals,\n onClick: onClickInterval,\n }),\n ],\n );\n }),\n ),\n h.if(unconformityLabels)(UnconformityLabels, {\n width: \"100%\",\n sections: packages,\n className: \"unconformity-labels\",\n axisType: ColumnAxisType.AGE,\n }),\n ]);\n}\n\nexport function UnconformityLabels(props: {\n width: string | number;\n sections: PackageScaleLayoutData[];\n axisType?: ColumnAxisType;\n className?: string;\n verbose?: boolean;\n}) {\n const { width, sections, className, axisType, verbose } = props;\n\n return h(\n \"div.unconformity-labels\",\n {\n style: {\n width,\n },\n className,\n },\n sections.map((scaleInfo, i) => {\n const lastGroup = sections[i - 1];\n const top = scaleInfo.offset - scaleInfo.paddingTop;\n const upperAge = lastGroup?.domain[0];\n const lowerAge = scaleInfo.domain[1];\n return h(Unconformity, {\n axisType,\n upperAge,\n lowerAge,\n style: {\n width,\n height: scaleInfo.paddingTop,\n top,\n },\n verbose,\n });\n }),\n );\n}\n\nfunction Unconformity({\n upperAge,\n lowerAge,\n style,\n axisType,\n verbose = false,\n}) {\n if (upperAge == null || lowerAge == null) {\n return null;\n }\n\n const ageGap = Math.abs(upperAge - lowerAge);\n\n let maximumFractionDigits = 0;\n\n let className: string = null;\n if (ageGap > 1000) {\n className = \"giga\";\n } else if (ageGap > 100) {\n className = \"mega\";\n } else if (ageGap > 10) {\n className = \"large\";\n } else if (ageGap < 1) {\n className = \"small\";\n maximumFractionDigits = 2;\n } else {\n maximumFractionDigits = 1;\n }\n\n let val: ReactNode;\n if (axisType === ColumnAxisType.DEPTH || axisType === ColumnAxisType.HEIGHT) {\n const _txt = ageGap.toLocaleString(\"en-US\", { maximumFractionDigits });\n val = h(Value, { value: _txt, unit: \"m\" });\n } else {\n val = h(Duration, { value: ageGap, maximumFractionDigits });\n }\n\n let prefix: ReactNode = null;\n if (verbose) {\n prefix = h([\" \", h(\"span.prefix\", \" gap\")]);\n }\n\n return h(\"div.unconformity\", { style, className }, [\n h(\"div.unconformity-inner\", h(\"div.unconformity-text\", [val, prefix])),\n ]);\n}\n"],"names":["hyper","styles","useMacrostratUnits","LabelTrackerProvider","SectionLabelsColumn","useMacrostratColumnData","SVG","useMemo","MacrostratColumnProvider","CompositeUnitsColumn","useMacrostratBaseURL","useMacrostratIntervals","Timescale","TimescaleOrientation","ColumnAxisType","Value","Duration"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,IAAIA,WAAAA,QAAM,OAAOC,qBAAM;AAyBtB,SAAS,eAAe,OAA2B;AACxD,QAAM;AAAA,IACJ,qBAAqB;AAAA,IACrB;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ;AAAA,EAAA,IACE;AAEJ,QAAM,QAAQC,MAAAA,mBAAA;AAGd,QAAM,MAAM,MAAM,CAAC,GAAG;AAEtB,SAAO,EAAEC,UAAAA,sBAAsB,EAAE,OAAO,OAAO;AAAA,IAC7C,EAAE,oBAAoB;AAAA,MACpB,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,IACD,EAAE,GAAG,eAAe,EAAEC,+BAAqB;AAAA,MACzC,OAAO,QAAQ;AAAA,IAAA,CAChB;AAAA,EAAA,CACF;AACH;AAEA,SAAS,mBAAmB,OAA2B;AACrD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,EAAA,IACnB;AAEJ,QAAM,EAAE,UAAU,YAAA,IAAgBC,8BAAA;AAElC,QAAM,YAAsC,SAAS,IAAI,CAAC,YAAY;AACpE,WAAO,QAAQ;AAAA,EACjB,CAAC;AAED,QAAM,aAAa,QAAQ;AAE3B,SAAO,EAAE,+BAA+B,EAAE,OAAO,EAAE,MAAA,KAAW;AAAA,IAC5D;AAAA,MACEC,iBAAAA;AAAAA,MACA;AAAA,QACE,WAAW;AAAA,QACX,QAAQ;AAAA,QACR;AAAA,QACA,UAAU;AAAA,MAAA;AAAA,MAEZ,SAAS,IAAI,CAAC,UAAU;AAC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