@macrostrat/column-views 3.6.1 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/column-views.css +118 -89
  3. package/dist/column.cjs +1 -2
  4. package/dist/column.cjs.map +1 -1
  5. package/dist/column.js +1 -2
  6. package/dist/column.js.map +1 -1
  7. package/dist/column.module.sass.cjs +15 -15
  8. package/dist/column.module.sass.js +15 -15
  9. package/dist/correlation-chart/main.cjs +136 -34
  10. package/dist/correlation-chart/main.cjs.map +1 -1
  11. package/dist/correlation-chart/main.d.ts +33 -2
  12. package/dist/correlation-chart/main.js +118 -15
  13. package/dist/correlation-chart/main.js.map +1 -1
  14. package/dist/correlation-chart/main.module.sass.cjs +23 -20
  15. package/dist/correlation-chart/main.module.sass.cjs.map +1 -1
  16. package/dist/correlation-chart/main.module.sass.js +23 -20
  17. package/dist/correlation-chart/main.module.sass.js.map +1 -1
  18. package/dist/correlation-chart/prepare-data.cjs +0 -1
  19. package/dist/correlation-chart/prepare-data.cjs.map +1 -1
  20. package/dist/correlation-chart/prepare-data.js +0 -1
  21. package/dist/correlation-chart/prepare-data.js.map +1 -1
  22. package/dist/data-provider/unit-selection.cjs +4 -1
  23. package/dist/data-provider/unit-selection.cjs.map +1 -1
  24. package/dist/data-provider/unit-selection.d.ts +1 -1
  25. package/dist/data-provider/unit-selection.js +4 -1
  26. package/dist/data-provider/unit-selection.js.map +1 -1
  27. package/dist/index.cjs +14 -4
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +3 -2
  30. package/dist/maps/column-correlation/core.cjs +127 -6
  31. package/dist/maps/column-correlation/core.cjs.map +1 -1
  32. package/dist/maps/column-correlation/core.js +128 -7
  33. package/dist/maps/column-correlation/core.js.map +1 -1
  34. package/dist/maps/column-correlation/state.cjs +63 -2
  35. package/dist/maps/column-correlation/state.cjs.map +1 -1
  36. package/dist/maps/column-correlation/state.d.ts +31 -1
  37. package/dist/maps/column-correlation/state.js +63 -2
  38. package/dist/maps/column-correlation/state.js.map +1 -1
  39. package/dist/maps/layers/columns.cjs +5 -1
  40. package/dist/maps/layers/columns.cjs.map +1 -1
  41. package/dist/maps/layers/columns.js +5 -1
  42. package/dist/maps/layers/columns.js.map +1 -1
  43. package/dist/section.cjs +8 -2
  44. package/dist/section.cjs.map +1 -1
  45. package/dist/section.d.ts +2 -0
  46. package/dist/section.js +8 -2
  47. package/dist/section.js.map +1 -1
  48. package/dist/unit-details/age-range.cjs +2 -1
  49. package/dist/unit-details/age-range.cjs.map +1 -1
  50. package/dist/unit-details/age-range.js +2 -1
  51. package/dist/unit-details/age-range.js.map +1 -1
  52. package/dist/unit-details/index.d.ts +1 -1
  53. package/dist/unit-details/panel.cjs +2 -3
  54. package/dist/unit-details/panel.cjs.map +1 -1
  55. package/dist/unit-details/panel.js +1 -2
  56. package/dist/unit-details/panel.js.map +1 -1
  57. package/dist/unit-details/panel.module.sass.cjs +18 -22
  58. package/dist/unit-details/panel.module.sass.cjs.map +1 -1
  59. package/dist/unit-details/panel.module.sass.js +18 -22
  60. package/dist/unit-details/panel.module.sass.js.map +1 -1
  61. package/dist/unit-details/strat-names.cjs +1 -2
  62. package/dist/unit-details/strat-names.cjs.map +1 -1
  63. package/dist/unit-details/strat-names.js +1 -2
  64. package/dist/unit-details/strat-names.js.map +1 -1
  65. package/dist/units/boxes.cjs +2 -1
  66. package/dist/units/boxes.cjs.map +1 -1
  67. package/dist/units/boxes.js +2 -1
  68. package/dist/units/boxes.js.map +1 -1
  69. package/package.json +7 -7
  70. package/src/column.module.sass +6 -0
  71. package/src/correlation-chart/main.module.sass +46 -2
  72. package/src/correlation-chart/main.ts +180 -9
  73. package/src/correlation-chart/prepare-data.ts +0 -1
  74. package/src/data-provider/unit-selection.ts +13 -2
  75. package/src/maps/column-correlation/column-correlation-map.stories.ts +12 -0
  76. package/src/maps/column-correlation/core.ts +155 -9
  77. package/src/maps/column-correlation/state.ts +110 -2
  78. package/src/maps/layers/columns.ts +7 -1
  79. package/src/section.ts +9 -1
  80. package/src/unit-details/age-range.ts +3 -1
  81. package/src/unit-details/index.ts +7 -1
  82. package/src/unit-details/panel.module.sass +0 -8
  83. package/src/unit-details/panel.ts +6 -6
  84. package/src/unit-details/strat-names.ts +1 -1
  85. package/src/units/boxes.ts +4 -2
  86. package/dist/correlation-chart/stories/utils.d.ts +0 -6
  87. package/dist/unit-details/identifiers.cjs +0 -56
  88. package/dist/unit-details/identifiers.cjs.map +0 -1
  89. package/dist/unit-details/identifiers.d.ts +0 -31
  90. package/dist/unit-details/identifiers.js +0 -54
  91. package/dist/unit-details/identifiers.js.map +0 -1
  92. package/src/correlation-chart/stories/correlation-chart.stories.ts +0 -228
  93. package/src/correlation-chart/stories/namibia-correlation.stories.ts +0 -151
  94. package/src/correlation-chart/stories/stories.module.sass +0 -18
  95. package/src/correlation-chart/stories/utils.ts +0 -24
  96. package/src/unit-details/identifiers.ts +0 -67
@@ -1 +1 @@
1
- {"version":3,"file":"unit-selection.cjs","sources":["../../src/data-provider/unit-selection.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { useKeyHandler } from \"@macrostrat/ui-components\";\nimport { useEffect, useRef, useCallback, useMemo } from \"react\";\nimport type { RectBounds, IUnit } from \"../units/types\";\nimport { atom } from \"jotai\";\nimport { scope, columnUnitsMapAtom } from \"./store\";\nimport {\n AgeRangeQuantifiedDifference,\n ageRangeQuantifiedDifference,\n AgeRangeRelationship,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ColumnData } from \"@macrostrat/data-provider\";\n\ntype UnitSelectDispatch = (\n unit: number | BaseUnit | null,\n target: HTMLElement | null,\n) => void;\n\nexport function useUnitSelection() {\n return scope.use(selectedUnitAtom);\n}\n\nexport function useUnitSelectionDispatch(): UnitSelectDispatch {\n return scope.useSetAtom(selectedUnitAtom);\n}\n\nexport function useSelectedUnit() {\n return scope.useAtomValue(selectedUnitAtom);\n}\n\nexport interface ColumnClickData {\n unitID: number | null;\n unit: BaseUnit | null;\n target: HTMLElement | null;\n height: number;\n // Room for boundary IDs eventually\n}\n\nexport interface UnitSelectionCallbacks {\n // It's sort of unfortunate that we need to pass in the column ref here\n onClickedColumn?: (columnClickData: ColumnClickData, event: Event) => void;\n onUnitSelected?: <T extends BaseUnit>(\n unitID: number | null,\n unit: T | null,\n ) => void;\n}\n\nexport const allowUnitSelectionAtom = atom<boolean>(true);\n\nexport const selectedUnitIDAtom = atom<number | null>();\nexport const selectedUnitElementAtom = atom<HTMLElement | null>();\n\nconst overlayPositionAtom = atom<RectBounds | null>();\n\nconst columnRefAtom = atom<{ current: HTMLElement | null }>({ current: null });\n\nexport function useColumnRef() {\n return scope.useAtomValue(columnRefAtom);\n}\n\nconst selectedUnitAtom = atom(\n (get) => {\n if (!get(allowUnitSelectionAtom)) return null;\n\n const unitID = get(selectedUnitIDAtom);\n if (unitID == null) return null;\n const unitsMap = get(columnUnitsMapAtom);\n return unitsMap?.get(unitID) || null;\n },\n (\n get,\n set,\n selectedUnit: number | BaseUnit | null,\n target: HTMLElement | null = null,\n ): BaseUnit | null => {\n if (!get(allowUnitSelectionAtom)) {\n console.error(\"Unit selection is disabled.\");\n return null;\n }\n\n let unitID: number | null = null;\n let unit: BaseUnit | null = null;\n if (selectedUnit == null) {\n unitID = null;\n } else if (typeof selectedUnit === \"number\") {\n unitID = selectedUnit;\n } else if (\"unit_id\" in selectedUnit) {\n unitID = selectedUnit.unit_id;\n }\n\n if (unitID != null) {\n const unitsMap = get(columnUnitsMapAtom);\n // Verify that the unit exists in the current colum, else throw\n if (!unitsMap?.has(unitID)) {\n throw new Error(\n `Unit with ID ${unitID} not found in current column units.`,\n );\n }\n unit = unitsMap.get(unitID) ?? null;\n }\n\n let overlayPosition: RectBounds | null = null;\n\n const columnEl = get(columnRefAtom)?.current;\n\n if (unit != null && columnEl != null && target != null) {\n const rect = columnEl.getBoundingClientRect();\n const targetRect = target.getBoundingClientRect();\n overlayPosition = {\n x: targetRect.left - rect.left,\n y: targetRect.top - rect.top,\n width: targetRect.width,\n height: targetRect.height,\n };\n }\n\n set(selectedUnitElementAtom, target);\n set(selectedUnitIDAtom, unitID);\n set(overlayPositionAtom, overlayPosition);\n\n return unit;\n },\n);\n\nexport function useAtomOverlayPosition() {\n return scope.useAtomValue(overlayPositionAtom);\n}\n\nexport function UnitSelectionCallbackManager({\n onUnitSelected,\n}: UnitSelectionCallbacks) {\n const selectedUnit = scope.useAtomValue(selectedUnitAtom);\n useEffect(() => {\n onUnitSelected?.(selectedUnit?.unit_id ?? null, selectedUnit ?? null);\n }, [selectedUnit?.unit_id]);\n return null;\n}\n\n/** TODO: figure out if onClickedColumn is still needed\n /** This is not the natural place to get positions within the column,\n * but it will work for now.\nif (props.onClickedColumn) {\n // Infer height from top and bottom height of unit (because that's passed back with the call)\n //const py = event.y;\n //const [bottom, top] = getUnitHeightRange(unit, axisType);\n //const height = Math.abs(bottom - top);\n\n const columnClickData: ColumnClickData = {\n unitID: unit?.unit_id,\n unit,\n target,\n height: el?.getBoundingClientRect().height || 0,\n };\n props.onClickedColumn(columnClickData, event);\n}*/\n\nexport function useUnitSelectionTarget(\n unit: IUnit,\n): [React.RefObject<HTMLElement>, boolean, (evt: Event) => void] {\n const ref = useRef<HTMLElement>(null);\n const [selectedUnit, selectUnit] = useUnitSelection();\n const selected = selectedUnit?.unit_id == unit.unit_id;\n const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);\n\n const onClick = useCallback(\n (evt: Event) => {\n selectUnit?.(unit, ref.current);\n evt.stopPropagation();\n },\n [unit, selectUnit],\n );\n\n useEffect(() => {\n // Sync selection with unit element...\n if (!selected) return;\n selectUnit?.(unit, ref.current);\n }, [ref.current, selected, selectUnit]);\n\n useEffect(() => {\n // Scroll the unit into view\n selectedUnitElement?.scrollIntoView({\n behavior: \"smooth\",\n block: \"center\",\n inline: \"nearest\",\n });\n }, [selectedUnitElement]);\n\n return [ref, selected, onClick];\n}\n\nexport function UnitKeyboardNavigation({\n columnData,\n units,\n allowHorizontalNavigation,\n}: {\n columnData?: ColumnData[];\n units?: UnitLong[];\n allowHorizontalNavigation?: boolean;\n}) {\n if (units == null && columnData == null) {\n throw new Error(\"Either units or columnData must be provided.\");\n }\n\n let _columnData: ColumnData[] = useMemo(() => {\n if (columnData != null) return columnData;\n // Build column data from units\n const colMap = new Map<number, UnitLong[]>();\n for (const unit of units!) {\n if (!colMap.has(unit.col_id)) {\n colMap.set(unit.col_id, []);\n }\n colMap.get(unit.col_id)!.push(unit);\n }\n const cols: ColumnData[] = [];\n for (const [colID, units] of colMap) {\n cols.push({ columnID: colID, units });\n }\n // Sort columns by columnID\n cols.sort((a, b) => a.columnID - b.columnID);\n return cols;\n }, [columnData, units]);\n\n // Default to allowing horizontal navigation only if columnData is provided\n const _allowHorizontalNavigation =\n allowHorizontalNavigation ?? columnData != null;\n\n const selectedUnit = useSelectedUnit() as UnitLong | null;\n const selectUnit = useUnitSelectionDispatch();\n\n const keyMap: Record<number, Direction> = {\n 38: \"up\",\n 40: \"down\",\n };\n if (_allowHorizontalNavigation) {\n keyMap[37] = \"left\";\n keyMap[39] = \"right\";\n }\n\n useKeyHandler(\n (event) => {\n const direction = keyMap[event.keyCode];\n if (direction == null) return;\n const nextUnit = getBestUnit(_columnData, selectedUnit, direction);\n if (nextUnit == null) return;\n selectUnit(nextUnit, null);\n event.stopPropagation();\n },\n [_columnData, selectedUnit],\n );\n return null;\n}\n\ntype Direction = \"up\" | \"down\" | \"left\" | \"right\";\n\nfunction getBestUnit(\n columnData: ColumnData[],\n targetUnit: UnitLong,\n direction: Direction,\n): UnitLong | null {\n const thisColIndex = columnData.findIndex(\n (col) => col.columnID === targetUnit.col_id,\n );\n if (thisColIndex === -1) return null;\n\n // If up or down, stay in the same column\n if (direction === \"up\" || direction === \"down\") {\n const units = columnData[thisColIndex].units;\n const ix = units.findIndex((unit) => unit.unit_id === targetUnit.unit_id);\n if (ix === -1) return null;\n if (direction === \"up\") {\n return units[ix - 1] || null;\n } else {\n return units[ix + 1] || null;\n }\n }\n\n // If left or right, move to adjacent column\n let adjacentColIndex: number;\n if (direction === \"left\") {\n adjacentColIndex =\n (thisColIndex - 1 + columnData.length) % columnData.length;\n } else {\n adjacentColIndex = (thisColIndex + 1) % columnData.length;\n }\n\n const adjacentColUnits = columnData[adjacentColIndex].units;\n return getMostOverlappingUnit(targetUnit, adjacentColUnits);\n}\n\ntype UnitAgeRangeRelationship = AgeRangeQuantifiedDifference & {\n unit: UnitLong;\n};\n\nfunction getMostOverlappingUnit(\n targetUnit: UnitLong,\n candidateUnits: UnitLong[],\n): UnitLong | null {\n const targetAgeRange = [targetUnit.b_age, targetUnit.t_age];\n\n const overlaps: UnitAgeRangeRelationship[] = [];\n for (const candidate of candidateUnits) {\n const candidateAgeRange = [candidate.b_age, candidate.t_age];\n\n const rel = ageRangeQuantifiedDifference(targetAgeRange, candidateAgeRange);\n if (rel.type === AgeRangeRelationship.Identical) {\n return candidate;\n }\n overlaps.push({ ...rel, unit: candidate });\n }\n\n let bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Containing,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Contained,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.PartialOverlap,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Disjoint,\n );\n bestOverlaps.sort((a, b) => a.distance - b.distance);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n return null;\n}\n"],"names":["scope","atom","columnUnitsMapAtom","useEffect","useRef","useCallback","useMemo","units","useKeyHandler","ageRangeQuantifiedDifference","AgeRangeRelationship"],"mappings":";;;;;;;AAkBO,SAAS,mBAAmB;AACjC,SAAOA,MAAAA,MAAM,IAAI,gBAAgB;AACnC;AAEO,SAAS,2BAA+C;AAC7D,SAAOA,MAAAA,MAAM,WAAW,gBAAgB;AAC1C;AAEO,SAAS,kBAAkB;AAChC,SAAOA,MAAAA,MAAM,aAAa,gBAAgB;AAC5C;AAmBO,MAAM,yBAAyBC,MAAAA,KAAc,IAAI;AAEjD,MAAM,qBAAqBA,MAAAA,KAAA;AAC3B,MAAM,0BAA0BA,MAAAA,KAAA;AAEvC,MAAM,sBAAsBA,MAAAA,KAAA;AAE5B,MAAM,gBAAgBA,MAAAA,KAAsC,EAAE,SAAS,MAAM;AAEtE,SAAS,eAAe;AAC7B,SAAOD,MAAAA,MAAM,aAAa,aAAa;AACzC;AAEA,MAAM,mBAAmBC,MAAAA;AAAAA,EACvB,CAAC,QAAQ;AACP,QAAI,CAAC,IAAI,sBAAsB,EAAG,QAAO;AAEzC,UAAM,SAAS,IAAI,kBAAkB;AACrC,QAAI,UAAU,KAAM,QAAO;AAC3B,UAAM,WAAW,IAAIC,wBAAkB;AACvC,WAAO,UAAU,IAAI,MAAM,KAAK;AAAA,EAClC;AAAA,EACA,CACE,KACA,KACA,cACA,SAA6B,SACT;AACpB,QAAI,CAAC,IAAI,sBAAsB,GAAG;AAChC,cAAQ,MAAM,6BAA6B;AAC3C,aAAO;AAAA,IACT;AAEA,QAAI,SAAwB;AAC5B,QAAI,OAAwB;AAC5B,QAAI,gBAAgB,MAAM;AACxB,eAAS;AAAA,IACX,WAAW,OAAO,iBAAiB,UAAU;AAC3C,eAAS;AAAA,IACX,WAAW,aAAa,cAAc;AACpC,eAAS,aAAa;AAAA,IACxB;AAEA,QAAI,UAAU,MAAM;AAClB,YAAM,WAAW,IAAIA,wBAAkB;AA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B;AAC1E,QAAI,IAAI,SAASC,kBAAAA,qBAAqB,WAAW;AAC/C,aAAO;AAAA,IACT;AACA,aAAS,KAAK,EAAE,GAAG,KAAK,MAAM,WAAW;AAAA,EAC3C;AAEA,MAAI,eAAe,SAAS;AAAA,IAC1B,CAAC,MAAM,EAAE,SAASA,uCAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AACjD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAASA,uCAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AACjD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAASA,uCAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AACjD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAASA,uCAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AACnD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AACA,SAAO;AACT;;;;;;;;;;;;"}
1
+ {"version":3,"file":"unit-selection.cjs","sources":["../../src/data-provider/unit-selection.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { useKeyHandler } from \"@macrostrat/ui-components\";\nimport { useEffect, useRef, useCallback, useMemo } from \"react\";\nimport type { RectBounds, IUnit } from \"../units/types\";\nimport { atom } from \"jotai\";\nimport { scope, columnUnitsMapAtom } from \"./store\";\nimport {\n AgeRangeQuantifiedDifference,\n ageRangeQuantifiedDifference,\n AgeRangeRelationship,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ColumnData } from \"@macrostrat/data-provider\";\n\ntype UnitSelectDispatch = (\n unit: number | BaseUnit | null,\n target: HTMLElement | null,\n) => void;\n\nexport function useUnitSelection() {\n return scope.use(selectedUnitAtom);\n}\n\nexport function useUnitSelectionDispatch(): UnitSelectDispatch {\n return scope.useSetAtom(selectedUnitAtom);\n}\n\nexport function useSelectedUnit() {\n return scope.useAtomValue(selectedUnitAtom);\n}\n\nexport interface ColumnClickData {\n unitID: number | null;\n unit: BaseUnit | null;\n target: HTMLElement | null;\n height: number;\n // Room for boundary IDs eventually\n}\n\nexport interface UnitSelectionCallbacks {\n // It's sort of unfortunate that we need to pass in the column ref here\n onClickedColumn?: (columnClickData: ColumnClickData, event: Event) => void;\n onUnitSelected?: <T extends BaseUnit>(\n unitID: number | null,\n unit: T | null,\n ) => void;\n}\n\nexport const allowUnitSelectionAtom = atom<boolean>(true);\n\nexport const selectedUnitIDAtom = atom<number | null>();\nexport const selectedUnitElementAtom = atom<HTMLElement | null>();\n\nconst overlayPositionAtom = atom<RectBounds | null>();\n\nconst columnRefAtom = atom<{ current: HTMLElement | null }>({ current: null });\n\nexport function useColumnRef() {\n return scope.useAtomValue(columnRefAtom);\n}\n\nconst selectedUnitAtom = atom(\n (get) => {\n if (!get(allowUnitSelectionAtom)) return null;\n\n const unitID = get(selectedUnitIDAtom);\n if (unitID == null) return null;\n const unitsMap = get(columnUnitsMapAtom);\n return unitsMap?.get(unitID) || null;\n },\n (\n get,\n set,\n selectedUnit: number | BaseUnit | null,\n target: HTMLElement | null = null,\n ): BaseUnit | null => {\n if (!get(allowUnitSelectionAtom)) {\n console.error(\"Unit selection is disabled.\");\n return null;\n }\n\n let unitID: number | null = null;\n let unit: BaseUnit | null = null;\n if (selectedUnit == null) {\n unitID = null;\n } else if (typeof selectedUnit === \"number\") {\n unitID = selectedUnit;\n } else if (\"unit_id\" in selectedUnit) {\n unitID = selectedUnit.unit_id;\n }\n\n if (unitID != null) {\n const unitsMap = get(columnUnitsMapAtom);\n // Verify that the unit exists in the current colum, else throw\n if (!unitsMap?.has(unitID)) {\n throw new Error(\n `Unit with ID ${unitID} not found in current column units.`,\n );\n }\n unit = unitsMap.get(unitID) ?? null;\n }\n\n let overlayPosition: RectBounds | null = null;\n\n const columnEl = get(columnRefAtom)?.current;\n\n if (unit != null && columnEl != null && target != null) {\n const rect = columnEl.getBoundingClientRect();\n const targetRect = target.getBoundingClientRect();\n overlayPosition = {\n x: targetRect.left - rect.left,\n y: targetRect.top - rect.top,\n width: targetRect.width,\n height: targetRect.height,\n };\n }\n\n set(selectedUnitElementAtom, target);\n set(selectedUnitIDAtom, unitID);\n set(overlayPositionAtom, overlayPosition);\n\n return unit;\n },\n);\n\nexport function useAtomOverlayPosition() {\n return scope.useAtomValue(overlayPositionAtom);\n}\n\nexport function UnitSelectionCallbackManager({\n onUnitSelected,\n}: UnitSelectionCallbacks) {\n const selectedUnit = scope.useAtomValue(selectedUnitAtom);\n useEffect(() => {\n onUnitSelected?.(selectedUnit?.unit_id ?? null, selectedUnit ?? null);\n }, [selectedUnit?.unit_id]);\n return null;\n}\n\n/** TODO: figure out if onClickedColumn is still needed\n /** This is not the natural place to get positions within the column,\n * but it will work for now.\nif (props.onClickedColumn) {\n // Infer height from top and bottom height of unit (because that's passed back with the call)\n //const py = event.y;\n //const [bottom, top] = getUnitHeightRange(unit, axisType);\n //const height = Math.abs(bottom - top);\n\n const columnClickData: ColumnClickData = {\n unitID: unit?.unit_id,\n unit,\n target,\n height: el?.getBoundingClientRect().height || 0,\n };\n props.onClickedColumn(columnClickData, event);\n}*/\n\nexport function useUnitSelectionTarget(\n unit: IUnit,\n): [React.RefObject<HTMLElement>, boolean, (evt: Event) => void, boolean] {\n const ref = useRef<HTMLElement>(null);\n const [selectedUnit, selectUnit] = useUnitSelection();\n const selected = selectedUnit?.unit_id == unit.unit_id;\n const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);\n\n // \"Linked\" units share a stratigraphic name with the selected unit (e.g.\n // the same formation correlated across columns), but are not the selection\n // itself. They receive a subtler highlight.\n const selectedStratName = (selectedUnit as any)?.strat_name_id;\n const unitStratName = (unit as any)?.strat_name_id;\n const linked =\n !selected &&\n selectedStratName != null &&\n unitStratName != null &&\n unitStratName === selectedStratName;\n\n const onClick = useCallback(\n (evt: Event) => {\n selectUnit?.(unit, ref.current);\n evt.stopPropagation();\n },\n [unit, selectUnit],\n );\n\n useEffect(() => {\n // Sync selection with unit element...\n if (!selected) return;\n selectUnit?.(unit, ref.current);\n }, [ref.current, selected, selectUnit]);\n\n useEffect(() => {\n // Scroll the unit into view\n selectedUnitElement?.scrollIntoView({\n behavior: \"smooth\",\n block: \"center\",\n inline: \"nearest\",\n });\n }, [selectedUnitElement]);\n\n return [ref, selected, onClick, linked];\n}\n\nexport function UnitKeyboardNavigation({\n columnData,\n units,\n allowHorizontalNavigation,\n}: {\n columnData?: ColumnData[];\n units?: UnitLong[];\n allowHorizontalNavigation?: boolean;\n}) {\n if (units == null && columnData == null) {\n throw new Error(\"Either units or columnData must be provided.\");\n }\n\n let _columnData: ColumnData[] = useMemo(() => {\n if (columnData != null) return columnData;\n // Build column data from units\n const colMap = new Map<number, UnitLong[]>();\n for (const unit of units!) {\n if (!colMap.has(unit.col_id)) {\n colMap.set(unit.col_id, []);\n }\n colMap.get(unit.col_id)!.push(unit);\n }\n const cols: ColumnData[] = [];\n for (const [colID, units] of colMap) {\n cols.push({ columnID: colID, units });\n }\n // Sort columns by columnID\n cols.sort((a, b) => a.columnID - b.columnID);\n return cols;\n }, [columnData, units]);\n\n // Default to allowing horizontal navigation only if columnData is provided\n const _allowHorizontalNavigation =\n allowHorizontalNavigation ?? columnData != null;\n\n const selectedUnit = useSelectedUnit() as UnitLong | null;\n const selectUnit = useUnitSelectionDispatch();\n\n const keyMap: Record<number, Direction> = {\n 38: \"up\",\n 40: \"down\",\n };\n if (_allowHorizontalNavigation) {\n keyMap[37] = \"left\";\n keyMap[39] = \"right\";\n }\n\n useKeyHandler(\n (event) => {\n const direction = keyMap[event.keyCode];\n if (direction == null) return;\n const nextUnit = getBestUnit(_columnData, selectedUnit, direction);\n if (nextUnit == null) return;\n selectUnit(nextUnit, null);\n event.stopPropagation();\n },\n [_columnData, selectedUnit],\n );\n return null;\n}\n\ntype Direction = \"up\" | \"down\" | \"left\" | \"right\";\n\nfunction getBestUnit(\n columnData: ColumnData[],\n targetUnit: UnitLong,\n direction: Direction,\n): UnitLong | null {\n const thisColIndex = columnData.findIndex(\n (col) => col.columnID === targetUnit.col_id,\n );\n if (thisColIndex === -1) return null;\n\n // If up or down, stay in the same column\n if (direction === \"up\" || direction === \"down\") {\n const units = columnData[thisColIndex].units;\n const ix = units.findIndex((unit) => unit.unit_id === targetUnit.unit_id);\n if (ix === -1) return null;\n if (direction === \"up\") {\n return units[ix - 1] || null;\n } else {\n return units[ix + 1] || null;\n }\n }\n\n // If left or right, move to adjacent column\n let adjacentColIndex: number;\n if (direction === \"left\") {\n adjacentColIndex =\n (thisColIndex - 1 + columnData.length) % columnData.length;\n } else {\n adjacentColIndex = (thisColIndex + 1) % columnData.length;\n }\n\n const adjacentColUnits = columnData[adjacentColIndex].units;\n return getMostOverlappingUnit(targetUnit, adjacentColUnits);\n}\n\ntype UnitAgeRangeRelationship = AgeRangeQuantifiedDifference & {\n unit: UnitLong;\n};\n\nfunction getMostOverlappingUnit(\n targetUnit: UnitLong,\n candidateUnits: UnitLong[],\n): UnitLong | null {\n const targetAgeRange = [targetUnit.b_age, targetUnit.t_age];\n\n const overlaps: UnitAgeRangeRelationship[] = [];\n for (const candidate of candidateUnits) {\n const candidateAgeRange = [candidate.b_age, candidate.t_age];\n\n const rel = ageRangeQuantifiedDifference(targetAgeRange, candidateAgeRange);\n if (rel.type === AgeRangeRelationship.Identical) {\n return candidate;\n }\n overlaps.push({ ...rel, unit: candidate });\n }\n\n let bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Containing,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Contained,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.PartialOverlap,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Disjoint,\n );\n bestOverlaps.sort((a, b) => a.distance - b.distance);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n return null;\n}\n"],"names":["scope","atom","columnUnitsMapAtom","useEffect","useRef","useCallback","useMemo","units","useKeyHandler","ageRangeQuantifiedDifference","AgeRangeRelationship"],"mappings":";;;;;;;AAkBO,SAAS,mBAAmB;AACjC,SAAOA,MAAAA,MAAM,IAAI,gBAAgB;AACnC;AAEO,SAAS,2BAA+C;AAC7D,SAAOA,MAAAA,MAAM,WAAW,gBAAgB;AAC1C;AAEO,SAAS,kBAAkB;AAChC,SAAOA,MAAAA,MAAM,aAAa,gBAAgB;AAC5C;AAmBO,MAAM,yBAAyBC,MAAAA,KAAc,IAAI;AAEjD,MAAM,qBAAqBA,MAAAA,KAAA;AAC3B,MAAM,0BAA0BA,MAAAA,KAAA;AAEvC,MAAM,sBAAsBA,MAAAA,KAAA;AAE5B,MAAM,gBAAgBA,MAAAA,KAAsC,EAAE,SAAS,MAAM;AAEtE,SAAS,eAAe;AAC7B,SAAOD,MAAAA,MAAM,aAAa,aAAa;AACzC;AAEA,MAAM,mBAAmBC,MAAAA;A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S,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAASA,uCAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AACjD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAASA,uCAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AACnD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AACA,SAAO;AACT;;;;;;;;;;;;"}
@@ -44,7 +44,7 @@ if (props.onClickedColumn) {
44
44
  };
45
45
  props.onClickedColumn(columnClickData, event);
46
46
  }*/
47
- export declare function useUnitSelectionTarget(unit: IUnit): [React.RefObject<HTMLElement>, boolean, (evt: Event) => void];
47
+ export declare function useUnitSelectionTarget(unit: IUnit): [React.RefObject<HTMLElement>, boolean, (evt: Event) => void, boolean];
48
48
  export declare function UnitKeyboardNavigation({ columnData, units, allowHorizontalNavigation, }: {
49
49
  columnData?: ColumnData[];
50
50
  units?: UnitLong[];
@@ -86,6 +86,9 @@ function useUnitSelectionTarget(unit) {
86
86
  const [selectedUnit, selectUnit] = useUnitSelection();
87
87
  const selected = selectedUnit?.unit_id == unit.unit_id;
88
88
  const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);
89
+ const selectedStratName = selectedUnit?.strat_name_id;
90
+ const unitStratName = unit?.strat_name_id;
91
+ const linked = !selected && selectedStratName != null && unitStratName != null && unitStratName === selectedStratName;
89
92
  const onClick = useCallback(
90
93
  (evt) => {
91
94
  selectUnit?.(unit, ref.current);
@@ -104,7 +107,7 @@ function useUnitSelectionTarget(unit) {
104
107
  inline: "nearest"
105
108
  });
106
109
  }, [selectedUnitElement]);
107
- return [ref, selected, onClick];
110
+ return [ref, selected, onClick, linked];
108
111
  }
109
112
  function UnitKeyboardNavigation({
110
113
  columnData,
@@ -1 +1 @@
1
- {"version":3,"file":"unit-selection.js","sources":["../../src/data-provider/unit-selection.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { useKeyHandler } from \"@macrostrat/ui-components\";\nimport { useEffect, useRef, useCallback, useMemo } from \"react\";\nimport type { RectBounds, IUnit } from \"../units/types\";\nimport { atom } from \"jotai\";\nimport { scope, columnUnitsMapAtom } from \"./store\";\nimport {\n AgeRangeQuantifiedDifference,\n ageRangeQuantifiedDifference,\n AgeRangeRelationship,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ColumnData } from \"@macrostrat/data-provider\";\n\ntype UnitSelectDispatch = (\n unit: number | BaseUnit | null,\n target: HTMLElement | null,\n) => void;\n\nexport function useUnitSelection() {\n return scope.use(selectedUnitAtom);\n}\n\nexport function useUnitSelectionDispatch(): UnitSelectDispatch {\n return scope.useSetAtom(selectedUnitAtom);\n}\n\nexport function useSelectedUnit() {\n return scope.useAtomValue(selectedUnitAtom);\n}\n\nexport interface ColumnClickData {\n unitID: number | null;\n unit: BaseUnit | null;\n target: HTMLElement | null;\n height: number;\n // Room for boundary IDs eventually\n}\n\nexport interface UnitSelectionCallbacks {\n // It's sort of unfortunate that we need to pass in the column ref here\n onClickedColumn?: (columnClickData: ColumnClickData, event: Event) => void;\n onUnitSelected?: <T extends BaseUnit>(\n unitID: number | null,\n unit: T | null,\n ) => void;\n}\n\nexport const allowUnitSelectionAtom = atom<boolean>(true);\n\nexport const selectedUnitIDAtom = atom<number | null>();\nexport const selectedUnitElementAtom = atom<HTMLElement | null>();\n\nconst overlayPositionAtom = atom<RectBounds | null>();\n\nconst columnRefAtom = atom<{ current: HTMLElement | null }>({ current: null });\n\nexport function useColumnRef() {\n return scope.useAtomValue(columnRefAtom);\n}\n\nconst selectedUnitAtom = atom(\n (get) => {\n if (!get(allowUnitSelectionAtom)) return null;\n\n const unitID = get(selectedUnitIDAtom);\n if (unitID == null) return null;\n const unitsMap = get(columnUnitsMapAtom);\n return unitsMap?.get(unitID) || null;\n },\n (\n get,\n set,\n selectedUnit: number | BaseUnit | null,\n target: HTMLElement | null = null,\n ): BaseUnit | null => {\n if (!get(allowUnitSelectionAtom)) {\n console.error(\"Unit selection is disabled.\");\n return null;\n }\n\n let unitID: number | null = null;\n let unit: BaseUnit | null = null;\n if (selectedUnit == null) {\n unitID = null;\n } else if (typeof selectedUnit === \"number\") {\n unitID = selectedUnit;\n } else if (\"unit_id\" in selectedUnit) {\n unitID = selectedUnit.unit_id;\n }\n\n if (unitID != null) {\n const unitsMap = get(columnUnitsMapAtom);\n // Verify that the unit exists in the current colum, else throw\n if (!unitsMap?.has(unitID)) {\n throw new Error(\n `Unit with ID ${unitID} not found in current column units.`,\n );\n }\n unit = unitsMap.get(unitID) ?? null;\n }\n\n let overlayPosition: RectBounds | null = null;\n\n const columnEl = get(columnRefAtom)?.current;\n\n if (unit != null && columnEl != null && target != null) {\n const rect = columnEl.getBoundingClientRect();\n const targetRect = target.getBoundingClientRect();\n overlayPosition = {\n x: targetRect.left - rect.left,\n y: targetRect.top - rect.top,\n width: targetRect.width,\n height: targetRect.height,\n };\n }\n\n set(selectedUnitElementAtom, target);\n set(selectedUnitIDAtom, unitID);\n set(overlayPositionAtom, overlayPosition);\n\n return unit;\n },\n);\n\nexport function useAtomOverlayPosition() {\n return scope.useAtomValue(overlayPositionAtom);\n}\n\nexport function UnitSelectionCallbackManager({\n onUnitSelected,\n}: UnitSelectionCallbacks) {\n const selectedUnit = scope.useAtomValue(selectedUnitAtom);\n useEffect(() => {\n onUnitSelected?.(selectedUnit?.unit_id ?? null, selectedUnit ?? null);\n }, [selectedUnit?.unit_id]);\n return null;\n}\n\n/** TODO: figure out if onClickedColumn is still needed\n /** This is not the natural place to get positions within the column,\n * but it will work for now.\nif (props.onClickedColumn) {\n // Infer height from top and bottom height of unit (because that's passed back with the call)\n //const py = event.y;\n //const [bottom, top] = getUnitHeightRange(unit, axisType);\n //const height = Math.abs(bottom - top);\n\n const columnClickData: ColumnClickData = {\n unitID: unit?.unit_id,\n unit,\n target,\n height: el?.getBoundingClientRect().height || 0,\n };\n props.onClickedColumn(columnClickData, event);\n}*/\n\nexport function useUnitSelectionTarget(\n unit: IUnit,\n): [React.RefObject<HTMLElement>, boolean, (evt: Event) => void] {\n const ref = useRef<HTMLElement>(null);\n const [selectedUnit, selectUnit] = useUnitSelection();\n const selected = selectedUnit?.unit_id == unit.unit_id;\n const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);\n\n const onClick = useCallback(\n (evt: Event) => {\n selectUnit?.(unit, ref.current);\n evt.stopPropagation();\n },\n [unit, selectUnit],\n );\n\n useEffect(() => {\n // Sync selection with unit element...\n if (!selected) return;\n selectUnit?.(unit, ref.current);\n }, [ref.current, selected, selectUnit]);\n\n useEffect(() => {\n // Scroll the unit into view\n selectedUnitElement?.scrollIntoView({\n behavior: \"smooth\",\n block: \"center\",\n inline: \"nearest\",\n });\n }, [selectedUnitElement]);\n\n return [ref, selected, onClick];\n}\n\nexport function UnitKeyboardNavigation({\n columnData,\n units,\n allowHorizontalNavigation,\n}: {\n columnData?: ColumnData[];\n units?: UnitLong[];\n allowHorizontalNavigation?: boolean;\n}) {\n if (units == null && columnData == null) {\n throw new Error(\"Either units or columnData must be provided.\");\n }\n\n let _columnData: ColumnData[] = useMemo(() => {\n if (columnData != null) return columnData;\n // Build column data from units\n const colMap = new Map<number, UnitLong[]>();\n for (const unit of units!) {\n if (!colMap.has(unit.col_id)) {\n colMap.set(unit.col_id, []);\n }\n colMap.get(unit.col_id)!.push(unit);\n }\n const cols: ColumnData[] = [];\n for (const [colID, units] of colMap) {\n cols.push({ columnID: colID, units });\n }\n // Sort columns by columnID\n cols.sort((a, b) => a.columnID - b.columnID);\n return cols;\n }, [columnData, units]);\n\n // Default to allowing horizontal navigation only if columnData is provided\n const _allowHorizontalNavigation =\n allowHorizontalNavigation ?? columnData != null;\n\n const selectedUnit = useSelectedUnit() as UnitLong | null;\n const selectUnit = useUnitSelectionDispatch();\n\n const keyMap: Record<number, Direction> = {\n 38: \"up\",\n 40: \"down\",\n };\n if (_allowHorizontalNavigation) {\n keyMap[37] = \"left\";\n keyMap[39] = \"right\";\n }\n\n useKeyHandler(\n (event) => {\n const direction = keyMap[event.keyCode];\n if (direction == null) return;\n const nextUnit = getBestUnit(_columnData, selectedUnit, direction);\n if (nextUnit == null) return;\n selectUnit(nextUnit, null);\n event.stopPropagation();\n },\n [_columnData, selectedUnit],\n );\n return null;\n}\n\ntype Direction = \"up\" | \"down\" | \"left\" | \"right\";\n\nfunction getBestUnit(\n columnData: ColumnData[],\n targetUnit: UnitLong,\n direction: Direction,\n): UnitLong | null {\n const thisColIndex = columnData.findIndex(\n (col) => col.columnID === targetUnit.col_id,\n );\n if (thisColIndex === -1) return null;\n\n // If up or down, stay in the same column\n if (direction === \"up\" || direction === \"down\") {\n const units = columnData[thisColIndex].units;\n const ix = units.findIndex((unit) => unit.unit_id === targetUnit.unit_id);\n if (ix === -1) return null;\n if (direction === \"up\") {\n return units[ix - 1] || null;\n } else {\n return units[ix + 1] || null;\n }\n }\n\n // If left or right, move to adjacent column\n let adjacentColIndex: number;\n if (direction === \"left\") {\n adjacentColIndex =\n (thisColIndex - 1 + columnData.length) % columnData.length;\n } else {\n adjacentColIndex = (thisColIndex + 1) % columnData.length;\n }\n\n const adjacentColUnits = columnData[adjacentColIndex].units;\n return getMostOverlappingUnit(targetUnit, adjacentColUnits);\n}\n\ntype UnitAgeRangeRelationship = AgeRangeQuantifiedDifference & {\n unit: UnitLong;\n};\n\nfunction getMostOverlappingUnit(\n targetUnit: UnitLong,\n candidateUnits: UnitLong[],\n): UnitLong | null {\n const targetAgeRange = [targetUnit.b_age, targetUnit.t_age];\n\n const overlaps: UnitAgeRangeRelationship[] = [];\n for (const candidate of candidateUnits) {\n const candidateAgeRange = [candidate.b_age, candidate.t_age];\n\n const rel = ageRangeQuantifiedDifference(targetAgeRange, candidateAgeRange);\n if (rel.type === AgeRangeRelationship.Identical) {\n return candidate;\n }\n overlaps.push({ ...rel, unit: candidate });\n }\n\n let bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Containing,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Contained,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.PartialOverlap,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Disjoint,\n );\n bestOverlaps.sort((a, b) => a.distance - b.distance);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n return null;\n}\n"],"names":["units"],"mappings":";;;;;AAkBO,SAAS,mBAAmB;AACjC,SAAO,MAAM,IAAI,gBAAgB;AACnC;AAEO,SAAS,2BAA+C;AAC7D,SAAO,MAAM,WAAW,gBAAgB;AAC1C;AAEO,SAAS,kBAAkB;AAChC,SAAO,MAAM,aAAa,gBAAgB;AAC5C;AAmBO,MAAM,yBAAyB,KAAc,IAAI;AAEjD,MAAM,qBAAqB,KAAA;AAC3B,MAAM,0BAA0B,KAAA;AAEvC,MAAM,sBAAsB,KAAA;AAE5B,MAAM,gBAAgB,KAAsC,EAAE,SAAS,MAAM;AAEtE,SAAS,eAAe;AAC7B,SAAO,MAAM,aAAa,aAAa;AACzC;AAEA,MAAM,mBAAmB;AAAA,EACvB,CAAC,QAAQ;AACP,QAAI,CAAC,IAAI,sBAAsB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ACtB,CAAC,MAAM,EAAE,SAAS,qBAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AACnD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AACA,SAAO;AACT;"}
1
+ {"version":3,"file":"unit-selection.js","sources":["../../src/data-provider/unit-selection.ts"],"sourcesContent":["import type { BaseUnit, UnitLong } from \"@macrostrat/api-types\";\nimport { useKeyHandler } from \"@macrostrat/ui-components\";\nimport { useEffect, useRef, useCallback, useMemo } from \"react\";\nimport type { RectBounds, IUnit } from \"../units/types\";\nimport { atom } from \"jotai\";\nimport { scope, columnUnitsMapAtom } from \"./store\";\nimport {\n AgeRangeQuantifiedDifference,\n ageRangeQuantifiedDifference,\n AgeRangeRelationship,\n} from \"@macrostrat/stratigraphy-utils\";\nimport type { ColumnData } from \"@macrostrat/data-provider\";\n\ntype UnitSelectDispatch = (\n unit: number | BaseUnit | null,\n target: HTMLElement | null,\n) => void;\n\nexport function useUnitSelection() {\n return scope.use(selectedUnitAtom);\n}\n\nexport function useUnitSelectionDispatch(): UnitSelectDispatch {\n return scope.useSetAtom(selectedUnitAtom);\n}\n\nexport function useSelectedUnit() {\n return scope.useAtomValue(selectedUnitAtom);\n}\n\nexport interface ColumnClickData {\n unitID: number | null;\n unit: BaseUnit | null;\n target: HTMLElement | null;\n height: number;\n // Room for boundary IDs eventually\n}\n\nexport interface UnitSelectionCallbacks {\n // It's sort of unfortunate that we need to pass in the column ref here\n onClickedColumn?: (columnClickData: ColumnClickData, event: Event) => void;\n onUnitSelected?: <T extends BaseUnit>(\n unitID: number | null,\n unit: T | null,\n ) => void;\n}\n\nexport const allowUnitSelectionAtom = atom<boolean>(true);\n\nexport const selectedUnitIDAtom = atom<number | null>();\nexport const selectedUnitElementAtom = atom<HTMLElement | null>();\n\nconst overlayPositionAtom = atom<RectBounds | null>();\n\nconst columnRefAtom = atom<{ current: HTMLElement | null }>({ current: null });\n\nexport function useColumnRef() {\n return scope.useAtomValue(columnRefAtom);\n}\n\nconst selectedUnitAtom = atom(\n (get) => {\n if (!get(allowUnitSelectionAtom)) return null;\n\n const unitID = get(selectedUnitIDAtom);\n if (unitID == null) return null;\n const unitsMap = get(columnUnitsMapAtom);\n return unitsMap?.get(unitID) || null;\n },\n (\n get,\n set,\n selectedUnit: number | BaseUnit | null,\n target: HTMLElement | null = null,\n ): BaseUnit | null => {\n if (!get(allowUnitSelectionAtom)) {\n console.error(\"Unit selection is disabled.\");\n return null;\n }\n\n let unitID: number | null = null;\n let unit: BaseUnit | null = null;\n if (selectedUnit == null) {\n unitID = null;\n } else if (typeof selectedUnit === \"number\") {\n unitID = selectedUnit;\n } else if (\"unit_id\" in selectedUnit) {\n unitID = selectedUnit.unit_id;\n }\n\n if (unitID != null) {\n const unitsMap = get(columnUnitsMapAtom);\n // Verify that the unit exists in the current colum, else throw\n if (!unitsMap?.has(unitID)) {\n throw new Error(\n `Unit with ID ${unitID} not found in current column units.`,\n );\n }\n unit = unitsMap.get(unitID) ?? null;\n }\n\n let overlayPosition: RectBounds | null = null;\n\n const columnEl = get(columnRefAtom)?.current;\n\n if (unit != null && columnEl != null && target != null) {\n const rect = columnEl.getBoundingClientRect();\n const targetRect = target.getBoundingClientRect();\n overlayPosition = {\n x: targetRect.left - rect.left,\n y: targetRect.top - rect.top,\n width: targetRect.width,\n height: targetRect.height,\n };\n }\n\n set(selectedUnitElementAtom, target);\n set(selectedUnitIDAtom, unitID);\n set(overlayPositionAtom, overlayPosition);\n\n return unit;\n },\n);\n\nexport function useAtomOverlayPosition() {\n return scope.useAtomValue(overlayPositionAtom);\n}\n\nexport function UnitSelectionCallbackManager({\n onUnitSelected,\n}: UnitSelectionCallbacks) {\n const selectedUnit = scope.useAtomValue(selectedUnitAtom);\n useEffect(() => {\n onUnitSelected?.(selectedUnit?.unit_id ?? null, selectedUnit ?? null);\n }, [selectedUnit?.unit_id]);\n return null;\n}\n\n/** TODO: figure out if onClickedColumn is still needed\n /** This is not the natural place to get positions within the column,\n * but it will work for now.\nif (props.onClickedColumn) {\n // Infer height from top and bottom height of unit (because that's passed back with the call)\n //const py = event.y;\n //const [bottom, top] = getUnitHeightRange(unit, axisType);\n //const height = Math.abs(bottom - top);\n\n const columnClickData: ColumnClickData = {\n unitID: unit?.unit_id,\n unit,\n target,\n height: el?.getBoundingClientRect().height || 0,\n };\n props.onClickedColumn(columnClickData, event);\n}*/\n\nexport function useUnitSelectionTarget(\n unit: IUnit,\n): [React.RefObject<HTMLElement>, boolean, (evt: Event) => void, boolean] {\n const ref = useRef<HTMLElement>(null);\n const [selectedUnit, selectUnit] = useUnitSelection();\n const selected = selectedUnit?.unit_id == unit.unit_id;\n const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);\n\n // \"Linked\" units share a stratigraphic name with the selected unit (e.g.\n // the same formation correlated across columns), but are not the selection\n // itself. They receive a subtler highlight.\n const selectedStratName = (selectedUnit as any)?.strat_name_id;\n const unitStratName = (unit as any)?.strat_name_id;\n const linked =\n !selected &&\n selectedStratName != null &&\n unitStratName != null &&\n unitStratName === selectedStratName;\n\n const onClick = useCallback(\n (evt: Event) => {\n selectUnit?.(unit, ref.current);\n evt.stopPropagation();\n },\n [unit, selectUnit],\n );\n\n useEffect(() => {\n // Sync selection with unit element...\n if (!selected) return;\n selectUnit?.(unit, ref.current);\n }, [ref.current, selected, selectUnit]);\n\n useEffect(() => {\n // Scroll the unit into view\n selectedUnitElement?.scrollIntoView({\n behavior: \"smooth\",\n block: \"center\",\n inline: \"nearest\",\n });\n }, [selectedUnitElement]);\n\n return [ref, selected, onClick, linked];\n}\n\nexport function UnitKeyboardNavigation({\n columnData,\n units,\n allowHorizontalNavigation,\n}: {\n columnData?: ColumnData[];\n units?: UnitLong[];\n allowHorizontalNavigation?: boolean;\n}) {\n if (units == null && columnData == null) {\n throw new Error(\"Either units or columnData must be provided.\");\n }\n\n let _columnData: ColumnData[] = useMemo(() => {\n if (columnData != null) return columnData;\n // Build column data from units\n const colMap = new Map<number, UnitLong[]>();\n for (const unit of units!) {\n if (!colMap.has(unit.col_id)) {\n colMap.set(unit.col_id, []);\n }\n colMap.get(unit.col_id)!.push(unit);\n }\n const cols: ColumnData[] = [];\n for (const [colID, units] of colMap) {\n cols.push({ columnID: colID, units });\n }\n // Sort columns by columnID\n cols.sort((a, b) => a.columnID - b.columnID);\n return cols;\n }, [columnData, units]);\n\n // Default to allowing horizontal navigation only if columnData is provided\n const _allowHorizontalNavigation =\n allowHorizontalNavigation ?? columnData != null;\n\n const selectedUnit = useSelectedUnit() as UnitLong | null;\n const selectUnit = useUnitSelectionDispatch();\n\n const keyMap: Record<number, Direction> = {\n 38: \"up\",\n 40: \"down\",\n };\n if (_allowHorizontalNavigation) {\n keyMap[37] = \"left\";\n keyMap[39] = \"right\";\n }\n\n useKeyHandler(\n (event) => {\n const direction = keyMap[event.keyCode];\n if (direction == null) return;\n const nextUnit = getBestUnit(_columnData, selectedUnit, direction);\n if (nextUnit == null) return;\n selectUnit(nextUnit, null);\n event.stopPropagation();\n },\n [_columnData, selectedUnit],\n );\n return null;\n}\n\ntype Direction = \"up\" | \"down\" | \"left\" | \"right\";\n\nfunction getBestUnit(\n columnData: ColumnData[],\n targetUnit: UnitLong,\n direction: Direction,\n): UnitLong | null {\n const thisColIndex = columnData.findIndex(\n (col) => col.columnID === targetUnit.col_id,\n );\n if (thisColIndex === -1) return null;\n\n // If up or down, stay in the same column\n if (direction === \"up\" || direction === \"down\") {\n const units = columnData[thisColIndex].units;\n const ix = units.findIndex((unit) => unit.unit_id === targetUnit.unit_id);\n if (ix === -1) return null;\n if (direction === \"up\") {\n return units[ix - 1] || null;\n } else {\n return units[ix + 1] || null;\n }\n }\n\n // If left or right, move to adjacent column\n let adjacentColIndex: number;\n if (direction === \"left\") {\n adjacentColIndex =\n (thisColIndex - 1 + columnData.length) % columnData.length;\n } else {\n adjacentColIndex = (thisColIndex + 1) % columnData.length;\n }\n\n const adjacentColUnits = columnData[adjacentColIndex].units;\n return getMostOverlappingUnit(targetUnit, adjacentColUnits);\n}\n\ntype UnitAgeRangeRelationship = AgeRangeQuantifiedDifference & {\n unit: UnitLong;\n};\n\nfunction getMostOverlappingUnit(\n targetUnit: UnitLong,\n candidateUnits: UnitLong[],\n): UnitLong | null {\n const targetAgeRange = [targetUnit.b_age, targetUnit.t_age];\n\n const overlaps: UnitAgeRangeRelationship[] = [];\n for (const candidate of candidateUnits) {\n const candidateAgeRange = [candidate.b_age, candidate.t_age];\n\n const rel = ageRangeQuantifiedDifference(targetAgeRange, candidateAgeRange);\n if (rel.type === AgeRangeRelationship.Identical) {\n return candidate;\n }\n overlaps.push({ ...rel, unit: candidate });\n }\n\n let bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Containing,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Contained,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.PartialOverlap,\n );\n bestOverlaps.sort((a, b) => b.overlap - a.overlap);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n\n bestOverlaps = overlaps.filter(\n (d) => d.type === AgeRangeRelationship.Disjoint,\n );\n bestOverlaps.sort((a, b) => a.distance - b.distance);\n if (bestOverlaps.length > 0) {\n return bestOverlaps[0].unit;\n }\n return null;\n}\n"],"names":["units"],"mappings":";;;;;AAkBO,SAAS,mBAAmB;AACjC,SAAO,MAAM,IAAI,gBAAgB;AACnC;AAEO,SAAS,2BAA+C;AAC7D,SAAO,MAAM,WAAW,gBAAgB;AAC1C;AAEO,SAAS,kBAAkB;AAChC,SAAO,MAAM,aAAa,gBAAgB;AAC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A,IACtB,CAAC,MAAM,EAAE,SAAS,qBAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AACjD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAAS,qBAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO;AACjD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AAEA,iBAAe,SAAS;AAAA,IACtB,CAAC,MAAM,EAAE,SAAS,qBAAqB;AAAA,EAAA;AAEzC,eAAa,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AACnD,MAAI,aAAa,SAAS,GAAG;AAC3B,WAAO,aAAa,CAAC,EAAE;AAAA,EACzB;AACA,SAAO;AACT;"}
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ const ageRange = require("./unit-details/age-range.cjs");
10
10
  const composite = require("./units/composite.cjs");
11
11
  const columns = require("./maps/layers/columns.cjs");
12
12
  const base = require("./facets/measurements/base.cjs");
13
- const identifiers = require("./unit-details/identifiers.cjs");
13
+ const dataComponents = require("@macrostrat/data-components");
14
14
  const layers = require("./maps/column-navigation/svg/layers.cjs");
15
15
  const core = require("./maps/column-correlation/core.cjs");
16
16
  const state = require("./maps/column-correlation/state.cjs");
@@ -81,9 +81,18 @@ exports.TruncatedList = base.TruncatedList;
81
81
  exports.groupNotesByPixelDistance = base.groupNotesByPixelDistance;
82
82
  exports.mergeHeightRanges = base.mergeHeightRanges;
83
83
  exports.standardizeMeasurementHeight = base.standardizeMeasurementHeight;
84
- exports.ClickableText = identifiers.ClickableText;
85
- exports.Identifier = identifiers.Identifier;
86
- exports.UnitIdentifier = identifiers.UnitIdentifier;
84
+ Object.defineProperty(exports, "ClickableText", {
85
+ enumerable: true,
86
+ get: () => dataComponents.ClickableText
87
+ });
88
+ Object.defineProperty(exports, "Identifier", {
89
+ enumerable: true,
90
+ get: () => dataComponents.Identifier
91
+ });
92
+ Object.defineProperty(exports, "UnitIdentifier", {
93
+ enumerable: true,
94
+ get: () => dataComponents.UnitIdentifier
95
+ });
87
96
  exports.ColumnCenters = layers.ColumnCenters;
88
97
  exports.ColumnFeatures = layers.ColumnFeatures;
89
98
  exports.ColumnKeyboardNavigation = layers.ColumnKeyboardNavigation;
@@ -92,6 +101,7 @@ exports.CurrentColumn = layers.CurrentColumn;
92
101
  exports.MeasurementsLayer = layers.MeasurementsLayer;
93
102
  exports.ColumnCorrelationMap = core.ColumnCorrelationMap;
94
103
  exports.ColumnCorrelationProvider = state.ColumnCorrelationProvider;
104
+ exports.useColumnMapLink = state.useColumnMapLink;
95
105
  exports.useCorrelationMapStore = state.useCorrelationMapStore;
96
106
  exports.ColumnHoverInteraction = index$1.ColumnHoverInteraction;
97
107
  exports.ColumnNavigationMap = index$1.ColumnNavigationMap;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -8,10 +8,10 @@ import { AgeField, AgeLabel, AgeRange, Duration, IntervalProportions, getAge, ge
8
8
  import { AnnotatedUnitsColumn, ColumnNotesProvider, CompositeUnitComponent, CompositeUnitsColumn, LabelTrackerProvider, SectionLabelsColumn, TrackedLabeledUnit } from "./units/composite.js";
9
9
  import { BaseColumnsLayer, SelectedColumnOverlay, buildColumnsStyle } from "./maps/layers/columns.js";
10
10
  import { BaseMeasurementsColumn, TruncatedList, groupNotesByPixelDistance, mergeHeightRanges, standardizeMeasurementHeight } from "./facets/measurements/base.js";
11
- import { ClickableText, Identifier, UnitIdentifier } from "./unit-details/identifiers.js";
11
+ import { ClickableText, Identifier, UnitIdentifier } from "@macrostrat/data-components";
12
12
  import { ColumnCenters, ColumnFeatures, ColumnKeyboardNavigation, Columns, CurrentColumn, MeasurementsLayer } from "./maps/column-navigation/svg/layers.js";
13
13
  import { ColumnCorrelationMap } from "./maps/column-correlation/core.js";
14
- import { ColumnCorrelationProvider, useCorrelationMapStore } from "./maps/column-correlation/state.js";
14
+ import { ColumnCorrelationProvider, useColumnMapLink, useCorrelationMapStore } from "./maps/column-correlation/state.js";
15
15
  import { ColumnHoverInteraction, ColumnNavigationMap, ColumnSelectionManager, ColumnsNavigationLayer } from "./maps/column-navigation/mapbox/index.js";
16
16
  import { ColumnNavProvider, useColumnNav } from "./data-provider/column-nav.js";
17
17
  import { ColumnNavigationSVGMap, ResizableMapFrame } from "./maps/column-navigation/svg/index.js";
@@ -148,6 +148,7 @@ export {
148
148
  stringifyLine,
149
149
  unitsOverlap,
150
150
  useAtomOverlayPosition,
151
+ useColumnMapLink,
151
152
  useColumnNav,
152
153
  useColumnRef,
153
154
  useColumnUnitsMap,
@@ -24,11 +24,40 @@ function ColumnCorrelationMap(props) {
24
24
  h__default.default(ColumnsLayer, { color: columnColor }),
25
25
  h__default.default(SelectedColumnsLayer),
26
26
  h__default.default(MapClickHandler),
27
+ h__default.default(ColumnInteractionHandler),
28
+ h__default.default(HoveredColumnHighlight),
29
+ h__default.default(ColumnZoomer, { padding }),
27
30
  h__default.default(SectionLine, { padding }),
28
31
  children
29
32
  ]
30
33
  );
31
34
  }
35
+ function ColumnZoomer({ padding }) {
36
+ const zoomColumn = state.useCorrelationMapStore((state2) => state2.zoomColumn);
37
+ const zoomNonce = state.useCorrelationMapStore((state2) => state2.zoomNonce);
38
+ const columns2 = state.useCorrelationMapStore((state2) => state2.columns);
39
+ const bounds = React.useMemo(() => {
40
+ if (zoomColumn == null || columns2 == null) return null;
41
+ const col = columns2.find((c) => c.properties?.col_id === zoomColumn);
42
+ if (col?.geometry == null) return null;
43
+ const b = new mapboxGl.LngLatBounds();
44
+ forEachCoordinate(col.geometry, (coord) => b.extend(coord));
45
+ return b.isEmpty() ? null : b;
46
+ }, [zoomColumn, zoomNonce, columns2]);
47
+ mapboxReact.useMapEaseTo({ bounds, padding: padding * 2 });
48
+ return null;
49
+ }
50
+ function forEachCoordinate(geometry, fn) {
51
+ const walk = (coords) => {
52
+ if (typeof coords[0] === "number") {
53
+ fn(coords);
54
+ } else {
55
+ for (const c of coords) walk(c);
56
+ }
57
+ };
58
+ if (geometry?.coordinates != null) walk(geometry.coordinates);
59
+ }
60
+ const columnLayers = ["columns-fill", "columns-points"];
32
61
  function MapClickHandler() {
33
62
  const onClickMap = state.useCorrelationMapStore((state2) => state2.onClickMap);
34
63
  mapboxReact.useMapClickHandler(
@@ -39,6 +68,90 @@ function MapClickHandler() {
39
68
  );
40
69
  return null;
41
70
  }
71
+ function ColumnInteractionHandler() {
72
+ const toggleColumn = state.useCorrelationMapStore((state2) => state2.toggleColumn);
73
+ const setHoveredColumn = state.useCorrelationMapStore(
74
+ (state2) => state2.setHoveredColumn
75
+ );
76
+ const isManual = state.useCorrelationMapStore(
77
+ (state2) => state2.selectionMode === "manual"
78
+ );
79
+ const hoveredRef = React.useRef(null);
80
+ mapboxReact.useMapStyleOperator(
81
+ (map) => {
82
+ if (!isManual) return;
83
+ const onClick = (e) => {
84
+ const colID = e.features?.[0]?.properties?.col_id;
85
+ if (colID != null) toggleColumn(colID);
86
+ };
87
+ map.on("click", columnLayers, onClick);
88
+ return () => map.off("click", columnLayers, onClick);
89
+ },
90
+ [isManual, toggleColumn]
91
+ );
92
+ mapboxReact.useMapStyleOperator(
93
+ (map) => {
94
+ const clearHover = () => {
95
+ if (hoveredRef.current != null) {
96
+ map.setFeatureState(
97
+ { source: "columns", id: hoveredRef.current },
98
+ { hover: false }
99
+ );
100
+ hoveredRef.current = null;
101
+ }
102
+ };
103
+ const onMove = (e) => {
104
+ const f = e.features?.[0];
105
+ if (f == null) return;
106
+ if (hoveredRef.current !== f.id) {
107
+ clearHover();
108
+ map.setFeatureState({ source: "columns", id: f.id }, { hover: true });
109
+ hoveredRef.current = f.id;
110
+ }
111
+ setHoveredColumn(f.properties?.col_id ?? null);
112
+ map.getCanvas().style.cursor = "pointer";
113
+ };
114
+ const onLeave = () => {
115
+ clearHover();
116
+ setHoveredColumn(null);
117
+ map.getCanvas().style.cursor = "";
118
+ };
119
+ map.on("mousemove", columnLayers, onMove);
120
+ map.on("mouseleave", columnLayers, onLeave);
121
+ return () => {
122
+ map.off("mousemove", columnLayers, onMove);
123
+ map.off("mouseleave", columnLayers, onLeave);
124
+ clearHover();
125
+ };
126
+ },
127
+ [setHoveredColumn]
128
+ );
129
+ return null;
130
+ }
131
+ function HoveredColumnHighlight() {
132
+ const hoveredColumn = state.useCorrelationMapStore((state2) => state2.hoveredColumn);
133
+ const columns2 = state.useCorrelationMapStore((state2) => state2.columns);
134
+ const appliedRef = React.useRef(null);
135
+ mapboxReact.useMapStyleOperator(
136
+ (map) => {
137
+ if (appliedRef.current != null) {
138
+ map.setFeatureState(
139
+ { source: "columns", id: appliedRef.current },
140
+ { highlighted: false }
141
+ );
142
+ appliedRef.current = null;
143
+ }
144
+ if (hoveredColumn == null || columns2 == null) return;
145
+ const col = columns2.find((c) => c.properties?.col_id === hoveredColumn);
146
+ const id = col?.id ?? col?.properties?.col_id;
147
+ if (id == null) return;
148
+ map.setFeatureState({ source: "columns", id }, { highlighted: true });
149
+ appliedRef.current = id;
150
+ },
151
+ [hoveredColumn, columns2]
152
+ );
153
+ return null;
154
+ }
42
155
  function SelectedColumnsLayer() {
43
156
  mapboxReact.useOverlayStyle(() => selectedColumnsStyle, []);
44
157
  const focusedColumns = state.useCorrelationMapStore(
@@ -123,9 +236,14 @@ const lineOfSectionStyle = {
123
236
  function SectionLine({ padding }) {
124
237
  mapboxReact.useOverlayStyle(() => lineOfSectionStyle, []);
125
238
  const focusedLine = state.useCorrelationMapStore((state2) => state2.focusedLine);
239
+ const focusedColumns = state.useCorrelationMapStore(
240
+ (state2) => state2.focusedColumns
241
+ );
126
242
  mapboxReact.useMapStyleOperator(
127
243
  (map) => {
128
244
  if (focusedLine == null) {
245
+ mapboxUtils.setGeoJSON(map, "crossSectionLine", emptyFeatureCollection);
246
+ mapboxUtils.setGeoJSON(map, "crossSectionEndpoints", emptyFeatureCollection);
129
247
  return;
130
248
  }
131
249
  const data = {
@@ -151,17 +269,20 @@ function SectionLine({ padding }) {
151
269
  [focusedLine]
152
270
  );
153
271
  const bounds = React.useMemo(() => {
154
- if (focusedLine == null || focusedLine?.coordinates.length < 2) {
155
- return null;
156
- }
157
- let bounds2 = new mapboxGl.LngLatBounds();
158
- for (let coord of focusedLine.coordinates) {
272
+ const coords = focusedLine != null && focusedLine.coordinates.length >= 2 ? focusedLine.coordinates : focusedColumns.map((c) => c.properties.centroid.geometry.coordinates);
273
+ if (coords.length < 2) return null;
274
+ const bounds2 = new mapboxGl.LngLatBounds();
275
+ for (const coord of coords) {
159
276
  bounds2.extend(coord);
160
277
  }
161
278
  return bounds2;
162
- }, [focusedLine]);
279
+ }, [focusedLine, focusedColumns]);
163
280
  mapboxReact.useMapEaseTo({ bounds, padding, trackResize: true });
164
281
  return null;
165
282
  }
283
+ const emptyFeatureCollection = {
284
+ type: "FeatureCollection",
285
+ features: []
286
+ };
166
287
  exports.ColumnCorrelationMap = ColumnCorrelationMap;
167
288
  //# sourceMappingURL=core.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs","sources":["../../../src/maps/column-correlation/core.ts"],"sourcesContent":["import {\n useMapClickHandler,\n useMapEaseTo,\n useMapStyleOperator,\n useOverlayStyle,\n} from \"@macrostrat/mapbox-react\";\nimport { LngLatBounds, Style } from \"mapbox-gl\";\nimport h from \"@macrostrat/hyper\";\nimport { Feature, FeatureCollection } from \"geojson\";\nimport { ReactNode, useMemo } from \"react\";\nimport { setGeoJSON, buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\n\nimport { useCorrelationMapStore } from \"./state\";\nimport { InsetMap, type InsetMapProps } from \"../inset-map\";\nimport { BaseColumnsLayer } from \"../layers\";\nimport { buildCrossSectionLayers } from \"@macrostrat/map-styles\";\n\nexport interface CorrelationMapProps extends InsetMapProps {\n padding?: number;\n children?: ReactNode;\n accessToken?: string;\n columnColor?: string;\n}\n\nexport function ColumnCorrelationMap(props: CorrelationMapProps) {\n const { padding = 50, children, columnColor, projectID, ...rest } = props;\n\n return h(\n InsetMap,\n {\n ...rest,\n boxZoom: false,\n dragRotate: false,\n },\n [\n h(ColumnsLayer, { color: columnColor }),\n h(SelectedColumnsLayer),\n h(MapClickHandler),\n h(SectionLine, { padding }),\n children,\n ],\n );\n}\n\nfunction MapClickHandler() {\n const onClickMap = useCorrelationMapStore((state) => state.onClickMap);\n\n useMapClickHandler(\n (e) => {\n onClickMap(e, { type: \"Point\", coordinates: e.lngLat.toArray() });\n },\n [onClickMap],\n );\n\n return null;\n}\n\nfunction SelectedColumnsLayer() {\n useOverlayStyle(() => selectedColumnsStyle, []);\n\n const focusedColumns = useCorrelationMapStore(\n (state) => state.focusedColumns,\n );\n\n useMapStyleOperator(\n (map) => {\n let features = focusedColumns;\n\n const data: FeatureCollection = {\n type: \"FeatureCollection\",\n features,\n };\n\n const columnCentroidLine: Feature = {\n type: \"Feature\",\n geometry: {\n type: \"LineString\",\n coordinates: features.map(\n (col) => col.properties.centroid.geometry.coordinates,\n ),\n },\n properties: {},\n };\n\n setGeoJSON(map, \"selected-columns\", data);\n setGeoJSON(map, \"selected-column-centroids\", {\n type: \"FeatureCollection\",\n features: [columnCentroidLine],\n });\n },\n [focusedColumns],\n );\n return null;\n}\n\nfunction ColumnsLayer({ enabled = true, color }) {\n const columns = useCorrelationMapStore((state) => state.columns);\n return h(BaseColumnsLayer, { enabled, color, columns });\n}\n\nconst selectedColumnsStyle: Style = {\n version: 8,\n sources: {\n \"selected-columns\": buildGeoJSONSource(),\n \"selected-column-centroids\": buildGeoJSONSource(),\n },\n layers: [\n {\n id: \"selected-columns-fill\",\n type: \"fill\",\n source: \"selected-columns\",\n paint: {\n \"fill-color\": \"rgba(255, 0, 0, 0.1)\",\n },\n },\n {\n id: \"selected-column-centroids-line\",\n type: \"line\",\n source: \"selected-column-centroids\",\n paint: {\n \"line-color\": \"rgba(255, 0, 0, 0.8)\",\n \"line-width\": 2,\n \"line-dasharray\": [2, 2],\n },\n },\n {\n id: \"selected-column-centroids-points\",\n type: \"circle\",\n source: \"selected-column-centroids\",\n paint: {\n \"circle-radius\": 4,\n \"circle-color\": \"rgba(255, 0, 0, 0.8)\",\n },\n },\n ],\n};\n\nconst lineOfSectionStyle: Style = {\n version: 8,\n sources: {\n elevationMarker: buildGeoJSONSource(),\n crossSectionLine: buildGeoJSONSource(),\n crossSectionEndpoints: buildGeoJSONSource(),\n },\n layers: buildCrossSectionLayers(),\n};\n\nfunction SectionLine({ padding }: { padding: number }) {\n useOverlayStyle(() => lineOfSectionStyle, []);\n const focusedLine = useCorrelationMapStore((state) => state.focusedLine);\n\n // Setup focused line\n useMapStyleOperator(\n (map) => {\n if (focusedLine == null) {\n return;\n }\n const data: FeatureCollection = {\n type: \"FeatureCollection\",\n features: [\n {\n type: \"Feature\",\n geometry: focusedLine,\n properties: { id: \"focusedLine\" },\n },\n ],\n };\n\n setGeoJSON(map, \"crossSectionLine\", data);\n setGeoJSON(map, \"crossSectionEndpoints\", {\n type: \"FeatureCollection\",\n features: focusedLine.coordinates.map((coord) => ({\n type: \"Feature\",\n geometry: { type: \"Point\", coordinates: coord },\n properties: {},\n })),\n });\n },\n [focusedLine],\n );\n\n const bounds = useMemo(() => {\n if (focusedLine == null || focusedLine?.coordinates.length < 2) {\n return null;\n }\n let bounds = new LngLatBounds();\n for (let coord of focusedLine.coordinates) {\n bounds.extend(coord);\n }\n return bounds;\n }, [focusedLine]);\n\n useMapEaseTo({ bounds, padding, trackResize: true });\n\n return null;\n}\n"],"names":["h","InsetMap","useCorrelationMapStore","state","useMapClickHandler","useOverlayStyle","useMapStyleOperator","setGeoJSON","columns","BaseColumnsLayer","buildGeoJSONSource","buildCrossSectionLayers","useMemo","bounds","LngLatBounds","useMapEaseTo"],"mappings":";;;;;;;;;;;;;AAwBO,SAAS,qBAAqB,OAA4B;AAC/D,QAAM,EAAE,UAAU,IAAI,UAAU,aAAa,WAAW,GAAG,SAAS;AAEpE,SAAOA,WAAAA;AAAAA,IACLC,MAAAA;AAAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,SAAS;AAAA,MACT,YAAY;AAAA,IAAA;AAAA,IAEd;AAAA,MACED,WAAAA,QAAE,cAAc,EAAE,OAAO,aAAa;AAAA,MACtCA,WAAAA,QAAE,oBAAoB;AAAA,MACtBA,WAAAA,QAAE,eAAe;AAAA,MACjBA,mBAAE,aAAa,EAAE,SAAS;AAAA,MAC1B;AAAA,IAAA;AAAA,EACF;AAEJ;AAEA,SAAS,kBAAkB;AACzB,QAAM,aAAaE,MAAAA,uBAAuB,CAACC,WAAUA,OAAM,UAAU;AAErEC,cAAAA;AAAAA,IACE,CAAC,MAAM;AACL,iBAAW,GAAG,EAAE,MAAM,SAAS,aAAa,EAAE,OAAO,QAAA,GAAW;AAAA,IAClE;AAAA,IACA,CAAC,UAAU;AAAA,EAAA;AAGb,SAAO;AACT;AAEA,SAAS,uBAAuB;AAC9BC,8BAAgB,MAAM,sBAAsB,EAAE;AAE9C,QAAM,iBA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a;AACzCD,cAAO,OAAO,KAAK;AAAA,IACrB;AACA,WAAOA;AAAAA,EACT,GAAG,CAAC,WAAW,CAAC;AAEhBE,cAAAA,aAAa,EAAE,QAAQ,SAAS,aAAa,MAAM;AAEnD,SAAO;AACT;;"}
1
+ {"version":3,"file":"core.cjs","sources":["../../../src/maps/column-correlation/core.ts"],"sourcesContent":["import {\n useMapClickHandler,\n useMapEaseTo,\n useMapStyleOperator,\n useOverlayStyle,\n} from \"@macrostrat/mapbox-react\";\nimport { LngLatBounds, Style } from \"mapbox-gl\";\nimport h from \"@macrostrat/hyper\";\nimport { Feature, FeatureCollection } from \"geojson\";\nimport { ReactNode, useMemo, useRef } from \"react\";\nimport { setGeoJSON, buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\n\nimport { useCorrelationMapStore } from \"./state\";\nimport { InsetMap, type InsetMapProps } from \"../inset-map\";\nimport { BaseColumnsLayer } from \"../layers\";\nimport { buildCrossSectionLayers } from \"@macrostrat/map-styles\";\n\nexport interface CorrelationMapProps extends InsetMapProps {\n padding?: number;\n children?: ReactNode;\n accessToken?: string;\n columnColor?: string;\n}\n\nexport function ColumnCorrelationMap(props: CorrelationMapProps) {\n const { padding = 50, children, columnColor, projectID, ...rest } = props;\n\n return h(\n InsetMap,\n {\n ...rest,\n boxZoom: false,\n dragRotate: false,\n },\n [\n h(ColumnsLayer, { color: columnColor }),\n h(SelectedColumnsLayer),\n h(MapClickHandler),\n h(ColumnInteractionHandler),\n h(HoveredColumnHighlight),\n h(ColumnZoomer, { padding }),\n h(SectionLine, { padding }),\n children,\n ],\n );\n}\n\nfunction ColumnZoomer({ padding }: { padding: number }) {\n /** Frame a single column when `zoomColumn` is set (e.g. header click). */\n const zoomColumn = useCorrelationMapStore((state) => state.zoomColumn);\n const zoomNonce = useCorrelationMapStore((state) => state.zoomNonce);\n const columns = useCorrelationMapStore((state) => state.columns);\n\n const bounds = useMemo(() => {\n if (zoomColumn == null || columns == null) return null;\n const col = columns.find((c) => c.properties?.col_id === zoomColumn);\n if (col?.geometry == null) return null;\n const b = new LngLatBounds();\n forEachCoordinate(col.geometry, (coord) => b.extend(coord as [number, number]));\n return b.isEmpty() ? null : b;\n // zoomNonce forces a fresh bounds object so repeat clicks re-frame\n }, [zoomColumn, zoomNonce, columns]);\n\n useMapEaseTo({ bounds, padding: padding * 2 });\n return null;\n}\n\nfunction forEachCoordinate(geometry: any, fn: (coord: number[]) => void) {\n const walk = (coords: any) => {\n if (typeof coords[0] === \"number\") {\n fn(coords);\n } else {\n for (const c of coords) walk(c);\n }\n };\n if (geometry?.coordinates != null) walk(geometry.coordinates);\n}\n\nconst columnLayers = [\"columns-fill\", \"columns-points\"];\n\nfunction MapClickHandler() {\n const onClickMap = useCorrelationMapStore((state) => state.onClickMap);\n\n useMapClickHandler(\n (e) => {\n onClickMap(e, { type: \"Point\", coordinates: e.lngLat.toArray() });\n },\n [onClickMap],\n );\n\n return null;\n}\n\nfunction ColumnInteractionHandler() {\n /** Per-column click (manual selection) and hover highlighting. */\n const toggleColumn = useCorrelationMapStore((state) => state.toggleColumn);\n const setHoveredColumn = useCorrelationMapStore(\n (state) => state.setHoveredColumn,\n );\n const isManual = useCorrelationMapStore(\n (state) => state.selectionMode === \"manual\",\n );\n const hoveredRef = useRef<number | string | null>(null);\n\n // Click a column to toggle it in/out of the selection (manual mode only)\n useMapStyleOperator(\n (map) => {\n if (!isManual) return;\n const onClick = (e) => {\n const colID = e.features?.[0]?.properties?.col_id;\n if (colID != null) toggleColumn(colID);\n };\n map.on(\"click\", columnLayers, onClick);\n return () => map.off(\"click\", columnLayers, onClick);\n },\n [isManual, toggleColumn],\n );\n\n // Hover highlighting (via the columns layer's `hover` feature-state)\n useMapStyleOperator(\n (map) => {\n const clearHover = () => {\n if (hoveredRef.current != null) {\n map.setFeatureState(\n { source: \"columns\", id: hoveredRef.current },\n { hover: false },\n );\n hoveredRef.current = null;\n }\n };\n const onMove = (e) => {\n const f = e.features?.[0];\n if (f == null) return;\n if (hoveredRef.current !== f.id) {\n clearHover();\n map.setFeatureState({ source: \"columns\", id: f.id }, { hover: true });\n hoveredRef.current = f.id;\n }\n setHoveredColumn(f.properties?.col_id ?? null);\n map.getCanvas().style.cursor = \"pointer\";\n };\n const onLeave = () => {\n clearHover();\n setHoveredColumn(null);\n map.getCanvas().style.cursor = \"\";\n };\n map.on(\"mousemove\", columnLayers, onMove);\n map.on(\"mouseleave\", columnLayers, onLeave);\n return () => {\n map.off(\"mousemove\", columnLayers, onMove);\n map.off(\"mouseleave\", columnLayers, onLeave);\n clearHover();\n };\n },\n [setHoveredColumn],\n );\n\n return null;\n}\n\nfunction HoveredColumnHighlight() {\n /** Reflects the store's `hoveredColumn` on the map (e.g. when a column is\n * hovered elsewhere in the UI) using the `highlighted` feature-state. */\n const hoveredColumn = useCorrelationMapStore((state) => state.hoveredColumn);\n const columns = useCorrelationMapStore((state) => state.columns);\n const appliedRef = useRef<number | string | null>(null);\n\n useMapStyleOperator(\n (map) => {\n if (appliedRef.current != null) {\n map.setFeatureState(\n { source: \"columns\", id: appliedRef.current },\n { highlighted: false },\n );\n appliedRef.current = null;\n }\n if (hoveredColumn == null || columns == null) return;\n const col = columns.find((c) => c.properties?.col_id === hoveredColumn);\n const id = (col as any)?.id ?? col?.properties?.col_id;\n if (id == null) return;\n map.setFeatureState({ source: \"columns\", id }, { highlighted: true });\n appliedRef.current = id;\n },\n [hoveredColumn, columns],\n );\n\n return null;\n}\n\nfunction SelectedColumnsLayer() {\n useOverlayStyle(() => selectedColumnsStyle, []);\n\n const focusedColumns = useCorrelationMapStore(\n (state) => state.focusedColumns,\n );\n\n useMapStyleOperator(\n (map) => {\n let features = focusedColumns;\n\n const data: FeatureCollection = {\n type: \"FeatureCollection\",\n features,\n };\n\n const columnCentroidLine: Feature = {\n type: \"Feature\",\n geometry: {\n type: \"LineString\",\n coordinates: features.map(\n (col) => col.properties.centroid.geometry.coordinates,\n ),\n },\n properties: {},\n };\n\n setGeoJSON(map, \"selected-columns\", data);\n setGeoJSON(map, \"selected-column-centroids\", {\n type: \"FeatureCollection\",\n features: [columnCentroidLine],\n });\n },\n [focusedColumns],\n );\n return null;\n}\n\nfunction ColumnsLayer({ enabled = true, color }) {\n const columns = useCorrelationMapStore((state) => state.columns);\n return h(BaseColumnsLayer, { enabled, color, columns });\n}\n\nconst selectedColumnsStyle: Style = {\n version: 8,\n sources: {\n \"selected-columns\": buildGeoJSONSource(),\n \"selected-column-centroids\": buildGeoJSONSource(),\n },\n layers: [\n {\n id: \"selected-columns-fill\",\n type: \"fill\",\n source: \"selected-columns\",\n paint: {\n \"fill-color\": \"rgba(255, 0, 0, 0.1)\",\n },\n },\n {\n id: \"selected-column-centroids-line\",\n type: \"line\",\n source: \"selected-column-centroids\",\n paint: {\n \"line-color\": \"rgba(255, 0, 0, 0.8)\",\n \"line-width\": 2,\n \"line-dasharray\": [2, 2],\n },\n },\n {\n id: \"selected-column-centroids-points\",\n type: \"circle\",\n source: \"selected-column-centroids\",\n paint: {\n \"circle-radius\": 4,\n \"circle-color\": \"rgba(255, 0, 0, 0.8)\",\n },\n },\n ],\n};\n\nconst lineOfSectionStyle: Style = {\n version: 8,\n sources: {\n elevationMarker: buildGeoJSONSource(),\n crossSectionLine: buildGeoJSONSource(),\n crossSectionEndpoints: buildGeoJSONSource(),\n },\n layers: buildCrossSectionLayers(),\n};\n\nfunction SectionLine({ padding }: { padding: number }) {\n useOverlayStyle(() => lineOfSectionStyle, []);\n const focusedLine = useCorrelationMapStore((state) => state.focusedLine);\n const focusedColumns = useCorrelationMapStore(\n (state) => state.focusedColumns,\n );\n\n // Setup focused line (only drawn in line-of-section mode)\n useMapStyleOperator(\n (map) => {\n if (focusedLine == null) {\n // Clear any previously-drawn line (e.g. after switching to manual mode)\n setGeoJSON(map, \"crossSectionLine\", emptyFeatureCollection);\n setGeoJSON(map, \"crossSectionEndpoints\", emptyFeatureCollection);\n return;\n }\n const data: FeatureCollection = {\n type: \"FeatureCollection\",\n features: [\n {\n type: \"Feature\",\n geometry: focusedLine,\n properties: { id: \"focusedLine\" },\n },\n ],\n };\n\n setGeoJSON(map, \"crossSectionLine\", data);\n setGeoJSON(map, \"crossSectionEndpoints\", {\n type: \"FeatureCollection\",\n features: focusedLine.coordinates.map((coord) => ({\n type: \"Feature\",\n geometry: { type: \"Point\", coordinates: coord },\n properties: {},\n })),\n });\n },\n [focusedLine],\n );\n\n const bounds = useMemo(() => {\n // In line mode, frame the line; in manual mode, frame the selected columns\n const coords: number[][] =\n focusedLine != null && focusedLine.coordinates.length >= 2\n ? focusedLine.coordinates\n : focusedColumns.map((c) => c.properties.centroid.geometry.coordinates);\n if (coords.length < 2) return null;\n const bounds = new LngLatBounds();\n for (const coord of coords) {\n bounds.extend(coord as [number, number]);\n }\n return bounds;\n }, [focusedLine, focusedColumns]);\n\n useMapEaseTo({ bounds, padding, trackResize: true });\n\n return null;\n}\n\nconst emptyFeatureCollection: FeatureCollection = {\n type: \"FeatureCollection\",\n features: [],\n};\n"],"names":["h","InsetMap","useCorrelationMapStore","state","columns","useMemo","LngLatBounds","useMapEaseTo","useMapClickHandler","useRef","useMapStyleOperator","useOverlayStyle","setGeoJSON","BaseColumnsLayer","buildGeoJSONSource","buildCrossSectionLayers","bounds"],"mappings":";;;;;;;;;;;;;AAwBO,SAAS,qBAAqB,OAA4B;AAC/D,QAAM,EAAE,UAAU,IAAI,UAAU,aAAa,WAAW,GAAG,SAAS;AAEpE,SAAOA,WAAAA;AAAAA,IACLC,MAAAA;AAAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,SAAS;AAAA,MACT,YAAY;AAAA,IAAA;AAAA,IAEd;AAAA,MACED,WAAAA,QAAE,cAAc,EAAE,OAAO,aAAa;AAAA,MACtCA,WAAAA,QAAE,oBAAoB;AAAA,MACtBA,WAAAA,QAAE,eAAe;AAAA,MACjBA,WAAAA,QAAE,wBAAwB;AAAA,MAC1BA,WAAAA,QAAE,sBAAsB;AAAA,MACxBA,mBAAE,cAAc,EAAE,SAAS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