@macrostrat/column-views 3.12.1 → 3.13.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.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sources":["../../src/prepare-units/helpers.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { group } from \"d3-array\";\nimport { ColumnAxisType } from \"@macrostrat/column-components\";\nimport {\n createUnitSorter,\n ensureArray,\n ensureRealFloat,\n getUnitHeightRange,\n unitsOverlap,\n} from \"./utils\";\nimport {\n AgeRangeRelationship,\n compareAgeRanges,\n mergeAgeRanges,\n MergeMode,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ExtUnit, SectionInfo, StratigraphicPackage } from \"./types\";\n\nconst dt = 0.001;\n\nexport type UnitWithLayoutParameters<T extends BaseUnit> = T & {\n layout: UnitLayoutData<T>;\n};\n\nexport type UnitWithLayoutHints<T extends BaseUnit> = T & {\n layoutHints?: UnitLayoutHints;\n};\n\ninterface UnitLayoutInfo {\n column: number;\n nColumns: number;\n}\n\ntype UnitLayoutHints = Partial<UnitLayoutInfo>;\n\ntype UnitLayoutData<T extends BaseUnit> = UnitLayoutInfo & {\n totalColumns: number;\n unitGroup: UnitGroup<T>;\n};\n\nclass UnitGroup<T extends BaseUnit> implements StratigraphicPackage {\n units: T[];\n axisType: ColumnAxisType;\n\n constructor(units: T[], axisType: ColumnAxisType = ColumnAxisType.AGE) {\n this.units = units;\n this.axisType = axisType;\n }\n\n get t_age(): number {\n return Math.min(...this.units.map((d) => d.t_age));\n }\n\n get b_age(): number {\n return Math.max(...this.units.map((d) => d.b_age));\n }\n\n getUnits(): UnitWithLayoutParameters<T>[] {\n return assignColumnsToUnitsWithinOverlappingGroup(this);\n }\n}\n\nfunction groupUnitsByMutualOverlap<T extends BaseUnit>(\n units: T[],\n tolerance: number = dt,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): UnitGroup<T>[] {\n /** Group units within a section that have mutual overlap. */\n\n const sections = groupUnitsIntoSectionsByOverlap(units, axisType, tolerance);\n\n return sections.map((d) => {\n return new UnitGroup(d.units, axisType);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<UnitWithLayoutHints<T>>,\n): UnitWithLayoutParameters<T>[] {\n /** A relatively naïve function to assign columns to units within a mutually overlapping group.\n * This gets the number of columns that would be needed to accommodate the units in the group.\n * It then assigns columns to units in the group based on the number of columns needed, with\n * lower units further to the left.\n */\n\n const sortedUnits = [...group.units].sort(createUnitSorter(group.axisType));\n\n const columns: T[][] = [];\n\n let nColumns = 1;\n\n for (const unit of sortedUnits) {\n let startIndex = 0;\n let endIndex = 0;\n // Find a column that is not already occupied by an overlapping unit\n const colHint = unit.layoutHints?.column;\n if (colHint != null) {\n columns[colHint] ??= [];\n columns[colHint].push(unit);\n continue;\n }\n let didAddToExistingColumn = false;\n\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, group.axisType, dt)) {\n column.push(unit);\n didAddToExistingColumn = true;\n break;\n }\n }\n if (!didAddToExistingColumn) {\n columns.push([unit]);\n }\n }\n\n const units: UnitWithLayoutParameters<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n layout: {\n column: columnIndex,\n nColumns: 1,\n totalColumns: columns.length,\n unitGroup: group,\n },\n };\n }),\n );\n\n return units.toSorted(sortByAge);\n}\n\nexport function preprocessUnits<T extends UnitLong = UnitLong>(\n section: SectionInfo<T>,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit[] {\n /** Preprocess units to add overlapping units and columns. */\n let units = section.units;\n\n let tolerance = 0.001; // 1 kyr tolerance for age columns\n if (axisType != ColumnAxisType.AGE) {\n tolerance = 0.01; // 1cm tolerance for height/depth columns\n }\n\n const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);\n\n const divisions: any[] = [];\n // Serialize all groups' units to a single array\n for (const group of unitGroups) {\n divisions.push(...group.getUnits());\n }\n\n return divisions.map((d) =>\n enhanceUnitWithClippingPosition(section, d, axisType),\n );\n}\n\nexport function enhanceUnitWithClippingPosition(section, d, axisType) {\n const [b_pos, t_pos] = getUnitHeightRange(d, axisType);\n if (axisType == ColumnAxisType.AGE) {\n if (b_pos > section.b_age) {\n d.b_clip_pos = section.b_age;\n }\n if (t_pos < section.t_age) {\n d.t_clip_pos = section.t_age;\n }\n }\n if (axisType == ColumnAxisType.DEPTH) {\n if (b_pos > section.b_pos) {\n d.b_clip_pos = section.b_pos;\n }\n if (t_pos < section.t_pos) {\n d.t_clip_pos = section.t_pos;\n }\n }\n return d;\n}\n\nexport function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): SectionInfo<T>[] {\n /** Group units into sections by section_id.\n * This works for large-scale Macrostrat columns, where units are grouped by section_id.\n * */\n let groups = Array.from(group(units, (d) => d.section_id));\n const unitComparator = createUnitSorter(axisType);\n\n const groups1 = groups.map(([section_id, sectionUnits]) => {\n const [b_age, t_age] = getSectionAgeRange(sectionUnits);\n const [b_pos, t_pos] = getSectionPosRange(sectionUnits, axisType);\n\n // sort units by position\n sectionUnits.sort(unitComparator);\n return { section_id, t_age, b_age, b_pos, t_pos, units: sectionUnits };\n });\n // Sort sections by increasing top age, then increasing bottom age.\n // Sections have no relative ordinal position other than age...\n const compareSections = createUnitSorter(axisType) as (\n a: StratigraphicPackage,\n b: StratigraphicPackage,\n ) => number;\n groups1.sort(compareSections);\n return groups1;\n}\n\ninterface WorkingSection {\n units: UnitLong[];\n // Position or age\n heightRange: [number, number];\n}\n\nexport function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n tolerance: number = dt,\n): SectionInfo<T>[] {\n /** Group units into sections by overlap.\n * This creates \"synthetic\" sections that correspond to packages bound by scale gaps.\n * This is most useful in the height and depth domains, where gaps (e.g., missing core) are\n * common.\n * */\n // Start with each unit as its own \"section\", and progressively merge...\n const sectionList: WorkingSection[] = [];\n\n const initialSections: WorkingSection[] = units.map((unit) => {\n return {\n units: [unit],\n heightRange: getUnitHeightRange(unit, axisType),\n };\n });\n\n const isOverlapping = (a: WorkingSection, b: WorkingSection) => {\n const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);\n return res !== AgeRangeRelationship.Disjoint;\n };\n\n const mergeSections = (a: WorkingSection, b: WorkingSection) => {\n return {\n units: [...a.units, ...b.units],\n heightRange: mergeAgeRanges(\n [a.heightRange, b.heightRange],\n MergeMode.Outer,\n ),\n };\n };\n\n // Merge overlapping sections progressively until no more merges are possible\n let finalSectionList = initialSections;\n\n while (true) {\n let merged = false;\n const nextSections: WorkingSection[] = [];\n\n for (const section of finalSectionList) {\n if (nextSections.length === 0) {\n nextSections.push(section);\n } else {\n const lastSection = nextSections[nextSections.length - 1];\n if (isOverlapping(section, lastSection)) {\n // Merge with the last section\n nextSections[nextSections.length - 1] = mergeSections(\n lastSection,\n section,\n );\n merged = true;\n } else {\n nextSections.push(section);\n }\n }\n }\n\n finalSectionList = nextSections;\n\n // Stop when no more merges occurred in this pass\n if (!merged) {\n break;\n }\n }\n\n return finalSectionList.map((section, i) => {\n const [b_age, t_age] = getSectionAgeRange(section.units);\n const [b_pos, t_pos] = getSectionPosRange(section.units, axisType);\n return {\n // Negative section IDs are used to indicate that these are synthetic sections\n section_id: -i,\n t_age,\n b_age,\n t_pos,\n b_pos,\n units: section.units as T[],\n };\n });\n}\n\nexport function getSectionPosRange(\n units: BaseUnit[],\n axisType: ColumnAxisType,\n): [number, number] {\n /** Get the overall position range of a set of units. */\n const t_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.t_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.t_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n const b_positions = units.map((d) => {\n switch (axisType) {\n case ColumnAxisType.AGE:\n return d.b_age;\n case ColumnAxisType.DEPTH:\n case ColumnAxisType.HEIGHT:\n case ColumnAxisType.ORDINAL:\n return d.b_pos;\n default:\n throw new Error(`Unknown axis type: ${axisType}`);\n }\n });\n if (axisType == ColumnAxisType.AGE || axisType == ColumnAxisType.DEPTH) {\n return [Math.max(...b_positions), Math.min(...t_positions)];\n } else {\n return [Math.min(...b_positions), Math.max(...t_positions)];\n }\n}\n\nexport function getSectionAgeRange(units: BaseUnit[]): [number, number] {\n /** Get the overall age range of a set of units. */\n return getSectionPosRange(units, ColumnAxisType.AGE);\n}\n\nexport function mergeOverlappingSections<T extends UnitLong>(\n sections: SectionInfo<T>[],\n): SectionInfo<T>[] {\n /** Columns can have sections that overlap in time. Here, we merge overlapping\n * sections into a single section to correctly render gap-bound packages.\n */\n const [firstSection, ...rest] = sections;\n const newSections = [firstSection];\n for (const section of rest) {\n const lastSection = newSections[newSections.length - 1];\n if (\n lastSection.b_age < section.t_age ||\n lastSection.t_age > section.b_age\n ) {\n // No overlap, add the section as normal\n newSections.push(section);\n continue;\n }\n\n // Overlap, merge the sections\n lastSection.section_id = [\n ...ensureArray(lastSection.section_id),\n ...ensureArray(section.section_id),\n ];\n lastSection.units.push(...section.units);\n lastSection.b_age = Math.max(lastSection.b_age, section.b_age);\n lastSection.t_age = Math.min(lastSection.t_age, section.t_age);\n }\n return newSections;\n}\n\nexport function preprocessSectionUnit(unit: UnitLong): UnitLong {\n /** Preprocess a single unit for a \"section\" column type.\n * This mostly handles vagaries of eODP-style columns.\n * */\n\n let b_pos = unit.b_pos;\n let t_pos = unit.t_pos;\n\n let unit_name = unit.unit_name;\n\n // eODP columns sometimes have overlapping core sections, which are encoded in the name field\n // Match eODP section names\n const match = unit.unit_name.match(/^(\\d+(\\.\\d+)?)-(\\d+(\\.\\d+)?): (.+)/);\n\n if (match) {\n // These values should already be set if we've used the show_positions flag\n t_pos ??= ensureRealFloat(match[1]);\n b_pos ??= ensureRealFloat(match[3]);\n unit_name = match[5];\n }\n\n return {\n ...unit,\n b_pos: ensureRealFloat(b_pos),\n t_pos: ensureRealFloat(t_pos),\n unit_name,\n };\n}\n"],"names":["group"],"mappings":";;;;AAkBA,MAAM,KAAK;AAsBX,MAAM,UAA8D;AAAA,EAClE;AAAA,EACA;AAAA,EAEA,YAAY,OAAY,WAA2B,eAAe,KAAK;AACrE,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,WAA0C;AACxC,WAAO,2CAA2C,IAAI;AAAA,EACxD;AACF;AAEA,SAAS,0BACP,OACA,YAAoB,IACpB,WAA2B,eAAe,KAC1B;AAGhB,QAAM,WAAW,gCAAgC,OAAO,UAAU,SAAS;AAE3E,SAAO,SAAS,IAAI,CAAC,MAAM;AACzB,WAAO,IAAI,UAAU,EAAE,OAAO,QAAQ;AAAA,EACxC,CAAC;AACH;AAEA,MAAM,YAAY,iBAAiB,eAAe,GAAG;AAErD,SAAS,2CACPA,QAC+B;AAO/B,QAAM,cAAc,CAAC,GAAGA,OAAM,KAAK,EAAE,KAAK,iBAAiBA,OAAM,QAAQ,CAAC;AAE1E,QAAM,UAAiB,CAAA;AAIvB,aAAW,QAAQ,aAAa;AAI9B,UAAM,UAAU,KAAK,aAAa;AAClC,QAAI,WAAW,MAAM;AACnB,cAAQ,OAAO,MAAM,CAAA;AACrB,cAAQ,OAAO,EAAE,KAAK,IAAI;AAC1B;AAAA,IACF;AACA,QAA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,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 return sections.map((d) => {\n return new UnitGroup(d.units, axisType);\n });\n}\n\nconst sortByAge = createUnitSorter(ColumnAxisType.AGE);\n\nfunction assignColumnsToUnitsWithinOverlappingGroup<T extends BaseUnit>(\n group: UnitGroup<UnitWithLayoutHints<T>>,\n): UnitWithLayoutParameters<T>[] {\n /** A relatively naïve function to assign columns to units within a mutually overlapping group.\n * This gets the number of columns that would be needed to accommodate the units in the group.\n * It then assigns columns to units in the group based on the number of columns needed, with\n * lower units further to the left.\n */\n\n const sortedUnits = [...group.units].sort(createUnitSorter(group.axisType));\n\n const columns: T[][] = [];\n\n let nColumns = 1;\n\n for (const unit of sortedUnits) {\n let startIndex = 0;\n let endIndex = 0;\n // Find a column that is not already occupied by an overlapping unit\n const colHint = unit.layoutHints?.column;\n if (colHint != null) {\n columns[colHint] ??= [];\n columns[colHint].push(unit);\n continue;\n }\n let didAddToExistingColumn = false;\n\n for (const column of columns) {\n const lastUnit = column[column.length - 1];\n if (!unitsOverlap(unit, lastUnit, group.axisType, dt)) {\n column.push(unit);\n didAddToExistingColumn = true;\n break;\n }\n }\n if (!didAddToExistingColumn) {\n columns.push([unit]);\n }\n }\n\n const units: UnitWithLayoutParameters<T>[] = columns.flatMap(\n (column, columnIndex) =>\n column.map((unit) => {\n return {\n ...unit,\n layout: {\n column: columnIndex,\n nColumns: 1,\n totalColumns: columns.length,\n unitGroup: group,\n },\n };\n }),\n );\n\n return units.toSorted(sortByAge);\n}\n\nexport function preprocessUnits<T extends UnitLong = UnitLong>(\n section: SectionInfo<T>,\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): ExtUnit[] {\n /** Preprocess units to add overlapping units and columns. */\n let units = section.units;\n\n let tolerance = 0.001; // 1 kyr tolerance for age columns\n if (axisType != ColumnAxisType.AGE) {\n tolerance = 0.01; // 1cm tolerance for height/depth columns\n }\n\n const unitGroups = groupUnitsByMutualOverlap(units, tolerance, axisType);\n\n const divisions: any[] = [];\n // Serialize all groups' units to a single array\n for (const group of unitGroups) {\n divisions.push(...group.getUnits());\n }\n\n return divisions.map((d) =>\n enhanceUnitWithClippingPosition(section, d, axisType),\n );\n}\n\nexport function enhanceUnitWithClippingPosition(section, d, axisType) {\n const [b_pos, t_pos] = getUnitHeightRange(d, axisType);\n if (axisType == ColumnAxisType.AGE) {\n if (b_pos > section.b_age) {\n d.b_clip_pos = section.b_age;\n }\n if (t_pos < section.t_age) {\n d.t_clip_pos = section.t_age;\n }\n }\n if (axisType == ColumnAxisType.DEPTH) {\n if (b_pos > section.b_pos) {\n d.b_clip_pos = section.b_pos;\n }\n if (t_pos < section.t_pos) {\n d.t_clip_pos = section.t_pos;\n }\n }\n return d;\n}\n\nexport function groupUnitsIntoSectionsBySectionID<T extends UnitLong>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n): SectionInfo<T>[] {\n /** Group units into sections by section_id.\n * This works for large-scale Macrostrat columns, where units are grouped by section_id.\n * */\n let groups = Array.from(group(units, (d) => d.section_id));\n const unitComparator = createUnitSorter(axisType);\n\n const groups1 = groups.map(([section_id, sectionUnits]) => {\n const [b_age, t_age] = getSectionAgeRange(sectionUnits);\n const [b_pos, t_pos] = getSectionPosRange(sectionUnits, axisType);\n\n // sort units by position\n sectionUnits.sort(unitComparator);\n return { section_id, t_age, b_age, b_pos, t_pos, units: sectionUnits };\n });\n // Sort sections by increasing top age, then increasing bottom age.\n // Sections have no relative ordinal position other than age...\n const compareSections = createUnitSorter(axisType) as (\n a: StratigraphicPackage,\n b: StratigraphicPackage,\n ) => number;\n groups1.sort(compareSections);\n return groups1;\n}\n\ninterface WorkingSection {\n units: UnitLong[];\n // Position or age\n heightRange: [number, number];\n}\n\nexport function groupUnitsIntoSectionsByOverlap<T extends BaseUnit>(\n units: T[],\n axisType: ColumnAxisType = ColumnAxisType.AGE,\n tolerance: number = dt,\n): SectionInfo<T>[] {\n /** Group units into sections by overlap.\n * This creates \"synthetic\" sections that correspond to packages bound by scale gaps.\n * This is most useful in the height and depth domains, where gaps (e.g., missing core) are\n * common.\n * */\n // Start with each unit as its own \"section\", and progressively merge...\n const sectionList: WorkingSection[] = [];\n\n const initialSections: WorkingSection[] = units.map((unit) => {\n return {\n units: [unit],\n heightRange: getUnitHeightRange(unit, axisType),\n };\n });\n\n const isOverlapping = (a: WorkingSection, b: WorkingSection) => {\n const res = compareAgeRanges(a.heightRange, b.heightRange, tolerance);\n return res !== AgeRangeRelationship.Disjoint;\n };\n\n const mergeSections = (a: WorkingSection, b: WorkingSection) => {\n return {\n units: [...a.units, ...b.units],\n heightRange: mergeAgeRanges(\n [a.heightRange, b.heightRange],\n MergeMode.Outer,\n ),\n };\n };\n\n // Merge overlapping sections progressively until no more merges are possible\n let finalSectionList = initialSections;\n\n while (true) {\n let merged = false;\n const nextSections: WorkingSection[] = [];\n\n for (const section of finalSectionList) {\n if (nextSections.length === 0) {\n nextSections.push(section);\n } else {\n const lastSection = nextSections[nextSections.length - 1];\n if (isOverlapping(section, lastSection)) {\n // Merge with the last section\n nextSections[nextSections.length - 1] = mergeSections(\n lastSection,\n section,\n );\n merged = true;\n } else {\n nextSections.push(section);\n }\n }\n }\n\n finalSectionList = nextSections;\n\n // Stop when no more merges occurred in this pass\n if (!merged) {\n break;\n }\n }\n\n const s1 = 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 return sortUnits(s1, axisType);\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\nfunction forEachSection(fn, sections, ...args) {\n return sections.map((section) => {\n return {\n ...section,\n units: fn(section.units, ...args),\n };\n });\n}\n\nfunction sortUnits(units: BaseUnit[], axisType: ColumnAxisType) {\n return units.sort((a, b) => {\n if (\n axisType === ColumnAxisType.HEIGHT &&\n b.t_pos !== undefined &&\n a.t_pos !== undefined\n ) {\n return b.t_pos - a.t_pos;\n }\n if (\n axisType === ColumnAxisType.DEPTH &&\n b.t_pos !== undefined &&\n a.t_pos !== undefined\n ) {\n return a.t_pos - b.t_pos;\n }\n if (axisType === ColumnAxisType.AGE) {\n return a.t_age - b.t_age;\n }\n return 0;\n });\n}\n\nexport function mergeOverlappingSections<T extends UnitLong>(\n sections: SectionInfo<T>[],\n): SectionInfo<T>[] {\n /** Columns can have sections that overlap in time. Here, we merge overlapping\n * sections into a single section to correctly render gap-bound packages.\n */\n const [firstSection, ...rest] = sections;\n const newSections = [firstSection];\n for (const section of rest) {\n const lastSection = newSections[newSections.length - 1];\n if (\n lastSection.b_age < section.t_age ||\n lastSection.t_age > section.b_age\n ) {\n // No overlap, add the section as normal\n newSections.push(section);\n continue;\n }\n\n // Overlap, merge the sections\n lastSection.section_id = [\n ...ensureArray(lastSection.section_id),\n ...ensureArray(section.section_id),\n ];\n lastSection.units.push(...section.units);\n lastSection.b_age = Math.max(lastSection.b_age, section.b_age);\n lastSection.t_age = Math.min(lastSection.t_age, section.t_age);\n }\n return newSections;\n}\n\nexport function preprocessSectionUnit(unit: UnitLong): UnitLong {\n /** Preprocess a single unit for a \"section\" column type.\n * This mostly handles vagaries of eODP-style columns.\n * */\n\n let b_pos = unit.b_pos;\n let t_pos = unit.t_pos;\n\n let unit_name = unit.unit_name;\n\n // eODP columns sometimes have overlapping core sections, which are encoded in the name field\n // Match eODP section names\n const match = unit.unit_name.match(/^(\\d+(\\.\\d+)?)-(\\d+(\\.\\d+)?): (.+)/);\n\n if (match) {\n // These values should already be set if we've used the show_positions flag\n t_pos ??= ensureRealFloat(match[1]);\n b_pos ??= ensureRealFloat(match[3]);\n unit_name = match[5];\n }\n\n return {\n ...unit,\n b_pos: ensureRealFloat(b_pos),\n t_pos: ensureRealFloat(t_pos),\n unit_name,\n };\n}\n"],"names":["group"],"mappings":";;;;AAkBA,MAAM,KAAK;AAsBX,MAAM,UAA8D;AAAA,EAClE;AAAA,EACA;AAAA,EAEA,YAAY,OAAY,WAA2B,eAAe,KAAK;AACrE,SAAK,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,WAA0C;AACxC,WAAO,2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BAAgB,KAAK;AAAA,IAC5B,OAAO,gBAAgB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
@@ -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 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 padWindowByPixels,\n resolveWindowScales,\n trimSectionsToWindow,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { type ColumnHeightScaleOptions, SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport * from \"./density\";\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 windowPadding = 0,\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 /** Age columns lay every section out at its full extent and clip to the\n * window at the end (see below), so that a section abutting the window is\n * sized by its own content rather than by the sliver that survives the clip.\n * Hybrid and externally-supplied scales build their own mapping and can't be\n * re-derived that way, so they keep the original clip-then-lay-out path. */\n const clipBeforeLayout =\n axisType != ColumnAxisType.AGE || hybridScale != null || scale != null;\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 /** A bound that isn't set doesn't bound anything. Passing `null` for one is\n * the ordinary way to say \"no window\", and comparing against it as though\n * it were an age would throw every unit out. */\n const window = {\n t_age: t_age ?? -Infinity,\n b_age: b_age ?? Infinity,\n t_pos: t_pos ?? -Infinity,\n b_pos: b_pos ?? Infinity,\n };\n const isWindowed =\n axisType == ColumnAxisType.AGE\n ? t_age != null || b_age != null\n : t_pos != null || b_pos != null;\n\n if (clipBeforeLayout && isWindowed) {\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, window);\n } else {\n return unitsOverlap(d, window as any, axisType);\n }\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 clipBeforeLayout ? 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 /** The window we've been asked to render. Unit density is derived from what\n * it shows (see `findAverageUnitHeight`), so it has to be known before any\n * section is laid out — but nothing is *clipped* to it until the very end.\n */\n const focalWindow: [number, number] | null = clipBeforeLayout\n ? null\n : [b_age ?? Infinity, t_age ?? -Infinity];\n\n const layoutOptions = { ...options, visibleWindow: focalWindow };\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, layoutOptions);\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 layoutOptions,\n );\n }\n\n /** Now that every section is laid out at full extent — with its own density\n * and `minSectionHeight` already settled — apply the rendered window. Padding\n * is spent here, against real pixel heights, so `windowPadding` px of an\n * abutting section is exactly that many pixels.\n */\n if (focalWindow != null && (t_age != null || b_age != null)) {\n // Resolve final densities first (a section the window cuts short is\n // stretched to `minSectionHeight`), then spend the padding budget against\n // them, so a margin is the pixels asked for rather than those pixels times\n // whatever stretch its neighbor happened to need.\n const floor =\n layoutOptions.minSectionHeight ?? layoutOptions.targetUnitHeight ?? 0;\n const scales = resolveWindowScales(sectionsWithScales, focalWindow, floor);\n const natural = (section) =>\n scales.get(section) ?? section.scaleInfo.pixelScale;\n\n\n const scaleFor = natural;\n\n const window =\n windowPadding > 0\n ? padWindowByPixels(\n sectionsWithScales,\n focalWindow,\n windowPadding,\n scaleFor,\n )\n : focalWindow;\n\n sectionsWithScales = trimSectionsToWindow(\n sectionsWithScales,\n window,\n scaleFor,\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","computeSectionHeights","collapseUnconformitiesByPixelHeight","resolveWindowScales","window","padWindowByPixels","trimSectionsToWindow","finalizeSectionHeights","preprocessUnits","units"],"mappings":";;;;;;;AAqCO,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;AAAA,IACA,8BAA8B;AAAA,IAC9B;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,EAAA,IACd;AAEJ,MAAI,eAA8B;AAElC,MAAI,SAAS,MAAM;AAEjB,UAAM,SAAS,MAAM,OAAA;AACrB,QAAI,YAAYC,iBAAAA,eAAe,KAAK;AAClC,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,qBAAe,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACrD,OAAO;AACL,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,qBAAe,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACrD;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EjB,UAAMC,UACJ,gBAAgB,IACZC,eAAAA;AAAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,IAEF;AAEN,yBAAqBC,eAAAA;AAAAA,MACnB;AAAA,MACAF;AAAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAKA,MAAI,EAAE,aAAa,UAAU,UAAA,IAAcG,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 padWindowByPixels,\n resolveWindowScales,\n trimSectionsToWindow,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { type ColumnHeightScaleOptions, SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport * from \"./density\";\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 windowPadding = 0,\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 /** Age columns lay every section out at its full extent and clip to the\n * window at the end (see below), so that a section abutting the window is\n * sized by its own content rather than by the sliver that survives the clip.\n * Hybrid and externally-supplied scales build their own mapping and can't be\n * re-derived that way, so they keep the original clip-then-lay-out path. */\n const clipBeforeLayout =\n axisType != ColumnAxisType.AGE || hybridScale != null || scale != null;\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 /** A bound that isn't set doesn't bound anything. Passing `null` for one is\n * the ordinary way to say \"no window\", and comparing against it as though\n * it were an age would throw every unit out. */\n const window = {\n t_age: t_age ?? -Infinity,\n b_age: b_age ?? Infinity,\n t_pos: t_pos ?? -Infinity,\n b_pos: b_pos ?? Infinity,\n };\n const isWindowed =\n axisType == ColumnAxisType.AGE\n ? t_age != null || b_age != null\n : t_pos != null || b_pos != null;\n\n if (clipBeforeLayout && isWindowed) {\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, window);\n } else {\n return unitsOverlap(d, window as any, axisType);\n }\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 clipBeforeLayout ? 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 /** The window we've been asked to render. Unit density is derived from what\n * it shows (see `findAverageUnitHeight`), so it has to be known before any\n * section is laid out — but nothing is *clipped* to it until the very end.\n */\n const focalWindow: [number, number] | null = clipBeforeLayout\n ? null\n : [b_age ?? Infinity, t_age ?? -Infinity];\n\n const layoutOptions = { ...options, visibleWindow: focalWindow };\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, layoutOptions);\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 layoutOptions,\n );\n }\n\n /** Now that every section is laid out at full extent — with its own density\n * and `minSectionHeight` already settled — apply the rendered window. Padding\n * is spent here, against real pixel heights, so `windowPadding` px of an\n * abutting section is exactly that many pixels.\n */\n if (focalWindow != null && (t_age != null || b_age != null)) {\n // Resolve final densities first (a section the window cuts short is\n // stretched to `minSectionHeight`), then spend the padding budget against\n // them, so a margin is the pixels asked for rather than those pixels times\n // whatever stretch its neighbor happened to need.\n const floor =\n layoutOptions.minSectionHeight ?? layoutOptions.targetUnitHeight ?? 0;\n const scales = resolveWindowScales(sectionsWithScales, focalWindow, floor);\n const natural = (section) =>\n scales.get(section) ?? section.scaleInfo.pixelScale;\n\n const scaleFor = natural;\n\n const window =\n windowPadding > 0\n ? padWindowByPixels(\n sectionsWithScales,\n focalWindow,\n windowPadding,\n scaleFor,\n )\n : focalWindow;\n\n sectionsWithScales = trimSectionsToWindow(\n sectionsWithScales,\n window,\n scaleFor,\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","computeSectionHeights","collapseUnconformitiesByPixelHeight","resolveWindowScales","window","padWindowByPixels","trimSectionsToWindow","finalizeSectionHeights","preprocessUnits","units"],"mappings":";;;;;;;AAqCO,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,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AAEL,SAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,gBAAgB;AAAA,IAC7B,UAAU;AAAA,EAAA;AAEd;;;;;;;;;;;;"}
@@ -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 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 padWindowByPixels,\n resolveWindowScales,\n trimSectionsToWindow,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { type ColumnHeightScaleOptions, SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport * from \"./density\";\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 windowPadding = 0,\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 /** Age columns lay every section out at its full extent and clip to the\n * window at the end (see below), so that a section abutting the window is\n * sized by its own content rather than by the sliver that survives the clip.\n * Hybrid and externally-supplied scales build their own mapping and can't be\n * re-derived that way, so they keep the original clip-then-lay-out path. */\n const clipBeforeLayout =\n axisType != ColumnAxisType.AGE || hybridScale != null || scale != null;\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 /** A bound that isn't set doesn't bound anything. Passing `null` for one is\n * the ordinary way to say \"no window\", and comparing against it as though\n * it were an age would throw every unit out. */\n const window = {\n t_age: t_age ?? -Infinity,\n b_age: b_age ?? Infinity,\n t_pos: t_pos ?? -Infinity,\n b_pos: b_pos ?? Infinity,\n };\n const isWindowed =\n axisType == ColumnAxisType.AGE\n ? t_age != null || b_age != null\n : t_pos != null || b_pos != null;\n\n if (clipBeforeLayout && isWindowed) {\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, window);\n } else {\n return unitsOverlap(d, window as any, axisType);\n }\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 clipBeforeLayout ? 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 /** The window we've been asked to render. Unit density is derived from what\n * it shows (see `findAverageUnitHeight`), so it has to be known before any\n * section is laid out — but nothing is *clipped* to it until the very end.\n */\n const focalWindow: [number, number] | null = clipBeforeLayout\n ? null\n : [b_age ?? Infinity, t_age ?? -Infinity];\n\n const layoutOptions = { ...options, visibleWindow: focalWindow };\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, layoutOptions);\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 layoutOptions,\n );\n }\n\n /** Now that every section is laid out at full extent — with its own density\n * and `minSectionHeight` already settled — apply the rendered window. Padding\n * is spent here, against real pixel heights, so `windowPadding` px of an\n * abutting section is exactly that many pixels.\n */\n if (focalWindow != null && (t_age != null || b_age != null)) {\n // Resolve final densities first (a section the window cuts short is\n // stretched to `minSectionHeight`), then spend the padding budget against\n // them, so a margin is the pixels asked for rather than those pixels times\n // whatever stretch its neighbor happened to need.\n const floor =\n layoutOptions.minSectionHeight ?? layoutOptions.targetUnitHeight ?? 0;\n const scales = resolveWindowScales(sectionsWithScales, focalWindow, floor);\n const natural = (section) =>\n scales.get(section) ?? section.scaleInfo.pixelScale;\n\n\n const scaleFor = natural;\n\n const window =\n windowPadding > 0\n ? padWindowByPixels(\n sectionsWithScales,\n focalWindow,\n windowPadding,\n scaleFor,\n )\n : focalWindow;\n\n sectionsWithScales = trimSectionsToWindow(\n sectionsWithScales,\n window,\n scaleFor,\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":["window","units"],"mappings":";;;;;;AAqCO,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,IACA,gBAAgB;AAAA,EAAA,IACd;AAEJ,MAAI,eAA8B;AAElC,MAAI,SAAS,MAAM;AAEjB,UAAM,SAAS,MAAM,OAAA;AACrB,QAAI,YAAY,eAAe,KAAK;AAClC,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,qBAAe,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACrD,OAAO;AACL,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,qBAAe,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACrD;AAAA,EACF;AAOA,QAAM,mBACJ,YAAY,eAAe,OAAO,eAAe,QAAQ,SAAS;AAIpE,MAAI,SAAS,MAAM,IAAI,qBAAqB;AAK5C,QAAM,SAAS;AAAA,IACb,OAAO,SAAS;AAAA,IAChB,OAAO,SAAS;AAAA,IAChB,OAAO,SAAS;AAAA,IAChB,OAAO,SAAS;AAAA,EAAA;AAEl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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.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 padWindowByPixels,\n resolveWindowScales,\n trimSectionsToWindow,\n type CompositeColumnScale,\n} from \"./composite-scale\";\nimport {\n agesOverlap,\n MergeSectionsMode,\n PrepareColumnOptions,\n PreparedColumnData,\n unitsOverlap,\n} from \"./utils\";\nimport { type ColumnHeightScaleOptions, SectionInfo } from \"./types\";\n\nexport * from \"./utils\";\nexport * from \"./types\";\nexport * from \"./density\";\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 windowPadding = 0,\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 /** Age columns lay every section out at its full extent and clip to the\n * window at the end (see below), so that a section abutting the window is\n * sized by its own content rather than by the sliver that survives the clip.\n * Hybrid and externally-supplied scales build their own mapping and can't be\n * re-derived that way, so they keep the original clip-then-lay-out path. */\n const clipBeforeLayout =\n axisType != ColumnAxisType.AGE || hybridScale != null || scale != null;\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 /** A bound that isn't set doesn't bound anything. Passing `null` for one is\n * the ordinary way to say \"no window\", and comparing against it as though\n * it were an age would throw every unit out. */\n const window = {\n t_age: t_age ?? -Infinity,\n b_age: b_age ?? Infinity,\n t_pos: t_pos ?? -Infinity,\n b_pos: b_pos ?? Infinity,\n };\n const isWindowed =\n axisType == ColumnAxisType.AGE\n ? t_age != null || b_age != null\n : t_pos != null || b_pos != null;\n\n if (clipBeforeLayout && isWindowed) {\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, window);\n } else {\n return unitsOverlap(d, window as any, axisType);\n }\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 clipBeforeLayout ? 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 /** The window we've been asked to render. Unit density is derived from what\n * it shows (see `findAverageUnitHeight`), so it has to be known before any\n * section is laid out — but nothing is *clipped* to it until the very end.\n */\n const focalWindow: [number, number] | null = clipBeforeLayout\n ? null\n : [b_age ?? Infinity, t_age ?? -Infinity];\n\n const layoutOptions = { ...options, visibleWindow: focalWindow };\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, layoutOptions);\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 layoutOptions,\n );\n }\n\n /** Now that every section is laid out at full extent — with its own density\n * and `minSectionHeight` already settled — apply the rendered window. Padding\n * is spent here, against real pixel heights, so `windowPadding` px of an\n * abutting section is exactly that many pixels.\n */\n if (focalWindow != null && (t_age != null || b_age != null)) {\n // Resolve final densities first (a section the window cuts short is\n // stretched to `minSectionHeight`), then spend the padding budget against\n // them, so a margin is the pixels asked for rather than those pixels times\n // whatever stretch its neighbor happened to need.\n const floor =\n layoutOptions.minSectionHeight ?? layoutOptions.targetUnitHeight ?? 0;\n const scales = resolveWindowScales(sectionsWithScales, focalWindow, floor);\n const natural = (section) =>\n scales.get(section) ?? section.scaleInfo.pixelScale;\n\n const scaleFor = natural;\n\n const window =\n windowPadding > 0\n ? padWindowByPixels(\n sectionsWithScales,\n focalWindow,\n windowPadding,\n scaleFor,\n )\n : focalWindow;\n\n sectionsWithScales = trimSectionsToWindow(\n sectionsWithScales,\n window,\n scaleFor,\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":["window","units"],"mappings":";;;;;;AAqCO,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,IACA,gBAAgB;AAAA,EAAA,IACd;AAEJ,MAAI,eAA8B;AAElC,MAAI,SAAS,MAAM;AAEjB,UAAM,SAAS,MAAM,OAAA;AACrB,QAAI,YAAY,eAAe,KAAK;AAClC,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,qBAAe,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACrD,OAAO;AACL,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,UAAI,SAAS,KAAM,SAAQ,KAAK,IAAI,GAAG,MAAM;AAC7C,qBAAe,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACrD;AAAA,EACF;AAOA,QAAM,mBACJ,YAAY,eAAe,OAAO,eAAe,QAAQ,SAAS;AAIpE,MAAI,SAAS,MAAM,IAAI,qBAA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AC,YAAY;AAC7C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,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;"}
@@ -324,7 +324,7 @@ function ThicknessField({ unit, label = "Thickness" }) {
324
324
  });
325
325
  }
326
326
  function BibInfo({ refs }) {
327
- const refData = dataProvider.useMacrostratData("refs", refs);
327
+ const refData = dataProvider.useMacrostratData("refs", refs)?.filter((d) => d != null);
328
328
  if (refData == null || refData.length === 0) {
329
329
  return null;
330
330
  }
@@ -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 {\n Identifier,\n UnitIdentifier,\n UnitInfo,\n} from \"@macrostrat/data-components\";\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 | Environment | UnitLong | Interval | { 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":";;;;;;;;;;;;;;;;AAyDO,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,MA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OA,aAAAA;AAAAA,IACL2B,eAAAA;AAAAA,IACA,EAAE,WAAW,aAAA;AAAA,IACb,SAAS,IAAI,CAAC,SAAS;AACrB,aAAO3B,aAAAA;AAAAA,QACL;AAAA,QACAA,aAAAA,QAAE4B,eAAAA,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 {\n Identifier,\n UnitIdentifier,\n UnitInfo,\n} from \"@macrostrat/data-components\";\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 | Environment | UnitLong | Interval | { 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 // A reference the server doesn't know comes back as a hole, not a record\n const refData = useMacrostratData(\"refs\", refs)?.filter((d) => d != null);\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":";;;;;;;;;;;;;;;;AAyDO,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,W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AG,oBAAoB,wBAAwB;AAAA,YAC7C,SAAS,KAAK;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IAEL,CAAC;AAAA,EAAA;AAEL;;;;;;"}
@@ -320,7 +320,7 @@ function ThicknessField({ unit, label = "Thickness" }) {
320
320
  });
321
321
  }
322
322
  function BibInfo({ refs }) {
323
- const refData = useMacrostratData("refs", refs);
323
+ const refData = useMacrostratData("refs", refs)?.filter((d) => d != null);
324
324
  if (refData == null || refData.length === 0) {
325
325
  return null;
326
326
  }
@@ -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 {\n Identifier,\n UnitIdentifier,\n UnitInfo,\n} from \"@macrostrat/data-components\";\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 | Environment | UnitLong | Interval | { 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":";;;;;;;;;;;;AAyDO,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;AAAA,QACP,SAAS;AAAA,QACT,KAAK;AAAA,QACL,WAAW,WAAW,oBAAoB,EAAE,SAAS,aAAa;AAAA,QAClE,QAAQ,KAAK;AACX,sBAAY,CAAC,SAAS;AACtB,cAAI,gBAAA;AAAA,QACN;AAAA,MAAA,CACD;AAAA,MACD;AAAA,IAAA,CACD;AAAA,EACH;AAEA,QAAM,OAAO,EAAE,0BAA0B,EAAE,aAAa;AAAA,IACtD,EAAE,mBAAmB;AAAA,MACnB;AAAA,MACA;AAAA,MACA,IAAI,KAAK;AAAA,MACT;AAAA,MACA;AAAA,IAAA,CACD;AAAA,IAC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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 {\n Identifier,\n UnitIdentifier,\n UnitInfo,\n} from \"@macrostrat/data-components\";\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 | Environment | UnitLong | Interval | { 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 // A reference the server doesn't know comes back as a hole, not a record\n const refData = useMacrostratData(\"refs\", refs)?.filter((d) => d != null);\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":";;;;;;;;;;;;AAyDO,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;AAAA,QACP,SAAS;AAAA,QACT,KAAK;AAAA,QACL,WAAW,WAAW,oBAAoB,EAAE,SAAS,aAAa;AAAA,QAClE,QAAQ,KAAK;AACX,sBAAY,CAAC,SAAS;AACtB,cAAI,gBAAA;AAAA,QACN;AAAA,MAAA,CACD;AAAA,MACD;AAAA,IAAA,CACD;AAAA,EACH;AAEA,QAAM,OAAO,EAAE,0BAA0B,EAAE,aAAa;AAAA,IACtD,EAAE,mBAAmB;AAAA,MACnB;AAAA,MACA;AAAA,MACA,IAAI,KAAK;AAAA,MACT;AAAA,MACA;AAAA,IAAA,CACD;AAAA,IACD,EAAE,mCAAmC,OAAO;AAAA,EAAA,CAC7C;AAGD,QAAM,sBA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,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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@macrostrat/column-views",
3
- "version": "3.12.1",
3
+ "version": "3.13.0",
4
4
  "description": "Data views for Macrostrat stratigraphic columns",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,8 +49,8 @@
49
49
  "@macrostrat/api-types": "^1.4.0",
50
50
  "@macrostrat/color-utils": "^1.2.2",
51
51
  "@macrostrat/column-components": "^2.2.0",
52
- "@macrostrat/data-components": "^1.7.0",
53
- "@macrostrat/data-provider": "^1.4.0",
52
+ "@macrostrat/data-components": "^1.8.0",
53
+ "@macrostrat/data-provider": "^1.4.1",
54
54
  "@macrostrat/hyper": "^3.1.1",
55
55
  "@macrostrat/map-views": "^1.1.1",
56
56
  "@macrostrat/scoped-store": "^1.1.0",
package/src/column.ts CHANGED
@@ -65,7 +65,13 @@ interface BaseColumnProps extends Omit<
65
65
  keyboardNavigation?: boolean;
66
66
  showLabels?: boolean;
67
67
  maxInternalColumns?: number;
68
+ /** Draw the age (or height) axis beside the column (default). Off for a
69
+ * column whose coordinates aren't a measure — one laid out by surface order
70
+ * alone, say. */
71
+ showAgeAxis?: boolean;
68
72
  // Timescale properties
73
+ /** Draw the timescale. Defaults to on for an age column; an explicit value
74
+ * wins over `timescaleLevels` / `timescales`, which otherwise turn it on. */
69
75
  showTimescale?: boolean;
70
76
  timescaleLevels?: number | [number, number];
71
77
  /** Regional or project timescales drawn as extra columns beside the
@@ -169,6 +175,22 @@ export function Column(props: ColumnProps) {
169
175
  _axisType = ColumnAxisType.AGE;
170
176
  }
171
177
 
178
+ let _sectionOptions = sectionOptions;
179
+ if (_sectionOptions == undefined) {
180
+ // Build our own section options function based on targetUnitHeight
181
+ _sectionOptions = (ctx) => {
182
+ /** Scale targetUnitHeight by the number of units, so that a section with just a few units
183
+ * is drawn taller than a section with many units.
184
+ */
185
+ const n = ctx.units.length;
186
+ const expansionFactor = 8 / Math.min(Math.max(n, 1), 8);
187
+
188
+ return {
189
+ targetUnitHeight: targetUnitHeight * expansionFactor,
190
+ };
191
+ };
192
+ }
193
+
172
194
  const { sections, units, totalHeight } = usePreparedColumnUnits(rawUnits, {
173
195
  axisType: _axisType,
174
196
  t_age,
@@ -177,7 +199,7 @@ export function Column(props: ColumnProps) {
177
199
  b_pos,
178
200
  mergeSections,
179
201
  targetUnitHeight,
180
- sectionOptions,
202
+ sectionOptions: _sectionOptions,
181
203
  unconformityHeight,
182
204
  pixelScale,
183
205
  pixelsPerMyr,
@@ -260,6 +282,7 @@ function ColumnInner(props: ColumnInnerProps) {
260
282
  onClickTimescaleInterval,
261
283
  timescaleIntervalStyle,
262
284
  ageAxisComponent = CompositeAgeAxis,
285
+ showAgeAxis = true,
263
286
  } = props;
264
287
 
265
288
  const { axisType } = useMacrostratColumnData();
@@ -288,11 +311,9 @@ function ColumnInner(props: ColumnInnerProps) {
288
311
  showLabelColumn = false;
289
312
  }
290
313
 
291
- let _showTimescale = showTimescale ?? true;
292
- if (timescaleLevels != null || timescales != null) {
293
- _showTimescale = true;
294
- }
295
- _showTimescale = axisType == ColumnAxisType.AGE && _showTimescale;
314
+ // On unless turned off outright: passing levels or timescales no longer
315
+ // overrides an explicit `false`
316
+ const _showTimescale = axisType == ColumnAxisType.AGE && (showTimescale ?? true);
296
317
 
297
318
  return h(
298
319
  ColumnContainer,
@@ -302,7 +323,7 @@ function ColumnInner(props: ColumnInnerProps) {
302
323
  className,
303
324
  },
304
325
  h("div.column", { ref: columnRef }, [
305
- h(ageAxisComponent),
326
+ h.if(showAgeAxis)(ageAxisComponent),
306
327
  h.if(_showTimescale)(CompositeTimescale, {
307
328
  levels: timescaleLevels,
308
329
  additionalTimescales,