Skip to content

Commit 8d228c9

Browse files
committed
Merge branch 'section-overlap-test'
* section-overlap-test: Remove some docs code Fixed some stories Split sections by overlap
2 parents 1937d7b + 6dbb837 commit 8d228c9

File tree

9 files changed

+106
-16
lines changed

9 files changed

+106
-16
lines changed

packages/column-views/src/facets/fossils/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ export function PBDBFossilsColumn({ columnID, color = "magenta" }) {
8484

8585
return unitRefData.map((d) => {
8686
const { unit, data } = d;
87-
console.log(unit);
8887
const heightRange = getUnitHeightRange(unit, axisType);
8988

90-
console.log(heightRange);
91-
9289
return {
9390
top_height: heightRange[1],
9491
height: heightRange[0],

packages/column-views/src/prepare-units/helpers.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
createUnitSorter,
88
ensureArray,
99
ensureRealFloat,
10+
PossiblyClippedUnit,
1011
} from "./utils";
12+
import { compareAgeRanges } from "@macrostrat/stratigraphy-utils";
1113

1214
const dt = 0.001;
1315

@@ -111,6 +113,13 @@ export function groupUnitsIntoSections<T extends UnitLong>(
111113
units: T[],
112114
axisType: ColumnAxisType = ColumnAxisType.AGE
113115
): SectionInfo<T>[] {
116+
if (axisType != ColumnAxisType.AGE) {
117+
return groupUnitsIntoSectionByOverlap(units, axisType);
118+
}
119+
120+
/** Group units into sections by section_id.
121+
* This works for large-scale Macrostrat columns, where units are grouped by section_id.
122+
* */
114123
let groups = Array.from(group(units, (d) => d.section_id));
115124
const unitComparator = createUnitSorter(axisType);
116125

@@ -130,6 +139,60 @@ export function groupUnitsIntoSections<T extends UnitLong>(
130139
return groups1;
131140
}
132141

142+
interface WorkingSection {
143+
units: UnitLong[];
144+
// Position or age
145+
heightRange?: [number, number];
146+
}
147+
148+
function groupUnitsIntoSectionByOverlap<T extends UnitLong>(
149+
units: T[],
150+
axisType: ColumnAxisType = ColumnAxisType.AGE
151+
): SectionInfo<T>[] {
152+
/** Group units into sections by overlap.
153+
* This creates "synthetic" sections that correspond to packages bound by scale gaps.
154+
* This is most useful in the height and depth domains, where gaps (e.g., missing core) are
155+
* common.
156+
* */
157+
// Start with each unit as its own "section", and progressively merge...
158+
const sectionList: WorkingSection[] = [];
159+
for (const unit of units) {
160+
// Check if the unit overlaps with any existing section
161+
const heightRange = getUnitHeightRange(unit, axisType);
162+
let section: WorkingSection | undefined = sectionList.find((s) =>
163+
compareAgeRanges(heightRange, s.heightRange)
164+
);
165+
if (section == null) {
166+
// No overlap, create a new section
167+
sectionList.push({
168+
heightRange,
169+
units: [unit],
170+
});
171+
} else {
172+
// Overlap, merge the unit into the section
173+
section.units.push(unit);
174+
// Update the height range
175+
section.heightRange = [
176+
Math.max(section.heightRange[0], heightRange[0]),
177+
Math.min(section.heightRange[1], heightRange[1]),
178+
];
179+
}
180+
}
181+
// We should have a section for each unit, now we can convert to SectionInfo
182+
// Ages have to be really actually ages, not heights
183+
184+
return sectionList.map((section, i) => {
185+
const [b_age, t_age] = getSectionAgeRange(section.units);
186+
return {
187+
// Negative section IDs are used to indicate that these are synthetic sections
188+
section_id: -i,
189+
t_age: t_age,
190+
b_age: b_age,
191+
units: section.units as T[],
192+
};
193+
});
194+
}
195+
133196
export function getSectionAgeRange(units: BaseUnit[]): [number, number] {
134197
/** Get the overall age range of a set of units. */
135198
const t_ages = units.map((d) => d.t_age);

packages/column-views/src/prepare-units/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
PackageLayoutData,
1818
} from "./composite-scale";
1919
import type { SectionInfo } from "./helpers";
20-
import { agesOverlap, unitsOverlap } from "./utils";
20+
import { agesOverlap, getUnitHeightRange, unitsOverlap } from "./utils";
2121

2222
export * from "./utils";
2323
export { preprocessUnits, groupUnitsIntoSections };

packages/column-views/src/prepare-units/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function agesOverlap(
4646
return unitsOverlap(a, b, ColumnAxisType.AGE, tolerance);
4747
}
4848

49-
interface PossiblyClippedUnit extends BaseUnit {
49+
export interface PossiblyClippedUnit extends BaseUnit {
5050
// Internally created clipped positions
5151
t_clip_pos?: number;
5252
b_clip_pos?: number;

packages/column-views/stories/column-ui/standalone.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ export function StandaloneColumn(props: StandaloneColumnProps) {
4141
}
4242

4343
return h("div", [
44-
h(FlexRow, { alignmentBaseline: "baseline" }, [
44+
h(FlexRow, { gap: "2em", alignItems: "baseline" }, [
4545
h("h2", info.col_name),
46-
h(Spacer),
4746
h("code", info.col_id),
4847
]),
4948
h(Column, { ...rest, units }),

packages/column-views/stories/column-ui/story-ui.module.sass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
flex-direction: row
44
justify-content: center
55

6-
.column-container
6+
.column-container, .column-view
77
width: 600px
88

99
.right-column

packages/column-views/stories/facets/carbon-isotopes.stories.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function CarbonIsotopesColumn(props) {
4545
}
4646

4747
export default {
48+
tags: ["!autodocs"],
4849
title: "Column views/Facets/Carbon isotopes",
4950
component: CarbonIsotopesColumn,
5051
};
@@ -97,13 +98,13 @@ export function EdiacaranCompilation(defaultArgs) {
9798
},
9899
})
99100
),
100-
]),
101-
h("div.column-view", [
102-
h(CarbonIsotopesColumn, {
103-
id: columnArgs.col_id,
104-
inProcess: true,
105-
showLabelColumn: false,
106-
}),
101+
h("div.column-view", [
102+
h(CarbonIsotopesColumn, {
103+
id: columnArgs.col_id,
104+
inProcess: true,
105+
showLabelColumn: false,
106+
}),
107+
]),
107108
]),
108109
])
109110
);

packages/column-views/stories/facets/detrital-zircon.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function DetritalZirconColumn(props) {
3333
}
3434

3535
export default {
36+
tags: ["!autodocs"],
3637
title: "Column views/Facets/Detrital zircons",
3738
component: DetritalZirconColumn,
3839
};

packages/column-views/stories/facets/pbdb.stories.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,40 @@ function PBDBFossilsDemoColumn(props) {
3131
export default {
3232
title: "Column views/Facets/Fossil occurrences",
3333
component: PBDBFossilsDemoColumn,
34-
autodocs: false,
34+
tags: ["!autodocs"],
35+
argTypes: {
36+
axisType: {
37+
options: ["age", "depth"],
38+
control: { type: "radio" },
39+
},
40+
},
3541
} as Meta;
3642

3743
export const eODPColumn: Story = {
3844
args: {
3945
id: 5576,
4046
inProcess: true,
4147
axisType: ColumnAxisType.DEPTH,
48+
pixelScale: 5,
49+
allowUnitSelection: true,
50+
showUnitPopover: true,
51+
collapseSmallUnconformities: true,
52+
keyboardNavigation: true,
53+
},
54+
};
55+
56+
export const eODPColumnMoreComplete: Story = {
57+
args: {
58+
id: 5278,
59+
inProcess: true,
60+
axisType: ColumnAxisType.DEPTH,
61+
pixelScale: 5,
62+
allowUnitSelection: true,
63+
showUnitPopover: true,
64+
collapseSmallUnconformities: true,
65+
keyboardNavigation: true,
4266
},
67+
title: "eODP Column (more complete)",
4368
};
4469

4570
export const eODPColumnAgeFramework: Story = {
@@ -49,6 +74,7 @@ export const eODPColumnAgeFramework: Story = {
4974
collapseSmallUnconformities: false,
5075
mergeSections: MergeSectionsMode.OVERLAPPING,
5176
},
77+
title: "eODP Column (with age model applied)",
5278
};
5379

5480
export const ParadoxBasin = {
@@ -70,5 +96,8 @@ export const BighornBasinColored = {
7096
allowUnitSelection: true,
7197
unitComponent: ColoredUnitComponent,
7298
spectraColor: "lightgreen",
99+
showUnitPopover: true,
100+
collapseSmallUnconformities: true,
101+
keyboardNavigation: true,
73102
},
74103
};

0 commit comments

Comments
 (0)