@macrostrat/column-views 3.4.2 → 3.5.1
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 +25 -0
- package/dist/column-views.css +7 -7
- package/dist/column.cjs +21 -21
- package/dist/column.cjs.map +1 -1
- package/dist/column.d.ts +3 -1
- package/dist/column.js +4 -4
- package/dist/column.js.map +1 -1
- package/dist/data-provider/store.cjs +26 -3
- package/dist/data-provider/store.cjs.map +1 -1
- package/dist/data-provider/store.d.ts +52 -0
- package/dist/data-provider/store.js +27 -4
- package/dist/data-provider/store.js.map +1 -1
- package/dist/data-provider/unit-selection.cjs +10 -4
- package/dist/data-provider/unit-selection.cjs.map +1 -1
- package/dist/data-provider/unit-selection.d.ts +3 -0
- package/dist/data-provider/unit-selection.js +10 -4
- package/dist/data-provider/unit-selection.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -1
- package/dist/prepare-units/helpers.cjs +58 -36
- package/dist/prepare-units/helpers.cjs.map +1 -1
- package/dist/prepare-units/helpers.d.ts +13 -5
- package/dist/prepare-units/helpers.js +59 -37
- package/dist/prepare-units/helpers.js.map +1 -1
- package/dist/prepare-units/index.cjs +1 -0
- package/dist/prepare-units/index.cjs.map +1 -1
- package/dist/prepare-units/index.d.ts +2 -2
- package/dist/prepare-units/index.js +1 -0
- package/dist/prepare-units/index.js.map +1 -1
- package/dist/unit-details/panel.cjs +1 -1
- package/dist/unit-details/panel.cjs.map +1 -1
- package/dist/unit-details/panel.js +1 -1
- package/dist/unit-details/panel.js.map +1 -1
- package/dist/units/boxes.module.sass.cjs +3 -3
- package/dist/units/boxes.module.sass.js +3 -3
- package/dist/units/index.cjs +5 -5
- package/dist/units/index.cjs.map +1 -1
- package/dist/units/index.d.ts +2 -2
- package/dist/units/index.js +5 -5
- package/dist/units/index.js.map +1 -1
- package/package.json +4 -4
- package/src/column.ts +6 -4
- package/src/correlation-chart/stories/namibia-correlation.stories.ts +151 -0
- package/src/data-provider/store.ts +48 -4
- package/src/data-provider/unit-selection.ts +10 -5
- package/src/prepare-units/helpers.ts +98 -50
- package/src/prepare-units/index.ts +4 -1
- package/src/unit-details/panel.ts +1 -1
- package/src/units/boxes.module.sass +2 -2
- package/src/units/index.ts +7 -7
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { group } from "d3-array";
|
|
2
2
|
import { ColumnAxisType } from "@macrostrat/column-components";
|
|
3
3
|
import { ensureRealFloat, getUnitHeightRange, ensureArray, createUnitSorter, unitsOverlap } from "./utils.js";
|
|
4
|
-
import { compareAgeRanges, AgeRangeRelationship } from "@macrostrat/stratigraphy-utils";
|
|
4
|
+
import { compareAgeRanges, AgeRangeRelationship, mergeAgeRanges, MergeMode } from "@macrostrat/stratigraphy-utils";
|
|
5
5
|
const dt = 1e-3;
|
|
6
6
|
class UnitGroup {
|
|
7
7
|
units;
|
|
8
|
-
|
|
8
|
+
axisType;
|
|
9
|
+
constructor(units, axisType = ColumnAxisType.AGE) {
|
|
9
10
|
this.units = units;
|
|
11
|
+
this.axisType = axisType;
|
|
10
12
|
}
|
|
11
13
|
get t_age() {
|
|
12
14
|
return Math.min(...this.units.map((d) => d.t_age));
|
|
@@ -18,25 +20,28 @@ class UnitGroup {
|
|
|
18
20
|
return assignColumnsToUnitsWithinOverlappingGroup(this);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
function groupUnitsByMutualOverlap(units, tolerance = dt) {
|
|
22
|
-
const sections = groupUnitsIntoSectionsByOverlap(
|
|
23
|
-
|
|
24
|
-
ColumnAxisType.AGE,
|
|
25
|
-
tolerance
|
|
26
|
-
);
|
|
23
|
+
function groupUnitsByMutualOverlap(units, tolerance = dt, axisType = ColumnAxisType.AGE) {
|
|
24
|
+
const sections = groupUnitsIntoSectionsByOverlap(units, axisType, tolerance);
|
|
25
|
+
console.log("Grouped sections", sections);
|
|
27
26
|
return sections.map((d) => {
|
|
28
|
-
return new UnitGroup(d.units);
|
|
27
|
+
return new UnitGroup(d.units, axisType);
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
30
|
const sortByAge = createUnitSorter(ColumnAxisType.AGE);
|
|
32
31
|
function assignColumnsToUnitsWithinOverlappingGroup(group2) {
|
|
33
|
-
const sortedUnits = [...group2.units].sort((
|
|
32
|
+
const sortedUnits = [...group2.units].sort(createUnitSorter(group2.axisType));
|
|
34
33
|
const columns = [];
|
|
35
34
|
for (const unit of sortedUnits) {
|
|
35
|
+
const colHint = unit.layoutHints?.column;
|
|
36
|
+
if (colHint != null) {
|
|
37
|
+
columns[colHint] ??= [];
|
|
38
|
+
columns[colHint].push(unit);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
36
41
|
let didAddToExistingColumn = false;
|
|
37
42
|
for (const column of columns) {
|
|
38
43
|
const lastUnit = column[column.length - 1];
|
|
39
|
-
if (!unitsOverlap(unit, lastUnit,
|
|
44
|
+
if (!unitsOverlap(unit, lastUnit, group2.axisType, dt)) {
|
|
40
45
|
column.push(unit);
|
|
41
46
|
didAddToExistingColumn = true;
|
|
42
47
|
break;
|
|
@@ -46,13 +51,15 @@ function assignColumnsToUnitsWithinOverlappingGroup(group2) {
|
|
|
46
51
|
columns.push([unit]);
|
|
47
52
|
}
|
|
48
53
|
}
|
|
54
|
+
console.log(columns);
|
|
49
55
|
const units = columns.flatMap(
|
|
50
56
|
(column, columnIndex) => column.map((unit) => {
|
|
51
57
|
return {
|
|
52
58
|
...unit,
|
|
53
|
-
|
|
59
|
+
layout: {
|
|
54
60
|
column: columnIndex,
|
|
55
|
-
nColumns:
|
|
61
|
+
nColumns: 1,
|
|
62
|
+
totalColumns: columns.length,
|
|
56
63
|
unitGroup: group2
|
|
57
64
|
}
|
|
58
65
|
};
|
|
@@ -66,7 +73,7 @@ function preprocessUnits(section, axisType = ColumnAxisType.AGE) {
|
|
|
66
73
|
if (axisType != ColumnAxisType.AGE) {
|
|
67
74
|
tolerance = 0.01;
|
|
68
75
|
}
|
|
69
|
-
const unitGroups = groupUnitsByMutualOverlap(units, tolerance);
|
|
76
|
+
const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);
|
|
70
77
|
const divisions = [];
|
|
71
78
|
for (const group2 of unitGroups) {
|
|
72
79
|
divisions.push(...group2.getUnits());
|
|
@@ -109,33 +116,48 @@ function groupUnitsIntoSectionsBySectionID(units, axisType = ColumnAxisType.AGE)
|
|
|
109
116
|
return groups1;
|
|
110
117
|
}
|
|
111
118
|
function groupUnitsIntoSectionsByOverlap(units, axisType = ColumnAxisType.AGE, tolerance = dt) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
const initialSections = units.map((unit) => {
|
|
120
|
+
return {
|
|
121
|
+
units: [unit],
|
|
122
|
+
heightRange: getUnitHeightRange(unit, axisType)
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
const isOverlapping = (a, b) => {
|
|
126
|
+
const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);
|
|
127
|
+
return res !== AgeRangeRelationship.Disjoint;
|
|
128
|
+
};
|
|
129
|
+
const mergeSections = (a, b) => {
|
|
130
|
+
return {
|
|
131
|
+
units: [...a.units, ...b.units],
|
|
132
|
+
heightRange: mergeAgeRanges(
|
|
133
|
+
[a.heightRange, b.heightRange],
|
|
134
|
+
MergeMode.Outer
|
|
135
|
+
)
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
let finalSectionList = initialSections;
|
|
139
|
+
while (true) {
|
|
140
|
+
let merged = false;
|
|
141
|
+
const nextSections = [];
|
|
142
|
+
for (const section of finalSectionList) {
|
|
143
|
+
if (nextSections.length === 0) {
|
|
144
|
+
nextSections.push(section);
|
|
130
145
|
} else {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
146
|
+
const lastSection = nextSections[nextSections.length - 1];
|
|
147
|
+
if (isOverlapping(section, lastSection)) {
|
|
148
|
+
nextSections[nextSections.length - 1] = mergeSections(lastSection, section);
|
|
149
|
+
merged = true;
|
|
150
|
+
} else {
|
|
151
|
+
nextSections.push(section);
|
|
152
|
+
}
|
|
135
153
|
}
|
|
136
154
|
}
|
|
155
|
+
finalSectionList = nextSections;
|
|
156
|
+
if (!merged) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
137
159
|
}
|
|
138
|
-
return
|
|
160
|
+
return finalSectionList.map((section, i) => {
|
|
139
161
|
const [b_age, t_age] = getSectionAgeRange(section.units);
|
|
140
162
|
const [b_pos, t_pos] = getSectionPosRange(section.units, axisType);
|
|
141
163
|
return {
|
|
@@ -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} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\n\nexport type UnitWithDefinedOverlap<T extends BaseUnit> = T & {\n overlap: UnitOverlapInfo<T>;\n};\n\ntype UnitOverlapInfo<T extends BaseUnit> = {\n column: number;\n nColumns: number;\n unitGroup: UnitGroup<T>;\n};\n\nclass UnitGroup<T extends BaseUnit> implements StratigraphicPackage {\n units: T[];\n\n constructor(units: T[]) {\n this.units = units;\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(): UnitWithDefinedOverlap<T>[] {\n return assignColumnsToUnitsWithinOverlappingGroup(this);\n }\n}\n\nfunction groupUnitsByMutualOverlap<T extends BaseUnit>(\n units: T[],\n tolerance: number = dt,\n): UnitGroup<T>[] {\n /** Group units within a section that have mutual overlap. */\n const sections = groupUnitsIntoSectionsByOverlap(\n units,\n ColumnAxisType.AGE,\n tolerance,\n );\n return sections.map((d) => {\n return new UnitGroup(d.units);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<T>,\n): UnitWithDefinedOverlap<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((a, b) => b.b_age - a.b_age);\n\n const columns: T[][] = [];\n\n for (const unit of sortedUnits) {\n // Find a column that is not already occupied by an overlapping unit\n let didAddToExistingColumn = false;\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, ColumnAxisType.AGE, 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: UnitWithDefinedOverlap<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n overlap: {\n column: columnIndex,\n nColumns: 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);\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 for (const unit of units) {\n // Check if the unit overlaps with any existing section\n const heightRange = getUnitHeightRange(unit, axisType);\n let section: WorkingSection | undefined = sectionList.find(\n (s) =>\n compareAgeRanges(heightRange, s.heightRange, tolerance) !==\n AgeRangeRelationship.Disjoint,\n );\n if (section == null) {\n // No overlap, create a new section\n sectionList.push({\n heightRange,\n units: [unit],\n });\n } else {\n // Overlap, merge the unit into the section\n section.units.push(unit);\n // Update the height range\n if (axisType == ColumnAxisType.DEPTH || axisType == ColumnAxisType.AGE) {\n section.heightRange = [\n Math.max(section.heightRange[0], heightRange[0]),\n Math.min(section.heightRange[1], heightRange[1]),\n ];\n } else {\n section.heightRange = [\n Math.min(section.heightRange[0], heightRange[0]),\n Math.max(section.heightRange[1], heightRange[1]),\n ];\n }\n }\n }\n // We should have a section for each unit, now we can convert to SectionInfo\n // Ages have to be really actually ages, not heights\n\n return sectionList.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":";;;;AAgBA,MAAM,KAAK;AAYX,MAAM,UAA8D;AAAA,EAClE;AAAA,EAEA,YAAY,OAAY;AACtB,SAAK,QAAQ;AAAA,EACf;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,WAAwC;AACtC,WAAO,2CAA2C,IAAI;AAAA,EACxD;AACF;AAEA,SAAS,0BACP,OACA,YAAoB,IACJ;AAEhB,QAAM,WAAW;AAAA,IACf;AAAA,IACA,eAAe;AAAA,IACf;AAAA,EAAA;AAEF,SAAO,SAAS,IAAI,CAAC,MAAM;AACzB,WAAO,IAAI,UAAU,EAAE,KAAK;AAAA,EAC9B,CAAC;AACH;AAEA,MAAM,YAAY,iBAAiB,eAAe,GAAG;AAErD,SAAS,2CACPA,QAC6B;AAO7B,QAAM,cAAc,CAAC,GAAGA,OAAM,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAErE,QAAM,UAAiB,CAAA;AAEvB,aAAW,QAAQ,aAAa;AAE9B,QAAI,yBAAyB;AAC7B,eAAW,UAAU,SAAS;AAC5B,YAAM,WAAW,OAAO,OAAO,SAAS,CAAC;AACzC,UAAI,CAAC,aAAa,MAAM,UAAU,eAAe,KAAK,EAAE,GAAG;AACzD,eAAO,KAAK,IAAI;AAChB,iCAAyB;AACzB;AAAA,MACF;AAAA,IACF;AACA,QAAI,CAAC,wBAAwB;AAC3B,cAAQ,KAAK,CAAC,IAAI,CAAC;AAAA,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;AACrD;AAEO,SAAS,yBACd,UACkB;AAIlB,QAAM,CAAC,cAAc,GAAG,IAAI,IAAI;AAChC,QAAM,cAAc,CAAC,YAAY;AACjC,aAAW,WAAW,MAAM;AAC1B,UAAM,cAAc,YAAY,YAAY,SAAS,CAAC;AACtD,QACE,YAAY,QAAQ,QAAQ,SAC5B,YAAY,QAAQ,QAAQ,OAC5B;AAEA,kBAAY,KAAK,OAAO;AACxB;AAAA,IACF;AAGA,gBAAY,aAAa;AAAA,MACvB,GAAG,YAAY,YAAY,UAAU;AAAA,MACrC,GAAG,YAAY,QAAQ,UAAU;AAAA,IAAA;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,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 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;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;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/prepare-units/index.ts"],"sourcesContent":["import {\n getSectionAgeRange,\n getSectionPosRange,\n groupUnitsIntoSectionsByOverlap,\n groupUnitsIntoSectionsBySectionID,\n mergeOverlappingSections,\n preprocessSectionUnit,\n preprocessUnits,\n} from \"./helpers\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport { useMemo } from \"react\";\nimport { UnitLong } from \"@macrostrat/api-types\";\nimport {\n collapseUnconformitiesByPixelHeight,\n computeSectionHeights,\n finalizeSectionHeights,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport { preprocessUnits };\nexport type { CompositeColumnScale };\n\nexport function usePreparedColumnUnits(\n data: UnitLong[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** This function wraps and memoizes all preparation steps for converting\n * an array of units from the /units route to a form ready for usage.\n */\n return useMemo(() => {\n return prepareColumnUnits(data, options);\n }, [data, ...Object.values(options)]);\n}\n\nexport function prepareColumnUnits(\n units: UnitLong[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** Prepare units for rendering into Macrostrat columns */\n\n let { t_age, b_age, t_pos, b_pos } = options;\n\n const {\n mergeSections = MergeSectionsMode.OVERLAPPING,\n axisType,\n unconformityHeight,\n collapseSmallUnconformities = false,\n hybridScale,\n scale,\n } = options;\n\n let _totalHeight: number | null = null;\n\n if (scale != null) {\n // Set t_age and b_age based on scale domain if not already set\n const domain = scale.domain();\n if (axisType == ColumnAxisType.AGE) {\n if (t_age == null) t_age = Math.min(...domain);\n if (b_age == null) b_age = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_age) - scale(t_age));\n } else {\n if (t_pos == null) t_pos = Math.min(...domain);\n if (b_pos == null) b_pos = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_pos) - scale(t_pos));\n }\n }\n\n // Start by ensuring that ages and positions are numbers\n // also set up some values for eODP-style columns\n let units1 = units.map(preprocessSectionUnit);\n\n /** Prototype filtering to age range */\n units1 = units1.filter((d) => {\n // Filter units by t_age and b_age, inclusive\n if (axisType == ColumnAxisType.AGE) {\n return agesOverlap(d, { t_age, b_age });\n } else {\n return unitsOverlap(d, { t_pos, b_pos } as any, axisType);\n }\n });\n\n let mergeMode = mergeSections;\n // if (axisType != ColumnAxisType.AGE) {\n // // For non-age columns, we always merge sections.\n // // This is because the \"groupUnitsIntoSections\" function is not well-defined\n // // for non-age columns.\n // mergeMode = MergeSectionsMode.ALL;\n // }\n\n let sections0: SectionInfo<UnitLong>[];\n if (mergeMode == MergeSectionsMode.ALL) {\n // For the \"merge sections\" mode, we need to create a single section\n const [b_unit_pos, t_unit_pos] = getSectionPosRange(units1, axisType);\n const [b_unit_age, t_unit_age] = getSectionAgeRange(units1);\n sections0 = [\n {\n section_id: 0,\n /**\n * If ages limits are directly specified, use them to define the section bounds.\n * */\n t_pos: t_unit_pos,\n b_pos: b_unit_pos,\n t_age: t_unit_age,\n b_age: b_unit_age,\n units: units1,\n },\n ];\n } else if (axisType == ColumnAxisType.AGE) {\n sections0 = groupUnitsIntoSectionsBySectionID(units1, axisType);\n } else {\n sections0 = groupUnitsIntoSectionsByOverlap(units1, axisType);\n }\n\n // Limit sections to the range specified by t_age/b_age or t_pos/b_pos global options\n for (let section of sections0) {\n if (axisType == ColumnAxisType.AGE) {\n section.t_age = Math.max(section.t_age, t_age ?? -Infinity);\n section.b_age = Math.min(section.b_age, b_age ?? Infinity);\n } else if (axisType == ColumnAxisType.DEPTH) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n } else if (axisType == ColumnAxisType.HEIGHT) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n }\n }\n\n /** Merging overlapping sections really only makes sense for age/height/depth\n * columns. Ordinal columns are numbered by section so merging them\n * results in collisions.\n */\n let sections = sections0;\n if (\n mergeSections == MergeSectionsMode.OVERLAPPING &&\n axisType == ColumnAxisType.AGE\n ) {\n sections = mergeOverlappingSections(sections);\n }\n // Filter out undefined sections just in case\n sections = sections.filter((d) => d != null);\n\n // SCALES\n\n /* Compute pixel scales etc. for sections\n * We need to do this now to determine which unconformities\n * are small enough to collapse.\n */\n let sectionsWithScales = computeSectionHeights(sections, options);\n\n if (collapseSmallUnconformities && hybridScale == null) {\n // Collapse small unconformities in pixel height space\n // TODO: this doesn't seem to work properly for non-age columns?\n let threshold = unconformityHeight ?? 30;\n if (typeof collapseSmallUnconformities == \"number\") {\n threshold = collapseSmallUnconformities;\n }\n\n sectionsWithScales = collapseUnconformitiesByPixelHeight(\n sectionsWithScales,\n threshold,\n options,\n );\n }\n\n /** Prepare section scale information using groups.\n * Total height is computed from section scales.\n * */\n let { totalHeight, sections: sections2 } = finalizeSectionHeights(\n sectionsWithScales,\n unconformityHeight,\n );\n\n /** For each section, find units that are overlapping.\n * We do this after merging sections so that we can\n * handle cases where there are overlapping units across sections\n * */\n const sectionsOut = sections2.map((section) => {\n return {\n ...section,\n units: preprocessUnits(section, axisType),\n };\n });\n\n /** Reconstitute the units so that they are sorted by section and properly enhanced.\n * This is mostly important so that unit keyboard navigation\n * predictably selects adjacent units.\n */\n const units2 = sectionsOut.reduce((acc, group) => {\n const { units } = group;\n for (const unit of units) {\n acc.push(unit);\n }\n return acc;\n }, []);\n\n return {\n units: units2,\n totalHeight: _totalHeight ?? totalHeight,\n sections: sectionsOut,\n };\n}\n"],"names":["useMemo","MergeSectionsMode","ColumnAxisType","preprocessSectionUnit","agesOverlap","unitsOverlap","getSectionPosRange","getSectionAgeRange","groupUnitsIntoSectionsBySectionID","groupUnitsIntoSectionsByOverlap","mergeOverlappingSections","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AAO,CAAC,MAAM,KAAK,IAAI;AAQ3C,MAAI,qBAAqBC,eAAAA,sBAAsB,UAAU,OAAO;AAEhE,MAAI,+BAA+B,eAAe,MAAM;AAGtD,QAAI,YAAY,sBAAsB;AACtC,QAAI,OAAO,+BAA+B,UAAU;AAClD,kBAAY;AAAA,IACd;AAEA,yBAAqBC,eAAAA;AAAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAKA,MAAI,EAAE,aAAa,UAAU,UAAA,IAAcC,eAAAA;AAAAA,IACzC;AAAA,IACA;AAAA,EAAA;AAOF,QAAM,cAAc,UAAU,IAAI,CAAC,YAAY;AAC7C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAOC,QAAAA,gBAAgB,SAAS,QAAQ;AAAA,IAAA;AAAA,EAE5C,CAAC;AAMD,QAAM,SAAS,YAAY,OAAO,CAAC,KAAK,UAAU;AAChD,UAAM,EAAE,OAAAC,OAAAA,IAAU;AAClB,eAAW,QAAQA,QAAO;AACxB,UAAI,KAAK,IAAI;AAAA,IACf;AACA,WAAO;AAAA,EACT,GAAG,CAAA,CAAE;AAEL,SAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,gBAAgB;AAAA,IAC7B,UAAU;AAAA,EAAA;AAEd;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/prepare-units/index.ts"],"sourcesContent":["import {\n getSectionAgeRange,\n getSectionPosRange,\n groupUnitsIntoSectionsByOverlap,\n groupUnitsIntoSectionsBySectionID,\n mergeOverlappingSections,\n preprocessSectionUnit,\n preprocessUnits,\n UnitWithLayoutHints,\n} from \"./helpers\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport { useMemo } from \"react\";\nimport { UnitLong } from \"@macrostrat/api-types\";\nimport {\n collapseUnconformitiesByPixelHeight,\n computeSectionHeights,\n finalizeSectionHeights,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport { preprocessUnits };\nexport type { CompositeColumnScale };\n\nexport function usePreparedColumnUnits(\n data: UnitLong[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** This function wraps and memoizes all preparation steps for converting\n * an array of units from the /units route to a form ready for usage.\n */\n return useMemo(() => {\n return prepareColumnUnits(data, options);\n }, [data, ...Object.values(options)]);\n}\n\nexport function prepareColumnUnits(\n units: UnitWithLayoutHints<UnitLong>[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** Prepare units for rendering into Macrostrat columns */\n\n let { t_age, b_age, t_pos, b_pos } = options;\n\n const {\n mergeSections = MergeSectionsMode.OVERLAPPING,\n axisType,\n unconformityHeight,\n collapseSmallUnconformities = false,\n hybridScale,\n scale,\n } = options;\n\n let _totalHeight: number | null = null;\n\n if (scale != null) {\n // Set t_age and b_age based on scale domain if not already set\n const domain = scale.domain();\n if (axisType == ColumnAxisType.AGE) {\n if (t_age == null) t_age = Math.min(...domain);\n if (b_age == null) b_age = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_age) - scale(t_age));\n } else {\n if (t_pos == null) t_pos = Math.min(...domain);\n if (b_pos == null) b_pos = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_pos) - scale(t_pos));\n }\n }\n\n // Start by ensuring that ages and positions are numbers\n // also set up some values for eODP-style columns\n let units1 = units.map(preprocessSectionUnit);\n\n /** Prototype filtering to age range */\n units1 = units1.filter((d) => {\n // Filter units by t_age and b_age, inclusive\n if (axisType == ColumnAxisType.AGE) {\n return agesOverlap(d, { t_age, b_age });\n } else {\n return unitsOverlap(d, { t_pos, b_pos } as any, axisType);\n }\n });\n\n let mergeMode = mergeSections;\n // if (axisType != ColumnAxisType.AGE) {\n // // For non-age columns, we always merge sections.\n // // This is because the \"groupUnitsIntoSections\" function is not well-defined\n // // for non-age columns.\n // mergeMode = MergeSectionsMode.ALL;\n // }\n\n let sections0: SectionInfo<UnitLong>[];\n if (mergeMode == MergeSectionsMode.ALL) {\n // For the \"merge sections\" mode, we need to create a single section\n const [b_unit_pos, t_unit_pos] = getSectionPosRange(units1, axisType);\n const [b_unit_age, t_unit_age] = getSectionAgeRange(units1);\n sections0 = [\n {\n section_id: 0,\n /**\n * If ages limits are directly specified, use them to define the section bounds.\n * */\n t_pos: t_unit_pos,\n b_pos: b_unit_pos,\n t_age: t_unit_age,\n b_age: b_unit_age,\n units: units1,\n },\n ];\n } else if (axisType == ColumnAxisType.AGE) {\n sections0 = groupUnitsIntoSectionsBySectionID(units1, axisType);\n } else {\n sections0 = groupUnitsIntoSectionsByOverlap(units1, axisType);\n }\n\n // Limit sections to the range specified by t_age/b_age or t_pos/b_pos global options\n for (let section of sections0) {\n if (axisType == ColumnAxisType.AGE) {\n section.t_age = Math.max(section.t_age, t_age ?? -Infinity);\n section.b_age = Math.min(section.b_age, b_age ?? Infinity);\n } else if (axisType == ColumnAxisType.DEPTH) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n } else if (axisType == ColumnAxisType.HEIGHT) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n }\n }\n\n /** Merging overlapping sections really only makes sense for age/height/depth\n * columns. Ordinal columns are numbered by section so merging them\n * results in collisions.\n */\n let sections = sections0;\n if (\n mergeSections == MergeSectionsMode.OVERLAPPING &&\n axisType == ColumnAxisType.AGE\n ) {\n sections = mergeOverlappingSections(sections);\n }\n // Filter out undefined sections just in case\n sections = sections.filter((d) => d != null);\n\n // SCALES\n\n /* Compute pixel scales etc. for sections\n * We need to do this now to determine which unconformities\n * are small enough to collapse.\n */\n let sectionsWithScales = computeSectionHeights(sections, options);\n\n if (collapseSmallUnconformities && hybridScale == null) {\n // Collapse small unconformities in pixel height space\n // TODO: this doesn't seem to work properly for non-age columns?\n let threshold = unconformityHeight ?? 30;\n if (typeof collapseSmallUnconformities == \"number\") {\n threshold = collapseSmallUnconformities;\n }\n\n sectionsWithScales = collapseUnconformitiesByPixelHeight(\n sectionsWithScales,\n threshold,\n options,\n );\n }\n\n /** Prepare section scale information using groups.\n * Total height is computed from section scales.\n * */\n let { totalHeight, sections: sections2 } = finalizeSectionHeights(\n sectionsWithScales,\n unconformityHeight,\n );\n\n /** For each section, find units that are overlapping.\n * We do this after merging sections so that we can\n * handle cases where there are overlapping units across sections\n * */\n console.log(sections2, \"sections\");\n\n const sectionsOut = sections2.map((section) => {\n return {\n ...section,\n units: preprocessUnits(section, axisType),\n };\n });\n\n /** Reconstitute the units so that they are sorted by section and properly enhanced.\n * This is mostly important so that unit keyboard navigation\n * predictably selects adjacent units.\n */\n const units2 = sectionsOut.reduce((acc, group) => {\n const { units } = group;\n for (const unit of units) {\n acc.push(unit);\n }\n return acc;\n }, []);\n\n return {\n units: units2,\n totalHeight: _totalHeight ?? totalHeight,\n sections: sectionsOut,\n };\n}\n"],"names":["useMemo","MergeSectionsMode","ColumnAxisType","preprocessSectionUnit","agesOverlap","unitsOverlap","getSectionPosRange","getSectionAgeRange","groupUnitsIntoSectionsBySectionID","groupUnitsIntoSectionsByOverlap","mergeOverlappingSections","computeSectionHeights","collapseUnconformitiesByPixelHeight","finalizeSectionHeights","preprocessUnits","units"],"mappings":";;;;;;;AAiCO,SAAS,uBACd,MACA,SACoB;AAIpB,SAAOA,MAAAA,QAAQ,MAAM;AACnB,WAAO,mBAAmB,MAAM,OAAO;AAAA,EACzC,GAAG,CAAC,MAAM,GAAG,OAAO,OAAO,OAAO,CAAC,CAAC;AACtC;AAEO,SAAS,mBACd,OACA,SACoB;AAGpB,MAAI,EAAE,OAAO,OAAO,OAAO,UAAU;AAErC,QAAM;AAAA,IACJ,gBAAgBC,MAAAA,kBAAkB;AAAA,IAClC;AAAA,IACA;AAA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W,UAAU;AAEjC,QAAM,cAAc,UAAU,IAAI,CAAC,YAAY;AAC7C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAOC,QAAAA,gBAAgB,SAAS,QAAQ;AAAA,IAAA;AAAA,EAE5C,CAAC;AAMD,QAAM,SAAS,YAAY,OAAO,CAAC,KAAK,UAAU;AAChD,UAAM,EAAE,OAAAC,OAAAA,IAAU;AAClB,eAAW,QAAQA,QAAO;AACxB,UAAI,KAAK,IAAI;AAAA,IACf;AACA,WAAO;AAAA,EACT,GAAG,CAAA,CAAE;AAEL,SAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,gBAAgB;AAAA,IAC7B,UAAU;AAAA,EAAA;AAEd;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { preprocessUnits } from './helpers';
|
|
1
|
+
import { preprocessUnits, UnitWithLayoutHints } from './helpers';
|
|
2
2
|
import { UnitLong } from '@macrostrat/api-types';
|
|
3
3
|
import { CompositeColumnScale } from './composite-scale';
|
|
4
4
|
import { PrepareColumnOptions, PreparedColumnData } from './utils';
|
|
@@ -7,4 +7,4 @@ export * from './types';
|
|
|
7
7
|
export { preprocessUnits };
|
|
8
8
|
export type { CompositeColumnScale };
|
|
9
9
|
export declare function usePreparedColumnUnits(data: UnitLong[], options: PrepareColumnOptions): PreparedColumnData;
|
|
10
|
-
export declare function prepareColumnUnits(units: UnitLong[], options: PrepareColumnOptions): PreparedColumnData;
|
|
10
|
+
export declare function prepareColumnUnits(units: UnitWithLayoutHints<UnitLong>[], options: PrepareColumnOptions): PreparedColumnData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/prepare-units/index.ts"],"sourcesContent":["import {\n getSectionAgeRange,\n getSectionPosRange,\n groupUnitsIntoSectionsByOverlap,\n groupUnitsIntoSectionsBySectionID,\n mergeOverlappingSections,\n preprocessSectionUnit,\n preprocessUnits,\n} from \"./helpers\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport { useMemo } from \"react\";\nimport { UnitLong } from \"@macrostrat/api-types\";\nimport {\n collapseUnconformitiesByPixelHeight,\n computeSectionHeights,\n finalizeSectionHeights,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport { preprocessUnits };\nexport type { CompositeColumnScale };\n\nexport function usePreparedColumnUnits(\n data: UnitLong[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** This function wraps and memoizes all preparation steps for converting\n * an array of units from the /units route to a form ready for usage.\n */\n return useMemo(() => {\n return prepareColumnUnits(data, options);\n }, [data, ...Object.values(options)]);\n}\n\nexport function prepareColumnUnits(\n units: UnitLong[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** Prepare units for rendering into Macrostrat columns */\n\n let { t_age, b_age, t_pos, b_pos } = options;\n\n const {\n mergeSections = MergeSectionsMode.OVERLAPPING,\n axisType,\n unconformityHeight,\n collapseSmallUnconformities = false,\n hybridScale,\n scale,\n } = options;\n\n let _totalHeight: number | null = null;\n\n if (scale != null) {\n // Set t_age and b_age based on scale domain if not already set\n const domain = scale.domain();\n if (axisType == ColumnAxisType.AGE) {\n if (t_age == null) t_age = Math.min(...domain);\n if (b_age == null) b_age = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_age) - scale(t_age));\n } else {\n if (t_pos == null) t_pos = Math.min(...domain);\n if (b_pos == null) b_pos = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_pos) - scale(t_pos));\n }\n }\n\n // Start by ensuring that ages and positions are numbers\n // also set up some values for eODP-style columns\n let units1 = units.map(preprocessSectionUnit);\n\n /** Prototype filtering to age range */\n units1 = units1.filter((d) => {\n // Filter units by t_age and b_age, inclusive\n if (axisType == ColumnAxisType.AGE) {\n return agesOverlap(d, { t_age, b_age });\n } else {\n return unitsOverlap(d, { t_pos, b_pos } as any, axisType);\n }\n });\n\n let mergeMode = mergeSections;\n // if (axisType != ColumnAxisType.AGE) {\n // // For non-age columns, we always merge sections.\n // // This is because the \"groupUnitsIntoSections\" function is not well-defined\n // // for non-age columns.\n // mergeMode = MergeSectionsMode.ALL;\n // }\n\n let sections0: SectionInfo<UnitLong>[];\n if (mergeMode == MergeSectionsMode.ALL) {\n // For the \"merge sections\" mode, we need to create a single section\n const [b_unit_pos, t_unit_pos] = getSectionPosRange(units1, axisType);\n const [b_unit_age, t_unit_age] = getSectionAgeRange(units1);\n sections0 = [\n {\n section_id: 0,\n /**\n * If ages limits are directly specified, use them to define the section bounds.\n * */\n t_pos: t_unit_pos,\n b_pos: b_unit_pos,\n t_age: t_unit_age,\n b_age: b_unit_age,\n units: units1,\n },\n ];\n } else if (axisType == ColumnAxisType.AGE) {\n sections0 = groupUnitsIntoSectionsBySectionID(units1, axisType);\n } else {\n sections0 = groupUnitsIntoSectionsByOverlap(units1, axisType);\n }\n\n // Limit sections to the range specified by t_age/b_age or t_pos/b_pos global options\n for (let section of sections0) {\n if (axisType == ColumnAxisType.AGE) {\n section.t_age = Math.max(section.t_age, t_age ?? -Infinity);\n section.b_age = Math.min(section.b_age, b_age ?? Infinity);\n } else if (axisType == ColumnAxisType.DEPTH) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n } else if (axisType == ColumnAxisType.HEIGHT) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n }\n }\n\n /** Merging overlapping sections really only makes sense for age/height/depth\n * columns. Ordinal columns are numbered by section so merging them\n * results in collisions.\n */\n let sections = sections0;\n if (\n mergeSections == MergeSectionsMode.OVERLAPPING &&\n axisType == ColumnAxisType.AGE\n ) {\n sections = mergeOverlappingSections(sections);\n }\n // Filter out undefined sections just in case\n sections = sections.filter((d) => d != null);\n\n // SCALES\n\n /* Compute pixel scales etc. for sections\n * We need to do this now to determine which unconformities\n * are small enough to collapse.\n */\n let sectionsWithScales = computeSectionHeights(sections, options);\n\n if (collapseSmallUnconformities && hybridScale == null) {\n // Collapse small unconformities in pixel height space\n // TODO: this doesn't seem to work properly for non-age columns?\n let threshold = unconformityHeight ?? 30;\n if (typeof collapseSmallUnconformities == \"number\") {\n threshold = collapseSmallUnconformities;\n }\n\n sectionsWithScales = collapseUnconformitiesByPixelHeight(\n sectionsWithScales,\n threshold,\n options,\n );\n }\n\n /** Prepare section scale information using groups.\n * Total height is computed from section scales.\n * */\n let { totalHeight, sections: sections2 } = finalizeSectionHeights(\n sectionsWithScales,\n unconformityHeight,\n );\n\n /** For each section, find units that are overlapping.\n * We do this after merging sections so that we can\n * handle cases where there are overlapping units across sections\n * */\n const sectionsOut = sections2.map((section) => {\n return {\n ...section,\n units: preprocessUnits(section, axisType),\n };\n });\n\n /** Reconstitute the units so that they are sorted by section and properly enhanced.\n * This is mostly important so that unit keyboard navigation\n * predictably selects adjacent units.\n */\n const units2 = sectionsOut.reduce((acc, group) => {\n const { units } = group;\n for (const unit of units) {\n acc.push(unit);\n }\n return acc;\n }, []);\n\n return {\n units: units2,\n totalHeight: _totalHeight ?? totalHeight,\n sections: sectionsOut,\n };\n}\n"],"names":["units"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/prepare-units/index.ts"],"sourcesContent":["import {\n getSectionAgeRange,\n getSectionPosRange,\n groupUnitsIntoSectionsByOverlap,\n groupUnitsIntoSectionsBySectionID,\n mergeOverlappingSections,\n preprocessSectionUnit,\n preprocessUnits,\n UnitWithLayoutHints,\n} from \"./helpers\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport { useMemo } from \"react\";\nimport { UnitLong } from \"@macrostrat/api-types\";\nimport {\n collapseUnconformitiesByPixelHeight,\n computeSectionHeights,\n finalizeSectionHeights,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport { preprocessUnits };\nexport type { CompositeColumnScale };\n\nexport function usePreparedColumnUnits(\n data: UnitLong[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** This function wraps and memoizes all preparation steps for converting\n * an array of units from the /units route to a form ready for usage.\n */\n return useMemo(() => {\n return prepareColumnUnits(data, options);\n }, [data, ...Object.values(options)]);\n}\n\nexport function prepareColumnUnits(\n units: UnitWithLayoutHints<UnitLong>[],\n options: PrepareColumnOptions,\n): PreparedColumnData {\n /** Prepare units for rendering into Macrostrat columns */\n\n let { t_age, b_age, t_pos, b_pos } = options;\n\n const {\n mergeSections = MergeSectionsMode.OVERLAPPING,\n axisType,\n unconformityHeight,\n collapseSmallUnconformities = false,\n hybridScale,\n scale,\n } = options;\n\n let _totalHeight: number | null = null;\n\n if (scale != null) {\n // Set t_age and b_age based on scale domain if not already set\n const domain = scale.domain();\n if (axisType == ColumnAxisType.AGE) {\n if (t_age == null) t_age = Math.min(...domain);\n if (b_age == null) b_age = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_age) - scale(t_age));\n } else {\n if (t_pos == null) t_pos = Math.min(...domain);\n if (b_pos == null) b_pos = Math.max(...domain);\n _totalHeight = Math.abs(scale(b_pos) - scale(t_pos));\n }\n }\n\n // Start by ensuring that ages and positions are numbers\n // also set up some values for eODP-style columns\n let units1 = units.map(preprocessSectionUnit);\n\n /** Prototype filtering to age range */\n units1 = units1.filter((d) => {\n // Filter units by t_age and b_age, inclusive\n if (axisType == ColumnAxisType.AGE) {\n return agesOverlap(d, { t_age, b_age });\n } else {\n return unitsOverlap(d, { t_pos, b_pos } as any, axisType);\n }\n });\n\n let mergeMode = mergeSections;\n // if (axisType != ColumnAxisType.AGE) {\n // // For non-age columns, we always merge sections.\n // // This is because the \"groupUnitsIntoSections\" function is not well-defined\n // // for non-age columns.\n // mergeMode = MergeSectionsMode.ALL;\n // }\n\n let sections0: SectionInfo<UnitLong>[];\n if (mergeMode == MergeSectionsMode.ALL) {\n // For the \"merge sections\" mode, we need to create a single section\n const [b_unit_pos, t_unit_pos] = getSectionPosRange(units1, axisType);\n const [b_unit_age, t_unit_age] = getSectionAgeRange(units1);\n sections0 = [\n {\n section_id: 0,\n /**\n * If ages limits are directly specified, use them to define the section bounds.\n * */\n t_pos: t_unit_pos,\n b_pos: b_unit_pos,\n t_age: t_unit_age,\n b_age: b_unit_age,\n units: units1,\n },\n ];\n } else if (axisType == ColumnAxisType.AGE) {\n sections0 = groupUnitsIntoSectionsBySectionID(units1, axisType);\n } else {\n sections0 = groupUnitsIntoSectionsByOverlap(units1, axisType);\n }\n\n // Limit sections to the range specified by t_age/b_age or t_pos/b_pos global options\n for (let section of sections0) {\n if (axisType == ColumnAxisType.AGE) {\n section.t_age = Math.max(section.t_age, t_age ?? -Infinity);\n section.b_age = Math.min(section.b_age, b_age ?? Infinity);\n } else if (axisType == ColumnAxisType.DEPTH) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n } else if (axisType == ColumnAxisType.HEIGHT) {\n section.t_pos = Math.max(section.t_pos, t_pos ?? -Infinity);\n section.b_pos = Math.min(section.b_pos, b_pos ?? Infinity);\n }\n }\n\n /** Merging overlapping sections really only makes sense for age/height/depth\n * columns. Ordinal columns are numbered by section so merging them\n * results in collisions.\n */\n let sections = sections0;\n if (\n mergeSections == MergeSectionsMode.OVERLAPPING &&\n axisType == ColumnAxisType.AGE\n ) {\n sections = mergeOverlappingSections(sections);\n }\n // Filter out undefined sections just in case\n sections = sections.filter((d) => d != null);\n\n // SCALES\n\n /* Compute pixel scales etc. for sections\n * We need to do this now to determine which unconformities\n * are small enough to collapse.\n */\n let sectionsWithScales = computeSectionHeights(sections, options);\n\n if (collapseSmallUnconformities && hybridScale == null) {\n // Collapse small unconformities in pixel height space\n // TODO: this doesn't seem to work properly for non-age columns?\n let threshold = unconformityHeight ?? 30;\n if (typeof collapseSmallUnconformities == \"number\") {\n threshold = collapseSmallUnconformities;\n }\n\n sectionsWithScales = collapseUnconformitiesByPixelHeight(\n sectionsWithScales,\n threshold,\n options,\n );\n }\n\n /** Prepare section scale information using groups.\n * Total height is computed from section scales.\n * */\n let { totalHeight, sections: sections2 } = finalizeSectionHeights(\n sectionsWithScales,\n unconformityHeight,\n );\n\n /** For each section, find units that are overlapping.\n * We do this after merging sections so that we can\n * handle cases where there are overlapping units across sections\n * */\n console.log(sections2, \"sections\");\n\n const sectionsOut = sections2.map((section) => {\n return {\n ...section,\n units: preprocessUnits(section, axisType),\n };\n });\n\n /** Reconstitute the units so that they are sorted by section and properly enhanced.\n * This is mostly important so that unit keyboard navigation\n * predictably selects adjacent units.\n */\n const units2 = sectionsOut.reduce((acc, group) => {\n const { units } = group;\n for (const unit of units) {\n acc.push(unit);\n }\n return acc;\n }, []);\n\n return {\n units: units2,\n totalHeight: _totalHeight ?? totalHeight,\n sections: sectionsOut,\n };\n}\n"],"names":["units"],"mappings":";;;;;;AAiCO,SAAS,uBACd,MACA,SACoB;AAIpB,SAAO,QAAQ,MAAM;AACnB,WAAO,mBAAmB,MAAM,OAAO;AAAA,EACzC,GAAG,CAAC,MAAM,GAAG,OAAO,OAAO,OAAO,CAAC,CAAC;AACtC;AAEO,SAAS,mBACd,OACA,SACoB;AAGpB,MAAI,EAAE,OAAO,OAAO,OAAO,UAAU;AAErC,QAAM;AAAA,IACJ,gBAAgB,kBAAkB;AAAA,IAClC;AAAA,IACA;AAAA,IACA,8BAA8B;AAAA,IAC9B;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,MAAI,eAA8B;AAElC,MAAI,SAAS,MAAM;AAEjB,UAAM,SAAS,MAAM,OAAA;AACrB,QAAI,YAAY,eAAe,KAAK;AAClC,UA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AAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,gBAAgB;AAAA,IAC7B,UAAU;AAAA,EAAA;AAEd;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel.cjs","sources":["../../src/unit-details/panel.ts"],"sourcesContent":["import { JSONView } from \"@macrostrat/ui-components\";\nimport { Button, ButtonGroup } from \"@blueprintjs/core\";\nimport { ReactNode, useMemo, useState } from \"react\";\nimport {\n DataField,\n EnvironmentsList,\n ItemList,\n LithologyList,\n LithologyTagFeature,\n MacrostratInteractionManager,\n MacrostratInteractionProvider,\n MacrostratItemIdentifier,\n Parenthetical,\n useInteractionManager,\n Value,\n} from \"@macrostrat/data-components\";\nimport { useColumnUnitsMap } from \"../data-provider\";\nimport {\n useMacrostratColumnInfo,\n useMacrostratData,\n useMacrostratDefs,\n} from \"@macrostrat/data-provider\";\nimport type {\n Environment,\n EnvironmentIdentifier,\n Interval,\n Lithology,\n UnitLong,\n UnitLongFull,\n} from \"@macrostrat/api-types\";\nimport { defaultNameFunction } from \"../units/names\";\nimport classNames from \"classnames\";\nimport { AgeField, Duration, IntervalProportions } from \"./age-range\";\nimport { formatRange, formatSignificance } from \"./utils.ts\";\nimport h from \"./panel.module.sass\";\nimport { StratNameField } from \"./strat-names.ts\";\nimport { Identifier, UnitIdentifier, UnitInfo } from \"./identifiers.ts\";\nimport { LithologyIdentifier } from \"@macrostrat/api-types/src/lithologies\";\n\nexport interface UnitDetailsPanelProps {\n unit: any;\n onClose?: any;\n className?: string;\n actions?: ReactNode;\n hiddenActions?: ReactNode;\n features?: Set<UnitDetailsFeature>;\n lithologyFeatures?: Set<LithologyTagFeature>;\n onSelectUnit?: (unitID: number) => void;\n onClickItem?: MacrostratItemClickHandler;\n interactionManager?: MacrostratInteractionManager;\n showJSON?: boolean;\n}\n\nexport function UnitDetailsPanel({\n unit,\n onClose,\n className,\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n UnitDetailsFeature.JSONToggle,\n UnitDetailsFeature.DepthRange,\n ]),\n lithologyFeatures,\n actions,\n hiddenActions = null,\n onSelectUnit,\n onClickItem,\n showJSON,\n}: UnitDetailsPanelProps) {\n const [_showJSON, setShowJSON] = useState(false);\n\n let content: ReactNode = null;\n if (showJSON ?? _showJSON) {\n content = h(JSONView, { data: unit, showRoot: false });\n } else {\n content = h(UnitDetailsContent, {\n unit,\n features,\n lithologyFeatures,\n onClickItem,\n });\n }\n\n let title = defaultNameFunction(unit);\n\n if (features.has(UnitDetailsFeature.JSONToggle)) {\n hiddenActions = h([\n h(Button, {\n icon: \"code\",\n small: true,\n minimal: true,\n key: \"json-view-toggle\",\n className: classNames(\"json-view-toggle\", { enabled: setShowJSON }),\n onClick(evt) {\n setShowJSON(!showJSON);\n evt.stopPropagation();\n },\n }),\n hiddenActions,\n ]);\n }\n\n const main = h(\"div.unit-details-panel\", { className }, [\n h(LegendPanelHeader, {\n onClose,\n title,\n id: unit.unit_id,\n actions,\n hiddenActions,\n }),\n h(\"div.unit-details-content-holder\", content),\n ]);\n\n /** Handle unit selection clicks */\n const clickHandlerForItem = useMemo(() => {\n if (onSelectUnit == null && onClickItem == null) return null;\n return (item: MacrostratItemIdentifier) => {\n if (\"unit_id\" in item && !(\"col_id\" in item)) {\n // We are selecting a unit within the column\n return (event: MouseEvent) => {\n if (onSelectUnit != null) {\n onSelectUnit(item.unit_id);\n } else if (onClickItem != null) {\n console.warn(\n \"Unit selection: onClickItem is defined but onSelectUnit is not; ignoring click\",\n );\n }\n // Don't allow event to propagate further (e.g., to open a link)\n event.preventDefault();\n };\n }\n return undefined;\n };\n }, [onSelectUnit, onClickItem]);\n\n if (clickHandlerForItem != null) {\n // We wrap this in a MacrostratInteractionManager to handle unit selection\n return h(\n MacrostratInteractionProvider,\n {\n clickHandlerForItem,\n inherit: true,\n },\n main,\n );\n }\n\n return main;\n}\n\nexport function LegendPanelHeader({\n title,\n id,\n onClose,\n actions = null,\n hiddenActions,\n}: {\n title?: string | null;\n id?: number | null;\n onClose?: () => void;\n actions?: ReactNode | null;\n hiddenActions?: ReactNode | null;\n}) {\n return h(\"header.legend-panel-header\", [\n h(\"div.title-container\", [\n h.if(title != null)(\"h3\", title),\n h.if(hiddenActions != null)(\n \"span.hidden-actions-container\",\n h(\"div.hidden-actions\", hiddenActions),\n ),\n ]),\n h(\"div.spacer\"),\n h.if(id != null)(\"code.unit-id\", id),\n h.if(actions != null)(ButtonGroup, { minimal: true }, actions),\n h.if(onClose != null)(Button, {\n icon: \"cross\",\n minimal: true,\n small: true,\n onClick() {\n onClose?.();\n },\n }),\n ]);\n}\n\nexport enum UnitDetailsFeature {\n AdjacentUnits = \"adjacent-units\",\n Color = \"color\",\n OutcropType = \"outcrop-type\",\n JSONToggle = \"json-toggle\",\n DepthRange = \"depth-range\",\n ColumnName = \"column-name\",\n}\n\nexport type MacrostratItemClickHandler = (\n event: MouseEvent,\n item:\n | Lithology\n | Environment\n | UnitLong\n | Interval\n | { strat_name_id: number },\n) => void;\n\nfunction UnitDetailsContent({\n unit,\n lithologyFeatures = new Set([\n LithologyTagFeature.Proportion,\n LithologyTagFeature.Attributes,\n ]),\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n ]),\n onClickItem,\n getItemHref,\n}: {\n unit: UnitLong;\n lithologyFeatures?: Set<LithologyTagFeature>;\n features?: Set<UnitDetailsFeature>;\n onClickItem?: MacrostratItemClickHandler;\n getItemHref?: (item: Lithology | Environment | UnitLong) => string | null;\n}) {\n const lithMap = useMacrostratDefs(\"lithologies\");\n const envMap = useMacrostratDefs(\"environments\");\n\n const environments = enhanceEnvironments(unit.environ, envMap);\n const lithologies = enhanceLithologies(unit.lith ?? [], lithMap);\n\n let outcropField: ReactNode = null;\n if (features.has(UnitDetailsFeature.OutcropType)) {\n // Determine outcrop type\n let outcrop = unit.outcrop;\n if (outcrop == \"both\") {\n outcrop = \"surface and subsurface\";\n }\n outcropField = h(DataField, {\n label: \"Outcrop\",\n value: outcrop,\n });\n }\n\n let thicknessOrHeightRange: ReactNode = null;\n const [thickness, thicknessUnit] = getThickness(unit);\n // Proxy for actual heights in t_pos and b_pos\n if (\n features.has(UnitDetailsFeature.DepthRange) &&\n unit.t_pos != null &&\n unit.b_pos != null &&\n unit.min_thick == unit.max_thick && // We have an actual fixed height\n unit.min_thick != 0 // Not a zero thickness\n ) {\n const label = unit.t_pos < unit.b_pos ? \"Depth\" : \"Height\";\n const u1 = \"m\";\n\n thicknessOrHeightRange = h(DataField, {\n unit: u1,\n label,\n value: formatRange(unit.b_pos, unit.t_pos),\n children: h(\n Parenthetical,\n h(Value, { value: thickness, unit: thicknessUnit }),\n ),\n });\n }\n thicknessOrHeightRange ??= h(DataField, {\n label: \"Thickness\",\n value: thickness,\n unit: thicknessUnit,\n });\n\n /** We are trying to move away from passing the \"color\" parameter in the API */\n let colorSwatch: ReactNode = null;\n if (\"color\" in unit && features.has(UnitDetailsFeature.Color)) {\n const unit1 = unit as UnitLongFull;\n colorSwatch = h(\"div.color-swatch\", {\n style: { backgroundColor: unit1.color },\n });\n }\n\n return h(\"div.unit-details-content\", [\n h.if(features.has(UnitDetailsFeature.ColumnName))(ColumnNameField, {\n col_id: unit.col_id,\n }),\n thicknessOrHeightRange,\n h.if(lithologies != null)(LithologyList, {\n label: \"Lithology\",\n lithologies: lithologies ?? [],\n features: lithologyFeatures,\n }),\n h(AgeField, { unit }, [\n h(Parenthetical, h(Duration, { value: unit.b_age - unit.t_age })),\n h(IntervalProportions, {\n unit,\n onClickItem,\n }),\n ]),\n h.if(environments != null)(EnvironmentsList, {\n environments,\n }),\n h.if(unit.strat_name_id != null)(StratNameField, {\n strat_name_id: unit.strat_name_id,\n }),\n outcropField,\n h.if(features.has(UnitDetailsFeature.AdjacentUnits))([\n h.if(unit.units_above != null)(\n DataField,\n { label: \"Above\" },\n h(UnitIDList, {\n units: unit.units_above,\n showNames: true,\n }),\n ),\n h.if(unit.units_below != null)(\n DataField,\n { label: \"Below\" },\n h(UnitIDList, {\n units: unit.units_below,\n showNames: true,\n }),\n ),\n ]),\n colorSwatch,\n h(ReferencesField, { refs: unit.refs, inline: true }),\n ]);\n}\n\nfunction ColumnNameField({\n col_id,\n showIdentifier = false,\n}: {\n col_id: number;\n showIdentifier?: boolean;\n}) {\n const colData = useMacrostratColumnInfo(col_id);\n let inner: any = h(Identifier, { id: col_id });\n const name = colData?.col_name;\n if (name != null) {\n inner = h(\"span.value\", [\n h(\"span.col-name\", name),\n h.if(showIdentifier)([\" \", h(Parenthetical, inner)]),\n ]);\n }\n\n return h(\n DataField,\n {\n label: \"Column\",\n },\n inner,\n );\n}\n\nexport function ReferencesField({ refs, className = null, ...rest }) {\n if (refs == null || refs.length === 0) {\n return null;\n }\n\n return h(\n DataField,\n {\n label: \"References\",\n className: classNames(\"refs-field\", className),\n ...rest,\n },\n h(BibInfo, { refs }),\n );\n}\n\nfunction getThickness(unit): [string, string | null] {\n let minThickness = unit.min_thick ?? 0;\n let maxThickness = unit.max_thick ?? unit.min_thick ?? 0;\n let _unit = \"m\";\n\n if (minThickness == 0 && maxThickness == 0) {\n return [\"Unknown\", null];\n }\n\n if (minThickness < 0.8 && maxThickness < 1.2) {\n // Convert to cm\n minThickness = minThickness * 100;\n maxThickness = maxThickness * 100;\n _unit = \"cm\";\n } else if (minThickness > 800 && maxThickness > 1200) {\n // Convert to km\n minThickness = minThickness / 1000;\n maxThickness = maxThickness / 1000;\n _unit = \"km\";\n }\n\n if (minThickness == maxThickness) {\n return [formatSignificance(minThickness), _unit];\n }\n\n return [formatRange(minThickness, maxThickness), _unit];\n}\n\nexport function ThicknessField({ unit, label = \"Thickness\" }) {\n const [value, thicknessUnit] = getThickness(unit);\n return h(DataField, {\n label,\n value,\n unit: thicknessUnit,\n });\n}\n\nfunction BibInfo({ refs }) {\n const refData = useMacrostratData(\"refs\", refs);\n\n if (refData == null || refData.length === 0) {\n return null;\n }\n\n if (refData.length == 1) {\n return h(Citation, {\n data: refData[0],\n tag: \"span\",\n key: refData[0].ref_id,\n });\n }\n\n return h(\n \"ul.refs\",\n refData.map((data, i) =>\n h(Citation, { data, tag: \"li\", key: data.ref_id }),\n ),\n );\n}\n\nfunction Citation({ data, tag = \"p\" }) {\n return h(tag, { className: \"citation\" }, [\n h(\"span.authors\", data.author),\n \", \",\n h(\"span.year\", data.pub_year),\n \", \",\n h(\"span.title\", data.ref),\n ]);\n}\n\nfunction enhanceEnvironments(\n environments?: EnvironmentIdentifier[] | null,\n envMap?: Map<number, Environment> | null,\n) {\n return environments?.map((env) => {\n return {\n ...(envMap?.get(env.environ_id) ?? {}),\n ...env,\n };\n });\n}\n\nfunction enhanceLithologies(\n lithologies?: LithologyIdentifier[] | null,\n lithMap?: Map<number, any> | null,\n) {\n return lithologies?.map((lith) => {\n return {\n ...(lithMap?.get(lith.lith_id) ?? {}), // get lithology details\n ...lith, // override with the unit's specific lithology data\n };\n });\n}\n\nfunction UnitIDList({ units, showNames = false }) {\n const unitsMap = useColumnUnitsMap();\n\n const interactionManager = useInteractionManager();\n\n const extUnits: UnitInfo[] = useMemo(() => {\n const u1 = units.filter((d) => d != 0);\n if (showNames) {\n return u1.map((unitID) => {\n const unitData = unitsMap?.get(unitID);\n let name: string | null = null;\n if (unitData != null) {\n name = defaultNameFunction(unitData);\n }\n return {\n unitID,\n colID: unitData?.col_id,\n name,\n };\n });\n } else {\n return u1.map((unitID) => ({ unitID }));\n }\n }, [units, unitsMap]);\n\n if (extUnits.length === 0) {\n return h(\"span.no-units\", \"None\");\n }\n\n return h(\n ItemList,\n { className: \"units-list\" },\n extUnits.map((info) => {\n return h(\n \"span.item\",\n h(UnitIdentifier, {\n ...info,\n ...interactionManager?.interactionPropsForItem({\n unit_id: info.unitID,\n }),\n }),\n );\n }),\n );\n}\n"],"names":["useState","h","JSONView","defaultNameFunction","Button","classNames","useMemo","MacrostratInteractionProvider","ButtonGroup","UnitDetailsFeature","LithologyTagFeature","useMacrostratDefs","DataField","formatRange","Parenthetical","Value","LithologyList","AgeField","Duration","IntervalProportions","EnvironmentsList","StratNameField","useMacrostratColumnInfo","Identifier","formatSignificance","useMacrostratData","useColumnUnitsMap","useInteractionManager","ItemList","UnitIdentifier"],"mappings":";;;;;;;;;;;;;;;;;AAqDO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAe,IAAwB;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAAA,CACD;AAAA,EACD;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,QAAM,CAAC,WAAW,WAAW,IAAIA,MAAAA,SAAS,KAAK;AAE/C,MAAI,UAAqB;AACzB,MAAI,YAAY,WAAW;AACzB,cAAUC,aAAAA,QAAEC,uBAAU,EAAE,MAAM,MAAM,UAAU,OAAO;AAAA,EACvD,OAAO;AACL,cAAUD,aAAAA,QAAE,oBAAoB;AAAA,MAC9B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH;AAEA,MAAI,QAAQE,MAAAA,oBAAoB,IAAI;AAEpC,MAAI,SAAS;AAAA,IAAI;AAAA;AAAA,KAAgC;AAC/C,oBAAgBF,aAAAA,QAAE;AAAA,MAChBA,aAAAA,QAAEG,KAAAA,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAO;AAAA,QACP,SAAS;AAAA,QACT,KAAK;AAAA,QACL,WAAWC,oBAAAA,QAAW,oBAAoB,EAAE,SAAS,aAAa;AAAA,QAClE,QAAQ,KAAK;AACX,sBAAY,CAAC,QAAQ;AACrB,cAAI,gBAAA;AAAA,QACN;AAAA,MAAA,CACD;AAAA,MACD;AAAA,IAAA,CACD;AAAA,EACH;AAEA,QAAM,OAAOJ,aAAAA,QAAE,0BAA0B,EAAE,aAAa;AAAA,IACtDA,aAAAA,QAAE,mBAAmB;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AAA,IAAA;AAAA,EAEP,CAAC;AACH;AAEA,SAAS,WAAW,EAAE,OAAO,YAAY,SAAS;AAChD,QAAM,WAAWyB,MAAAA,kBAAA;AAEjB,QAAM,qBAAqBC,eAAAA,sBAAA;AAE3B,QAAM,WAAuBrB,MAAAA,QAAQ,MAAM;AACzC,UAAM,KAAK,MAAM,OAAO,CAAC,MAAM,KAAK,CAAC;AACrC,QAAI,WAAW;AACb,aAAO,GAAG,IAAI,CAAC,WAAW;AACxB,cAAM,WAAW,UAAU,IAAI,MAAM;AACrC,YAAI,OAAsB;AAC1B,YAAI,YAAY,MAAM;AACpB,iBAAOH,MAAAA,oBAAoB,QAAQ;AAAA,QACrC;AACA,eAAO;AAAA,UACL;AAAA,UACA,OAAO,UAAU;AAAA,UACjB;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IACH,OAAO;AACL,aAAO,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,OAAO,QAAQ,CAAC;AAEpB,MAAI,SAAS,WAAW,GAAG;AACzB,WAAOF,aAAAA,QAAE,iBAAiB,MAAM;AAAA,EAClC;AAEA,SAAOA,aAAAA;AAAAA,IACL2B,eAAAA;AAAAA,IACA,EAAE,WAAW,aAAA;AAAA,IACb,SAAS,IAAI,CAAC,SAAS;AACrB,aAAO3B,aAAAA;AAAAA,QACL;AAAA,QACAA,aAAAA,QAAE4B,YAAAA,gBAAgB;AAAA,UAChB,GAAG;AAAA,UACH,GAAG,oBAAoB,wBAAwB;AAAA,YAC7C,SAAS,KAAK;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IAEL,CAAC;AAAA,EAAA;AAEL;;;;;;"}
|
|
1
|
+
{"version":3,"file":"panel.cjs","sources":["../../src/unit-details/panel.ts"],"sourcesContent":["import { JSONView } from \"@macrostrat/ui-components\";\nimport { Button, ButtonGroup } from \"@blueprintjs/core\";\nimport { ReactNode, useMemo, useState } from \"react\";\nimport {\n DataField,\n EnvironmentsList,\n ItemList,\n LithologyList,\n LithologyTagFeature,\n MacrostratInteractionManager,\n MacrostratInteractionProvider,\n MacrostratItemIdentifier,\n Parenthetical,\n useInteractionManager,\n Value,\n} from \"@macrostrat/data-components\";\nimport { useColumnUnitsMap } from \"../data-provider\";\nimport {\n useMacrostratColumnInfo,\n useMacrostratData,\n useMacrostratDefs,\n} from \"@macrostrat/data-provider\";\nimport type {\n Environment,\n EnvironmentIdentifier,\n Interval,\n Lithology,\n UnitLong,\n UnitLongFull,\n} from \"@macrostrat/api-types\";\nimport { defaultNameFunction } from \"../units/names\";\nimport classNames from \"classnames\";\nimport { AgeField, Duration, IntervalProportions } from \"./age-range\";\nimport { formatRange, formatSignificance } from \"./utils.ts\";\nimport h from \"./panel.module.sass\";\nimport { StratNameField } from \"./strat-names.ts\";\nimport { Identifier, UnitIdentifier, UnitInfo } from \"./identifiers.ts\";\nimport { LithologyIdentifier } from \"@macrostrat/api-types/src/lithologies\";\n\nexport interface UnitDetailsPanelProps {\n unit: any;\n onClose?: any;\n className?: string;\n actions?: ReactNode;\n hiddenActions?: ReactNode;\n features?: Set<UnitDetailsFeature>;\n lithologyFeatures?: Set<LithologyTagFeature>;\n onSelectUnit?: (unitID: number) => void;\n onClickItem?: MacrostratItemClickHandler;\n interactionManager?: MacrostratInteractionManager;\n showJSON?: boolean;\n}\n\nexport function UnitDetailsPanel({\n unit,\n onClose,\n className,\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n UnitDetailsFeature.JSONToggle,\n UnitDetailsFeature.DepthRange,\n ]),\n lithologyFeatures,\n actions,\n hiddenActions = null,\n onSelectUnit,\n onClickItem,\n showJSON,\n}: UnitDetailsPanelProps) {\n const [_showJSON, setShowJSON] = useState(false);\n\n let content: ReactNode = null;\n if (showJSON ?? _showJSON) {\n content = h(JSONView, { data: unit, showRoot: false });\n } else {\n content = h(UnitDetailsContent, {\n unit,\n features,\n lithologyFeatures,\n onClickItem,\n });\n }\n\n let title = defaultNameFunction(unit);\n\n if (features.has(UnitDetailsFeature.JSONToggle)) {\n hiddenActions = h([\n h(Button, {\n icon: \"code\",\n small: true,\n minimal: true,\n key: \"json-view-toggle\",\n className: classNames(\"json-view-toggle\", { enabled: setShowJSON }),\n onClick(evt) {\n setShowJSON(!_showJSON);\n evt.stopPropagation();\n },\n }),\n hiddenActions,\n ]);\n }\n\n const main = h(\"div.unit-details-panel\", { className }, [\n h(LegendPanelHeader, {\n onClose,\n title,\n id: unit.unit_id,\n actions,\n hiddenActions,\n }),\n h(\"div.unit-details-content-holder\", content),\n ]);\n\n /** Handle unit selection clicks */\n const clickHandlerForItem = useMemo(() => {\n if (onSelectUnit == null && onClickItem == null) return null;\n return (item: MacrostratItemIdentifier) => {\n if (\"unit_id\" in item && !(\"col_id\" in item)) {\n // We are selecting a unit within the column\n return (event: MouseEvent) => {\n if (onSelectUnit != null) {\n onSelectUnit(item.unit_id);\n } else if (onClickItem != null) {\n console.warn(\n \"Unit selection: onClickItem is defined but onSelectUnit is not; ignoring click\",\n );\n }\n // Don't allow event to propagate further (e.g., to open a link)\n event.preventDefault();\n };\n }\n return undefined;\n };\n }, [onSelectUnit, onClickItem]);\n\n if (clickHandlerForItem != null) {\n // We wrap this in a MacrostratInteractionManager to handle unit selection\n return h(\n MacrostratInteractionProvider,\n {\n clickHandlerForItem,\n inherit: true,\n },\n main,\n );\n }\n\n return main;\n}\n\nexport function LegendPanelHeader({\n title,\n id,\n onClose,\n actions = null,\n hiddenActions,\n}: {\n title?: string | null;\n id?: number | null;\n onClose?: () => void;\n actions?: ReactNode | null;\n hiddenActions?: ReactNode | null;\n}) {\n return h(\"header.legend-panel-header\", [\n h(\"div.title-container\", [\n h.if(title != null)(\"h3\", title),\n h.if(hiddenActions != null)(\n \"span.hidden-actions-container\",\n h(\"div.hidden-actions\", hiddenActions),\n ),\n ]),\n h(\"div.spacer\"),\n h.if(id != null)(\"code.unit-id\", id),\n h.if(actions != null)(ButtonGroup, { minimal: true }, actions),\n h.if(onClose != null)(Button, {\n icon: \"cross\",\n minimal: true,\n small: true,\n onClick() {\n onClose?.();\n },\n }),\n ]);\n}\n\nexport enum UnitDetailsFeature {\n AdjacentUnits = \"adjacent-units\",\n Color = \"color\",\n OutcropType = \"outcrop-type\",\n JSONToggle = \"json-toggle\",\n DepthRange = \"depth-range\",\n ColumnName = \"column-name\",\n}\n\nexport type MacrostratItemClickHandler = (\n event: MouseEvent,\n item:\n | Lithology\n | Environment\n | UnitLong\n | Interval\n | { strat_name_id: number },\n) => void;\n\nfunction UnitDetailsContent({\n unit,\n lithologyFeatures = new Set([\n LithologyTagFeature.Proportion,\n LithologyTagFeature.Attributes,\n ]),\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n ]),\n onClickItem,\n getItemHref,\n}: {\n unit: UnitLong;\n lithologyFeatures?: Set<LithologyTagFeature>;\n features?: Set<UnitDetailsFeature>;\n onClickItem?: MacrostratItemClickHandler;\n getItemHref?: (item: Lithology | Environment | UnitLong) => string | null;\n}) {\n const lithMap = useMacrostratDefs(\"lithologies\");\n const envMap = useMacrostratDefs(\"environments\");\n\n const environments = enhanceEnvironments(unit.environ, envMap);\n const lithologies = enhanceLithologies(unit.lith ?? [], lithMap);\n\n let outcropField: ReactNode = null;\n if (features.has(UnitDetailsFeature.OutcropType)) {\n // Determine outcrop type\n let outcrop = unit.outcrop;\n if (outcrop == \"both\") {\n outcrop = \"surface and subsurface\";\n }\n outcropField = h(DataField, {\n label: \"Outcrop\",\n value: outcrop,\n });\n }\n\n let thicknessOrHeightRange: ReactNode = null;\n const [thickness, thicknessUnit] = getThickness(unit);\n // Proxy for actual heights in t_pos and b_pos\n if (\n features.has(UnitDetailsFeature.DepthRange) &&\n unit.t_pos != null &&\n unit.b_pos != null &&\n unit.min_thick == unit.max_thick && // We have an actual fixed height\n unit.min_thick != 0 // Not a zero thickness\n ) {\n const label = unit.t_pos < unit.b_pos ? \"Depth\" : \"Height\";\n const u1 = \"m\";\n\n thicknessOrHeightRange = h(DataField, {\n unit: u1,\n label,\n value: formatRange(unit.b_pos, unit.t_pos),\n children: h(\n Parenthetical,\n h(Value, { value: thickness, unit: thicknessUnit }),\n ),\n });\n }\n thicknessOrHeightRange ??= h(DataField, {\n label: \"Thickness\",\n value: thickness,\n unit: thicknessUnit,\n });\n\n /** We are trying to move away from passing the \"color\" parameter in the API */\n let colorSwatch: ReactNode = null;\n if (\"color\" in unit && features.has(UnitDetailsFeature.Color)) {\n const unit1 = unit as UnitLongFull;\n colorSwatch = h(\"div.color-swatch\", {\n style: { backgroundColor: unit1.color },\n });\n }\n\n return h(\"div.unit-details-content\", [\n h.if(features.has(UnitDetailsFeature.ColumnName))(ColumnNameField, {\n col_id: unit.col_id,\n }),\n thicknessOrHeightRange,\n h.if(lithologies != null)(LithologyList, {\n label: \"Lithology\",\n lithologies: lithologies ?? [],\n features: lithologyFeatures,\n }),\n h(AgeField, { unit }, [\n h(Parenthetical, h(Duration, { value: unit.b_age - unit.t_age })),\n h(IntervalProportions, {\n unit,\n onClickItem,\n }),\n ]),\n h.if(environments != null)(EnvironmentsList, {\n environments,\n }),\n h.if(unit.strat_name_id != null)(StratNameField, {\n strat_name_id: unit.strat_name_id,\n }),\n outcropField,\n h.if(features.has(UnitDetailsFeature.AdjacentUnits))([\n h.if(unit.units_above != null)(\n DataField,\n { label: \"Above\" },\n h(UnitIDList, {\n units: unit.units_above,\n showNames: true,\n }),\n ),\n h.if(unit.units_below != null)(\n DataField,\n { label: \"Below\" },\n h(UnitIDList, {\n units: unit.units_below,\n showNames: true,\n }),\n ),\n ]),\n colorSwatch,\n h(ReferencesField, { refs: unit.refs, inline: true }),\n ]);\n}\n\nfunction ColumnNameField({\n col_id,\n showIdentifier = false,\n}: {\n col_id: number;\n showIdentifier?: boolean;\n}) {\n const colData = useMacrostratColumnInfo(col_id);\n let inner: any = h(Identifier, { id: col_id });\n const name = colData?.col_name;\n if (name != null) {\n inner = h(\"span.value\", [\n h(\"span.col-name\", name),\n h.if(showIdentifier)([\" \", h(Parenthetical, inner)]),\n ]);\n }\n\n return h(\n DataField,\n {\n label: \"Column\",\n },\n inner,\n );\n}\n\nexport function ReferencesField({ refs, className = null, ...rest }) {\n if (refs == null || refs.length === 0) {\n return null;\n }\n\n return h(\n DataField,\n {\n label: \"References\",\n className: classNames(\"refs-field\", className),\n ...rest,\n },\n h(BibInfo, { refs }),\n );\n}\n\nfunction getThickness(unit): [string, string | null] {\n let minThickness = unit.min_thick ?? 0;\n let maxThickness = unit.max_thick ?? unit.min_thick ?? 0;\n let _unit = \"m\";\n\n if (minThickness == 0 && maxThickness == 0) {\n return [\"Unknown\", null];\n }\n\n if (minThickness < 0.8 && maxThickness < 1.2) {\n // Convert to cm\n minThickness = minThickness * 100;\n maxThickness = maxThickness * 100;\n _unit = \"cm\";\n } else if (minThickness > 800 && maxThickness > 1200) {\n // Convert to km\n minThickness = minThickness / 1000;\n maxThickness = maxThickness / 1000;\n _unit = \"km\";\n }\n\n if (minThickness == maxThickness) {\n return [formatSignificance(minThickness), _unit];\n }\n\n return [formatRange(minThickness, maxThickness), _unit];\n}\n\nexport function ThicknessField({ unit, label = \"Thickness\" }) {\n const [value, thicknessUnit] = getThickness(unit);\n return h(DataField, {\n label,\n value,\n unit: thicknessUnit,\n });\n}\n\nfunction BibInfo({ refs }) {\n const refData = useMacrostratData(\"refs\", refs);\n\n if (refData == null || refData.length === 0) {\n return null;\n }\n\n if (refData.length == 1) {\n return h(Citation, {\n data: refData[0],\n tag: \"span\",\n key: refData[0].ref_id,\n });\n }\n\n return h(\n \"ul.refs\",\n refData.map((data, i) =>\n h(Citation, { data, tag: \"li\", key: data.ref_id }),\n ),\n );\n}\n\nfunction Citation({ data, tag = \"p\" }) {\n return h(tag, { className: \"citation\" }, [\n h(\"span.authors\", data.author),\n \", \",\n h(\"span.year\", data.pub_year),\n \", \",\n h(\"span.title\", data.ref),\n ]);\n}\n\nfunction enhanceEnvironments(\n environments?: EnvironmentIdentifier[] | null,\n envMap?: Map<number, Environment> | null,\n) {\n return environments?.map((env) => {\n return {\n ...(envMap?.get(env.environ_id) ?? {}),\n ...env,\n };\n });\n}\n\nfunction enhanceLithologies(\n lithologies?: LithologyIdentifier[] | null,\n lithMap?: Map<number, any> | null,\n) {\n return lithologies?.map((lith) => {\n return {\n ...(lithMap?.get(lith.lith_id) ?? {}), // get lithology details\n ...lith, // override with the unit's specific lithology data\n };\n });\n}\n\nfunction UnitIDList({ units, showNames = false }) {\n const unitsMap = useColumnUnitsMap();\n\n const interactionManager = useInteractionManager();\n\n const extUnits: UnitInfo[] = useMemo(() => {\n const u1 = units.filter((d) => d != 0);\n if (showNames) {\n return u1.map((unitID) => {\n const unitData = unitsMap?.get(unitID);\n let name: string | null = null;\n if (unitData != null) {\n name = defaultNameFunction(unitData);\n }\n return {\n unitID,\n colID: unitData?.col_id,\n name,\n };\n });\n } else {\n return u1.map((unitID) => ({ unitID }));\n }\n }, [units, unitsMap]);\n\n if (extUnits.length === 0) {\n return h(\"span.no-units\", \"None\");\n }\n\n return h(\n ItemList,\n { className: \"units-list\" },\n extUnits.map((info) => {\n return h(\n \"span.item\",\n h(UnitIdentifier, {\n ...info,\n ...interactionManager?.interactionPropsForItem({\n unit_id: info.unitID,\n }),\n }),\n );\n }),\n );\n}\n"],"names":["useState","h","JSONView","defaultNameFunction","Button","classNames","useMemo","MacrostratInteractionProvider","ButtonGroup","UnitDetailsFeature","LithologyTagFeature","useMacrostratDefs","DataField","formatRange","Parenthetical","Value","LithologyList","AgeField","Duration","IntervalProportions","EnvironmentsList","StratNameField","useMacrostratColumnInfo","Identifier","formatSignificance","useMacrostratData","useColumnUnitsMap","useInteractionManager","ItemList","UnitIdentifier"],"mappings":";;;;;;;;;;;;;;;;;AAqDO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAe,IAAw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AO,GAAG,IAAI,CAAC,WAAW;AACxB,cAAM,WAAW,UAAU,IAAI,MAAM;AACrC,YAAI,OAAsB;AAC1B,YAAI,YAAY,MAAM;AACpB,iBAAOH,MAAAA,oBAAoB,QAAQ;AAAA,QACrC;AACA,eAAO;AAAA,UACL;AAAA,UACA,OAAO,UAAU;AAAA,UACjB;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IACH,OAAO;AACL,aAAO,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,OAAO,QAAQ,CAAC;AAEpB,MAAI,SAAS,WAAW,GAAG;AACzB,WAAOF,aAAAA,QAAE,iBAAiB,MAAM;AAAA,EAClC;AAEA,SAAOA,aAAAA;AAAAA,IACL2B,eAAAA;AAAAA,IACA,EAAE,WAAW,aAAA;AAAA,IACb,SAAS,IAAI,CAAC,SAAS;AACrB,aAAO3B,aAAAA;AAAAA,QACL;AAAA,QACAA,aAAAA,QAAE4B,YAAAA,gBAAgB;AAAA,UAChB,GAAG;AAAA,UACH,GAAG,oBAAoB,wBAAwB;AAAA,YAC7C,SAAS,KAAK;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IAEL,CAAC;AAAA,EAAA;AAEL;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel.js","sources":["../../src/unit-details/panel.ts"],"sourcesContent":["import { JSONView } from \"@macrostrat/ui-components\";\nimport { Button, ButtonGroup } from \"@blueprintjs/core\";\nimport { ReactNode, useMemo, useState } from \"react\";\nimport {\n DataField,\n EnvironmentsList,\n ItemList,\n LithologyList,\n LithologyTagFeature,\n MacrostratInteractionManager,\n MacrostratInteractionProvider,\n MacrostratItemIdentifier,\n Parenthetical,\n useInteractionManager,\n Value,\n} from \"@macrostrat/data-components\";\nimport { useColumnUnitsMap } from \"../data-provider\";\nimport {\n useMacrostratColumnInfo,\n useMacrostratData,\n useMacrostratDefs,\n} from \"@macrostrat/data-provider\";\nimport type {\n Environment,\n EnvironmentIdentifier,\n Interval,\n Lithology,\n UnitLong,\n UnitLongFull,\n} from \"@macrostrat/api-types\";\nimport { defaultNameFunction } from \"../units/names\";\nimport classNames from \"classnames\";\nimport { AgeField, Duration, IntervalProportions } from \"./age-range\";\nimport { formatRange, formatSignificance } from \"./utils.ts\";\nimport h from \"./panel.module.sass\";\nimport { StratNameField } from \"./strat-names.ts\";\nimport { Identifier, UnitIdentifier, UnitInfo } from \"./identifiers.ts\";\nimport { LithologyIdentifier } from \"@macrostrat/api-types/src/lithologies\";\n\nexport interface UnitDetailsPanelProps {\n unit: any;\n onClose?: any;\n className?: string;\n actions?: ReactNode;\n hiddenActions?: ReactNode;\n features?: Set<UnitDetailsFeature>;\n lithologyFeatures?: Set<LithologyTagFeature>;\n onSelectUnit?: (unitID: number) => void;\n onClickItem?: MacrostratItemClickHandler;\n interactionManager?: MacrostratInteractionManager;\n showJSON?: boolean;\n}\n\nexport function UnitDetailsPanel({\n unit,\n onClose,\n className,\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n UnitDetailsFeature.JSONToggle,\n UnitDetailsFeature.DepthRange,\n ]),\n lithologyFeatures,\n actions,\n hiddenActions = null,\n onSelectUnit,\n onClickItem,\n showJSON,\n}: UnitDetailsPanelProps) {\n const [_showJSON, setShowJSON] = useState(false);\n\n let content: ReactNode = null;\n if (showJSON ?? _showJSON) {\n content = h(JSONView, { data: unit, showRoot: false });\n } else {\n content = h(UnitDetailsContent, {\n unit,\n features,\n lithologyFeatures,\n onClickItem,\n });\n }\n\n let title = defaultNameFunction(unit);\n\n if (features.has(UnitDetailsFeature.JSONToggle)) {\n hiddenActions = h([\n h(Button, {\n icon: \"code\",\n small: true,\n minimal: true,\n key: \"json-view-toggle\",\n className: classNames(\"json-view-toggle\", { enabled: setShowJSON }),\n onClick(evt) {\n setShowJSON(!showJSON);\n evt.stopPropagation();\n },\n }),\n hiddenActions,\n ]);\n }\n\n const main = h(\"div.unit-details-panel\", { className }, [\n h(LegendPanelHeader, {\n onClose,\n title,\n id: unit.unit_id,\n actions,\n hiddenActions,\n }),\n h(\"div.unit-details-content-holder\", content),\n ]);\n\n /** Handle unit selection clicks */\n const clickHandlerForItem = useMemo(() => {\n if (onSelectUnit == null && onClickItem == null) return null;\n return (item: MacrostratItemIdentifier) => {\n if (\"unit_id\" in item && !(\"col_id\" in item)) {\n // We are selecting a unit within the column\n return (event: MouseEvent) => {\n if (onSelectUnit != null) {\n onSelectUnit(item.unit_id);\n } else if (onClickItem != null) {\n console.warn(\n \"Unit selection: onClickItem is defined but onSelectUnit is not; ignoring click\",\n );\n }\n // Don't allow event to propagate further (e.g., to open a link)\n event.preventDefault();\n };\n }\n return undefined;\n };\n }, [onSelectUnit, onClickItem]);\n\n if (clickHandlerForItem != null) {\n // We wrap this in a MacrostratInteractionManager to handle unit selection\n return h(\n MacrostratInteractionProvider,\n {\n clickHandlerForItem,\n inherit: true,\n },\n main,\n );\n }\n\n return main;\n}\n\nexport function LegendPanelHeader({\n title,\n id,\n onClose,\n actions = null,\n hiddenActions,\n}: {\n title?: string | null;\n id?: number | null;\n onClose?: () => void;\n actions?: ReactNode | null;\n hiddenActions?: ReactNode | null;\n}) {\n return h(\"header.legend-panel-header\", [\n h(\"div.title-container\", [\n h.if(title != null)(\"h3\", title),\n h.if(hiddenActions != null)(\n \"span.hidden-actions-container\",\n h(\"div.hidden-actions\", hiddenActions),\n ),\n ]),\n h(\"div.spacer\"),\n h.if(id != null)(\"code.unit-id\", id),\n h.if(actions != null)(ButtonGroup, { minimal: true }, actions),\n h.if(onClose != null)(Button, {\n icon: \"cross\",\n minimal: true,\n small: true,\n onClick() {\n onClose?.();\n },\n }),\n ]);\n}\n\nexport enum UnitDetailsFeature {\n AdjacentUnits = \"adjacent-units\",\n Color = \"color\",\n OutcropType = \"outcrop-type\",\n JSONToggle = \"json-toggle\",\n DepthRange = \"depth-range\",\n ColumnName = \"column-name\",\n}\n\nexport type MacrostratItemClickHandler = (\n event: MouseEvent,\n item:\n | Lithology\n | Environment\n | UnitLong\n | Interval\n | { strat_name_id: number },\n) => void;\n\nfunction UnitDetailsContent({\n unit,\n lithologyFeatures = new Set([\n LithologyTagFeature.Proportion,\n LithologyTagFeature.Attributes,\n ]),\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n ]),\n onClickItem,\n getItemHref,\n}: {\n unit: UnitLong;\n lithologyFeatures?: Set<LithologyTagFeature>;\n features?: Set<UnitDetailsFeature>;\n onClickItem?: MacrostratItemClickHandler;\n getItemHref?: (item: Lithology | Environment | UnitLong) => string | null;\n}) {\n const lithMap = useMacrostratDefs(\"lithologies\");\n const envMap = useMacrostratDefs(\"environments\");\n\n const environments = enhanceEnvironments(unit.environ, envMap);\n const lithologies = enhanceLithologies(unit.lith ?? [], lithMap);\n\n let outcropField: ReactNode = null;\n if (features.has(UnitDetailsFeature.OutcropType)) {\n // Determine outcrop type\n let outcrop = unit.outcrop;\n if (outcrop == \"both\") {\n outcrop = \"surface and subsurface\";\n }\n outcropField = h(DataField, {\n label: \"Outcrop\",\n value: outcrop,\n });\n }\n\n let thicknessOrHeightRange: ReactNode = null;\n const [thickness, thicknessUnit] = getThickness(unit);\n // Proxy for actual heights in t_pos and b_pos\n if (\n features.has(UnitDetailsFeature.DepthRange) &&\n unit.t_pos != null &&\n unit.b_pos != null &&\n unit.min_thick == unit.max_thick && // We have an actual fixed height\n unit.min_thick != 0 // Not a zero thickness\n ) {\n const label = unit.t_pos < unit.b_pos ? \"Depth\" : \"Height\";\n const u1 = \"m\";\n\n thicknessOrHeightRange = h(DataField, {\n unit: u1,\n label,\n value: formatRange(unit.b_pos, unit.t_pos),\n children: h(\n Parenthetical,\n h(Value, { value: thickness, unit: thicknessUnit }),\n ),\n });\n }\n thicknessOrHeightRange ??= h(DataField, {\n label: \"Thickness\",\n value: thickness,\n unit: thicknessUnit,\n });\n\n /** We are trying to move away from passing the \"color\" parameter in the API */\n let colorSwatch: ReactNode = null;\n if (\"color\" in unit && features.has(UnitDetailsFeature.Color)) {\n const unit1 = unit as UnitLongFull;\n colorSwatch = h(\"div.color-swatch\", {\n style: { backgroundColor: unit1.color },\n });\n }\n\n return h(\"div.unit-details-content\", [\n h.if(features.has(UnitDetailsFeature.ColumnName))(ColumnNameField, {\n col_id: unit.col_id,\n }),\n thicknessOrHeightRange,\n h.if(lithologies != null)(LithologyList, {\n label: \"Lithology\",\n lithologies: lithologies ?? [],\n features: lithologyFeatures,\n }),\n h(AgeField, { unit }, [\n h(Parenthetical, h(Duration, { value: unit.b_age - unit.t_age })),\n h(IntervalProportions, {\n unit,\n onClickItem,\n }),\n ]),\n h.if(environments != null)(EnvironmentsList, {\n environments,\n }),\n h.if(unit.strat_name_id != null)(StratNameField, {\n strat_name_id: unit.strat_name_id,\n }),\n outcropField,\n h.if(features.has(UnitDetailsFeature.AdjacentUnits))([\n h.if(unit.units_above != null)(\n DataField,\n { label: \"Above\" },\n h(UnitIDList, {\n units: unit.units_above,\n showNames: true,\n }),\n ),\n h.if(unit.units_below != null)(\n DataField,\n { label: \"Below\" },\n h(UnitIDList, {\n units: unit.units_below,\n showNames: true,\n }),\n ),\n ]),\n colorSwatch,\n h(ReferencesField, { refs: unit.refs, inline: true }),\n ]);\n}\n\nfunction ColumnNameField({\n col_id,\n showIdentifier = false,\n}: {\n col_id: number;\n showIdentifier?: boolean;\n}) {\n const colData = useMacrostratColumnInfo(col_id);\n let inner: any = h(Identifier, { id: col_id });\n const name = colData?.col_name;\n if (name != null) {\n inner = h(\"span.value\", [\n h(\"span.col-name\", name),\n h.if(showIdentifier)([\" \", h(Parenthetical, inner)]),\n ]);\n }\n\n return h(\n DataField,\n {\n label: \"Column\",\n },\n inner,\n );\n}\n\nexport function ReferencesField({ refs, className = null, ...rest }) {\n if (refs == null || refs.length === 0) {\n return null;\n }\n\n return h(\n DataField,\n {\n label: \"References\",\n className: classNames(\"refs-field\", className),\n ...rest,\n },\n h(BibInfo, { refs }),\n );\n}\n\nfunction getThickness(unit): [string, string | null] {\n let minThickness = unit.min_thick ?? 0;\n let maxThickness = unit.max_thick ?? unit.min_thick ?? 0;\n let _unit = \"m\";\n\n if (minThickness == 0 && maxThickness == 0) {\n return [\"Unknown\", null];\n }\n\n if (minThickness < 0.8 && maxThickness < 1.2) {\n // Convert to cm\n minThickness = minThickness * 100;\n maxThickness = maxThickness * 100;\n _unit = \"cm\";\n } else if (minThickness > 800 && maxThickness > 1200) {\n // Convert to km\n minThickness = minThickness / 1000;\n maxThickness = maxThickness / 1000;\n _unit = \"km\";\n }\n\n if (minThickness == maxThickness) {\n return [formatSignificance(minThickness), _unit];\n }\n\n return [formatRange(minThickness, maxThickness), _unit];\n}\n\nexport function ThicknessField({ unit, label = \"Thickness\" }) {\n const [value, thicknessUnit] = getThickness(unit);\n return h(DataField, {\n label,\n value,\n unit: thicknessUnit,\n });\n}\n\nfunction BibInfo({ refs }) {\n const refData = useMacrostratData(\"refs\", refs);\n\n if (refData == null || refData.length === 0) {\n return null;\n }\n\n if (refData.length == 1) {\n return h(Citation, {\n data: refData[0],\n tag: \"span\",\n key: refData[0].ref_id,\n });\n }\n\n return h(\n \"ul.refs\",\n refData.map((data, i) =>\n h(Citation, { data, tag: \"li\", key: data.ref_id }),\n ),\n );\n}\n\nfunction Citation({ data, tag = \"p\" }) {\n return h(tag, { className: \"citation\" }, [\n h(\"span.authors\", data.author),\n \", \",\n h(\"span.year\", data.pub_year),\n \", \",\n h(\"span.title\", data.ref),\n ]);\n}\n\nfunction enhanceEnvironments(\n environments?: EnvironmentIdentifier[] | null,\n envMap?: Map<number, Environment> | null,\n) {\n return environments?.map((env) => {\n return {\n ...(envMap?.get(env.environ_id) ?? {}),\n ...env,\n };\n });\n}\n\nfunction enhanceLithologies(\n lithologies?: LithologyIdentifier[] | null,\n lithMap?: Map<number, any> | null,\n) {\n return lithologies?.map((lith) => {\n return {\n ...(lithMap?.get(lith.lith_id) ?? {}), // get lithology details\n ...lith, // override with the unit's specific lithology data\n };\n });\n}\n\nfunction UnitIDList({ units, showNames = false }) {\n const unitsMap = useColumnUnitsMap();\n\n const interactionManager = useInteractionManager();\n\n const extUnits: UnitInfo[] = useMemo(() => {\n const u1 = units.filter((d) => d != 0);\n if (showNames) {\n return u1.map((unitID) => {\n const unitData = unitsMap?.get(unitID);\n let name: string | null = null;\n if (unitData != null) {\n name = defaultNameFunction(unitData);\n }\n return {\n unitID,\n colID: unitData?.col_id,\n name,\n };\n });\n } else {\n return u1.map((unitID) => ({ unitID }));\n }\n }, [units, unitsMap]);\n\n if (extUnits.length === 0) {\n return h(\"span.no-units\", \"None\");\n }\n\n return h(\n ItemList,\n { className: \"units-list\" },\n extUnits.map((info) => {\n return h(\n \"span.item\",\n h(UnitIdentifier, {\n ...info,\n ...interactionManager?.interactionPropsForItem({\n unit_id: info.unitID,\n }),\n }),\n );\n }),\n );\n}\n"],"names":["UnitDetailsFeature"],"mappings":";;;;;;;;;;;;;AAqDO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAe,IAAwB;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAAA,CACD;AAAA,EACD;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,QAAM,CAAC,WAAW,WAAW,IAAI,SAAS,KAAK;AAE/C,MAAI,UAAqB;AACzB,MAAI,YAAY,WAAW;AACzB,cAAU,EAAE,UAAU,EAAE,MAAM,MAAM,UAAU,OAAO;AAAA,EACvD,OAAO;AACL,cAAU,EAAE,oBAAoB;AAAA,MAC9B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH;AAEA,MAAI,QAAQ,oBAAoB,IAAI;AAEpC,MAAI,SAAS;AAAA,IAAI;AAAA;A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AO,GAAG,IAAI,CAAC,WAAW;AACxB,cAAM,WAAW,UAAU,IAAI,MAAM;AACrC,YAAI,OAAsB;AAC1B,YAAI,YAAY,MAAM;AACpB,iBAAO,oBAAoB,QAAQ;AAAA,QACrC;AACA,eAAO;AAAA,UACL;AAAA,UACA,OAAO,UAAU;AAAA,UACjB;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IACH,OAAO;AACL,aAAO,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,OAAO,QAAQ,CAAC;AAEpB,MAAI,SAAS,WAAW,GAAG;AACzB,WAAO,EAAE,iBAAiB,MAAM;AAAA,EAClC;AAEA,SAAO;AAAA,IACL;AAAA,IACA,EAAE,WAAW,aAAA;AAAA,IACb,SAAS,IAAI,CAAC,SAAS;AACrB,aAAO;AAAA,QACL;AAAA,QACA,EAAE,gBAAgB;AAAA,UAChB,GAAG;AAAA,UACH,GAAG,oBAAoB,wBAAwB;AAAA,YAC7C,SAAS,KAAK;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IAEL,CAAC;AAAA,EAAA;AAEL;"}
|
|
1
|
+
{"version":3,"file":"panel.js","sources":["../../src/unit-details/panel.ts"],"sourcesContent":["import { JSONView } from \"@macrostrat/ui-components\";\nimport { Button, ButtonGroup } from \"@blueprintjs/core\";\nimport { ReactNode, useMemo, useState } from \"react\";\nimport {\n DataField,\n EnvironmentsList,\n ItemList,\n LithologyList,\n LithologyTagFeature,\n MacrostratInteractionManager,\n MacrostratInteractionProvider,\n MacrostratItemIdentifier,\n Parenthetical,\n useInteractionManager,\n Value,\n} from \"@macrostrat/data-components\";\nimport { useColumnUnitsMap } from \"../data-provider\";\nimport {\n useMacrostratColumnInfo,\n useMacrostratData,\n useMacrostratDefs,\n} from \"@macrostrat/data-provider\";\nimport type {\n Environment,\n EnvironmentIdentifier,\n Interval,\n Lithology,\n UnitLong,\n UnitLongFull,\n} from \"@macrostrat/api-types\";\nimport { defaultNameFunction } from \"../units/names\";\nimport classNames from \"classnames\";\nimport { AgeField, Duration, IntervalProportions } from \"./age-range\";\nimport { formatRange, formatSignificance } from \"./utils.ts\";\nimport h from \"./panel.module.sass\";\nimport { StratNameField } from \"./strat-names.ts\";\nimport { Identifier, UnitIdentifier, UnitInfo } from \"./identifiers.ts\";\nimport { LithologyIdentifier } from \"@macrostrat/api-types/src/lithologies\";\n\nexport interface UnitDetailsPanelProps {\n unit: any;\n onClose?: any;\n className?: string;\n actions?: ReactNode;\n hiddenActions?: ReactNode;\n features?: Set<UnitDetailsFeature>;\n lithologyFeatures?: Set<LithologyTagFeature>;\n onSelectUnit?: (unitID: number) => void;\n onClickItem?: MacrostratItemClickHandler;\n interactionManager?: MacrostratInteractionManager;\n showJSON?: boolean;\n}\n\nexport function UnitDetailsPanel({\n unit,\n onClose,\n className,\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n UnitDetailsFeature.JSONToggle,\n UnitDetailsFeature.DepthRange,\n ]),\n lithologyFeatures,\n actions,\n hiddenActions = null,\n onSelectUnit,\n onClickItem,\n showJSON,\n}: UnitDetailsPanelProps) {\n const [_showJSON, setShowJSON] = useState(false);\n\n let content: ReactNode = null;\n if (showJSON ?? _showJSON) {\n content = h(JSONView, { data: unit, showRoot: false });\n } else {\n content = h(UnitDetailsContent, {\n unit,\n features,\n lithologyFeatures,\n onClickItem,\n });\n }\n\n let title = defaultNameFunction(unit);\n\n if (features.has(UnitDetailsFeature.JSONToggle)) {\n hiddenActions = h([\n h(Button, {\n icon: \"code\",\n small: true,\n minimal: true,\n key: \"json-view-toggle\",\n className: classNames(\"json-view-toggle\", { enabled: setShowJSON }),\n onClick(evt) {\n setShowJSON(!_showJSON);\n evt.stopPropagation();\n },\n }),\n hiddenActions,\n ]);\n }\n\n const main = h(\"div.unit-details-panel\", { className }, [\n h(LegendPanelHeader, {\n onClose,\n title,\n id: unit.unit_id,\n actions,\n hiddenActions,\n }),\n h(\"div.unit-details-content-holder\", content),\n ]);\n\n /** Handle unit selection clicks */\n const clickHandlerForItem = useMemo(() => {\n if (onSelectUnit == null && onClickItem == null) return null;\n return (item: MacrostratItemIdentifier) => {\n if (\"unit_id\" in item && !(\"col_id\" in item)) {\n // We are selecting a unit within the column\n return (event: MouseEvent) => {\n if (onSelectUnit != null) {\n onSelectUnit(item.unit_id);\n } else if (onClickItem != null) {\n console.warn(\n \"Unit selection: onClickItem is defined but onSelectUnit is not; ignoring click\",\n );\n }\n // Don't allow event to propagate further (e.g., to open a link)\n event.preventDefault();\n };\n }\n return undefined;\n };\n }, [onSelectUnit, onClickItem]);\n\n if (clickHandlerForItem != null) {\n // We wrap this in a MacrostratInteractionManager to handle unit selection\n return h(\n MacrostratInteractionProvider,\n {\n clickHandlerForItem,\n inherit: true,\n },\n main,\n );\n }\n\n return main;\n}\n\nexport function LegendPanelHeader({\n title,\n id,\n onClose,\n actions = null,\n hiddenActions,\n}: {\n title?: string | null;\n id?: number | null;\n onClose?: () => void;\n actions?: ReactNode | null;\n hiddenActions?: ReactNode | null;\n}) {\n return h(\"header.legend-panel-header\", [\n h(\"div.title-container\", [\n h.if(title != null)(\"h3\", title),\n h.if(hiddenActions != null)(\n \"span.hidden-actions-container\",\n h(\"div.hidden-actions\", hiddenActions),\n ),\n ]),\n h(\"div.spacer\"),\n h.if(id != null)(\"code.unit-id\", id),\n h.if(actions != null)(ButtonGroup, { minimal: true }, actions),\n h.if(onClose != null)(Button, {\n icon: \"cross\",\n minimal: true,\n small: true,\n onClick() {\n onClose?.();\n },\n }),\n ]);\n}\n\nexport enum UnitDetailsFeature {\n AdjacentUnits = \"adjacent-units\",\n Color = \"color\",\n OutcropType = \"outcrop-type\",\n JSONToggle = \"json-toggle\",\n DepthRange = \"depth-range\",\n ColumnName = \"column-name\",\n}\n\nexport type MacrostratItemClickHandler = (\n event: MouseEvent,\n item:\n | Lithology\n | Environment\n | UnitLong\n | Interval\n | { strat_name_id: number },\n) => void;\n\nfunction UnitDetailsContent({\n unit,\n lithologyFeatures = new Set([\n LithologyTagFeature.Proportion,\n LithologyTagFeature.Attributes,\n ]),\n features = new Set<UnitDetailsFeature>([\n UnitDetailsFeature.AdjacentUnits,\n UnitDetailsFeature.OutcropType,\n ]),\n onClickItem,\n getItemHref,\n}: {\n unit: UnitLong;\n lithologyFeatures?: Set<LithologyTagFeature>;\n features?: Set<UnitDetailsFeature>;\n onClickItem?: MacrostratItemClickHandler;\n getItemHref?: (item: Lithology | Environment | UnitLong) => string | null;\n}) {\n const lithMap = useMacrostratDefs(\"lithologies\");\n const envMap = useMacrostratDefs(\"environments\");\n\n const environments = enhanceEnvironments(unit.environ, envMap);\n const lithologies = enhanceLithologies(unit.lith ?? [], lithMap);\n\n let outcropField: ReactNode = null;\n if (features.has(UnitDetailsFeature.OutcropType)) {\n // Determine outcrop type\n let outcrop = unit.outcrop;\n if (outcrop == \"both\") {\n outcrop = \"surface and subsurface\";\n }\n outcropField = h(DataField, {\n label: \"Outcrop\",\n value: outcrop,\n });\n }\n\n let thicknessOrHeightRange: ReactNode = null;\n const [thickness, thicknessUnit] = getThickness(unit);\n // Proxy for actual heights in t_pos and b_pos\n if (\n features.has(UnitDetailsFeature.DepthRange) &&\n unit.t_pos != null &&\n unit.b_pos != null &&\n unit.min_thick == unit.max_thick && // We have an actual fixed height\n unit.min_thick != 0 // Not a zero thickness\n ) {\n const label = unit.t_pos < unit.b_pos ? \"Depth\" : \"Height\";\n const u1 = \"m\";\n\n thicknessOrHeightRange = h(DataField, {\n unit: u1,\n label,\n value: formatRange(unit.b_pos, unit.t_pos),\n children: h(\n Parenthetical,\n h(Value, { value: thickness, unit: thicknessUnit }),\n ),\n });\n }\n thicknessOrHeightRange ??= h(DataField, {\n label: \"Thickness\",\n value: thickness,\n unit: thicknessUnit,\n });\n\n /** We are trying to move away from passing the \"color\" parameter in the API */\n let colorSwatch: ReactNode = null;\n if (\"color\" in unit && features.has(UnitDetailsFeature.Color)) {\n const unit1 = unit as UnitLongFull;\n colorSwatch = h(\"div.color-swatch\", {\n style: { backgroundColor: unit1.color },\n });\n }\n\n return h(\"div.unit-details-content\", [\n h.if(features.has(UnitDetailsFeature.ColumnName))(ColumnNameField, {\n col_id: unit.col_id,\n }),\n thicknessOrHeightRange,\n h.if(lithologies != null)(LithologyList, {\n label: \"Lithology\",\n lithologies: lithologies ?? [],\n features: lithologyFeatures,\n }),\n h(AgeField, { unit }, [\n h(Parenthetical, h(Duration, { value: unit.b_age - unit.t_age })),\n h(IntervalProportions, {\n unit,\n onClickItem,\n }),\n ]),\n h.if(environments != null)(EnvironmentsList, {\n environments,\n }),\n h.if(unit.strat_name_id != null)(StratNameField, {\n strat_name_id: unit.strat_name_id,\n }),\n outcropField,\n h.if(features.has(UnitDetailsFeature.AdjacentUnits))([\n h.if(unit.units_above != null)(\n DataField,\n { label: \"Above\" },\n h(UnitIDList, {\n units: unit.units_above,\n showNames: true,\n }),\n ),\n h.if(unit.units_below != null)(\n DataField,\n { label: \"Below\" },\n h(UnitIDList, {\n units: unit.units_below,\n showNames: true,\n }),\n ),\n ]),\n colorSwatch,\n h(ReferencesField, { refs: unit.refs, inline: true }),\n ]);\n}\n\nfunction ColumnNameField({\n col_id,\n showIdentifier = false,\n}: {\n col_id: number;\n showIdentifier?: boolean;\n}) {\n const colData = useMacrostratColumnInfo(col_id);\n let inner: any = h(Identifier, { id: col_id });\n const name = colData?.col_name;\n if (name != null) {\n inner = h(\"span.value\", [\n h(\"span.col-name\", name),\n h.if(showIdentifier)([\" \", h(Parenthetical, inner)]),\n ]);\n }\n\n return h(\n DataField,\n {\n label: \"Column\",\n },\n inner,\n );\n}\n\nexport function ReferencesField({ refs, className = null, ...rest }) {\n if (refs == null || refs.length === 0) {\n return null;\n }\n\n return h(\n DataField,\n {\n label: \"References\",\n className: classNames(\"refs-field\", className),\n ...rest,\n },\n h(BibInfo, { refs }),\n );\n}\n\nfunction getThickness(unit): [string, string | null] {\n let minThickness = unit.min_thick ?? 0;\n let maxThickness = unit.max_thick ?? unit.min_thick ?? 0;\n let _unit = \"m\";\n\n if (minThickness == 0 && maxThickness == 0) {\n return [\"Unknown\", null];\n }\n\n if (minThickness < 0.8 && maxThickness < 1.2) {\n // Convert to cm\n minThickness = minThickness * 100;\n maxThickness = maxThickness * 100;\n _unit = \"cm\";\n } else if (minThickness > 800 && maxThickness > 1200) {\n // Convert to km\n minThickness = minThickness / 1000;\n maxThickness = maxThickness / 1000;\n _unit = \"km\";\n }\n\n if (minThickness == maxThickness) {\n return [formatSignificance(minThickness), _unit];\n }\n\n return [formatRange(minThickness, maxThickness), _unit];\n}\n\nexport function ThicknessField({ unit, label = \"Thickness\" }) {\n const [value, thicknessUnit] = getThickness(unit);\n return h(DataField, {\n label,\n value,\n unit: thicknessUnit,\n });\n}\n\nfunction BibInfo({ refs }) {\n const refData = useMacrostratData(\"refs\", refs);\n\n if (refData == null || refData.length === 0) {\n return null;\n }\n\n if (refData.length == 1) {\n return h(Citation, {\n data: refData[0],\n tag: \"span\",\n key: refData[0].ref_id,\n });\n }\n\n return h(\n \"ul.refs\",\n refData.map((data, i) =>\n h(Citation, { data, tag: \"li\", key: data.ref_id }),\n ),\n );\n}\n\nfunction Citation({ data, tag = \"p\" }) {\n return h(tag, { className: \"citation\" }, [\n h(\"span.authors\", data.author),\n \", \",\n h(\"span.year\", data.pub_year),\n \", \",\n h(\"span.title\", data.ref),\n ]);\n}\n\nfunction enhanceEnvironments(\n environments?: EnvironmentIdentifier[] | null,\n envMap?: Map<number, Environment> | null,\n) {\n return environments?.map((env) => {\n return {\n ...(envMap?.get(env.environ_id) ?? {}),\n ...env,\n };\n });\n}\n\nfunction enhanceLithologies(\n lithologies?: LithologyIdentifier[] | null,\n lithMap?: Map<number, any> | null,\n) {\n return lithologies?.map((lith) => {\n return {\n ...(lithMap?.get(lith.lith_id) ?? {}), // get lithology details\n ...lith, // override with the unit's specific lithology data\n };\n });\n}\n\nfunction UnitIDList({ units, showNames = false }) {\n const unitsMap = useColumnUnitsMap();\n\n const interactionManager = useInteractionManager();\n\n const extUnits: UnitInfo[] = useMemo(() => {\n const u1 = units.filter((d) => d != 0);\n if (showNames) {\n return u1.map((unitID) => {\n const unitData = unitsMap?.get(unitID);\n let name: string | null = null;\n if (unitData != null) {\n name = defaultNameFunction(unitData);\n }\n return {\n unitID,\n colID: unitData?.col_id,\n name,\n };\n });\n } else {\n return u1.map((unitID) => ({ unitID }));\n }\n }, [units, unitsMap]);\n\n if (extUnits.length === 0) {\n return h(\"span.no-units\", \"None\");\n }\n\n return h(\n ItemList,\n { className: \"units-list\" },\n extUnits.map((info) => {\n return h(\n \"span.item\",\n h(UnitIdentifier, {\n ...info,\n ...interactionManager?.interactionPropsForItem({\n unit_id: info.unitID,\n }),\n }),\n );\n }),\n );\n}\n"],"names":["UnitDetailsFeature"],"mappings":";;;;;;;;;;;;;AAqDO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAe,IAAwB;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAAA,CACD;AAAA,EACD;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,QAAM,CAAC,WAAW,WAAW,IAAI,SAAS,KAAK;AAE/C,MAAI,UAAqB;AACzB,MAAI,YAAY,WAAW;AACzB,cAAU,EAAE,UAAU,EAAE,MAAM,MAAM,UAAU,OAAO;AAAA,EACvD,OAAO;AACL,cAAU,EAAE,oBAAoB;AAAA,MAC9B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH;AAEA,MAAI,QAAQ,oBAAoB,IAAI;AAEpC,MAAI,SAAS;AAAA,IAAI;AAAA;AAAA,KAAgC;AAC/C,oBAAgB,EAAE;AAAA,MAChB,EAAE,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAO;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