@macrostrat/column-views 3.9.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/dist/column-views.css +10 -0
- package/dist/correlation-chart/main.cjs +11 -3
- package/dist/correlation-chart/main.cjs.map +1 -1
- package/dist/correlation-chart/main.d.ts +1 -1
- package/dist/correlation-chart/main.js +11 -3
- package/dist/correlation-chart/main.js.map +1 -1
- package/dist/index.cjs +18 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -34
- package/dist/index.js.map +1 -1
- package/dist/unit-details/age-window-tag.cjs +68 -0
- package/dist/unit-details/age-window-tag.cjs.map +1 -0
- package/dist/unit-details/age-window-tag.d.ts +26 -0
- package/dist/unit-details/age-window-tag.js +66 -0
- package/dist/unit-details/age-window-tag.js.map +1 -0
- package/dist/unit-details/age-window-tag.module.sass.cjs +12 -0
- package/dist/unit-details/age-window-tag.module.sass.cjs.map +1 -0
- package/dist/unit-details/age-window-tag.module.sass.js +11 -0
- package/dist/unit-details/age-window-tag.module.sass.js.map +1 -0
- package/dist/unit-details/index.d.ts +1 -0
- package/dist/units/boxes.cjs +3 -3
- package/dist/units/boxes.cjs.map +1 -1
- package/dist/units/boxes.js +3 -3
- package/dist/units/boxes.js.map +1 -1
- package/dist/units/index.cjs +7 -11
- package/dist/units/index.cjs.map +1 -1
- package/dist/units/index.d.ts +0 -1
- package/dist/units/index.js +4 -9
- package/dist/units/index.js.map +1 -1
- package/package.json +6 -27
- package/src/correlation-chart/main.ts +14 -2
- package/src/index.ts +3 -1
- package/src/unit-details/age-window-tag.module.sass +10 -0
- package/src/unit-details/age-window-tag.ts +102 -0
- package/src/unit-details/index.ts +1 -0
- package/src/units/boxes.ts +7 -4
- package/src/units/index.ts +9 -26
- package/dist/maps/column-correlation/core.cjs +0 -288
- package/dist/maps/column-correlation/core.cjs.map +0 -1
- package/dist/maps/column-correlation/core.d.ts +0 -9
- package/dist/maps/column-correlation/core.js +0 -286
- package/dist/maps/column-correlation/core.js.map +0 -1
- package/dist/maps/column-correlation/index.d.ts +0 -2
- package/dist/maps/column-correlation/state.cjs +0 -193
- package/dist/maps/column-correlation/state.cjs.map +0 -1
- package/dist/maps/column-correlation/state.d.ts +0 -62
- package/dist/maps/column-correlation/state.js +0 -190
- package/dist/maps/column-correlation/state.js.map +0 -1
- package/dist/maps/column-navigation/index.d.ts +0 -2
- package/dist/maps/column-navigation/mapbox/index.cjs +0 -215
- package/dist/maps/column-navigation/mapbox/index.cjs.map +0 -1
- package/dist/maps/column-navigation/mapbox/index.d.ts +0 -38
- package/dist/maps/column-navigation/mapbox/index.js +0 -213
- package/dist/maps/column-navigation/mapbox/index.js.map +0 -1
- package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs +0 -105
- package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs.map +0 -1
- package/dist/maps/column-navigation/mapbox/keyboard-navigation.d.ts +0 -8
- package/dist/maps/column-navigation/mapbox/keyboard-navigation.js +0 -105
- package/dist/maps/column-navigation/mapbox/keyboard-navigation.js.map +0 -1
- package/dist/maps/column-navigation/mapbox/state.cjs +0 -73
- package/dist/maps/column-navigation/mapbox/state.cjs.map +0 -1
- package/dist/maps/column-navigation/mapbox/state.d.ts +0 -23
- package/dist/maps/column-navigation/mapbox/state.js +0 -71
- package/dist/maps/column-navigation/mapbox/state.js.map +0 -1
- package/dist/maps/column-navigation/svg/animated.d.ts +0 -1
- package/dist/maps/column-navigation/svg/data-fetcher.cjs +0 -25
- package/dist/maps/column-navigation/svg/data-fetcher.cjs.map +0 -1
- package/dist/maps/column-navigation/svg/data-fetcher.d.ts +0 -6
- package/dist/maps/column-navigation/svg/data-fetcher.js +0 -25
- package/dist/maps/column-navigation/svg/data-fetcher.js.map +0 -1
- package/dist/maps/column-navigation/svg/index.cjs +0 -94
- package/dist/maps/column-navigation/svg/index.cjs.map +0 -1
- package/dist/maps/column-navigation/svg/index.d.ts +0 -9
- package/dist/maps/column-navigation/svg/index.js +0 -93
- package/dist/maps/column-navigation/svg/index.js.map +0 -1
- package/dist/maps/column-navigation/svg/layers.cjs +0 -177
- package/dist/maps/column-navigation/svg/layers.cjs.map +0 -1
- package/dist/maps/column-navigation/svg/layers.d.ts +0 -54
- package/dist/maps/column-navigation/svg/layers.js +0 -174
- package/dist/maps/column-navigation/svg/layers.js.map +0 -1
- package/dist/maps/column-navigation/utils/keyboard-navigation.cjs +0 -50
- package/dist/maps/column-navigation/utils/keyboard-navigation.cjs.map +0 -1
- package/dist/maps/column-navigation/utils/keyboard-navigation.d.ts +0 -10
- package/dist/maps/column-navigation/utils/keyboard-navigation.js +0 -50
- package/dist/maps/column-navigation/utils/keyboard-navigation.js.map +0 -1
- package/dist/maps/index.d.ts +0 -4
- package/dist/maps/inset-map/index.cjs +0 -71
- package/dist/maps/inset-map/index.cjs.map +0 -1
- package/dist/maps/inset-map/index.d.ts +0 -16
- package/dist/maps/inset-map/index.js +0 -69
- package/dist/maps/inset-map/index.js.map +0 -1
- package/dist/maps/layers/columns.cjs +0 -165
- package/dist/maps/layers/columns.cjs.map +0 -1
- package/dist/maps/layers/columns.d.ts +0 -28
- package/dist/maps/layers/columns.js +0 -165
- package/dist/maps/layers/columns.js.map +0 -1
- package/dist/maps/layers/index.d.ts +0 -2
- package/dist/maps/layers/units.cjs +0 -207
- package/dist/maps/layers/units.cjs.map +0 -1
- package/dist/maps/layers/units.d.ts +0 -14
- package/dist/maps/layers/units.js +0 -204
- package/dist/maps/layers/units.js.map +0 -1
- package/dist/units/colors.cjs +0 -115
- package/dist/units/colors.cjs.map +0 -1
- package/dist/units/colors.d.ts +0 -20
- package/dist/units/colors.js +0 -113
- package/dist/units/colors.js.map +0 -1
- package/dist/units/resolvers.cjs +0 -125
- package/dist/units/resolvers.cjs.map +0 -1
- package/dist/units/resolvers.d.ts +0 -8
- package/dist/units/resolvers.js +0 -125
- package/dist/units/resolvers.js.map +0 -1
- package/src/maps/column-correlation/column-correlation-map.stories.ts +0 -108
- package/src/maps/column-correlation/core.ts +0 -342
- package/src/maps/column-correlation/index.ts +0 -2
- package/src/maps/column-correlation/state.ts +0 -315
- package/src/maps/column-navigation/index.ts +0 -2
- package/src/maps/column-navigation/mapbox/column-navigation-map.stories.ts +0 -278
- package/src/maps/column-navigation/mapbox/index.ts +0 -276
- package/src/maps/column-navigation/mapbox/keyboard-navigation.ts +0 -133
- package/src/maps/column-navigation/mapbox/state.ts +0 -119
- package/src/maps/column-navigation/svg/animated.ts +0 -78
- package/src/maps/column-navigation/svg/column-navigation-svg-map.stories.ts +0 -46
- package/src/maps/column-navigation/svg/data-fetcher.ts +0 -34
- package/src/maps/column-navigation/svg/index.ts +0 -96
- package/src/maps/column-navigation/svg/layers.ts +0 -233
- package/src/maps/column-navigation/utils/keyboard-navigation.ts +0 -58
- package/src/maps/index.ts +0 -4
- package/src/maps/inset-map/index.ts +0 -87
- package/src/maps/inset-map/inset-map.stories.ts +0 -20
- package/src/maps/layers/columns.ts +0 -216
- package/src/maps/layers/index.ts +0 -2
- package/src/maps/layers/units.ts +0 -286
- package/src/maps/unit-map.stories.ts +0 -79
- package/src/units/colors.ts +0 -183
- package/src/units/resolvers.ts +0 -141
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const dataProvider = require("@macrostrat/data-provider");
|
|
4
|
-
const uiComponents = require("@macrostrat/ui-components");
|
|
5
|
-
const mapboxReact = require("@macrostrat/mapbox-react");
|
|
6
|
-
const React = require("react");
|
|
7
|
-
const mapboxUtils = require("@macrostrat/mapbox-utils");
|
|
8
|
-
const resolvers = require("../../units/resolvers.cjs");
|
|
9
|
-
const mapStyles = require("@macrostrat/map-styles");
|
|
10
|
-
const colorUtils = require("@macrostrat/color-utils");
|
|
11
|
-
const pMap = require("p-map");
|
|
12
|
-
const columns = require("./columns.cjs");
|
|
13
|
-
const h = require("@macrostrat/hyper");
|
|
14
|
-
const colors = require("../../units/colors.cjs");
|
|
15
|
-
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
16
|
-
const pMap__default = /* @__PURE__ */ _interopDefault(pMap);
|
|
17
|
-
const h__default = /* @__PURE__ */ _interopDefault(h);
|
|
18
|
-
function MacrostratUnitsOverlay(props) {
|
|
19
|
-
const { time, ageSpan = 0.05, patterns = false } = props;
|
|
20
|
-
const lithMap = dataProvider.useLithologies();
|
|
21
|
-
mapboxReact.useOverlayStyle(() => {
|
|
22
|
-
return buildUnitsStyle({ patterns });
|
|
23
|
-
}, [patterns]);
|
|
24
|
-
mapboxReact.useMapStyleOperator(
|
|
25
|
-
(map) => {
|
|
26
|
-
if (!patterns) return;
|
|
27
|
-
mapStyles.setupStyleImageManager(map, { verbose: false });
|
|
28
|
-
},
|
|
29
|
-
[patterns]
|
|
30
|
-
);
|
|
31
|
-
const params = React.useMemo(() => {
|
|
32
|
-
let project;
|
|
33
|
-
if (Number.isFinite(props.project)) {
|
|
34
|
-
project = [props.project];
|
|
35
|
-
} else if (!Array.isArray(props.project)) {
|
|
36
|
-
project = void 0;
|
|
37
|
-
}
|
|
38
|
-
const projectCompat = project != null && project.length > 0 ? project[0] : void 0;
|
|
39
|
-
return {
|
|
40
|
-
age_bottom: time + ageSpan / 2,
|
|
41
|
-
age_top: time - ageSpan / 2,
|
|
42
|
-
response: "long",
|
|
43
|
-
project: projectCompat
|
|
44
|
-
};
|
|
45
|
-
}, [time, ageSpan, props.project]);
|
|
46
|
-
const units = uiComponents.useAPIResult("/units", params);
|
|
47
|
-
const columns$1 = dataProvider.useMacrostratColumns(params.project, false);
|
|
48
|
-
mapboxReact.useMapStyleOperator(
|
|
49
|
-
(map) => {
|
|
50
|
-
if (units == null || columns$1 == null || lithMap == null) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const getColorForLithology = (data) => {
|
|
54
|
-
return lithMap?.get(data.lith_id)?.color ?? null;
|
|
55
|
-
};
|
|
56
|
-
const unitsMap = postProcessUnits(units, getColorForLithology);
|
|
57
|
-
handleUnitsLayerUpdate(map, unitsMap, columns$1);
|
|
58
|
-
if (patterns) {
|
|
59
|
-
handlePatternOverlayUpdate(
|
|
60
|
-
map,
|
|
61
|
-
unitsMap,
|
|
62
|
-
columns$1,
|
|
63
|
-
getColorForLithology
|
|
64
|
-
).then(() => {
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
[units, lithMap, columns$1, patterns]
|
|
69
|
-
);
|
|
70
|
-
const isHovered = ["boolean", ["feature-state", "hover"], false];
|
|
71
|
-
const isShown = ["boolean", ["feature-state", "shown"], false];
|
|
72
|
-
const opacity = [
|
|
73
|
-
"case",
|
|
74
|
-
["all", isHovered, isShown],
|
|
75
|
-
0.9,
|
|
76
|
-
isShown,
|
|
77
|
-
0.8,
|
|
78
|
-
isHovered,
|
|
79
|
-
0.3,
|
|
80
|
-
0
|
|
81
|
-
];
|
|
82
|
-
return h__default.default([
|
|
83
|
-
h__default.default(columns.BaseColumnsLayer, {
|
|
84
|
-
enabled: true,
|
|
85
|
-
columns: columns$1,
|
|
86
|
-
opacity,
|
|
87
|
-
lineOpacity: 0.2,
|
|
88
|
-
lineColor: "lightgray",
|
|
89
|
-
color: "transparent"
|
|
90
|
-
})
|
|
91
|
-
]);
|
|
92
|
-
}
|
|
93
|
-
function handleUnitsLayerUpdate(map, unitsMap, columns2) {
|
|
94
|
-
for (const column of columns2) {
|
|
95
|
-
const col_id = column.properties.col_id;
|
|
96
|
-
const info = unitsMap.get(Number(col_id));
|
|
97
|
-
const color = info?.color;
|
|
98
|
-
map.setFeatureState(
|
|
99
|
-
{ source: "columns", id: col_id },
|
|
100
|
-
{
|
|
101
|
-
color,
|
|
102
|
-
shown: color != null
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function handlePatternOverlayUpdate(map, unitsMap, columns2, getColor) {
|
|
108
|
-
const colsWithPatterns = [];
|
|
109
|
-
const patternIDs = /* @__PURE__ */ new Set();
|
|
110
|
-
for (const column of columns2) {
|
|
111
|
-
const col_id = column.properties.col_id;
|
|
112
|
-
const info = unitsMap.get(Number(col_id));
|
|
113
|
-
if (info == null) continue;
|
|
114
|
-
const pattern = getPatternSpec(info?.liths, getColor);
|
|
115
|
-
if (pattern == null) continue;
|
|
116
|
-
colsWithPatterns.push({
|
|
117
|
-
type: "Feature",
|
|
118
|
-
geometry: column.geometry,
|
|
119
|
-
properties: {
|
|
120
|
-
col_id,
|
|
121
|
-
pattern
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
patternIDs.add(pattern);
|
|
125
|
-
}
|
|
126
|
-
const patternsToLoad = patternIDs.values().filter((d) => !map.hasImage(d));
|
|
127
|
-
const mapper = async (patternID) => {
|
|
128
|
-
try {
|
|
129
|
-
await mapStyles.loadStyleImage(map, patternID, { pixelRatio: 10 });
|
|
130
|
-
} catch (e) {
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
await pMap__default.default(patternsToLoad, mapper, { concurrency: 5 });
|
|
134
|
-
const patternData = {
|
|
135
|
-
type: "FeatureCollection",
|
|
136
|
-
features: colsWithPatterns
|
|
137
|
-
};
|
|
138
|
-
mapboxUtils.setGeoJSON(map, "column-patterns", patternData);
|
|
139
|
-
}
|
|
140
|
-
const cachedColors = /* @__PURE__ */ new Map();
|
|
141
|
-
function getDarkenedColor(color) {
|
|
142
|
-
if (cachedColors.has(color)) {
|
|
143
|
-
return cachedColors.get(color);
|
|
144
|
-
}
|
|
145
|
-
const c1 = colorUtils.asChromaColor(color).set("hsl.l", 0.4).set("hsl.s", 0.8).hex();
|
|
146
|
-
cachedColors.set(color, c1);
|
|
147
|
-
return c1;
|
|
148
|
-
}
|
|
149
|
-
function postProcessUnits(units, getColor) {
|
|
150
|
-
const unitsByColumn = /* @__PURE__ */ new Map();
|
|
151
|
-
for (const unit of units) {
|
|
152
|
-
const col_id = Number(unit.col_id);
|
|
153
|
-
if (!unitsByColumn.has(col_id)) {
|
|
154
|
-
unitsByColumn.set(col_id, [unit]);
|
|
155
|
-
} else {
|
|
156
|
-
unitsByColumn.set(col_id, [...unitsByColumn.get(col_id), unit]);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const res = /* @__PURE__ */ new Map();
|
|
160
|
-
for (const [col_id, unitList] of unitsByColumn.entries()) {
|
|
161
|
-
const liths = colors.flattenLithologies(unitList.map((u) => u.lith));
|
|
162
|
-
res.set(col_id, {
|
|
163
|
-
col_id,
|
|
164
|
-
units: unitList,
|
|
165
|
-
liths,
|
|
166
|
-
color: colors.getMixedColorForData(liths, getColor)
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
return res;
|
|
170
|
-
}
|
|
171
|
-
function getPatternSpec(liths, getColor) {
|
|
172
|
-
const patternData = resolvers.getBestFGDCPatternForLithologyList(liths);
|
|
173
|
-
if (patternData == null) return null;
|
|
174
|
-
let { patternID, lith } = patternData;
|
|
175
|
-
const color = getDarkenedColor(getColor(lith));
|
|
176
|
-
return `fgdc:${patternID}:${color}:transparent`;
|
|
177
|
-
}
|
|
178
|
-
function buildUnitsStyle(opts = {}) {
|
|
179
|
-
const { patterns = false } = opts;
|
|
180
|
-
const baseStyle = {
|
|
181
|
-
sources: {},
|
|
182
|
-
version: 8
|
|
183
|
-
};
|
|
184
|
-
if (!patterns) {
|
|
185
|
-
return baseStyle;
|
|
186
|
-
}
|
|
187
|
-
const patternStyle = {
|
|
188
|
-
sources: {
|
|
189
|
-
"column-patterns": mapboxUtils.buildGeoJSONSource()
|
|
190
|
-
},
|
|
191
|
-
layers: [
|
|
192
|
-
{
|
|
193
|
-
id: "columns-fill-pattern",
|
|
194
|
-
type: "fill",
|
|
195
|
-
source: "column-patterns",
|
|
196
|
-
paint: {
|
|
197
|
-
"fill-pattern": ["get", "pattern"],
|
|
198
|
-
"fill-opacity": 1
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
]
|
|
202
|
-
};
|
|
203
|
-
return mapboxUtils.mergeStyles(baseStyle, patternStyle);
|
|
204
|
-
}
|
|
205
|
-
exports.MacrostratUnitsOverlay = MacrostratUnitsOverlay;
|
|
206
|
-
exports.buildUnitsStyle = buildUnitsStyle;
|
|
207
|
-
//# sourceMappingURL=units.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"units.cjs","sources":["../../../src/maps/layers/units.ts"],"sourcesContent":["import {\n useLithologies,\n useMacrostratColumns,\n} from \"@macrostrat/data-provider\";\nimport { useAPIResult } from \"@macrostrat/ui-components\";\nimport { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { FeatureCollection } from \"geojson\";\nimport { useMemo } from \"react\";\nimport { mergeStyles, setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport { UnitLithology, UnitLong } from \"@macrostrat/api-types\";\nimport { flattenLithologies, getMixedColorForData } from \"../../units\";\nimport { getBestFGDCPatternForLithologyList } from \"../../units/resolvers\";\nimport {\n setupStyleImageManager,\n loadStyleImage,\n StyleFragment,\n} from \"@macrostrat/map-styles\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport pMap from \"p-map\";\nimport { BaseColumnsLayer } from \"./columns\";\nimport h from \"@macrostrat/hyper\";\n\nexport interface UnitsOverlayProps {\n time: number;\n ageSpan?: number;\n project?: number | number[];\n patterns?: boolean;\n}\n\nexport function MacrostratUnitsOverlay(props: UnitsOverlayProps) {\n const { time, ageSpan = 0.05, patterns = false } = props;\n const lithMap = useLithologies();\n\n useOverlayStyle(() => {\n return buildUnitsStyle({ patterns });\n }, [patterns]);\n\n useMapStyleOperator(\n (map) => {\n if (!patterns) return;\n setupStyleImageManager(map, { verbose: false });\n },\n [patterns],\n );\n\n const params = useMemo(() => {\n let project: number[] | undefined;\n if (Number.isFinite(props.project)) {\n project = [props.project as number];\n } else if (!Array.isArray(props.project)) {\n project = undefined;\n }\n // Project can only be a single project for now\n const projectCompat =\n project != null && project.length > 0 ? project[0] : undefined;\n\n return {\n age_bottom: time + ageSpan / 2,\n age_top: time - ageSpan / 2,\n response: \"long\",\n project: projectCompat,\n };\n }, [time, ageSpan, props.project]);\n\n const units: UnitLong[] = useAPIResult(\"/units\", params);\n const columns = useMacrostratColumns(params.project, false);\n\n useMapStyleOperator(\n (map) => {\n if (units == null || columns == null || lithMap == null) {\n return;\n }\n\n const getColorForLithology = (data: UnitLithology): string | null => {\n return lithMap?.get(data.lith_id)?.color ?? null;\n };\n\n const unitsMap = postProcessUnits(units, getColorForLithology);\n handleUnitsLayerUpdate(map, unitsMap, columns);\n if (patterns) {\n handlePatternOverlayUpdate(\n map,\n unitsMap,\n columns,\n getColorForLithology,\n ).then(() => {});\n }\n },\n [units, lithMap, columns, patterns],\n );\n\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n const isShown = [\"boolean\", [\"feature-state\", \"shown\"], false];\n\n const opacity = [\n \"case\",\n [\"all\", isHovered, isShown],\n 0.9,\n isShown,\n 0.8,\n isHovered,\n 0.3,\n 0.0,\n ];\n\n return h([\n h(BaseColumnsLayer, {\n enabled: true,\n columns,\n opacity,\n lineOpacity: 0.2,\n lineColor: \"lightgray\",\n color: \"transparent\",\n }),\n ]);\n}\n\nfunction handleUnitsLayerUpdate(\n map,\n unitsMap: Map<number, UnitsDisplayInfo>,\n columns: any[],\n) {\n // Update feature states\n for (const column of columns) {\n const col_id = column.properties.col_id;\n const info = unitsMap.get(Number(col_id));\n const color = info?.color;\n map.setFeatureState(\n { source: \"columns\", id: col_id },\n {\n color,\n shown: color != null,\n },\n );\n }\n}\n\nasync function handlePatternOverlayUpdate(\n map,\n unitsMap: Map<number, UnitsDisplayInfo>,\n columns: any[],\n getColor: LithologyColorGetter,\n) {\n // synthesize patterns not yet in cache\n\n const colsWithPatterns = [];\n const patternIDs = new Set<string>();\n // Update feature states\n for (const column of columns) {\n const col_id = column.properties.col_id;\n const info = unitsMap.get(Number(col_id));\n if (info == null) continue;\n const pattern = getPatternSpec(info?.liths, getColor);\n if (pattern == null) continue;\n\n colsWithPatterns.push({\n type: \"Feature\",\n geometry: column.geometry,\n properties: {\n col_id,\n pattern,\n },\n });\n patternIDs.add(pattern);\n }\n\n const patternsToLoad = patternIDs.values().filter((d) => !map.hasImage(d));\n\n const mapper = async (patternID) => {\n try {\n await loadStyleImage(map, patternID, { pixelRatio: 10 });\n } catch (e) {}\n };\n // Load all pattern images\n await pMap(patternsToLoad, mapper, { concurrency: 5 });\n\n // Set data for pattern layer\n // This is inefficient but the only way to set per-feature patterns in Mapbox\n const patternData: FeatureCollection = {\n type: \"FeatureCollection\",\n features: colsWithPatterns,\n };\n setGeoJSON(map, \"column-patterns\", patternData);\n}\n\nconst cachedColors = new Map<string, string>();\n\nfunction getDarkenedColor(color: string): string {\n /** Memoized function to get a darkened version of a color for pattern use */\n if (cachedColors.has(color)) {\n return cachedColors.get(color);\n }\n const c1 = asChromaColor(color).set(\"hsl.l\", 0.4).set(\"hsl.s\", 0.8).hex();\n cachedColors.set(color, c1);\n return c1;\n}\n\ninterface UnitsDisplayInfo {\n col_id: number;\n units: UnitLong[];\n color: string;\n liths: UnitLithology[];\n}\n\ntype LithologyColorGetter = (val: UnitLithology) => string | null;\n\nfunction postProcessUnits(\n units: UnitLong[],\n getColor: LithologyColorGetter,\n): Map<number, UnitsDisplayInfo> {\n // Group by col_id\n const unitsByColumn: Map<number, UnitLong[]> = new Map();\n for (const unit of units) {\n const col_id = Number(unit.col_id);\n if (!unitsByColumn.has(col_id)) {\n unitsByColumn.set(col_id, [unit]);\n } else {\n unitsByColumn.set(col_id, [...unitsByColumn.get(col_id), unit]);\n }\n }\n\n // Summarize units for display\n const res = new Map<number, UnitsDisplayInfo>();\n for (const [col_id, unitList] of unitsByColumn.entries()) {\n const liths = flattenLithologies(unitList.map((u) => u.lith));\n res.set(col_id, {\n col_id,\n units: unitList,\n liths,\n color: getMixedColorForData(liths, getColor),\n });\n }\n\n return res;\n}\n\nfunction getPatternSpec(\n liths: UnitLithology[],\n getColor: LithologyColorGetter,\n): string | null {\n const patternData = getBestFGDCPatternForLithologyList(liths);\n if (patternData == null) return null;\n let { patternID, lith } = patternData;\n const color = getDarkenedColor(getColor(lith));\n return `fgdc:${patternID}:${color}:transparent`;\n}\n\ntype UnitsStyleOptions = {\n color?: string;\n patterns?: boolean;\n};\n\nexport function buildUnitsStyle(opts: UnitsStyleOptions = {}): StyleFragment {\n const { patterns = false } = opts;\n\n // If color is in the feature state or geojson properties, use that as second choice\n\n const baseStyle: StyleFragment = {\n sources: {},\n version: 8,\n };\n\n if (!patterns) {\n return baseStyle;\n }\n\n const patternStyle: StyleFragment = {\n sources: {\n \"column-patterns\": buildGeoJSONSource(),\n },\n layers: [\n {\n id: \"columns-fill-pattern\",\n type: \"fill\",\n source: \"column-patterns\",\n paint: {\n \"fill-pattern\": [\"get\", \"pattern\"],\n \"fill-opacity\": 1,\n },\n },\n ],\n };\n\n return mergeStyles(baseStyle, patternStyle);\n}\n"],"names":["useLithologies","useOverlayStyle","useMapStyleOperator","setupStyleImageManager","useMemo","useAPIResult","columns","useMacrostratColumns","h","BaseColumnsLayer","loadStyleImage","pMap","setGeoJSON","asChromaColor","flattenLithologies","getMixedColorForData","getBestFGDCPatternForLithologyList","buildGeoJSONSource","mergeStyles"],"mappings":";;;;;;;;;;;;;;;;;AA8BO,SAAS,uBAAuB,OAA0B;AAC/D,QAAM,EAAE,MAAM,UAAU,MAAM,WAAW,UAAU;AACnD,QAAM,UAAUA,aAAAA,eAAA;AAEhBC,cAAAA,gBAAgB,MAAM;AACpB,WAAO,gBAAgB,EAAE,UAAU;AAAA,EACrC,GAAG,CAAC,QAAQ,CAAC;AAEbC,cAAAA;AAAAA,IACE,CAAC,QAAQ;AACP,UAAI,CAAC,SAAU;AACfC,gBAAAA,uBAAuB,KAAK,EAAE,SA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C,KAAK;AAC5D,MAAI,eAAe,KAAM,QAAO;AAChC,MAAI,EAAE,WAAW,KAAA,IAAS;AAC1B,QAAM,QAAQ,iBAAiB,SAAS,IAAI,CAAC;AAC7C,SAAO,QAAQ,SAAS,IAAI,KAAK;AACnC;AAOO,SAAS,gBAAgB,OAA0B,IAAmB;AAC3E,QAAM,EAAE,WAAW,MAAA,IAAU;AAI7B,QAAM,YAA2B;AAAA,IAC/B,SAAS,CAAA;AAAA,IACT,SAAS;AAAA,EAAA;AAGX,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,eAA8B;AAAA,IAClC,SAAS;AAAA,MACP,mBAAmBC,YAAAA,mBAAA;AAAA,IAAmB;AAAA,IAExC,QAAQ;AAAA,MACN;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,gBAAgB,CAAC,OAAO,SAAS;AAAA,UACjC,gBAAgB;AAAA,QAAA;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAGF,SAAOC,YAAAA,YAAY,WAAW,YAAY;AAC5C;;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { StyleFragment } from '@macrostrat/map-styles';
|
|
2
|
-
export interface UnitsOverlayProps {
|
|
3
|
-
time: number;
|
|
4
|
-
ageSpan?: number;
|
|
5
|
-
project?: number | number[];
|
|
6
|
-
patterns?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare function MacrostratUnitsOverlay(props: UnitsOverlayProps): import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>>;
|
|
9
|
-
type UnitsStyleOptions = {
|
|
10
|
-
color?: string;
|
|
11
|
-
patterns?: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare function buildUnitsStyle(opts?: UnitsStyleOptions): StyleFragment;
|
|
14
|
-
export {};
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { useLithologies, useMacrostratColumns } from "@macrostrat/data-provider";
|
|
2
|
-
import { useAPIResult } from "@macrostrat/ui-components";
|
|
3
|
-
import { useOverlayStyle, useMapStyleOperator } from "@macrostrat/mapbox-react";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
|
-
import { buildGeoJSONSource, mergeStyles, setGeoJSON } from "@macrostrat/mapbox-utils";
|
|
6
|
-
import { getBestFGDCPatternForLithologyList } from "../../units/resolvers.js";
|
|
7
|
-
import { setupStyleImageManager, loadStyleImage } from "@macrostrat/map-styles";
|
|
8
|
-
import { asChromaColor } from "@macrostrat/color-utils";
|
|
9
|
-
import pMap from "p-map";
|
|
10
|
-
import { BaseColumnsLayer } from "./columns.js";
|
|
11
|
-
import h from "@macrostrat/hyper";
|
|
12
|
-
import { flattenLithologies, getMixedColorForData } from "../../units/colors.js";
|
|
13
|
-
function MacrostratUnitsOverlay(props) {
|
|
14
|
-
const { time, ageSpan = 0.05, patterns = false } = props;
|
|
15
|
-
const lithMap = useLithologies();
|
|
16
|
-
useOverlayStyle(() => {
|
|
17
|
-
return buildUnitsStyle({ patterns });
|
|
18
|
-
}, [patterns]);
|
|
19
|
-
useMapStyleOperator(
|
|
20
|
-
(map) => {
|
|
21
|
-
if (!patterns) return;
|
|
22
|
-
setupStyleImageManager(map, { verbose: false });
|
|
23
|
-
},
|
|
24
|
-
[patterns]
|
|
25
|
-
);
|
|
26
|
-
const params = useMemo(() => {
|
|
27
|
-
let project;
|
|
28
|
-
if (Number.isFinite(props.project)) {
|
|
29
|
-
project = [props.project];
|
|
30
|
-
} else if (!Array.isArray(props.project)) {
|
|
31
|
-
project = void 0;
|
|
32
|
-
}
|
|
33
|
-
const projectCompat = project != null && project.length > 0 ? project[0] : void 0;
|
|
34
|
-
return {
|
|
35
|
-
age_bottom: time + ageSpan / 2,
|
|
36
|
-
age_top: time - ageSpan / 2,
|
|
37
|
-
response: "long",
|
|
38
|
-
project: projectCompat
|
|
39
|
-
};
|
|
40
|
-
}, [time, ageSpan, props.project]);
|
|
41
|
-
const units = useAPIResult("/units", params);
|
|
42
|
-
const columns = useMacrostratColumns(params.project, false);
|
|
43
|
-
useMapStyleOperator(
|
|
44
|
-
(map) => {
|
|
45
|
-
if (units == null || columns == null || lithMap == null) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const getColorForLithology = (data) => {
|
|
49
|
-
return lithMap?.get(data.lith_id)?.color ?? null;
|
|
50
|
-
};
|
|
51
|
-
const unitsMap = postProcessUnits(units, getColorForLithology);
|
|
52
|
-
handleUnitsLayerUpdate(map, unitsMap, columns);
|
|
53
|
-
if (patterns) {
|
|
54
|
-
handlePatternOverlayUpdate(
|
|
55
|
-
map,
|
|
56
|
-
unitsMap,
|
|
57
|
-
columns,
|
|
58
|
-
getColorForLithology
|
|
59
|
-
).then(() => {
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
[units, lithMap, columns, patterns]
|
|
64
|
-
);
|
|
65
|
-
const isHovered = ["boolean", ["feature-state", "hover"], false];
|
|
66
|
-
const isShown = ["boolean", ["feature-state", "shown"], false];
|
|
67
|
-
const opacity = [
|
|
68
|
-
"case",
|
|
69
|
-
["all", isHovered, isShown],
|
|
70
|
-
0.9,
|
|
71
|
-
isShown,
|
|
72
|
-
0.8,
|
|
73
|
-
isHovered,
|
|
74
|
-
0.3,
|
|
75
|
-
0
|
|
76
|
-
];
|
|
77
|
-
return h([
|
|
78
|
-
h(BaseColumnsLayer, {
|
|
79
|
-
enabled: true,
|
|
80
|
-
columns,
|
|
81
|
-
opacity,
|
|
82
|
-
lineOpacity: 0.2,
|
|
83
|
-
lineColor: "lightgray",
|
|
84
|
-
color: "transparent"
|
|
85
|
-
})
|
|
86
|
-
]);
|
|
87
|
-
}
|
|
88
|
-
function handleUnitsLayerUpdate(map, unitsMap, columns) {
|
|
89
|
-
for (const column of columns) {
|
|
90
|
-
const col_id = column.properties.col_id;
|
|
91
|
-
const info = unitsMap.get(Number(col_id));
|
|
92
|
-
const color = info?.color;
|
|
93
|
-
map.setFeatureState(
|
|
94
|
-
{ source: "columns", id: col_id },
|
|
95
|
-
{
|
|
96
|
-
color,
|
|
97
|
-
shown: color != null
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async function handlePatternOverlayUpdate(map, unitsMap, columns, getColor) {
|
|
103
|
-
const colsWithPatterns = [];
|
|
104
|
-
const patternIDs = /* @__PURE__ */ new Set();
|
|
105
|
-
for (const column of columns) {
|
|
106
|
-
const col_id = column.properties.col_id;
|
|
107
|
-
const info = unitsMap.get(Number(col_id));
|
|
108
|
-
if (info == null) continue;
|
|
109
|
-
const pattern = getPatternSpec(info?.liths, getColor);
|
|
110
|
-
if (pattern == null) continue;
|
|
111
|
-
colsWithPatterns.push({
|
|
112
|
-
type: "Feature",
|
|
113
|
-
geometry: column.geometry,
|
|
114
|
-
properties: {
|
|
115
|
-
col_id,
|
|
116
|
-
pattern
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
patternIDs.add(pattern);
|
|
120
|
-
}
|
|
121
|
-
const patternsToLoad = patternIDs.values().filter((d) => !map.hasImage(d));
|
|
122
|
-
const mapper = async (patternID) => {
|
|
123
|
-
try {
|
|
124
|
-
await loadStyleImage(map, patternID, { pixelRatio: 10 });
|
|
125
|
-
} catch (e) {
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
await pMap(patternsToLoad, mapper, { concurrency: 5 });
|
|
129
|
-
const patternData = {
|
|
130
|
-
type: "FeatureCollection",
|
|
131
|
-
features: colsWithPatterns
|
|
132
|
-
};
|
|
133
|
-
setGeoJSON(map, "column-patterns", patternData);
|
|
134
|
-
}
|
|
135
|
-
const cachedColors = /* @__PURE__ */ new Map();
|
|
136
|
-
function getDarkenedColor(color) {
|
|
137
|
-
if (cachedColors.has(color)) {
|
|
138
|
-
return cachedColors.get(color);
|
|
139
|
-
}
|
|
140
|
-
const c1 = asChromaColor(color).set("hsl.l", 0.4).set("hsl.s", 0.8).hex();
|
|
141
|
-
cachedColors.set(color, c1);
|
|
142
|
-
return c1;
|
|
143
|
-
}
|
|
144
|
-
function postProcessUnits(units, getColor) {
|
|
145
|
-
const unitsByColumn = /* @__PURE__ */ new Map();
|
|
146
|
-
for (const unit of units) {
|
|
147
|
-
const col_id = Number(unit.col_id);
|
|
148
|
-
if (!unitsByColumn.has(col_id)) {
|
|
149
|
-
unitsByColumn.set(col_id, [unit]);
|
|
150
|
-
} else {
|
|
151
|
-
unitsByColumn.set(col_id, [...unitsByColumn.get(col_id), unit]);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const res = /* @__PURE__ */ new Map();
|
|
155
|
-
for (const [col_id, unitList] of unitsByColumn.entries()) {
|
|
156
|
-
const liths = flattenLithologies(unitList.map((u) => u.lith));
|
|
157
|
-
res.set(col_id, {
|
|
158
|
-
col_id,
|
|
159
|
-
units: unitList,
|
|
160
|
-
liths,
|
|
161
|
-
color: getMixedColorForData(liths, getColor)
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return res;
|
|
165
|
-
}
|
|
166
|
-
function getPatternSpec(liths, getColor) {
|
|
167
|
-
const patternData = getBestFGDCPatternForLithologyList(liths);
|
|
168
|
-
if (patternData == null) return null;
|
|
169
|
-
let { patternID, lith } = patternData;
|
|
170
|
-
const color = getDarkenedColor(getColor(lith));
|
|
171
|
-
return `fgdc:${patternID}:${color}:transparent`;
|
|
172
|
-
}
|
|
173
|
-
function buildUnitsStyle(opts = {}) {
|
|
174
|
-
const { patterns = false } = opts;
|
|
175
|
-
const baseStyle = {
|
|
176
|
-
sources: {},
|
|
177
|
-
version: 8
|
|
178
|
-
};
|
|
179
|
-
if (!patterns) {
|
|
180
|
-
return baseStyle;
|
|
181
|
-
}
|
|
182
|
-
const patternStyle = {
|
|
183
|
-
sources: {
|
|
184
|
-
"column-patterns": buildGeoJSONSource()
|
|
185
|
-
},
|
|
186
|
-
layers: [
|
|
187
|
-
{
|
|
188
|
-
id: "columns-fill-pattern",
|
|
189
|
-
type: "fill",
|
|
190
|
-
source: "column-patterns",
|
|
191
|
-
paint: {
|
|
192
|
-
"fill-pattern": ["get", "pattern"],
|
|
193
|
-
"fill-opacity": 1
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
};
|
|
198
|
-
return mergeStyles(baseStyle, patternStyle);
|
|
199
|
-
}
|
|
200
|
-
export {
|
|
201
|
-
MacrostratUnitsOverlay,
|
|
202
|
-
buildUnitsStyle
|
|
203
|
-
};
|
|
204
|
-
//# sourceMappingURL=units.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","sources":["../../../src/maps/layers/units.ts"],"sourcesContent":["import {\n useLithologies,\n useMacrostratColumns,\n} from \"@macrostrat/data-provider\";\nimport { useAPIResult } from \"@macrostrat/ui-components\";\nimport { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { FeatureCollection } from \"geojson\";\nimport { useMemo } from \"react\";\nimport { mergeStyles, setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport { UnitLithology, UnitLong } from \"@macrostrat/api-types\";\nimport { flattenLithologies, getMixedColorForData } from \"../../units\";\nimport { getBestFGDCPatternForLithologyList } from \"../../units/resolvers\";\nimport {\n setupStyleImageManager,\n loadStyleImage,\n StyleFragment,\n} from \"@macrostrat/map-styles\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport pMap from \"p-map\";\nimport { BaseColumnsLayer } from \"./columns\";\nimport h from \"@macrostrat/hyper\";\n\nexport interface UnitsOverlayProps {\n time: number;\n ageSpan?: number;\n project?: number | number[];\n patterns?: boolean;\n}\n\nexport function MacrostratUnitsOverlay(props: UnitsOverlayProps) {\n const { time, ageSpan = 0.05, patterns = false } = props;\n const lithMap = useLithologies();\n\n useOverlayStyle(() => {\n return buildUnitsStyle({ patterns });\n }, [patterns]);\n\n useMapStyleOperator(\n (map) => {\n if (!patterns) return;\n setupStyleImageManager(map, { verbose: false });\n },\n [patterns],\n );\n\n const params = useMemo(() => {\n let project: number[] | undefined;\n if (Number.isFinite(props.project)) {\n project = [props.project as number];\n } else if (!Array.isArray(props.project)) {\n project = undefined;\n }\n // Project can only be a single project for now\n const projectCompat =\n project != null && project.length > 0 ? project[0] : undefined;\n\n return {\n age_bottom: time + ageSpan / 2,\n age_top: time - ageSpan / 2,\n response: \"long\",\n project: projectCompat,\n };\n }, [time, ageSpan, props.project]);\n\n const units: UnitLong[] = useAPIResult(\"/units\", params);\n const columns = useMacrostratColumns(params.project, false);\n\n useMapStyleOperator(\n (map) => {\n if (units == null || columns == null || lithMap == null) {\n return;\n }\n\n const getColorForLithology = (data: UnitLithology): string | null => {\n return lithMap?.get(data.lith_id)?.color ?? null;\n };\n\n const unitsMap = postProcessUnits(units, getColorForLithology);\n handleUnitsLayerUpdate(map, unitsMap, columns);\n if (patterns) {\n handlePatternOverlayUpdate(\n map,\n unitsMap,\n columns,\n getColorForLithology,\n ).then(() => {});\n }\n },\n [units, lithMap, columns, patterns],\n );\n\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n const isShown = [\"boolean\", [\"feature-state\", \"shown\"], false];\n\n const opacity = [\n \"case\",\n [\"all\", isHovered, isShown],\n 0.9,\n isShown,\n 0.8,\n isHovered,\n 0.3,\n 0.0,\n ];\n\n return h([\n h(BaseColumnsLayer, {\n enabled: true,\n columns,\n opacity,\n lineOpacity: 0.2,\n lineColor: \"lightgray\",\n color: \"transparent\",\n }),\n ]);\n}\n\nfunction handleUnitsLayerUpdate(\n map,\n unitsMap: Map<number, UnitsDisplayInfo>,\n columns: any[],\n) {\n // Update feature states\n for (const column of columns) {\n const col_id = column.properties.col_id;\n const info = unitsMap.get(Number(col_id));\n const color = info?.color;\n map.setFeatureState(\n { source: \"columns\", id: col_id },\n {\n color,\n shown: color != null,\n },\n );\n }\n}\n\nasync function handlePatternOverlayUpdate(\n map,\n unitsMap: Map<number, UnitsDisplayInfo>,\n columns: any[],\n getColor: LithologyColorGetter,\n) {\n // synthesize patterns not yet in cache\n\n const colsWithPatterns = [];\n const patternIDs = new Set<string>();\n // Update feature states\n for (const column of columns) {\n const col_id = column.properties.col_id;\n const info = unitsMap.get(Number(col_id));\n if (info == null) continue;\n const pattern = getPatternSpec(info?.liths, getColor);\n if (pattern == null) continue;\n\n colsWithPatterns.push({\n type: \"Feature\",\n geometry: column.geometry,\n properties: {\n col_id,\n pattern,\n },\n });\n patternIDs.add(pattern);\n }\n\n const patternsToLoad = patternIDs.values().filter((d) => !map.hasImage(d));\n\n const mapper = async (patternID) => {\n try {\n await loadStyleImage(map, patternID, { pixelRatio: 10 });\n } catch (e) {}\n };\n // Load all pattern images\n await pMap(patternsToLoad, mapper, { concurrency: 5 });\n\n // Set data for pattern layer\n // This is inefficient but the only way to set per-feature patterns in Mapbox\n const patternData: FeatureCollection = {\n type: \"FeatureCollection\",\n features: colsWithPatterns,\n };\n setGeoJSON(map, \"column-patterns\", patternData);\n}\n\nconst cachedColors = new Map<string, string>();\n\nfunction getDarkenedColor(color: string): string {\n /** Memoized function to get a darkened version of a color for pattern use */\n if (cachedColors.has(color)) {\n return cachedColors.get(color);\n }\n const c1 = asChromaColor(color).set(\"hsl.l\", 0.4).set(\"hsl.s\", 0.8).hex();\n cachedColors.set(color, c1);\n return c1;\n}\n\ninterface UnitsDisplayInfo {\n col_id: number;\n units: UnitLong[];\n color: string;\n liths: UnitLithology[];\n}\n\ntype LithologyColorGetter = (val: UnitLithology) => string | null;\n\nfunction postProcessUnits(\n units: UnitLong[],\n getColor: LithologyColorGetter,\n): Map<number, UnitsDisplayInfo> {\n // Group by col_id\n const unitsByColumn: Map<number, UnitLong[]> = new Map();\n for (const unit of units) {\n const col_id = Number(unit.col_id);\n if (!unitsByColumn.has(col_id)) {\n unitsByColumn.set(col_id, [unit]);\n } else {\n unitsByColumn.set(col_id, [...unitsByColumn.get(col_id), unit]);\n }\n }\n\n // Summarize units for display\n const res = new Map<number, UnitsDisplayInfo>();\n for (const [col_id, unitList] of unitsByColumn.entries()) {\n const liths = flattenLithologies(unitList.map((u) => u.lith));\n res.set(col_id, {\n col_id,\n units: unitList,\n liths,\n color: getMixedColorForData(liths, getColor),\n });\n }\n\n return res;\n}\n\nfunction getPatternSpec(\n liths: UnitLithology[],\n getColor: LithologyColorGetter,\n): string | null {\n const patternData = getBestFGDCPatternForLithologyList(liths);\n if (patternData == null) return null;\n let { patternID, lith } = patternData;\n const color = getDarkenedColor(getColor(lith));\n return `fgdc:${patternID}:${color}:transparent`;\n}\n\ntype UnitsStyleOptions = {\n color?: string;\n patterns?: boolean;\n};\n\nexport function buildUnitsStyle(opts: UnitsStyleOptions = {}): StyleFragment {\n const { patterns = false } = opts;\n\n // If color is in the feature state or geojson properties, use that as second choice\n\n const baseStyle: StyleFragment = {\n sources: {},\n version: 8,\n };\n\n if (!patterns) {\n return baseStyle;\n }\n\n const patternStyle: StyleFragment = {\n sources: {\n \"column-patterns\": buildGeoJSONSource(),\n },\n layers: [\n {\n id: \"columns-fill-pattern\",\n type: \"fill\",\n source: \"column-patterns\",\n paint: {\n \"fill-pattern\": [\"get\", \"pattern\"],\n \"fill-opacity\": 1,\n },\n },\n ],\n };\n\n return mergeStyles(baseStyle, patternStyle);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AA8BO,SAAS,uBAAuB,OAA0B;AAC/D,QAAM,EAAE,MAAM,UAAU,MAAM,WAAW,UAAU;AACnD,QAAM,UAAU,eAAA;AAEhB,kBAAgB,MAAM;AACpB,WAAO,gBAAgB,EAAE,UAAU;AAAA,EACrC,GAAG,CAAC,QAAQ,CAAC;AAEb;AAAA,IACE,CAAC,QAAQ;AACP,UAAI,CAAC,SAAU;AACf,6BAAuB,KAAK,EAAE,SAAS,MAAA,CAAO;AAAA,IAChD;AAAA,IACA,CAAC,QAAQ;AAAA,EAAA;AAGX,QAAM,SAAS,QAAQ,MAAM;AAC3B,QAAI;AACJ,QAAI,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I7B,QAAM,YAA2B;AAAA,IAC/B,SAAS,CAAA;AAAA,IACT,SAAS;AAAA,EAAA;AAGX,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,eAA8B;AAAA,IAClC,SAAS;AAAA,MACP,mBAAmB,mBAAA;AAAA,IAAmB;AAAA,IAExC,QAAQ;AAAA,MACN;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,gBAAgB,CAAC,OAAO,SAAS;AAAA,UACjC,gBAAgB;AAAA,QAAA;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAGF,SAAO,YAAY,WAAW,YAAY;AAC5C;"}
|
package/dist/units/colors.cjs
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const chroma = require("chroma-js");
|
|
4
|
-
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
5
|
-
const chroma__default = /* @__PURE__ */ _interopDefault(chroma);
|
|
6
|
-
function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = true, keyOpts = null) {
|
|
7
|
-
const { key = "lith", id_key = "lith_id" } = keyOpts ?? {};
|
|
8
|
-
const liths = unit[key];
|
|
9
|
-
const getColor = (data) => {
|
|
10
|
-
return lithMap?.get(data[id_key])?.color ?? null;
|
|
11
|
-
};
|
|
12
|
-
return getMixedColorForData(liths, getColor, {
|
|
13
|
-
inDarkMode,
|
|
14
|
-
asBackground
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function flattenLithologies(liths, normalize = true) {
|
|
18
|
-
if (liths == null || liths.length === 0) {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
const unitCount = liths.length;
|
|
22
|
-
let newLiths = [];
|
|
23
|
-
for (const unitLiths of liths) {
|
|
24
|
-
let l1 = unitLiths;
|
|
25
|
-
if (normalize) {
|
|
26
|
-
l1 = addProportionsToAllData(unitLiths);
|
|
27
|
-
}
|
|
28
|
-
for (const lith of l1) {
|
|
29
|
-
if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
lith.prop = lith.prop / unitCount;
|
|
33
|
-
}
|
|
34
|
-
newLiths.push(...l1);
|
|
35
|
-
}
|
|
36
|
-
if (newLiths[0]?.lith_id != null) {
|
|
37
|
-
newLiths = mergeLikeData(newLiths, "lith_id");
|
|
38
|
-
} else if (newLiths[0]?.environ_id != null) {
|
|
39
|
-
newLiths = mergeLikeData(newLiths, "environ_id");
|
|
40
|
-
}
|
|
41
|
-
newLiths.sort((a, b) => b.prop - a.prop);
|
|
42
|
-
return newLiths;
|
|
43
|
-
}
|
|
44
|
-
function getMixedColorForData(liths, getColor, options = {}) {
|
|
45
|
-
const { inDarkMode = false, asBackground = true } = options;
|
|
46
|
-
if (liths == null || liths.length === 0) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const lithData = liths.map((d) => {
|
|
50
|
-
let prop = d.prop;
|
|
51
|
-
if (prop == null || isNaN(prop) || prop <= 0) {
|
|
52
|
-
prop = null;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
...d,
|
|
56
|
-
prop,
|
|
57
|
-
color: getColor?.(d) ?? d.color
|
|
58
|
-
};
|
|
59
|
-
}).filter((d) => d.color != null);
|
|
60
|
-
if (lithData.length == 0) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
const lithsWithProp = addProportionsToAllData(lithData);
|
|
64
|
-
const baseColor = chroma__default.default.average(
|
|
65
|
-
lithsWithProp.map((d) => d.color),
|
|
66
|
-
"lrgb",
|
|
67
|
-
lithsWithProp.map((d) => d.prop)
|
|
68
|
-
);
|
|
69
|
-
if (!asBackground) {
|
|
70
|
-
return baseColor.hex();
|
|
71
|
-
}
|
|
72
|
-
if (inDarkMode) {
|
|
73
|
-
return baseColor.set("hsl.l", 0.2).hex();
|
|
74
|
-
} else {
|
|
75
|
-
return baseColor.set("hsl.l", 0.9).hex();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function addProportionsToAllData(liths) {
|
|
79
|
-
const lithsWithProp = liths.filter((d) => d.prop != null);
|
|
80
|
-
const lithsWithoutProp = liths.filter((d) => d.prop == null);
|
|
81
|
-
const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
|
|
82
|
-
let overallTotal = 1;
|
|
83
|
-
if (totalProp < overallTotal && lithsWithoutProp.length > 0) {
|
|
84
|
-
const remainingProp = overallTotal - totalProp;
|
|
85
|
-
const equalProp = remainingProp / lithsWithoutProp.length;
|
|
86
|
-
lithsWithoutProp.forEach((d) => {
|
|
87
|
-
lithsWithProp.push({
|
|
88
|
-
...d,
|
|
89
|
-
prop: equalProp
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return lithsWithProp;
|
|
94
|
-
}
|
|
95
|
-
function mergeLikeData(liths, key) {
|
|
96
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
97
|
-
for (const lith of liths) {
|
|
98
|
-
const id = lith[key];
|
|
99
|
-
if (id == null) continue;
|
|
100
|
-
if (mergedMap.has(id)) {
|
|
101
|
-
const existing = mergedMap.get(id);
|
|
102
|
-
mergedMap.set(id, {
|
|
103
|
-
...existing,
|
|
104
|
-
prop: existing.prop + lith.prop
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
mergedMap.set(id, { ...lith });
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return Array.from(mergedMap.values());
|
|
111
|
-
}
|
|
112
|
-
exports.flattenLithologies = flattenLithologies;
|
|
113
|
-
exports.getMixedColorForData = getMixedColorForData;
|
|
114
|
-
exports.getMixedUnitColor = getMixedUnitColor;
|
|
115
|
-
//# sourceMappingURL=colors.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colors.cjs","sources":["../../src/units/colors.ts"],"sourcesContent":["import chroma from \"chroma-js\";\nimport {\n Environment,\n Lithology,\n UnitLithology,\n UnitLong,\n} from \"@macrostrat/api-types\";\n\ninterface KeyOptions {\n key?: \"lith\" | \"environ\";\n id_key?: \"lith_id\" | \"environ_id\";\n}\n\nexport function getMixedUnitColor(\n unit: UnitLong,\n lithMap: Map<number, { color: string }>,\n inDarkMode = false,\n asBackground = true,\n keyOpts: KeyOptions = null,\n): string | null {\n const { key = \"lith\", id_key = \"lith_id\" } = keyOpts ?? {};\n const liths = unit[key];\n const getColor = (data: UnitLithology): string | null => {\n return lithMap?.get(data[id_key])?.color ?? null;\n };\n\n return getMixedColorForData(liths, getColor, {\n inDarkMode,\n asBackground,\n key: id_key,\n });\n}\n\ninterface ColorBuilderOptions {\n key?: \"lith_id\" | \"environ_id\";\n inDarkMode?: boolean;\n asBackground?: boolean;\n}\n\nexport function flattenLithologies<\n T extends { prop: number | null; lith_id?: number; environ_id?: number },\n>(liths: T[][], normalize: boolean = true): T[] {\n /** Unify proportions in lithology/environment data across several units, normalizing if needed.\n * If normalize is true, proportions are scaled to sum to 1 within each unit (with remaining proportions\n * distributed equally among liths without specified proportions). This helps ensure that units with a\n * few lithologies with specified proportions don't skew the color mixing.\n *\n * Lithologies are deduplicated based on their identifying property (lith_id or environ_id) if that is present.\n */\n if (liths == null || liths.length === 0) {\n return [];\n }\n\n const unitCount = liths.length;\n\n let newLiths: T[] = [];\n for (const unitLiths of liths) {\n let l1 = unitLiths;\n if (normalize) {\n l1 = addProportionsToAllData(unitLiths);\n }\n // Divide proportions by number of units to balance influence\n for (const lith of l1) {\n if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {\n continue;\n }\n lith.prop = lith.prop / unitCount;\n }\n newLiths.push(...l1);\n }\n if (newLiths[0]?.lith_id != null) {\n newLiths = mergeLikeData(newLiths, \"lith_id\");\n } else if (newLiths[0]?.environ_id != null) {\n newLiths = mergeLikeData(newLiths, \"environ_id\");\n }\n // Sort by proportion descending\n newLiths.sort((a, b) => b.prop - a.prop);\n return newLiths;\n}\n\nexport function getMixedColorForData<\n T extends UnitLithology | Lithology | Environment,\n>(\n liths: T[] | null,\n getColor: (val: T) => string | null,\n options: ColorBuilderOptions = {},\n): string | null {\n const { inDarkMode = false, asBackground = true } = options;\n if (liths == null || liths.length === 0) {\n return null;\n }\n const lithData = liths\n .map((d) => {\n let prop = d.prop;\n if (prop == null || isNaN(prop) || prop <= 0) {\n prop = null;\n }\n return {\n ...d,\n prop,\n color: getColor?.(d) ?? d.color,\n };\n })\n .filter((d) => d.color != null);\n\n if (lithData.length == 0) {\n return null;\n }\n\n const lithsWithProp = addProportionsToAllData(lithData);\n\n // Mix colors proportionally\n const baseColor = chroma.average(\n lithsWithProp.map((d) => d.color),\n \"lrgb\",\n lithsWithProp.map((d) => d.prop),\n );\n\n if (!asBackground) {\n return baseColor.hex();\n }\n\n if (inDarkMode) {\n return baseColor.set(\"hsl.l\", 0.2).hex();\n } else {\n return baseColor.set(\"hsl.l\", 0.9).hex();\n }\n}\n\nfunction addProportionsToAllData<T extends { prop?: number }>(liths: T[]): T[] {\n /** Make sure that all lithologies/environments have a defined proportion,\n * and that proportions sum to 1. If some liths lack a defined proportion,\n * the remaining proportion is distributed equally among them.\n *\n * NOTE: This function does not normalize proportions if they already sum to more than 1.\n */\n const lithsWithProp = liths.filter((d) => d.prop != null);\n const lithsWithoutProp = liths.filter((d) => d.prop == null);\n\n const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);\n let overallTotal = 1;\n\n if (totalProp < overallTotal && lithsWithoutProp.length > 0) {\n const remainingProp = overallTotal - totalProp;\n // Distribute remaining proportion equally among liths without prop\n const equalProp = remainingProp / lithsWithoutProp.length;\n lithsWithoutProp.forEach((d) => {\n lithsWithProp.push({\n ...d,\n prop: equalProp,\n } as T);\n });\n }\n return lithsWithProp as T[];\n}\n\nfunction mergeLikeData<\n T extends { prop: number; lith_id?: number; environ_id?: number },\n>(liths: T[], key: \"lith_id\" | \"environ_id\"): T[] {\n /** Merge lithology/environment data with the same identifying property (lith_id or environ_id),\n * summing their proportions.\n *\n * TODO: handle attribute merging\n */\n const mergedMap: Map<number, T> = new Map();\n\n for (const lith of liths) {\n const id = lith[key];\n if (id == null) continue;\n\n if (mergedMap.has(id)) {\n const existing = mergedMap.get(id);\n mergedMap.set(id, {\n ...existing,\n prop: existing.prop + lith.prop,\n });\n } else {\n mergedMap.set(id, { ...lith });\n }\n }\n\n return Array.from(mergedMap.values());\n}\n"],"names":["chroma"],"mappings":";;;;;AAaO,SAAS,kBACd,MACA,SACA,aAAa,OACb,eAAe,MACf,UAAsB,MACP;AACf,QAAM,EAAE,MAAM,QAAQ,SAAS,UAAA,IAAc,WAAW,CAAA;AACxD,QAAM,QAAQ,KAAK,GAAG;AACtB,QAAM,WAAW,CAAC,SAAuC;AACvD,WAAO,SAAS,IAAI,KAAK,MAAM,CAAC,GAAG,SAAS;AAAA,EAC9C;AAEA,SAAO,qBAAqB,OAAO,UAAU;AAAA,IAC3C;AAAA,IACA;AAAA,EAEF,CAAC;AACH;AAQO,SAAS,mBAEd,OAAc,YAAqB,MAAW;AAQ9C,MAAI,SAAS,QAAQ,MAAM,WAAW,GAAG;AACvC,WAAO,CAAA;AAAA,EACT;AAEA,QAAM,YAAY,MAAM;AAExB,MAAI,WAAgB,CAAA;AACpB,aAAW,aAAa,OAAO;AAC7B,QAAI,KAAK;AACT,QAAI,WAAW;AACb,WAAK,wBAAwB,SAAS;AAAA,IACxC;AAEA,eAAW,QAAQ,IAAI;AACrB,UAAI,KAAK,QAAQ,QAAQ,MAAM,KAAK,IAAI,KAAK,KAAK,QAAQ,GAAG;AAC3D;AAAA,MACF;AACA,WAAK,OAAO,KAAK,OAAO;AAAA,IAC1B;AACA,aAAS,KAAK,GAAG,EAAE;AAAA,EACrB;AACA,MAAI,SAAS,CAAC,GAAG,WAAW,MAAM;AAChC,eAAW,cAAc,UAAU,SAAS;A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D,QAAM,YAAY,cAAc,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,MAAM,CAAC;AAClE,MAAI,eAAe;AAEnB,MAAI,YAAY,gBAAgB,iBAAiB,SAAS,GAAG;AAC3D,UAAM,gBAAgB,eAAe;AAErC,UAAM,YAAY,gBAAgB,iBAAiB;AACnD,qBAAiB,QAAQ,CAAC,MAAM;AAC9B,oBAAc,KAAK;AAAA,QACjB,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACF;AAAA,IACR,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEA,SAAS,cAEP,OAAY,KAAoC;AAMhD,QAAM,gCAAgC,IAAA;AAEtC,aAAW,QAAQ,OAAO;AACxB,UAAM,KAAK,KAAK,GAAG;AACnB,QAAI,MAAM,KAAM;AAEhB,QAAI,UAAU,IAAI,EAAE,GAAG;AACrB,YAAM,WAAW,UAAU,IAAI,EAAE;AACjC,gBAAU,IAAI,IAAI;AAAA,QAChB,GAAG;AAAA,QACH,MAAM,SAAS,OAAO,KAAK;AAAA,MAAA,CAC5B;AAAA,IACH,OAAO;AACL,gBAAU,IAAI,IAAI,EAAE,GAAG,MAAM;AAAA,IAC/B;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,UAAU,OAAA,CAAQ;AACtC;;;;"}
|
package/dist/units/colors.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Environment, Lithology, UnitLithology, UnitLong } from '@macrostrat/api-types';
|
|
2
|
-
interface KeyOptions {
|
|
3
|
-
key?: "lith" | "environ";
|
|
4
|
-
id_key?: "lith_id" | "environ_id";
|
|
5
|
-
}
|
|
6
|
-
export declare function getMixedUnitColor(unit: UnitLong, lithMap: Map<number, {
|
|
7
|
-
color: string;
|
|
8
|
-
}>, inDarkMode?: boolean, asBackground?: boolean, keyOpts?: KeyOptions): string | null;
|
|
9
|
-
interface ColorBuilderOptions {
|
|
10
|
-
key?: "lith_id" | "environ_id";
|
|
11
|
-
inDarkMode?: boolean;
|
|
12
|
-
asBackground?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare function flattenLithologies<T extends {
|
|
15
|
-
prop: number | null;
|
|
16
|
-
lith_id?: number;
|
|
17
|
-
environ_id?: number;
|
|
18
|
-
}>(liths: T[][], normalize?: boolean): T[];
|
|
19
|
-
export declare function getMixedColorForData<T extends UnitLithology | Lithology | Environment>(liths: T[] | null, getColor: (val: T) => string | null, options?: ColorBuilderOptions): string | null;
|
|
20
|
-
export {};
|