@macrostrat/column-views 3.3.4 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/age-axis.d.ts +3 -3
  3. package/dist/column.cjs +2 -1
  4. package/dist/column.cjs.map +1 -1
  5. package/dist/column.d.ts +3 -3
  6. package/dist/column.js +2 -1
  7. package/dist/column.js.map +1 -1
  8. package/dist/correlation-chart/main.d.ts +1 -1
  9. package/dist/correlation-chart/prepare-data.d.ts +1 -1
  10. package/dist/data-provider/unit-selection.cjs +7 -3
  11. package/dist/data-provider/unit-selection.cjs.map +1 -1
  12. package/dist/data-provider/unit-selection.d.ts +3 -2
  13. package/dist/data-provider/unit-selection.js +7 -3
  14. package/dist/data-provider/unit-selection.js.map +1 -1
  15. package/dist/facets/carbon-isotopes/data-area.d.ts +1 -1
  16. package/dist/facets/carbon-isotopes/data-provider.d.ts +1 -1
  17. package/dist/facets/measurements/base.d.ts +2 -2
  18. package/dist/index.cjs +13 -8
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.js +7 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/maps/column-correlation/state.d.ts +1 -1
  23. package/dist/maps/column-navigation/mapbox/state.d.ts +1 -1
  24. package/dist/maps/column-navigation/svg/data-fetcher.d.ts +1 -1
  25. package/dist/maps/column-navigation/svg/layers.d.ts +3 -3
  26. package/dist/maps/inset-map/index.d.ts +1 -1
  27. package/dist/maps/layers/columns.d.ts +1 -1
  28. package/dist/maps/layers/units.d.ts +1 -1
  29. package/dist/prepare-units/composite-scale.d.ts +1 -1
  30. package/dist/prepare-units/dynamic-scales.d.ts +1 -1
  31. package/dist/prepare-units/helpers.cjs +83 -49
  32. package/dist/prepare-units/helpers.cjs.map +1 -1
  33. package/dist/prepare-units/helpers.d.ts +21 -4
  34. package/dist/prepare-units/helpers.js +84 -50
  35. package/dist/prepare-units/helpers.js.map +1 -1
  36. package/dist/prepare-units/index.cjs.map +1 -1
  37. package/dist/prepare-units/index.d.ts +1 -1
  38. package/dist/prepare-units/index.js.map +1 -1
  39. package/dist/prepare-units/types.d.ts +2 -2
  40. package/dist/prepare-units/utils.d.ts +2 -2
  41. package/dist/section.cjs +1 -2
  42. package/dist/section.cjs.map +1 -1
  43. package/dist/section.d.ts +1 -1
  44. package/dist/section.js +1 -2
  45. package/dist/section.js.map +1 -1
  46. package/dist/unit-details/age-range.cjs.map +1 -1
  47. package/dist/unit-details/age-range.d.ts +2 -1
  48. package/dist/unit-details/age-range.js.map +1 -1
  49. package/dist/unit-details/identifiers.cjs +56 -0
  50. package/dist/unit-details/identifiers.cjs.map +1 -0
  51. package/dist/unit-details/identifiers.d.ts +31 -0
  52. package/dist/unit-details/identifiers.js +54 -0
  53. package/dist/unit-details/identifiers.js.map +1 -0
  54. package/dist/unit-details/index.d.ts +2 -0
  55. package/dist/unit-details/panel.cjs +73 -147
  56. package/dist/unit-details/panel.cjs.map +1 -1
  57. package/dist/unit-details/panel.d.ts +67 -0
  58. package/dist/unit-details/panel.js +19 -92
  59. package/dist/unit-details/panel.js.map +1 -1
  60. package/dist/unit-details/popover.cjs +1 -2
  61. package/dist/unit-details/popover.cjs.map +1 -1
  62. package/dist/unit-details/popover.js +2 -3
  63. package/dist/unit-details/popover.js.map +1 -1
  64. package/dist/unit-details/strat-names.cjs +44 -0
  65. package/dist/unit-details/strat-names.cjs.map +1 -0
  66. package/dist/unit-details/strat-names.d.ts +14 -0
  67. package/dist/unit-details/strat-names.js +42 -0
  68. package/dist/unit-details/strat-names.js.map +1 -0
  69. package/dist/units/boxes.d.ts +2 -2
  70. package/dist/units/colors.d.ts +1 -1
  71. package/dist/units/composite.d.ts +4 -4
  72. package/dist/units/index.cjs +20 -6
  73. package/dist/units/index.cjs.map +1 -1
  74. package/dist/units/index.d.ts +12 -21
  75. package/dist/units/index.js +20 -6
  76. package/dist/units/index.js.map +1 -1
  77. package/dist/units/names.d.ts +3 -3
  78. package/dist/units/resolvers.d.ts +2 -2
  79. package/package.json +19 -19
  80. package/src/column.ts +1 -1
  81. package/src/data-provider/unit-selection.ts +8 -4
  82. package/src/prepare-units/helpers.ts +121 -72
  83. package/src/prepare-units/index.ts +1 -1
  84. package/src/section.ts +0 -1
  85. package/src/unit-details/age-range.ts +1 -0
  86. package/src/unit-details/identifiers.ts +67 -0
  87. package/src/unit-details/index.ts +2 -0
  88. package/src/unit-details/panel.ts +27 -131
  89. package/src/unit-details/popover.ts +2 -7
  90. package/src/unit-details/strat-names.ts +57 -0
  91. package/src/units/index.ts +31 -8
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ const ageRange = require("./unit-details/age-range.cjs");
10
10
  const composite = require("./units/composite.cjs");
11
11
  const columns = require("./maps/layers/columns.cjs");
12
12
  const base = require("./facets/measurements/base.cjs");
13
- const panel = require("./unit-details/panel.cjs");
13
+ const identifiers = require("./unit-details/identifiers.cjs");
14
14
  const layers = require("./maps/column-navigation/svg/layers.cjs");
15
15
  const core = require("./maps/column-correlation/core.cjs");
16
16
  const state = require("./maps/column-correlation/state.cjs");
@@ -23,6 +23,7 @@ const provider = require("./facets/fossils/provider.cjs");
23
23
  const types = require("./prepare-units/types.cjs");
24
24
  const index$4 = require("./maps/inset-map/index.cjs");
25
25
  const isotopesColumn = require("./facets/carbon-isotopes/isotopes-column.cjs");
26
+ const panel = require("./unit-details/panel.cjs");
26
27
  const store = require("./data-provider/store.cjs");
27
28
  const units = require("./maps/layers/units.cjs");
28
29
  const dataProvider = require("./facets/carbon-isotopes/data-provider.cjs");
@@ -30,6 +31,7 @@ const utils = require("./prepare-units/utils.cjs");
30
31
  const index$5 = require("./facets/fossils/index.cjs");
31
32
  const taxonRanges = require("./facets/fossils/taxon-ranges.cjs");
32
33
  const sgp = require("./facets/measurements/sgp.cjs");
34
+ const stratNames = require("./unit-details/strat-names.cjs");
33
35
  const modalPanel = require("./unit-details/modal-panel.cjs");
34
36
  const popover = require("./unit-details/popover.cjs");
35
37
  const unitSelection = require("./data-provider/unit-selection.cjs");
@@ -79,13 +81,9 @@ exports.TruncatedList = base.TruncatedList;
79
81
  exports.groupNotesByPixelDistance = base.groupNotesByPixelDistance;
80
82
  exports.mergeHeightRanges = base.mergeHeightRanges;
81
83
  exports.standardizeMeasurementHeight = base.standardizeMeasurementHeight;
82
- exports.ClickableText = panel.ClickableText;
83
- exports.Identifier = panel.Identifier;
84
- exports.LegendPanelHeader = panel.LegendPanelHeader;
85
- exports.ReferencesField = panel.ReferencesField;
86
- exports.ThicknessField = panel.ThicknessField;
87
- exports.UnitDetailsFeature = panel.UnitDetailsFeature;
88
- exports.UnitDetailsPanel = panel.UnitDetailsPanel;
84
+ exports.ClickableText = identifiers.ClickableText;
85
+ exports.Identifier = identifiers.Identifier;
86
+ exports.UnitIdentifier = identifiers.UnitIdentifier;
89
87
  exports.ColumnCenters = layers.ColumnCenters;
90
88
  exports.ColumnFeatures = layers.ColumnFeatures;
91
89
  exports.ColumnKeyboardNavigation = layers.ColumnKeyboardNavigation;
@@ -113,6 +111,11 @@ exports.HybridScaleType = types.HybridScaleType;
113
111
  exports.InsetMap = index$4.InsetMap;
114
112
  exports.IsotopesColumn = isotopesColumn.IsotopesColumn;
115
113
  exports.IsotopesDataset = isotopesColumn.IsotopesDataset;
114
+ exports.LegendPanelHeader = panel.LegendPanelHeader;
115
+ exports.ReferencesField = panel.ReferencesField;
116
+ exports.ThicknessField = panel.ThicknessField;
117
+ exports.UnitDetailsFeature = panel.UnitDetailsFeature;
118
+ exports.UnitDetailsPanel = panel.UnitDetailsPanel;
116
119
  exports.LithologiesProvider = store.LithologiesProvider;
117
120
  exports.MacrostratColumnDataProvider = store.MacrostratColumnDataProvider;
118
121
  exports.MacrostratColumnProvider = store.MacrostratColumnProvider;
@@ -141,6 +144,7 @@ exports.unitsOverlap = utils.unitsOverlap;
141
144
  exports.PBDBFossilsColumn = index$5.PBDBFossilsColumn;
142
145
  exports.PBDBOccurrencesMatrix = taxonRanges.PBDBOccurrencesMatrix;
143
146
  exports.SGPMeasurementsColumn = sgp.SGPMeasurementsColumn;
147
+ exports.StratNameField = stratNames.StratNameField;
144
148
  exports.UnitDetailsPanelWithNavigation = modalPanel.UnitDetailsPanelWithNavigation;
145
149
  exports.UnitDetailsPopover = popover.UnitDetailsPopover;
146
150
  exports.UnitSelectionPopover = popover.UnitSelectionPopover;
@@ -151,6 +155,7 @@ exports.selectedUnitIDAtom = unitSelection.selectedUnitIDAtom;
151
155
  exports.useAtomOverlayPosition = unitSelection.useAtomOverlayPosition;
152
156
  exports.useColumnRef = unitSelection.useColumnRef;
153
157
  exports.useSelectedUnit = unitSelection.useSelectedUnit;
158
+ exports.useUnitSelection = unitSelection.useUnitSelection;
154
159
  exports.useUnitSelectionDispatch = unitSelection.useUnitSelectionDispatch;
155
160
  exports.useUnitSelectionTarget = unitSelection.useUnitSelectionTarget;
156
161
  exports.flattenLithologies = colors.flattenLithologies;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { AgeField, AgeLabel, AgeRange, Duration, IntervalProportions, getAge, ge
8
8
  import { AnnotatedUnitsColumn, ColumnNotesProvider, CompositeUnitComponent, CompositeUnitsColumn, LabelTrackerProvider, SectionLabelsColumn, TrackedLabeledUnit } from "./units/composite.js";
9
9
  import { BaseColumnsLayer, SelectedColumnOverlay, buildColumnsStyle } from "./maps/layers/columns.js";
10
10
  import { BaseMeasurementsColumn, TruncatedList, groupNotesByPixelDistance, mergeHeightRanges, standardizeMeasurementHeight } from "./facets/measurements/base.js";
11
- import { ClickableText, Identifier, LegendPanelHeader, ReferencesField, ThicknessField, UnitDetailsFeature, UnitDetailsPanel } from "./unit-details/panel.js";
11
+ import { ClickableText, Identifier, UnitIdentifier } from "./unit-details/identifiers.js";
12
12
  import { ColumnCenters, ColumnFeatures, ColumnKeyboardNavigation, Columns, CurrentColumn, MeasurementsLayer } from "./maps/column-navigation/svg/layers.js";
13
13
  import { ColumnCorrelationMap } from "./maps/column-correlation/core.js";
14
14
  import { ColumnCorrelationProvider, useCorrelationMapStore } from "./maps/column-correlation/state.js";
@@ -21,6 +21,7 @@ import { FossilDataType, useFossilData } from "./facets/fossils/provider.js";
21
21
  import { HeightMethod, HybridScaleType } from "./prepare-units/types.js";
22
22
  import { InsetMap } from "./maps/inset-map/index.js";
23
23
  import { IsotopesColumn, IsotopesDataset } from "./facets/carbon-isotopes/isotopes-column.js";
24
+ import { LegendPanelHeader, ReferencesField, ThicknessField, UnitDetailsFeature, UnitDetailsPanel } from "./unit-details/panel.js";
24
25
  import { LithologiesProvider, MacrostratColumnDataProvider, MacrostratColumnProvider, MacrostratColumnStateProvider, UnitSelectionProvider, columnUnitsAtom, columnUnitsMapAtom, scope, useColumnUnitsMap, useCompositeScale, useMacrostratColumnData, useMacrostratUnits } from "./data-provider/store.js";
25
26
  import { MacrostratUnitsOverlay, buildUnitsStyle } from "./maps/layers/units.js";
26
27
  import { MeasurementDataContext, MeasurementDataProvider, useMeasurementData } from "./facets/carbon-isotopes/data-provider.js";
@@ -28,9 +29,10 @@ import { MergeSectionsMode, agesOverlap, createUnitSorter, ensureArray, ensureRe
28
29
  import { PBDBFossilsColumn } from "./facets/fossils/index.js";
29
30
  import { PBDBOccurrencesMatrix } from "./facets/fossils/taxon-ranges.js";
30
31
  import { SGPMeasurementsColumn } from "./facets/measurements/sgp.js";
32
+ import { StratNameField } from "./unit-details/strat-names.js";
31
33
  import { UnitDetailsPanelWithNavigation } from "./unit-details/modal-panel.js";
32
34
  import { UnitDetailsPopover, UnitSelectionPopover } from "./unit-details/popover.js";
33
- import { UnitKeyboardNavigation, UnitSelectionCallbackManager, allowUnitSelectionAtom, selectedUnitIDAtom, useAtomOverlayPosition, useColumnRef, useSelectedUnit, useUnitSelectionDispatch, useUnitSelectionTarget } from "./data-provider/unit-selection.js";
35
+ import { UnitKeyboardNavigation, UnitSelectionCallbackManager, allowUnitSelectionAtom, selectedUnitIDAtom, useAtomOverlayPosition, useColumnRef, useSelectedUnit, useUnitSelection, useUnitSelectionDispatch, useUnitSelectionTarget } from "./data-provider/unit-selection.js";
34
36
  import { flattenLithologies, getMixedColorForData, getMixedUnitColor } from "./units/colors.js";
35
37
  import { parseLineFromString, stringifyLine } from "./correlation-chart/hash-string.js";
36
38
  import { preprocessUnits } from "./prepare-units/helpers.js";
@@ -102,6 +104,7 @@ export {
102
104
  SectionLabelsColumn,
103
105
  SelectedColumnOverlay,
104
106
  SimpleUnitsColumn,
107
+ StratNameField,
105
108
  ThicknessField,
106
109
  TrackedLabeledUnit,
107
110
  TruncatedList,
@@ -110,6 +113,7 @@ export {
110
113
  UnitDetailsPanel,
111
114
  UnitDetailsPanelWithNavigation,
112
115
  UnitDetailsPopover,
116
+ UnitIdentifier,
113
117
  UnitKeyboardNavigation,
114
118
  UnitSelectionCallbackManager,
115
119
  UnitSelectionPopover,
@@ -156,6 +160,7 @@ export {
156
160
  useSelectedUnit,
157
161
  useUnitColor,
158
162
  useUnitColorByEnvironment,
163
+ useUnitSelection,
159
164
  useUnitSelectionDispatch,
160
165
  useUnitSelectionTarget
161
166
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { LineString, Point } from 'geojson';
2
2
  import { StoreApi } from 'zustand';
3
- import { ColumnGeoJSONRecord } from '../../../../api-types/src/index.ts';
3
+ import { ColumnGeoJSONRecord } from '@macrostrat/api-types';
4
4
  import { ReactNode } from 'react';
5
5
  export interface CorrelationMapInput {
6
6
  columns: ColumnGeoJSONRecord[];
@@ -1,5 +1,5 @@
1
1
  import { StoreApi } from 'zustand';
2
- import { ColumnGeoJSONRecordWithID } from '../../../../../api-types/src/index.ts';
2
+ import { ColumnGeoJSONRecordWithID } from '@macrostrat/api-types';
3
3
  import { ReactNode } from 'react';
4
4
  export interface NavigationStore {
5
5
  columns: ColumnGeoJSONRecordWithID[];
@@ -3,4 +3,4 @@ export declare function useColumnFeatures({ status_code, project_id, format, }:
3
3
  status_code?: string;
4
4
  project_id?: number;
5
5
  format?: "geojson" | "topojson" | "geojson_bare";
6
- }): import('../../../../../api-types/src/index.ts').ColumnGeoJSONRecord[] | null;
6
+ }): import('@macrostrat/api-types').ColumnGeoJSONRecord[] | null;
@@ -3,7 +3,7 @@ import { Polygon } from 'geojson';
3
3
  export declare function MeasurementsLayer(props: any): import('react').FunctionComponentElement<{
4
4
  [k: string]: any;
5
5
  geometry?: object;
6
- features?: import('../../../../../svg-map-components/src/index.ts').IFeature[];
6
+ features?: import('@macrostrat/svg-map-components').IFeature[];
7
7
  useCanvas?: boolean;
8
8
  } & {
9
9
  children?: import('react').ReactNode | undefined;
@@ -15,7 +15,7 @@ type ColumnFeature = ExtendedFeature<Polygon, ColumnProps>;
15
15
  declare function ColumnFeatures(props: any): import('react').FunctionComponentElement<{
16
16
  [k: string]: any;
17
17
  geometry?: object;
18
- features?: import('../../../../../svg-map-components/src/index.ts').IFeature[];
18
+ features?: import('@macrostrat/svg-map-components').IFeature[];
19
19
  useCanvas?: boolean;
20
20
  } & {
21
21
  children?: import('react').ReactNode | undefined;
@@ -46,7 +46,7 @@ declare const ColumnCenters: (props: ColumnNavProps) => import('react').Function
46
46
  declare const CurrentColumn: (props: any) => import('react').FunctionComponentElement<{
47
47
  [k: string]: any;
48
48
  geometry?: object;
49
- features?: import('../../../../../svg-map-components/src/index.ts').IFeature[];
49
+ features?: import('@macrostrat/svg-map-components').IFeature[];
50
50
  useCanvas?: boolean;
51
51
  } & {
52
52
  children?: import('react').ReactNode | undefined;
@@ -1,4 +1,4 @@
1
- import { MapViewProps } from '../../../../map-interface/src/index.ts';
1
+ import { MapViewProps } from '@macrostrat/map-interface';
2
2
  import { ReactNode, CSSProperties } from 'react';
3
3
  export interface InsetMapProps extends Omit<MapViewProps, "style"> {
4
4
  controls?: ReactNode;
@@ -1,6 +1,6 @@
1
1
  import { default as GeoJSON, FeatureCollection } from 'geojson';
2
2
  import { GeoJSONFeature } from 'mapbox-gl';
3
- import { StyleFragment } from '../../../../mapbox-react/src/index.ts';
3
+ import { StyleFragment } from '@macrostrat/mapbox-react';
4
4
  export interface ColumnsStyleOptions {
5
5
  color?: string | any[];
6
6
  selectedColor?: string | any[];
@@ -1,4 +1,4 @@
1
- import { StyleFragment } from '../../../../map-styles/src/index.ts';
1
+ import { StyleFragment } from '@macrostrat/map-styles';
2
2
  export interface UnitsOverlayProps {
3
3
  time: number;
4
4
  ageSpan?: number;
@@ -1,4 +1,4 @@
1
- import { UnitLong } from '../../../api-types/src/index.ts';
1
+ import { UnitLong } from '@macrostrat/api-types';
2
2
  import { ExtUnit, SectionInfo, ColumnScaleOptions, CompositeColumnData, CompositeScaleData, PackageLayoutData, PackageScaleInfo } from './types';
3
3
  export declare function buildCompositeScaleInfo(inputScales: PackageScaleInfo[], unconformityHeight: number): CompositeScaleData;
4
4
  export declare function finalizeSectionHeights<T extends UnitLong>(sections: SectionInfoWithScale<T>[], unconformityHeight: number): CompositeColumnData<T>;
@@ -1,4 +1,4 @@
1
- import { UnitLong } from '../../../api-types/src/index.ts';
1
+ import { UnitLong } from '@macrostrat/api-types';
2
2
  import { ApproxHeightScaleOptions, HybridScaleDefinition, HybridScaleOptions, PackageScaleInfo } from './types';
3
3
  interface BaseSurface {
4
4
  index: number;
@@ -5,64 +5,97 @@ const columnComponents = require("@macrostrat/column-components");
5
5
  const utils = require("./utils.cjs");
6
6
  const stratigraphyUtils = require("@macrostrat/stratigraphy-utils");
7
7
  const dt = 1e-3;
8
- function preprocessUnits(section, axisType = columnComponents.ColumnAxisType.AGE) {
9
- let units = section.units;
10
- let divisions = units.map((...args) => extendDivision(...args, axisType));
11
- for (let d of divisions) {
12
- const overlappingUnits = divisions.filter(
13
- (u) => d.overlappingUnits.includes(u.unit_id)
14
- );
15
- const columns = overlappingUnits.map((d2) => d2.column);
16
- if (columns.includes(d.column)) {
17
- let col = 0;
18
- while (columns.includes(col)) {
19
- col++;
20
- }
21
- d.column ??= col;
22
- }
23
- const [b_pos, t_pos] = utils.getUnitHeightRange(d, axisType);
24
- if (axisType == columnComponents.ColumnAxisType.AGE) {
25
- if (b_pos > section.b_age) {
26
- d.b_clip_pos = section.b_age;
27
- }
28
- if (t_pos < section.t_age) {
29
- d.t_clip_pos = section.t_age;
8
+ class UnitGroup {
9
+ units;
10
+ constructor(units) {
11
+ this.units = units;
12
+ }
13
+ get t_age() {
14
+ return Math.min(...this.units.map((d) => d.t_age));
15
+ }
16
+ get b_age() {
17
+ return Math.max(...this.units.map((d) => d.b_age));
18
+ }
19
+ getUnits() {
20
+ return assignColumnsToUnitsWithinOverlappingGroup(this);
21
+ }
22
+ }
23
+ function groupUnitsByMutualOverlap(units, tolerance = dt) {
24
+ const sections = groupUnitsIntoSectionsByOverlap(
25
+ units,
26
+ columnComponents.ColumnAxisType.AGE,
27
+ tolerance
28
+ );
29
+ return sections.map((d) => {
30
+ return new UnitGroup(d.units);
31
+ });
32
+ }
33
+ const sortByAge = utils.createUnitSorter(columnComponents.ColumnAxisType.AGE);
34
+ function assignColumnsToUnitsWithinOverlappingGroup(group2) {
35
+ const sortedUnits = [...group2.units].sort((a, b) => b.b_age - a.b_age);
36
+ const columns = [];
37
+ for (const unit of sortedUnits) {
38
+ let didAddToExistingColumn = false;
39
+ for (const column of columns) {
40
+ const lastUnit = column[column.length - 1];
41
+ if (!utils.unitsOverlap(unit, lastUnit, columnComponents.ColumnAxisType.AGE, dt)) {
42
+ column.push(unit);
43
+ didAddToExistingColumn = true;
44
+ break;
30
45
  }
31
46
  }
32
- if (axisType == columnComponents.ColumnAxisType.DEPTH) {
33
- if (b_pos > section.b_pos) {
34
- d.b_clip_pos = section.b_pos;
35
- }
36
- if (t_pos < section.t_pos) {
37
- d.t_clip_pos = section.t_pos;
38
- }
47
+ if (!didAddToExistingColumn) {
48
+ columns.push([unit]);
39
49
  }
40
50
  }
41
- return divisions;
51
+ const units = columns.flatMap(
52
+ (column, columnIndex) => column.map((unit) => {
53
+ return {
54
+ ...unit,
55
+ overlap: {
56
+ column: columnIndex,
57
+ nColumns: columns.length,
58
+ unitGroup: group2
59
+ }
60
+ };
61
+ })
62
+ );
63
+ return units.toSorted(sortByAge);
42
64
  }
43
- function extendDivision(unit, i, divisions, axisType = columnComponents.ColumnAxisType.AGE) {
65
+ function preprocessUnits(section, axisType = columnComponents.ColumnAxisType.AGE) {
66
+ let units = section.units;
44
67
  let tolerance = 1e-3;
45
68
  if (axisType != columnComponents.ColumnAxisType.AGE) {
46
69
  tolerance = 0.01;
47
70
  }
48
- const overlappingUnits = divisions.filter(
49
- (d) => d.unit_id != unit.unit_id && utils.unitsOverlap(unit, d, axisType, tolerance)
71
+ const unitGroups = groupUnitsByMutualOverlap(units, tolerance);
72
+ const divisions = [];
73
+ for (const group2 of unitGroups) {
74
+ divisions.push(...group2.getUnits());
75
+ }
76
+ return divisions.map(
77
+ (d) => enhanceUnitWithClippingPosition(section, d, axisType)
50
78
  );
51
- const u_pos = utils.getUnitHeightRange(unit, axisType);
52
- const bottomOverlap = overlappingUnits.some((d) => {
53
- const d_pos = utils.getUnitHeightRange(d, axisType);
54
- return d_pos[0] < u_pos[0] + dt;
55
- });
56
- let column = 0;
57
- if (overlappingUnits.length == 1) {
58
- column = 1;
79
+ }
80
+ function enhanceUnitWithClippingPosition(section, d, axisType) {
81
+ const [b_pos, t_pos] = utils.getUnitHeightRange(d, axisType);
82
+ if (axisType == columnComponents.ColumnAxisType.AGE) {
83
+ if (b_pos > section.b_age) {
84
+ d.b_clip_pos = section.b_age;
85
+ }
86
+ if (t_pos < section.t_age) {
87
+ d.t_clip_pos = section.t_age;
88
+ }
59
89
  }
60
- return {
61
- ...unit,
62
- bottomOverlap,
63
- column: unit.column ?? column,
64
- overlappingUnits: overlappingUnits.map((d) => d.unit_id)
65
- };
90
+ if (axisType == columnComponents.ColumnAxisType.DEPTH) {
91
+ if (b_pos > section.b_pos) {
92
+ d.b_clip_pos = section.b_pos;
93
+ }
94
+ if (t_pos < section.t_pos) {
95
+ d.t_clip_pos = section.t_pos;
96
+ }
97
+ }
98
+ return d;
66
99
  }
67
100
  function groupUnitsIntoSectionsBySectionID(units, axisType = columnComponents.ColumnAxisType.AGE) {
68
101
  let groups = Array.from(d3Array.group(units, (d) => d.section_id));
@@ -77,12 +110,12 @@ function groupUnitsIntoSectionsBySectionID(units, axisType = columnComponents.Co
77
110
  groups1.sort(compareSections);
78
111
  return groups1;
79
112
  }
80
- function groupUnitsIntoSectionsByOverlap(units, axisType = columnComponents.ColumnAxisType.AGE) {
113
+ function groupUnitsIntoSectionsByOverlap(units, axisType = columnComponents.ColumnAxisType.AGE, tolerance = dt) {
81
114
  const sectionList = [];
82
115
  for (const unit of units) {
83
116
  const heightRange = utils.getUnitHeightRange(unit, axisType);
84
117
  let section = sectionList.find(
85
- (s) => stratigraphyUtils.compareAgeRanges(heightRange, s.heightRange) !== stratigraphyUtils.AgeRangeRelationship.Disjoint
118
+ (s) => stratigraphyUtils.compareAgeRanges(heightRange, s.heightRange, tolerance) !== stratigraphyUtils.AgeRangeRelationship.Disjoint
86
119
  );
87
120
  if (section == null) {
88
121
  sectionList.push({
@@ -188,6 +221,7 @@ function preprocessSectionUnit(unit) {
188
221
  unit_name
189
222
  };
190
223
  }
224
+ exports.enhanceUnitWithClippingPosition = enhanceUnitWithClippingPosition;
191
225
  exports.getSectionAgeRange = getSectionAgeRange;
192
226
  exports.getSectionPosRange = getSectionPosRange;
193
227
  exports.groupUnitsIntoSectionsByOverlap = groupUnitsIntoSectionsByOverlap;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","sources":["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\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 divisions = units.map((...args) => extendDivision(...args, axisType));\n for (let d of divisions) {\n const overlappingUnits = divisions.filter((u) =>\n d.overlappingUnits.includes(u.unit_id),\n );\n\n // Overlapping columns\n const columns = overlappingUnits.map((d) => d.column);\n\n if (columns.includes(d.column)) {\n let col = 0;\n // Go through columns to find a better index\n while (columns.includes(col)) {\n col++;\n }\n d.column ??= col;\n }\n\n // If unit overlaps the edges of a section, set the clip positions\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 // if (axisType == ColumnAxisType.HEIGHT) {\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 }\n\n return divisions;\n}\n\nfunction extendDivision(\n unit: UnitLong,\n i: number,\n divisions: UnitLong[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit {\n // TODO: make this configurable\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 overlappingUnits = divisions.filter(\n (d) =>\n d.unit_id != unit.unit_id && unitsOverlap(unit, d, axisType, tolerance),\n );\n const u_pos = getUnitHeightRange(unit, axisType);\n const bottomOverlap = overlappingUnits.some((d) => {\n const d_pos = getUnitHeightRange(d, axisType);\n // Check if the unit is below the current unit\n return d_pos[0] < u_pos[0] + dt;\n });\n let column = 0;\n if (overlappingUnits.length == 1) {\n column = 1;\n }\n\n return {\n ...unit,\n bottomOverlap,\n column: unit.column ?? column,\n overlappingUnits: overlappingUnits.map((d) => d.unit_id),\n };\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 UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\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) !==\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":["ColumnAxisType","d","getUnitHeightRange","unitsOverlap","group","createUnitSorter","compareAgeRanges","AgeRangeRelationship","ensureArray","ensureRealFloat"],"mappings":";;;;;;AAgBA,MAAM,KAAK;AAEJ,SAAS,gBACd,SACA,WAA2BA,iBAAAA,eAAe,KAC/B;AAEX,MAAI,QAAQ,QAAQ;AAEpB,MAAI,YAAY,MAAM,IAAI,IAAI,SAAS,eAAe,GAAG,MAAM,QAAQ,CAAC;AACxE,WAAS,KAAK,WAAW;AACvB,UAAM,mBAAmB,UAAU;AAAA,MAAO,CAAC,MACzC,EAAE,iBAAiB,SAAS,EAAE,OAAO;AAAA,IAAA;AAIvC,UAAM,UAAU,iBAAiB,IAAI,CAACC,OAAMA,GAAE,MAAM;AAEpD,QAAI,QAAQ,SAAS,EAAE,MAAM,GAAG;AAC9B,UAAI,MAAM;AAEV,aAAO,QAAQ,SAAS,GAAG,GAAG;AAC5B;AAAA,MACF;AACA,QAAE,WAAW;AAAA,IACf;AAGA,UAAM,CAAC,OAAO,KAAK,IAAIC,MAAAA,mBAAmB,GAAG,QAAQ;AACrD,QAAI,YAAYF,iBAAAA,eAAe,KAAK;AAClC,UAAI,QAAQ,QAAQ,OAAO;A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AAqC;AAEtE,SAAO,mBAAmB,OAAOA,iBAAAA,eAAe,GAAG;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,GAAGQ,MAAAA,YAAY,YAAY,UAAU;AAAA,MACrC,GAAGA,MAAAA,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,cAAUC,MAAAA,gBAAgB,MAAM,CAAC,CAAC;AAClC,cAAUA,MAAAA,gBAAgB,MAAM,CAAC,CAAC;AAClC,gBAAY,MAAM,CAAC;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAOA,MAAAA,gBAAgB,KAAK;AAAA,IAC5B,OAAOA,MAAAA,gBAAgB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAEJ;;;;;;;;"}
1
+ {"version":3,"file":"helpers.cjs","sources":["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n} 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":["ColumnAxisType","createUnitSorter","group","unitsOverlap","getUnitHeightRange","compareAgeRanges","AgeRangeRelationship","ensureArray","ensureRealFloat"],"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,IACAA,iBAAAA,eAAe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,UAAU;AAAA,MACrC,GAAGA,MAAAA,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,cAAUC,MAAAA,gBAAgB,MAAM,CAAC,CAAC;AAClC,cAAUA,MAAAA,gBAAgB,MAAM,CAAC,CAAC;AAClC,gBAAY,MAAM,CAAC;AAAA,EACrB;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAOA,MAAAA,gBAAgB,KAAK;AAAA,IAC5B,OAAOA,MAAAA,gBAAgB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAEJ;;;;;;;;;"}
@@ -1,10 +1,27 @@
1
- import { BaseUnit, UnitLong } from '../../../api-types/src/index.ts';
2
- import { ColumnAxisType } from '../../../column-components/src/index.ts';
3
- import { ExtUnit, SectionInfo } from './types';
1
+ import { BaseUnit, UnitLong } from '@macrostrat/api-types';
2
+ import { ColumnAxisType } from '@macrostrat/column-components';
3
+ import { ExtUnit, SectionInfo, StratigraphicPackage } from './types';
4
+ export type UnitWithDefinedOverlap<T extends BaseUnit> = T & {
5
+ overlap: UnitOverlapInfo<T>;
6
+ };
7
+ type UnitOverlapInfo<T extends BaseUnit> = {
8
+ column: number;
9
+ nColumns: number;
10
+ unitGroup: UnitGroup<T>;
11
+ };
12
+ declare class UnitGroup<T extends BaseUnit> implements StratigraphicPackage {
13
+ units: T[];
14
+ constructor(units: T[]);
15
+ get t_age(): number;
16
+ get b_age(): number;
17
+ getUnits(): UnitWithDefinedOverlap<T>[];
18
+ }
4
19
  export declare function preprocessUnits<T extends UnitLong = UnitLong>(section: SectionInfo<T>, axisType?: ColumnAxisType): ExtUnit[];
20
+ export declare function enhanceUnitWithClippingPosition(section: any, d: any, axisType: any): any;
5
21
  export declare function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(units: T[], axisType?: ColumnAxisType): SectionInfo<T>[];
6
- export declare function groupUnitsIntoSectionsByOverlap<T extends UnitLong>(units: T[], axisType?: ColumnAxisType): SectionInfo<T>[];
22
+ export declare function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(units: T[], axisType?: ColumnAxisType, tolerance?: number): SectionInfo<T>[];
7
23
  export declare function getSectionPosRange(units: BaseUnit[], axisType: ColumnAxisType): [number, number];
8
24
  export declare function getSectionAgeRange(units: BaseUnit[]): [number, number];
9
25
  export declare function mergeOverlappingSections<T extends UnitLong>(sections: SectionInfo<T>[]): SectionInfo<T>[];
10
26
  export declare function preprocessSectionUnit(unit: UnitLong): UnitLong;
27
+ export {};