@macrostrat/column-views 3.8.0 → 3.10.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 (173) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/dist/animated-age-window.cjs +51 -0
  3. package/dist/animated-age-window.cjs.map +1 -0
  4. package/dist/animated-age-window.d.ts +51 -0
  5. package/dist/animated-age-window.js +51 -0
  6. package/dist/animated-age-window.js.map +1 -0
  7. package/dist/column.cjs +11 -1
  8. package/dist/column.cjs.map +1 -1
  9. package/dist/column.d.ts +11 -0
  10. package/dist/column.js +11 -1
  11. package/dist/column.js.map +1 -1
  12. package/dist/correlation-chart/main.cjs +24 -12
  13. package/dist/correlation-chart/main.cjs.map +1 -1
  14. package/dist/correlation-chart/main.d.ts +8 -1
  15. package/dist/correlation-chart/main.js +24 -12
  16. package/dist/correlation-chart/main.js.map +1 -1
  17. package/dist/data-provider/store.cjs +17 -4
  18. package/dist/data-provider/store.cjs.map +1 -1
  19. package/dist/data-provider/store.d.ts +6 -1
  20. package/dist/data-provider/store.js +17 -4
  21. package/dist/data-provider/store.js.map +1 -1
  22. package/dist/index.cjs +17 -42
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +3 -1
  25. package/dist/index.js +3 -34
  26. package/dist/index.js.map +1 -1
  27. package/dist/prepare-units/composite-scale.cjs +94 -8
  28. package/dist/prepare-units/composite-scale.cjs.map +1 -1
  29. package/dist/prepare-units/composite-scale.d.ts +39 -0
  30. package/dist/prepare-units/composite-scale.js +96 -10
  31. package/dist/prepare-units/composite-scale.js.map +1 -1
  32. package/dist/prepare-units/helpers.cjs +0 -1
  33. package/dist/prepare-units/helpers.cjs.map +1 -1
  34. package/dist/prepare-units/helpers.js +0 -1
  35. package/dist/prepare-units/helpers.js.map +1 -1
  36. package/dist/prepare-units/index.cjs +33 -12
  37. package/dist/prepare-units/index.cjs.map +1 -1
  38. package/dist/prepare-units/index.js +34 -13
  39. package/dist/prepare-units/index.js.map +1 -1
  40. package/dist/prepare-units/types.cjs.map +1 -1
  41. package/dist/prepare-units/types.d.ts +13 -0
  42. package/dist/prepare-units/types.js.map +1 -1
  43. package/dist/section.cjs +4 -2
  44. package/dist/section.cjs.map +1 -1
  45. package/dist/section.d.ts +4 -1
  46. package/dist/section.js +4 -2
  47. package/dist/section.js.map +1 -1
  48. package/dist/units/boxes.cjs +22 -39
  49. package/dist/units/boxes.cjs.map +1 -1
  50. package/dist/units/boxes.js +24 -41
  51. package/dist/units/boxes.js.map +1 -1
  52. package/dist/units/composite.cjs +12 -12
  53. package/dist/units/composite.cjs.map +1 -1
  54. package/dist/units/composite.js +12 -12
  55. package/dist/units/composite.js.map +1 -1
  56. package/dist/units/index.cjs +7 -11
  57. package/dist/units/index.cjs.map +1 -1
  58. package/dist/units/index.d.ts +0 -1
  59. package/dist/units/index.js +4 -9
  60. package/dist/units/index.js.map +1 -1
  61. package/package.json +10 -31
  62. package/src/animated-age-window.ts +120 -0
  63. package/src/column.ts +24 -0
  64. package/src/correlation-chart/main.ts +30 -8
  65. package/src/data-provider/store.ts +21 -2
  66. package/src/index.ts +4 -1
  67. package/src/prepare-units/composite-scale.ts +210 -10
  68. package/src/prepare-units/helpers.ts +0 -2
  69. package/src/prepare-units/index.ts +68 -14
  70. package/src/prepare-units/types.ts +13 -0
  71. package/src/section.ts +6 -0
  72. package/src/units/boxes.ts +37 -56
  73. package/src/units/composite.ts +21 -12
  74. package/src/units/index.ts +9 -26
  75. package/dist/maps/column-correlation/core.cjs +0 -288
  76. package/dist/maps/column-correlation/core.cjs.map +0 -1
  77. package/dist/maps/column-correlation/core.d.ts +0 -9
  78. package/dist/maps/column-correlation/core.js +0 -286
  79. package/dist/maps/column-correlation/core.js.map +0 -1
  80. package/dist/maps/column-correlation/index.d.ts +0 -2
  81. package/dist/maps/column-correlation/state.cjs +0 -193
  82. package/dist/maps/column-correlation/state.cjs.map +0 -1
  83. package/dist/maps/column-correlation/state.d.ts +0 -62
  84. package/dist/maps/column-correlation/state.js +0 -190
  85. package/dist/maps/column-correlation/state.js.map +0 -1
  86. package/dist/maps/column-navigation/index.d.ts +0 -2
  87. package/dist/maps/column-navigation/mapbox/index.cjs +0 -215
  88. package/dist/maps/column-navigation/mapbox/index.cjs.map +0 -1
  89. package/dist/maps/column-navigation/mapbox/index.d.ts +0 -38
  90. package/dist/maps/column-navigation/mapbox/index.js +0 -213
  91. package/dist/maps/column-navigation/mapbox/index.js.map +0 -1
  92. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs +0 -105
  93. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs.map +0 -1
  94. package/dist/maps/column-navigation/mapbox/keyboard-navigation.d.ts +0 -8
  95. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js +0 -105
  96. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js.map +0 -1
  97. package/dist/maps/column-navigation/mapbox/state.cjs +0 -73
  98. package/dist/maps/column-navigation/mapbox/state.cjs.map +0 -1
  99. package/dist/maps/column-navigation/mapbox/state.d.ts +0 -23
  100. package/dist/maps/column-navigation/mapbox/state.js +0 -71
  101. package/dist/maps/column-navigation/mapbox/state.js.map +0 -1
  102. package/dist/maps/column-navigation/svg/animated.d.ts +0 -1
  103. package/dist/maps/column-navigation/svg/data-fetcher.cjs +0 -25
  104. package/dist/maps/column-navigation/svg/data-fetcher.cjs.map +0 -1
  105. package/dist/maps/column-navigation/svg/data-fetcher.d.ts +0 -6
  106. package/dist/maps/column-navigation/svg/data-fetcher.js +0 -25
  107. package/dist/maps/column-navigation/svg/data-fetcher.js.map +0 -1
  108. package/dist/maps/column-navigation/svg/index.cjs +0 -94
  109. package/dist/maps/column-navigation/svg/index.cjs.map +0 -1
  110. package/dist/maps/column-navigation/svg/index.d.ts +0 -9
  111. package/dist/maps/column-navigation/svg/index.js +0 -93
  112. package/dist/maps/column-navigation/svg/index.js.map +0 -1
  113. package/dist/maps/column-navigation/svg/layers.cjs +0 -177
  114. package/dist/maps/column-navigation/svg/layers.cjs.map +0 -1
  115. package/dist/maps/column-navigation/svg/layers.d.ts +0 -54
  116. package/dist/maps/column-navigation/svg/layers.js +0 -174
  117. package/dist/maps/column-navigation/svg/layers.js.map +0 -1
  118. package/dist/maps/column-navigation/utils/keyboard-navigation.cjs +0 -50
  119. package/dist/maps/column-navigation/utils/keyboard-navigation.cjs.map +0 -1
  120. package/dist/maps/column-navigation/utils/keyboard-navigation.d.ts +0 -10
  121. package/dist/maps/column-navigation/utils/keyboard-navigation.js +0 -50
  122. package/dist/maps/column-navigation/utils/keyboard-navigation.js.map +0 -1
  123. package/dist/maps/index.d.ts +0 -4
  124. package/dist/maps/inset-map/index.cjs +0 -71
  125. package/dist/maps/inset-map/index.cjs.map +0 -1
  126. package/dist/maps/inset-map/index.d.ts +0 -16
  127. package/dist/maps/inset-map/index.js +0 -69
  128. package/dist/maps/inset-map/index.js.map +0 -1
  129. package/dist/maps/layers/columns.cjs +0 -165
  130. package/dist/maps/layers/columns.cjs.map +0 -1
  131. package/dist/maps/layers/columns.d.ts +0 -28
  132. package/dist/maps/layers/columns.js +0 -165
  133. package/dist/maps/layers/columns.js.map +0 -1
  134. package/dist/maps/layers/index.d.ts +0 -2
  135. package/dist/maps/layers/units.cjs +0 -207
  136. package/dist/maps/layers/units.cjs.map +0 -1
  137. package/dist/maps/layers/units.d.ts +0 -14
  138. package/dist/maps/layers/units.js +0 -204
  139. package/dist/maps/layers/units.js.map +0 -1
  140. package/dist/units/colors.cjs +0 -115
  141. package/dist/units/colors.cjs.map +0 -1
  142. package/dist/units/colors.d.ts +0 -20
  143. package/dist/units/colors.js +0 -113
  144. package/dist/units/colors.js.map +0 -1
  145. package/dist/units/resolvers.cjs +0 -125
  146. package/dist/units/resolvers.cjs.map +0 -1
  147. package/dist/units/resolvers.d.ts +0 -8
  148. package/dist/units/resolvers.js +0 -125
  149. package/dist/units/resolvers.js.map +0 -1
  150. package/src/maps/column-correlation/column-correlation-map.stories.ts +0 -108
  151. package/src/maps/column-correlation/core.ts +0 -342
  152. package/src/maps/column-correlation/index.ts +0 -2
  153. package/src/maps/column-correlation/state.ts +0 -315
  154. package/src/maps/column-navigation/index.ts +0 -2
  155. package/src/maps/column-navigation/mapbox/column-navigation-map.stories.ts +0 -278
  156. package/src/maps/column-navigation/mapbox/index.ts +0 -276
  157. package/src/maps/column-navigation/mapbox/keyboard-navigation.ts +0 -133
  158. package/src/maps/column-navigation/mapbox/state.ts +0 -119
  159. package/src/maps/column-navigation/svg/animated.ts +0 -78
  160. package/src/maps/column-navigation/svg/column-navigation-svg-map.stories.ts +0 -46
  161. package/src/maps/column-navigation/svg/data-fetcher.ts +0 -34
  162. package/src/maps/column-navigation/svg/index.ts +0 -96
  163. package/src/maps/column-navigation/svg/layers.ts +0 -233
  164. package/src/maps/column-navigation/utils/keyboard-navigation.ts +0 -58
  165. package/src/maps/index.ts +0 -4
  166. package/src/maps/inset-map/index.ts +0 -87
  167. package/src/maps/inset-map/inset-map.stories.ts +0 -20
  168. package/src/maps/layers/columns.ts +0 -216
  169. package/src/maps/layers/index.ts +0 -2
  170. package/src/maps/layers/units.ts +0 -286
  171. package/src/maps/unit-map.stories.ts +0 -79
  172. package/src/units/colors.ts +0 -183
  173. package/src/units/resolvers.ts +0 -141
@@ -1 +1 @@
1
- {"version":3,"file":"boxes.cjs","sources":["../../src/units/boxes.ts"],"sourcesContent":["import {\n ColumnAxisType,\n ColumnContext,\n ColumnLayoutContext,\n ForeignObject,\n PatternDefsProvider,\n useColumn,\n useGeologicPattern,\n zigZagBoxPath,\n} from \"@macrostrat/column-components\";\nimport { SizeAwareLabel, Clickable } from \"@macrostrat/ui-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport { forwardRef, ReactNode, useContext, useMemo } from \"react\";\nimport { resolveID, scalePattern } from \"./resolvers\";\nimport { useUnitSelectionTarget } from \"../data-provider\";\nimport { useLithologies } from \"@macrostrat/data-provider\";\nimport { IUnit } from \"./types\";\nimport styles from \"./boxes.module.sass\";\nimport classNames from \"classnames\";\nimport { getUnitHeightRange } from \"../prepare-units/utils\";\nimport { getMixedUnitColor } from \"./colors\";\nimport type { RectBounds } from \"./types\";\n\nconst h = hyper.styled(styles);\n\ninterface UnitRectOptions {\n widthFraction?: number;\n axisType?: ColumnAxisType;\n // Padding to create overflow for zig-zags or other ornamented edges\n padding?: number;\n}\n\ninterface UnitProps extends Clickable, Partial<RectBounds>, UnitRectOptions {\n division: IUnit;\n resolveID?(IUnit): string;\n UUID?: string;\n defaultFill?: string;\n widthFraction?: number;\n children?: ReactNode;\n className?: string;\n fill?: string;\n backgroundColor?: string;\n patternColor?: string;\n patternID?: string | number;\n}\n\nexport interface LabeledUnitProps\n extends UnitRectOptions, Clickable, Partial<RectBounds> {\n division: IUnit;\n patternID?: string | number;\n label: string;\n onLabelUpdated?(label: string, shown: boolean);\n halfWidth?: boolean;\n showLabel?: boolean;\n backgroundColor?: string;\n}\n\nfunction useUnitRect(\n division: IUnit,\n options: UnitRectOptions = {},\n): RectBounds {\n const {\n widthFraction = 1,\n axisType = ColumnAxisType.AGE,\n padding = 0,\n } = options;\n const { scale } = useContext(ColumnContext);\n const { width } = useContext(ColumnLayoutContext);\n\n const [bottomHeight, topHeight] = getUnitHeightRange(division, axisType);\n\n const y = scale(topHeight);\n const height = Math.abs(scale(bottomHeight) - y);\n\n return {\n x: width * (1 - widthFraction) - padding,\n y: y - padding,\n height: height + padding * 2,\n width: widthFraction * width + padding * 2,\n };\n}\n\nexport function MinimalUnit(props) {\n const {\n division: d,\n children,\n className,\n widthFraction = 1,\n axisType: _, // not sure why this is brought in...\n nColumns: __,\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n const lithMap = useLithologies();\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n };\n\n const backgroundColor = getMixedUnitColor(d, lithMap, null, false);\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n \"--column-stroke-color\": backgroundColor,\n },\n },\n [\n h(\"rect.unit.background\", {\n ref,\n ...bounds,\n fill: backgroundColor,\n fillOpacity: 0.8,\n stroke: backgroundColor,\n onClick,\n }),\n h.if(linked)(\"rect.linked-overlay\", bounds),\n h.if(selected)(\"rect.selection-overlay\", bounds),\n ],\n );\n}\n\nfunction Unit(props: UnitProps) {\n const {\n division: d,\n children,\n fill,\n defaultFill = \"transparent\",\n className,\n widthFraction = 1,\n backgroundColor,\n patternColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n\n const hasOverflowTop = d.t_clip_pos != null;\n const hasOverflowBottom = d.b_clip_pos != null;\n\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n overflowTop: hasOverflowTop,\n overflowBottom: hasOverflowBottom,\n };\n const _patternID = patternID ?? resolveID(d);\n let _fill = fill ?? useGeologicPattern(_patternID, defaultFill);\n\n const hasBackgroundColor = backgroundColor != null;\n\n const _className = classNames(className, { colored: hasBackgroundColor });\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className: _className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n },\n },\n [\n h(UnitRect, {\n ...bounds,\n fill: backgroundColor,\n onClick,\n className: \"background\",\n }),\n h(UnitRect, {\n ref,\n ...bounds,\n fill: _fill,\n //mask,\n onClick,\n className: \"unit\",\n }),\n h.if(linked)(UnitRect, { ...bounds, className: \"linked-overlay\" }),\n h.if(selected)(UnitRect, { ...bounds, className: \"selection-overlay\" }),\n //defs,\n children,\n ],\n );\n}\n\ninterface UnitRectProps {\n x: number;\n y: number;\n width: number;\n height: number;\n className: string;\n // Used to determine if the rect should have a zig-zag edge on the top or bottom\n overflowTop?: boolean;\n overflowBottom?: boolean;\n [key: string]: any;\n}\n\nconst UnitRect = forwardRef((props: UnitRectProps, ref) => {\n const {\n x,\n y,\n width,\n height,\n overflowTop = false,\n overflowBottom = false,\n ...rest\n } = props;\n\n if (!overflowTop && !overflowBottom) {\n return h(\"rect\", {\n x,\n y,\n width,\n height,\n ref,\n ...rest,\n });\n } else {\n const d = zigZagBoxPath(x, y, width, height, overflowTop, overflowBottom);\n return h(\"path\", {\n d,\n ref,\n ...rest,\n });\n }\n});\n\nfunction LabeledUnit(props: LabeledUnitProps) {\n const {\n division,\n label,\n onLabelUpdated,\n widthFraction,\n showLabel = true,\n backgroundColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n const bounds = {\n ...useUnitRect(division, { widthFraction, axisType }),\n ...baseBounds,\n };\n const { width, height } = bounds;\n return h(\n Unit,\n {\n className: \"labeled-unit\",\n division,\n backgroundColor,\n patternID,\n ...bounds,\n },\n [\n h.if(showLabel)(\n ForeignObject,\n { ...bounds, className: \"unit-label-container\" },\n h(SizeAwareLabel, {\n className: \"unit-overlay\",\n labelClassName: \"unit-label\",\n style: { width, height },\n label,\n onVisibilityChanged(viz) {\n onLabelUpdated(label, viz);\n },\n }),\n ),\n ],\n );\n}\n\nfunction UnitBoxes<T>(props: {\n unitComponent: React.FunctionComponent<{ division: T }>;\n unitComponentProps?: any;\n transformDivisions?(divisions: T[]): T[];\n transformDivision?: (\n division: any,\n index: number,\n divisions: any[],\n ) => T | null;\n}) {\n const { unitComponent = Unit, unitComponentProps = {} } = props;\n const { divisions } = useContext(ColumnContext);\n\n if (divisions.length == 0) {\n console.warn(\"No divisions found in column context\");\n return null;\n }\n\n const children = useMemo(() => {\n return divisions.map((division: any, i) => {\n // @ts-ignore\n return h(unitComponent, {\n division,\n key: division.unit_id,\n ...unitComponentProps,\n });\n });\n }, [divisions, unitComponent, unitComponentProps]);\n\n return h(\n PatternDefsProvider,\n { resolveID, scalePattern },\n h(\"g.divisions\", children),\n );\n}\n\nexport { LabeledUnit, Unit, UnitBoxes, UnitProps };\n"],"names":["hyper","styles","ColumnAxisType","useContext","ColumnContext","ColumnLayoutContext","getUnitHeightRange","useColumn","resolveID","useGeologicPattern","classNames","useUnitSelectionTarget","forwardRef","zigZagBoxPath","ForeignObject","SizeAwareLabel","useMemo","PatternDefsProvider","scalePattern"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAM,IAAIA,WAAAA,QAAM,OAAOC,oBAAM;AAkC7B,SAAS,YACP,UACA,UAA2B,IACf;AACZ,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,WAAWC,iBAAAA,eAAe;AAAA,IAC1B,UAAU;AAAA,EAAA,IACR;AACJ,QAAM,EAAE,MAAA,IAAUC,MAAAA,WAAWC,8BAAa;AAC1C,QAAM,EAAE,MAAA,IAAUD,MAAAA,WAAWE,oCAAmB;AAEhD,QAAM,CAAC,cAAc,SAAS,IAAIC,MAAAA,mBAAmB,UAAU,QAAQ;AAEvE,QAAM,IAAI,MAAM,SAAS;AACzB,QAAM,SAAS,KAAK,IAAI,MAAM,YAAY,IAAI,CAAC;AAE/C,SAAO;AAAA,IACL,GAAG,SAAS,IAAI,iBAAiB;AAAA,IACjC,GAAG,IAAI;AAAA,IACP,QAAQ,SAAS,UAAU;AAAA,IAC3B,OAAO,gBAAgB,QAAQ,UAAU;AAAA,EAAA;AAE7C;AAgDA,SAAS,KAAK,OAAkB;AAC9B,QAAM;AAAA,IACJ,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA;AAAA,IACV,GAAG;AAAA,EAAA,IACD;AAEJ,QAAM,EAAE,SAAA,IAAaC,2BAAA;AAErB,QAAM,iBAAiB,EAAE,cAAc;AACvC,QAAM,oBAAoB,EAAE,cAAc;AAE1C,QAAM,SAAS;AAAA,IACb,GAAG,YAAY,GAAG,EAAE,eAAe,UAAU;AAAA,IAC7C,GAAG;AAAA,IACH,aAAa;AAAA,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,aAAO,EAAE,eAAe;AAAA,QACtB;AAAA,QACA,KAAK,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AAAA,IACH,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,eAAe,kBAAkB,CAAC;AAEjD,SAAO;AAAA,IACLC,iBAAAA;AAAAA,IACA,EAAA,WAAET,UAAAA,yBAAWU,UAAAA,aAAA;AAAA,IACb,EAAE,eAAe,QAAQ;AAAA,EAAA;AAE7B;;;;"}
1
+ {"version":3,"file":"boxes.cjs","sources":["../../src/units/boxes.ts"],"sourcesContent":["import {\n ColumnAxisType,\n ColumnContext,\n ColumnLayoutContext,\n ClippableRect,\n ForeignObject,\n PatternDefsProvider,\n useColumn,\n useGeologicPattern,\n} from \"@macrostrat/column-components\";\nimport { SizeAwareLabel, Clickable } from \"@macrostrat/ui-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport { ReactNode, useContext, useMemo } from \"react\";\nimport { useUnitSelectionTarget } from \"../data-provider\";\nimport { useLithologies } from \"@macrostrat/data-provider\";\nimport { IUnit } from \"./types\";\nimport styles from \"./boxes.module.sass\";\nimport classNames from \"classnames\";\nimport { getUnitHeightRange } from \"../prepare-units/utils\";\nimport type { RectBounds } from \"./types\";\nimport {\n getBestFGDCPatternForUnit,\n scalePattern,\n getMixedUnitColor,\n} from \"@macrostrat/stratigraphy-utils\";\n\nconst h = hyper.styled(styles);\n\n/** Resolve a class name through this file's CSS module exactly as the styled\n * `h` would (module-scoped classes are hashed; unknown/global classes pass\n * through). Needed because `ClippableRect` renders the element in\n * `@macrostrat/column-components`, so class resolution must happen here. */\nconst cls = (name: string): string => (styles as any)[name] ?? name;\n\ninterface UnitRectOptions {\n widthFraction?: number;\n axisType?: ColumnAxisType;\n // Padding to create overflow for zig-zags or other ornamented edges\n padding?: number;\n}\n\ninterface UnitProps extends Clickable, Partial<RectBounds>, UnitRectOptions {\n division: IUnit;\n resolveID?(IUnit): string;\n UUID?: string;\n defaultFill?: string;\n widthFraction?: number;\n children?: ReactNode;\n className?: string;\n fill?: string;\n backgroundColor?: string;\n patternColor?: string;\n patternID?: string | number;\n}\n\nexport interface LabeledUnitProps\n extends UnitRectOptions, Clickable, Partial<RectBounds> {\n division: IUnit;\n patternID?: string | number;\n label: string;\n onLabelUpdated?(label: string, shown: boolean);\n halfWidth?: boolean;\n showLabel?: boolean;\n backgroundColor?: string;\n}\n\nfunction useUnitRect(\n division: IUnit,\n options: UnitRectOptions = {},\n): RectBounds {\n const {\n widthFraction = 1,\n axisType = ColumnAxisType.AGE,\n padding = 0,\n } = options;\n const { scale } = useContext(ColumnContext);\n const { width } = useContext(ColumnLayoutContext);\n\n const [bottomHeight, topHeight] = getUnitHeightRange(division, axisType);\n\n const y = scale(topHeight);\n const height = Math.abs(scale(bottomHeight) - y);\n\n return {\n x: width * (1 - widthFraction) - padding,\n y: y - padding,\n height: height + padding * 2,\n width: widthFraction * width + padding * 2,\n };\n}\n\nexport function MinimalUnit(props) {\n const {\n division: d,\n children,\n className,\n widthFraction = 1,\n axisType: _, // not sure why this is brought in...\n nColumns: __,\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n const lithMap = useLithologies();\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n };\n\n const backgroundColor = getMixedUnitColor(d, lithMap, null, false);\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n \"--column-stroke-color\": backgroundColor,\n },\n },\n [\n h(\"rect.unit.background\", {\n ref,\n ...bounds,\n fill: backgroundColor,\n fillOpacity: 0.8,\n stroke: backgroundColor,\n onClick,\n }),\n h.if(linked)(\"rect.linked-overlay\", bounds),\n h.if(selected)(\"rect.selection-overlay\", bounds),\n ],\n );\n}\n\nfunction Unit(props: UnitProps) {\n const {\n division: d,\n children,\n fill,\n defaultFill = \"transparent\",\n className,\n widthFraction = 1,\n backgroundColor,\n patternColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n\n const hasOverflowTop = d.t_clip_pos != null;\n const hasOverflowBottom = d.b_clip_pos != null;\n\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n overflowTop: hasOverflowTop,\n overflowBottom: hasOverflowBottom,\n };\n const _patternID = patternID ?? getBestFGDCPatternForUnit(d);\n let _fill = fill ?? useGeologicPattern(_patternID, defaultFill);\n\n const hasBackgroundColor = backgroundColor != null;\n\n const _className = classNames(className, { colored: hasBackgroundColor });\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className: _className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n },\n },\n [\n h(ClippableRect, {\n ...bounds,\n fill: backgroundColor,\n onClick,\n className: cls(\"background\"),\n }),\n h(ClippableRect, {\n ref,\n ...bounds,\n fill: _fill,\n //mask,\n onClick,\n className: cls(\"unit\"),\n }),\n h.if(linked)(ClippableRect, {\n ...bounds,\n className: cls(\"linked-overlay\"),\n }),\n h.if(selected)(ClippableRect, {\n ...bounds,\n className: cls(\"selection-overlay\"),\n }),\n //defs,\n children,\n ],\n );\n}\n\nfunction LabeledUnit(props: LabeledUnitProps) {\n const {\n division,\n label,\n onLabelUpdated,\n widthFraction,\n showLabel = true,\n backgroundColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType, isTransitioning, hideLabelsWhileTransitioning } =\n useColumn();\n const bounds = {\n ...useUnitRect(division, { widthFraction, axisType }),\n ...baseBounds,\n };\n const { width, height } = bounds;\n // Labels stay visible through the animation by default. `hideLabelsWhileTransitioning`\n // is a perf escape hatch: when set, the `foreignObject` label (whose HTML\n // reflows on every size change) is skipped mid-transition and restored on settle.\n const skipLabel = isTransitioning && hideLabelsWhileTransitioning;\n return h(\n Unit,\n {\n className: \"labeled-unit\",\n division,\n backgroundColor,\n patternID,\n ...bounds,\n },\n [\n h.if(showLabel && !skipLabel)(\n ForeignObject,\n { ...bounds, className: \"unit-label-container\" },\n h(SizeAwareLabel, {\n className: \"unit-overlay\",\n labelClassName: \"unit-label\",\n style: { width, height },\n label,\n // Re-fit the label when a transition settles (isTransitioning flips),\n // not on every intermediate frame.\n remeasureKey: isTransitioning,\n onVisibilityChanged(viz) {\n onLabelUpdated(label, viz);\n },\n }),\n ),\n ],\n );\n}\n\nfunction UnitBoxes<T>(props: {\n unitComponent: React.FunctionComponent<{ division: T }>;\n unitComponentProps?: any;\n transformDivisions?(divisions: T[]): T[];\n transformDivision?: (\n division: any,\n index: number,\n divisions: any[],\n ) => T | null;\n}) {\n const { unitComponent = Unit, unitComponentProps = {} } = props;\n const { divisions } = useContext(ColumnContext);\n\n if (divisions.length == 0) {\n console.warn(\"No divisions found in column context\");\n return null;\n }\n\n const children = useMemo(() => {\n return divisions.map((division: any, i) => {\n // @ts-ignore\n return h(unitComponent, {\n division,\n key: division.unit_id,\n ...unitComponentProps,\n });\n });\n }, [divisions, unitComponent, unitComponentProps]);\n\n return h(\n PatternDefsProvider,\n { resolveID: getBestFGDCPatternForUnit, scalePattern },\n h(\"g.divisions\", children),\n );\n}\n\nexport { LabeledUnit, Unit, UnitBoxes, UnitProps };\n"],"names":["hyper","styles","ColumnAxisType","useContext","ColumnContext","ColumnLayoutContext","getUnitHeightRange","useColumn","getBestFGDCPatternForUnit","useGeologicPattern","classNames","useUnitSelectionTarget","ClippableRect","ForeignObject","SizeAwareLabel","useMemo","PatternDefsProvider","scalePattern"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,IAAIA,WAAAA,QAAM,OAAOC,oBAAM;AAM7B,MAAM,MAAM,CAAC,SAA0BA,qBAAe,IAAI,KAAK;AAkC/D,SAAS,YACP,UACA,UAA2B,IACf;AACZ,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,WAAWC,iBAAAA,eAAe;AAAA,IAC1B,UAAU;AAAA,EAAA,IACR;A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gB;AAAA,UAChB,WAAW;AAAA,UACX,gBAAgB;AAAA,UAChB,OAAO,EAAE,OAAO,OAAA;AAAA,UAChB;AAAA;AAAA;AAAA,UAGA,cAAc;AAAA,UACd,oBAAoB,KAAK;AACvB,2BAAe,OAAO,GAAG;AAAA,UAC3B;AAAA,QAAA,CACD;AAAA,MAAA;AAAA,IACH;AAAA,EACF;AAEJ;AAEA,SAAS,UAAa,OASnB;AACD,QAAM,EAAE,gBAAgB,MAAM,qBAAqB,CAAA,MAAO;AAC1D,QAAM,EAAE,UAAA,IAAcX,MAAAA,WAAWC,8BAAa;AAE9C,MAAI,UAAU,UAAU,GAAG;AACzB,YAAQ,KAAK,sCAAsC;AACnD,WAAO;AAAA,EACT;AAEA,QAAM,WAAWW,MAAAA,QAAQ,MAAM;AAC7B,WAAO,UAAU,IAAI,CAAC,UAAe,MAAM;AAEzC,aAAO,EAAE,eAAe;AAAA,QACtB;AAAA,QACA,KAAK,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AAAA,IACH,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,eAAe,kBAAkB,CAAC;AAEjD,SAAO;AAAA,IACLC,iBAAAA;AAAAA,IACA,EAAE,WAAWR,kBAAAA,2BAAA,cAA2BS,+BAAA;AAAA,IACxC,EAAE,eAAe,QAAQ;AAAA,EAAA;AAE7B;;;;"}
@@ -1,14 +1,15 @@
1
- import { useColumn, ForeignObject, ColumnContext, PatternDefsProvider, ColumnAxisType, ColumnLayoutContext, useGeologicPattern, zigZagBoxPath } from "@macrostrat/column-components";
1
+ import { useColumn, ForeignObject, ColumnContext, PatternDefsProvider, ColumnAxisType, ColumnLayoutContext, useGeologicPattern, ClippableRect } from "@macrostrat/column-components";
2
2
  import { SizeAwareLabel } from "@macrostrat/ui-components";
3
3
  import h$1 from "@macrostrat/hyper";
4
- import { useContext, useMemo, forwardRef } from "react";
5
- import { scalePattern, resolveID } from "./resolvers.js";
4
+ import { useContext, useMemo } from "react";
6
5
  import "@macrostrat/data-provider";
7
6
  import h$2 from "./boxes.module.sass.js";
8
7
  import classNames from "classnames";
9
8
  import { getUnitHeightRange } from "../prepare-units/utils.js";
9
+ import { scalePattern, getBestFGDCPatternForUnit } from "@macrostrat/stratigraphy-utils";
10
10
  import { useUnitSelectionTarget } from "../data-provider/unit-selection.js";
11
11
  const h = h$1.styled(h$2);
12
+ const cls = (name) => h$2[name] ?? name;
12
13
  function useUnitRect(division, options = {}) {
13
14
  const {
14
15
  widthFraction = 1,
@@ -51,7 +52,7 @@ function Unit(props) {
51
52
  overflowTop: hasOverflowTop,
52
53
  overflowBottom: hasOverflowBottom
53
54
  };
54
- const _patternID = patternID ?? resolveID(d);
55
+ const _patternID = patternID ?? getBestFGDCPatternForUnit(d);
55
56
  let _fill = fill ?? useGeologicPattern(_patternID, defaultFill);
56
57
  const hasBackgroundColor = backgroundColor != null;
57
58
  const _className = classNames(className, { colored: hasBackgroundColor });
@@ -65,55 +66,33 @@ function Unit(props) {
65
66
  }
66
67
  },
67
68
  [
68
- h(UnitRect, {
69
+ h(ClippableRect, {
69
70
  ...bounds,
70
71
  fill: backgroundColor,
71
72
  onClick,
72
- className: "background"
73
+ className: cls("background")
73
74
  }),
74
- h(UnitRect, {
75
+ h(ClippableRect, {
75
76
  ref,
76
77
  ...bounds,
77
78
  fill: _fill,
78
79
  //mask,
79
80
  onClick,
80
- className: "unit"
81
+ className: cls("unit")
82
+ }),
83
+ h.if(linked)(ClippableRect, {
84
+ ...bounds,
85
+ className: cls("linked-overlay")
86
+ }),
87
+ h.if(selected)(ClippableRect, {
88
+ ...bounds,
89
+ className: cls("selection-overlay")
81
90
  }),
82
- h.if(linked)(UnitRect, { ...bounds, className: "linked-overlay" }),
83
- h.if(selected)(UnitRect, { ...bounds, className: "selection-overlay" }),
84
91
  //defs,
85
92
  children
86
93
  ]
87
94
  );
88
95
  }
89
- const UnitRect = forwardRef((props, ref) => {
90
- const {
91
- x,
92
- y,
93
- width,
94
- height,
95
- overflowTop = false,
96
- overflowBottom = false,
97
- ...rest
98
- } = props;
99
- if (!overflowTop && !overflowBottom) {
100
- return h("rect", {
101
- x,
102
- y,
103
- width,
104
- height,
105
- ref,
106
- ...rest
107
- });
108
- } else {
109
- const d = zigZagBoxPath(x, y, width, height, overflowTop, overflowBottom);
110
- return h("path", {
111
- d,
112
- ref,
113
- ...rest
114
- });
115
- }
116
- });
117
96
  function LabeledUnit(props) {
118
97
  const {
119
98
  division,
@@ -127,12 +106,13 @@ function LabeledUnit(props) {
127
106
  // not sure why this is brought in...
128
107
  ...baseBounds
129
108
  } = props;
130
- const { axisType } = useColumn();
109
+ const { axisType, isTransitioning, hideLabelsWhileTransitioning } = useColumn();
131
110
  const bounds = {
132
111
  ...useUnitRect(division, { widthFraction, axisType }),
133
112
  ...baseBounds
134
113
  };
135
114
  const { width, height } = bounds;
115
+ const skipLabel = isTransitioning && hideLabelsWhileTransitioning;
136
116
  return h(
137
117
  Unit,
138
118
  {
@@ -143,7 +123,7 @@ function LabeledUnit(props) {
143
123
  ...bounds
144
124
  },
145
125
  [
146
- h.if(showLabel)(
126
+ h.if(showLabel && !skipLabel)(
147
127
  ForeignObject,
148
128
  { ...bounds, className: "unit-label-container" },
149
129
  h(SizeAwareLabel, {
@@ -151,6 +131,9 @@ function LabeledUnit(props) {
151
131
  labelClassName: "unit-label",
152
132
  style: { width, height },
153
133
  label,
134
+ // Re-fit the label when a transition settles (isTransitioning flips),
135
+ // not on every intermediate frame.
136
+ remeasureKey: isTransitioning,
154
137
  onVisibilityChanged(viz) {
155
138
  onLabelUpdated(label, viz);
156
139
  }
@@ -177,7 +160,7 @@ function UnitBoxes(props) {
177
160
  }, [divisions, unitComponent, unitComponentProps]);
178
161
  return h(
179
162
  PatternDefsProvider,
180
- { resolveID, scalePattern },
163
+ { resolveID: getBestFGDCPatternForUnit, scalePattern },
181
164
  h("g.divisions", children)
182
165
  );
183
166
  }
@@ -1 +1 @@
1
- {"version":3,"file":"boxes.js","sources":["../../src/units/boxes.ts"],"sourcesContent":["import {\n ColumnAxisType,\n ColumnContext,\n ColumnLayoutContext,\n ForeignObject,\n PatternDefsProvider,\n useColumn,\n useGeologicPattern,\n zigZagBoxPath,\n} from \"@macrostrat/column-components\";\nimport { SizeAwareLabel, Clickable } from \"@macrostrat/ui-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport { forwardRef, ReactNode, useContext, useMemo } from \"react\";\nimport { resolveID, scalePattern } from \"./resolvers\";\nimport { useUnitSelectionTarget } from \"../data-provider\";\nimport { useLithologies } from \"@macrostrat/data-provider\";\nimport { IUnit } from \"./types\";\nimport styles from \"./boxes.module.sass\";\nimport classNames from \"classnames\";\nimport { getUnitHeightRange } from \"../prepare-units/utils\";\nimport { getMixedUnitColor } from \"./colors\";\nimport type { RectBounds } from \"./types\";\n\nconst h = hyper.styled(styles);\n\ninterface UnitRectOptions {\n widthFraction?: number;\n axisType?: ColumnAxisType;\n // Padding to create overflow for zig-zags or other ornamented edges\n padding?: number;\n}\n\ninterface UnitProps extends Clickable, Partial<RectBounds>, UnitRectOptions {\n division: IUnit;\n resolveID?(IUnit): string;\n UUID?: string;\n defaultFill?: string;\n widthFraction?: number;\n children?: ReactNode;\n className?: string;\n fill?: string;\n backgroundColor?: string;\n patternColor?: string;\n patternID?: string | number;\n}\n\nexport interface LabeledUnitProps\n extends UnitRectOptions, Clickable, Partial<RectBounds> {\n division: IUnit;\n patternID?: string | number;\n label: string;\n onLabelUpdated?(label: string, shown: boolean);\n halfWidth?: boolean;\n showLabel?: boolean;\n backgroundColor?: string;\n}\n\nfunction useUnitRect(\n division: IUnit,\n options: UnitRectOptions = {},\n): RectBounds {\n const {\n widthFraction = 1,\n axisType = ColumnAxisType.AGE,\n padding = 0,\n } = options;\n const { scale } = useContext(ColumnContext);\n const { width } = useContext(ColumnLayoutContext);\n\n const [bottomHeight, topHeight] = getUnitHeightRange(division, axisType);\n\n const y = scale(topHeight);\n const height = Math.abs(scale(bottomHeight) - y);\n\n return {\n x: width * (1 - widthFraction) - padding,\n y: y - padding,\n height: height + padding * 2,\n width: widthFraction * width + padding * 2,\n };\n}\n\nexport function MinimalUnit(props) {\n const {\n division: d,\n children,\n className,\n widthFraction = 1,\n axisType: _, // not sure why this is brought in...\n nColumns: __,\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n const lithMap = useLithologies();\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n };\n\n const backgroundColor = getMixedUnitColor(d, lithMap, null, false);\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n \"--column-stroke-color\": backgroundColor,\n },\n },\n [\n h(\"rect.unit.background\", {\n ref,\n ...bounds,\n fill: backgroundColor,\n fillOpacity: 0.8,\n stroke: backgroundColor,\n onClick,\n }),\n h.if(linked)(\"rect.linked-overlay\", bounds),\n h.if(selected)(\"rect.selection-overlay\", bounds),\n ],\n );\n}\n\nfunction Unit(props: UnitProps) {\n const {\n division: d,\n children,\n fill,\n defaultFill = \"transparent\",\n className,\n widthFraction = 1,\n backgroundColor,\n patternColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n\n const hasOverflowTop = d.t_clip_pos != null;\n const hasOverflowBottom = d.b_clip_pos != null;\n\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n overflowTop: hasOverflowTop,\n overflowBottom: hasOverflowBottom,\n };\n const _patternID = patternID ?? resolveID(d);\n let _fill = fill ?? useGeologicPattern(_patternID, defaultFill);\n\n const hasBackgroundColor = backgroundColor != null;\n\n const _className = classNames(className, { colored: hasBackgroundColor });\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className: _className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n },\n },\n [\n h(UnitRect, {\n ...bounds,\n fill: backgroundColor,\n onClick,\n className: \"background\",\n }),\n h(UnitRect, {\n ref,\n ...bounds,\n fill: _fill,\n //mask,\n onClick,\n className: \"unit\",\n }),\n h.if(linked)(UnitRect, { ...bounds, className: \"linked-overlay\" }),\n h.if(selected)(UnitRect, { ...bounds, className: \"selection-overlay\" }),\n //defs,\n children,\n ],\n );\n}\n\ninterface UnitRectProps {\n x: number;\n y: number;\n width: number;\n height: number;\n className: string;\n // Used to determine if the rect should have a zig-zag edge on the top or bottom\n overflowTop?: boolean;\n overflowBottom?: boolean;\n [key: string]: any;\n}\n\nconst UnitRect = forwardRef((props: UnitRectProps, ref) => {\n const {\n x,\n y,\n width,\n height,\n overflowTop = false,\n overflowBottom = false,\n ...rest\n } = props;\n\n if (!overflowTop && !overflowBottom) {\n return h(\"rect\", {\n x,\n y,\n width,\n height,\n ref,\n ...rest,\n });\n } else {\n const d = zigZagBoxPath(x, y, width, height, overflowTop, overflowBottom);\n return h(\"path\", {\n d,\n ref,\n ...rest,\n });\n }\n});\n\nfunction LabeledUnit(props: LabeledUnitProps) {\n const {\n division,\n label,\n onLabelUpdated,\n widthFraction,\n showLabel = true,\n backgroundColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n const bounds = {\n ...useUnitRect(division, { widthFraction, axisType }),\n ...baseBounds,\n };\n const { width, height } = bounds;\n return h(\n Unit,\n {\n className: \"labeled-unit\",\n division,\n backgroundColor,\n patternID,\n ...bounds,\n },\n [\n h.if(showLabel)(\n ForeignObject,\n { ...bounds, className: \"unit-label-container\" },\n h(SizeAwareLabel, {\n className: \"unit-overlay\",\n labelClassName: \"unit-label\",\n style: { width, height },\n label,\n onVisibilityChanged(viz) {\n onLabelUpdated(label, viz);\n },\n }),\n ),\n ],\n );\n}\n\nfunction UnitBoxes<T>(props: {\n unitComponent: React.FunctionComponent<{ division: T }>;\n unitComponentProps?: any;\n transformDivisions?(divisions: T[]): T[];\n transformDivision?: (\n division: any,\n index: number,\n divisions: any[],\n ) => T | null;\n}) {\n const { unitComponent = Unit, unitComponentProps = {} } = props;\n const { divisions } = useContext(ColumnContext);\n\n if (divisions.length == 0) {\n console.warn(\"No divisions found in column context\");\n return null;\n }\n\n const children = useMemo(() => {\n return divisions.map((division: any, i) => {\n // @ts-ignore\n return h(unitComponent, {\n division,\n key: division.unit_id,\n ...unitComponentProps,\n });\n });\n }, [divisions, unitComponent, unitComponentProps]);\n\n return h(\n PatternDefsProvider,\n { resolveID, scalePattern },\n h(\"g.divisions\", children),\n );\n}\n\nexport { LabeledUnit, Unit, UnitBoxes, UnitProps };\n"],"names":["hyper","styles"],"mappings":";;;;;;;;;;AAuBA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AAkC7B,SAAS,YACP,UACA,UAA2B,IACf;AACZ,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,WAAW,eAAe;AAAA,IAC1B,UAAU;AAAA,EAAA,IACR;AACJ,QAAM,EAAE,MAAA,IAAU,WAAW,aAAa;AAC1C,QAAM,EAAE,MAAA,IAAU,WAAW,mBAAmB;AAEhD,QAAM,CAAC,cAAc,SAAS,IAAI,mBAAmB,UAAU,QAAQ;AAEvE,QAAM,IAAI,MAAM,SAAS;AACzB,QAAM,SAAS,KAAK,IAAI,MAAM,YAAY,IAAI,CAAC;AAE/C,SAAO;AAAA,IACL,GAAG,SAAS,IAAI,iBAAiB;AAAA,IACjC,GAAG,IAAI;AAAA,IACP,QAAQ,SAAS,UAAU;AAAA,IAC3B,OAAO,gBAAgB,QAAQ,UAAU;AAAA,EAAA;AAE7C;AAgDA,SAAS,KAAK,OAAkB;AAC9B,QAAM;AAAA,IACJ,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA;AAAA,IACV,GAAG;AAAA,EAAA,IACD;AAEJ,QAAM,EAAE,SAAA,IAAa,UAAA;A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,EACT;AAEA,QAAM,WAAW,QAAQ,MAAM;AAC7B,WAAO,UAAU,IAAI,CAAC,UAAe,MAAM;AAEzC,aAAO,EAAE,eAAe;AAAA,QACtB;AAAA,QACA,KAAK,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AAAA,IACH,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,eAAe,kBAAkB,CAAC;AAEjD,SAAO;AAAA,IACL;AAAA,IACA,EAAE,WAAW,aAAA;AAAA,IACb,EAAE,eAAe,QAAQ;AAAA,EAAA;AAE7B;"}
1
+ {"version":3,"file":"boxes.js","sources":["../../src/units/boxes.ts"],"sourcesContent":["import {\n ColumnAxisType,\n ColumnContext,\n ColumnLayoutContext,\n ClippableRect,\n ForeignObject,\n PatternDefsProvider,\n useColumn,\n useGeologicPattern,\n} from \"@macrostrat/column-components\";\nimport { SizeAwareLabel, Clickable } from \"@macrostrat/ui-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport { ReactNode, useContext, useMemo } from \"react\";\nimport { useUnitSelectionTarget } from \"../data-provider\";\nimport { useLithologies } from \"@macrostrat/data-provider\";\nimport { IUnit } from \"./types\";\nimport styles from \"./boxes.module.sass\";\nimport classNames from \"classnames\";\nimport { getUnitHeightRange } from \"../prepare-units/utils\";\nimport type { RectBounds } from \"./types\";\nimport {\n getBestFGDCPatternForUnit,\n scalePattern,\n getMixedUnitColor,\n} from \"@macrostrat/stratigraphy-utils\";\n\nconst h = hyper.styled(styles);\n\n/** Resolve a class name through this file's CSS module exactly as the styled\n * `h` would (module-scoped classes are hashed; unknown/global classes pass\n * through). Needed because `ClippableRect` renders the element in\n * `@macrostrat/column-components`, so class resolution must happen here. */\nconst cls = (name: string): string => (styles as any)[name] ?? name;\n\ninterface UnitRectOptions {\n widthFraction?: number;\n axisType?: ColumnAxisType;\n // Padding to create overflow for zig-zags or other ornamented edges\n padding?: number;\n}\n\ninterface UnitProps extends Clickable, Partial<RectBounds>, UnitRectOptions {\n division: IUnit;\n resolveID?(IUnit): string;\n UUID?: string;\n defaultFill?: string;\n widthFraction?: number;\n children?: ReactNode;\n className?: string;\n fill?: string;\n backgroundColor?: string;\n patternColor?: string;\n patternID?: string | number;\n}\n\nexport interface LabeledUnitProps\n extends UnitRectOptions, Clickable, Partial<RectBounds> {\n division: IUnit;\n patternID?: string | number;\n label: string;\n onLabelUpdated?(label: string, shown: boolean);\n halfWidth?: boolean;\n showLabel?: boolean;\n backgroundColor?: string;\n}\n\nfunction useUnitRect(\n division: IUnit,\n options: UnitRectOptions = {},\n): RectBounds {\n const {\n widthFraction = 1,\n axisType = ColumnAxisType.AGE,\n padding = 0,\n } = options;\n const { scale } = useContext(ColumnContext);\n const { width } = useContext(ColumnLayoutContext);\n\n const [bottomHeight, topHeight] = getUnitHeightRange(division, axisType);\n\n const y = scale(topHeight);\n const height = Math.abs(scale(bottomHeight) - y);\n\n return {\n x: width * (1 - widthFraction) - padding,\n y: y - padding,\n height: height + padding * 2,\n width: widthFraction * width + padding * 2,\n };\n}\n\nexport function MinimalUnit(props) {\n const {\n division: d,\n children,\n className,\n widthFraction = 1,\n axisType: _, // not sure why this is brought in...\n nColumns: __,\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n const lithMap = useLithologies();\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n };\n\n const backgroundColor = getMixedUnitColor(d, lithMap, null, false);\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n \"--column-stroke-color\": backgroundColor,\n },\n },\n [\n h(\"rect.unit.background\", {\n ref,\n ...bounds,\n fill: backgroundColor,\n fillOpacity: 0.8,\n stroke: backgroundColor,\n onClick,\n }),\n h.if(linked)(\"rect.linked-overlay\", bounds),\n h.if(selected)(\"rect.selection-overlay\", bounds),\n ],\n );\n}\n\nfunction Unit(props: UnitProps) {\n const {\n division: d,\n children,\n fill,\n defaultFill = \"transparent\",\n className,\n widthFraction = 1,\n backgroundColor,\n patternColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType } = useColumn();\n\n const hasOverflowTop = d.t_clip_pos != null;\n const hasOverflowBottom = d.b_clip_pos != null;\n\n const bounds = {\n ...useUnitRect(d, { widthFraction, axisType }),\n ...baseBounds,\n overflowTop: hasOverflowTop,\n overflowBottom: hasOverflowBottom,\n };\n const _patternID = patternID ?? getBestFGDCPatternForUnit(d);\n let _fill = fill ?? useGeologicPattern(_patternID, defaultFill);\n\n const hasBackgroundColor = backgroundColor != null;\n\n const _className = classNames(className, { colored: hasBackgroundColor });\n\n const [ref, selected, onClick, linked] = useUnitSelectionTarget(d);\n\n return h(\n \"g.unit\",\n {\n className: _className,\n style: {\n \"--column-unit-background-color\": backgroundColor,\n },\n },\n [\n h(ClippableRect, {\n ...bounds,\n fill: backgroundColor,\n onClick,\n className: cls(\"background\"),\n }),\n h(ClippableRect, {\n ref,\n ...bounds,\n fill: _fill,\n //mask,\n onClick,\n className: cls(\"unit\"),\n }),\n h.if(linked)(ClippableRect, {\n ...bounds,\n className: cls(\"linked-overlay\"),\n }),\n h.if(selected)(ClippableRect, {\n ...bounds,\n className: cls(\"selection-overlay\"),\n }),\n //defs,\n children,\n ],\n );\n}\n\nfunction LabeledUnit(props: LabeledUnitProps) {\n const {\n division,\n label,\n onLabelUpdated,\n widthFraction,\n showLabel = true,\n backgroundColor,\n patternID,\n axisType: _, // not sure why this is brought in...\n ...baseBounds\n } = props;\n\n const { axisType, isTransitioning, hideLabelsWhileTransitioning } =\n useColumn();\n const bounds = {\n ...useUnitRect(division, { widthFraction, axisType }),\n ...baseBounds,\n };\n const { width, height } = bounds;\n // Labels stay visible through the animation by default. `hideLabelsWhileTransitioning`\n // is a perf escape hatch: when set, the `foreignObject` label (whose HTML\n // reflows on every size change) is skipped mid-transition and restored on settle.\n const skipLabel = isTransitioning && hideLabelsWhileTransitioning;\n return h(\n Unit,\n {\n className: \"labeled-unit\",\n division,\n backgroundColor,\n patternID,\n ...bounds,\n },\n [\n h.if(showLabel && !skipLabel)(\n ForeignObject,\n { ...bounds, className: \"unit-label-container\" },\n h(SizeAwareLabel, {\n className: \"unit-overlay\",\n labelClassName: \"unit-label\",\n style: { width, height },\n label,\n // Re-fit the label when a transition settles (isTransitioning flips),\n // not on every intermediate frame.\n remeasureKey: isTransitioning,\n onVisibilityChanged(viz) {\n onLabelUpdated(label, viz);\n },\n }),\n ),\n ],\n );\n}\n\nfunction UnitBoxes<T>(props: {\n unitComponent: React.FunctionComponent<{ division: T }>;\n unitComponentProps?: any;\n transformDivisions?(divisions: T[]): T[];\n transformDivision?: (\n division: any,\n index: number,\n divisions: any[],\n ) => T | null;\n}) {\n const { unitComponent = Unit, unitComponentProps = {} } = props;\n const { divisions } = useContext(ColumnContext);\n\n if (divisions.length == 0) {\n console.warn(\"No divisions found in column context\");\n return null;\n }\n\n const children = useMemo(() => {\n return divisions.map((division: any, i) => {\n // @ts-ignore\n return h(unitComponent, {\n division,\n key: division.unit_id,\n ...unitComponentProps,\n });\n });\n }, [divisions, unitComponent, unitComponentProps]);\n\n return h(\n PatternDefsProvider,\n { resolveID: getBestFGDCPatternForUnit, scalePattern },\n h(\"g.divisions\", children),\n );\n}\n\nexport { LabeledUnit, Unit, UnitBoxes, UnitProps };\n"],"names":["hyper","styles"],"mappings":";;;;;;;;;;AA0BA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AAM7B,MAAM,MAAM,CAAC,SAA0BA,IAAe,IAAI,KAAK;AAkC/D,SAAS,YACP,UACA,UAA2B,IACf;AACZ,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,WAAW,eAAe;AAAA,IAC1B,UAAU;AAAA,EAAA,IACR;AACJ,QAAM,EAAE,MAAA,IAAU,WAAW,aAAa;AAC1C,QAAM,EAAE,MAAA,IAAU,WAAW,mBAAmB;AAEhD,QAAM,CAAC,cAAc,SAAS,IAAI,mBAAmB,UAA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AAS,UAAa,OASnB;AACD,QAAM,EAAE,gBAAgB,MAAM,qBAAqB,CAAA,MAAO;AAC1D,QAAM,EAAE,UAAA,IAAc,WAAW,aAAa;AAE9C,MAAI,UAAU,UAAU,GAAG;AACzB,YAAQ,KAAK,sCAAsC;AACnD,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,QAAQ,MAAM;AAC7B,WAAO,UAAU,IAAI,CAAC,UAAe,MAAM;AAEzC,aAAO,EAAE,eAAe;AAAA,QACtB;AAAA,QACA,KAAK,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AAAA,IACH,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,eAAe,kBAAkB,CAAC;AAEjD,SAAO;AAAA,IACL;AAAA,IACA,EAAE,WAAW,2BAA2B,aAAA;AAAA,IACxC,EAAE,eAAe,QAAQ;AAAA,EAAA;AAE7B;"}
@@ -16,22 +16,22 @@ function LabelTrackerProvider(props) {
16
16
  const { children, units, findUnitID = findMacrostratUnitID } = props;
17
17
  const [unlabeledDivisions, setUnlabeledDivisions] = React.useState(null);
18
18
  const labelTrackerRef = React.useRef({});
19
+ const recompute = React.useCallback(() => {
20
+ const tracker = labelTrackerRef.current;
21
+ const allReported = units.every((d) => findUnitID(d) in tracker);
22
+ if (!allReported) return;
23
+ setUnlabeledDivisions(units.filter((d) => tracker[findUnitID(d)] === false));
24
+ }, [units, findUnitID]);
19
25
  const trackLabelVisibility = React.useCallback(
20
26
  (div, visible) => {
21
- const id = findUnitID(div);
22
- labelTrackerRef.current[id] = visible;
23
- if (Object.keys(labelTrackerRef.current).length == units.length) {
24
- setUnlabeledDivisions(
25
- // @ts-ignore
26
- units.filter((d) => {
27
- const id2 = findUnitID(d);
28
- return labelTrackerRef.current[id2] == false;
29
- })
30
- );
31
- }
27
+ labelTrackerRef.current[findUnitID(div)] = visible;
28
+ recompute();
32
29
  },
33
- [labelTrackerRef, units, findUnitID]
30
+ [recompute, findUnitID]
34
31
  );
32
+ React.useEffect(() => {
33
+ recompute();
34
+ }, [recompute]);
35
35
  const value = trackLabelVisibility;
36
36
  return h(
37
37
  LabelTrackerContext.Provider,
@@ -1 +1 @@
1
- {"version":3,"file":"composite.cjs","sources":["../../src/units/composite.ts"],"sourcesContent":["import { hyperStyled } from \"@macrostrat/hyper\";\nimport {\n ColumnContext,\n LithologyColumn,\n SVG,\n} from \"@macrostrat/column-components\";\nimport { defaultNameFunction, UnitNamesColumn } from \"./names\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { BaseUnit } from \"@macrostrat/api-types\";\nimport { LabeledUnit, UnitBoxes } from \"./boxes\";\nimport styles from \"./composite.module.sass\";\nimport {\n useCompositeScale,\n useMacrostratColumnData,\n useUnitSelectionDispatch,\n} from \"../data-provider\";\n\nconst h = hyperStyled(styles);\n\ninterface LabelTracker {\n [key: number]: boolean;\n}\n\nconst LabelTrackerContext = createContext(null);\nconst UnlabeledDivisionsContext = createContext(null);\n\nconst findMacrostratUnitID = (u) => u.unit_id;\n\nexport function LabelTrackerProvider(props) {\n /** Tracker for units to handle state for whether their labels fit inline or not.\n * Designed to work for single or composite columns.\n */\n const { children, units, findUnitID = findMacrostratUnitID } = props;\n const [unlabeledDivisions, setUnlabeledDivisions] = useState<\n BaseUnit[] | null\n >(null);\n const labelTrackerRef = useRef<LabelTracker>({});\n const trackLabelVisibility = useCallback(\n (div, visible) => {\n const id = findUnitID(div);\n labelTrackerRef.current[id] = visible;\n if (Object.keys(labelTrackerRef.current).length == units.length) {\n setUnlabeledDivisions(\n // @ts-ignore\n units.filter((d) => {\n const id = findUnitID(d);\n return labelTrackerRef.current[id] == false;\n }),\n );\n }\n },\n [labelTrackerRef, units, findUnitID],\n );\n\n const value = trackLabelVisibility;\n return h(\n LabelTrackerContext.Provider,\n { value },\n h(\n UnlabeledDivisionsContext.Provider,\n { value: unlabeledDivisions },\n children,\n ),\n );\n}\n\nfunction TrackedLabeledUnit({\n division,\n nameForDivision = defaultNameFunction,\n ...rest\n}) {\n const trackLabelVisibility = useContext(LabelTrackerContext);\n return h(LabeledUnit, {\n division,\n label: nameForDivision(division),\n onLabelUpdated(label, visible) {\n // If there is al LabelTrackerContext, update the label visibility\n trackLabelVisibility?.(division, visible);\n },\n ...rest,\n });\n}\n\nexport const CompositeUnitComponent = TrackedLabeledUnit;\n\ntype BaseUnitProps = {\n width: number;\n showLabels?: boolean;\n columnWidth?: number;\n clipToFrame?: boolean;\n};\n\ntype ICompositeUnitProps = BaseUnitProps & {\n gutterWidth?: number;\n labelOffset?: number;\n paddingLeft?: number;\n nameForDivision?: (division: BaseUnit) => string;\n children?: React.ReactNode;\n unitComponent?: React.FC<any>;\n unitComponentProps?: any;\n noteMode?: \"labeled\" | \"unlabeled\";\n showLabelColumn?: boolean;\n noteComponent?: React.FC<any>;\n shouldRenderNote?: (d: any) => boolean;\n};\n\ninterface CompositeUnitProps {\n unitComponent: React.FC<any>;\n unitComponentProps?: any;\n width: number;\n showLabels?: boolean;\n clipToFrame?: boolean;\n}\n\nexport function CompositeUnitsColumn(props: CompositeUnitProps) {\n /*\n A column with units and names either\n overlapping or offset to the right\n */\n const {\n width,\n unitComponent = TrackedLabeledUnit,\n unitComponentProps,\n clipToFrame,\n ...rest\n } = props;\n\n return h(LithologyColumn, { width, clipToFrame }, [\n h(UnitBoxes, {\n unitComponent,\n unitComponentProps,\n ...rest,\n }),\n ]);\n}\n\nexport function AnnotatedUnitsColumn(props: ICompositeUnitProps) {\n useEffect(() => {\n console.warn(\n \"AnnotatedUnitsColumn is deprecated and currently renders a no-op for transition purposes\",\n );\n }, []);\n return null;\n}\n\nexport function SectionLabelsColumn(props: ICompositeUnitProps) {\n // Section with \"squishy\" time scale\n const {\n width = 300,\n noteMode = \"unlabeled\",\n labelOffset = 30,\n noteComponent,\n shouldRenderNote,\n } = props;\n\n const { totalHeight, axisType } = useMacrostratColumnData();\n const _compositeScale = useCompositeScale();\n\n const unlabeledUnits = useContext(UnlabeledDivisionsContext);\n const unitsToLabel = noteMode == \"unlabeled\" ? unlabeledUnits : undefined;\n\n const selectUnit = useUnitSelectionDispatch();\n\n return h(\"div.section-labels-column\", [\n h(\n ColumnNotesProvider,\n {\n units: [],\n scale: _compositeScale,\n totalHeight,\n axisType,\n },\n h(\n SVG,\n {\n height: totalHeight,\n innerWidth: width - 4,\n paddingH: 1,\n paddingLeft: 3,\n },\n h(UnitNamesColumn, {\n divisions: unitsToLabel,\n paddingLeft: labelOffset,\n width,\n noteComponent,\n shouldRenderNote,\n scale: _compositeScale,\n onClickNote(note) {\n selectUnit(note.data, null, null);\n },\n }),\n ),\n ),\n ]);\n}\n\nexport function ColumnNotesProvider(props) {\n // A fake column axis provider that allows scales to cross\n const { children, scale, totalHeight, pixelScale } = props;\n\n const { axisType } = useMacrostratColumnData();\n\n return h(\n ColumnContext.Provider,\n {\n value: {\n divisions: [],\n scale,\n scaleClamped: scale,\n pixelHeight: totalHeight,\n pixelsPerMeter: pixelScale,\n axisType,\n zoom: 1,\n },\n },\n children,\n );\n}\n\nexport { TrackedLabeledUnit, ICompositeUnitProps };\n"],"names":["hyperStyled","styles","createContext","useState","useRef","useCallback","id","defaultNameFunction","useContext","LabeledUnit","LithologyColumn","UnitBoxes","useEffect","useMacrostratColumnData","useCompositeScale","useUnitSelectionDispatch","SVG","UnitNamesColumn","ColumnContext"],"mappings":";;;;;;;;;;AAwBA,MAAM,IAAIA,IAAAA,YAAYC,gBAAM;AAM5B,MAAM,sBAAsBC,MAAAA,cAAc,IAAI;AAC9C,MAAM,4BAA4BA,MAAAA,cAAc,IAAI;AAEpD,MAAM,uBAAuB,CAAC,MAAM,EAAE;AAE/B,SAAS,qBAAqB,OAAO;AAI1C,QAAM,EAAE,UAAU,OAAO,aAAa,yBAAyB;AAC/D,QAAM,CAAC,oBAAoB,qBAAqB,IAAIC,MAAAA,SAElD,IAAI;AACN,QAAM,kBAAkBC,MAAAA,OAAqB,EAAE;AAC/C,QAAM,uBAAuBC,MAAAA;A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ChB;AAAA,QACA,MAAM;AAAA,MAAA;AAAA,IACR;AAAA,IAEF;AAAA,EAAA;AAEJ;;;;;;;;"}
1
+ {"version":3,"file":"composite.cjs","sources":["../../src/units/composite.ts"],"sourcesContent":["import { hyperStyled } from \"@macrostrat/hyper\";\nimport {\n ColumnContext,\n LithologyColumn,\n SVG,\n} from \"@macrostrat/column-components\";\nimport { defaultNameFunction, UnitNamesColumn } from \"./names\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { BaseUnit } from \"@macrostrat/api-types\";\nimport { LabeledUnit, UnitBoxes } from \"./boxes\";\nimport styles from \"./composite.module.sass\";\nimport {\n useCompositeScale,\n useMacrostratColumnData,\n useUnitSelectionDispatch,\n} from \"../data-provider\";\n\nconst h = hyperStyled(styles);\n\ninterface LabelTracker {\n [key: number]: boolean;\n}\n\nconst LabelTrackerContext = createContext(null);\nconst UnlabeledDivisionsContext = createContext(null);\n\nconst findMacrostratUnitID = (u) => u.unit_id;\n\nexport function LabelTrackerProvider(props) {\n /** Tracker for units to handle state for whether their labels fit inline or not.\n * Designed to work for single or composite columns.\n */\n const { children, units, findUnitID = findMacrostratUnitID } = props;\n const [unlabeledDivisions, setUnlabeledDivisions] = useState<\n BaseUnit[] | null\n >(null);\n const labelTrackerRef = useRef<LabelTracker>({});\n\n const recompute = useCallback(() => {\n // Recompute over the *current* unit set (which changes as the column zooms).\n // The tracker ref accumulates entries for units seen at any zoom level, so\n // we gate on whether every currently-visible unit has reported — not on the\n // total number of tracked units, which would go stale and freeze the notes.\n const tracker = labelTrackerRef.current;\n const allReported = units.every((d) => findUnitID(d) in tracker);\n if (!allReported) return;\n setUnlabeledDivisions(units.filter((d) => tracker[findUnitID(d)] === false));\n }, [units, findUnitID]);\n\n const trackLabelVisibility = useCallback(\n (div, visible) => {\n labelTrackerRef.current[findUnitID(div)] = visible;\n recompute();\n },\n [recompute, findUnitID],\n );\n\n // Re-sync when the visible unit set changes (e.g. on zoom), so a unit whose\n // label now fits inline stops also rendering as a note, and vice versa.\n useEffect(() => {\n recompute();\n }, [recompute]);\n\n const value = trackLabelVisibility;\n return h(\n LabelTrackerContext.Provider,\n { value },\n h(\n UnlabeledDivisionsContext.Provider,\n { value: unlabeledDivisions },\n children,\n ),\n );\n}\n\nfunction TrackedLabeledUnit({\n division,\n nameForDivision = defaultNameFunction,\n ...rest\n}) {\n const trackLabelVisibility = useContext(LabelTrackerContext);\n return h(LabeledUnit, {\n division,\n label: nameForDivision(division),\n onLabelUpdated(label, visible) {\n // If there is al LabelTrackerContext, update the label visibility\n trackLabelVisibility?.(division, visible);\n },\n ...rest,\n });\n}\n\nexport const CompositeUnitComponent = TrackedLabeledUnit;\n\ntype BaseUnitProps = {\n width: number;\n showLabels?: boolean;\n columnWidth?: number;\n clipToFrame?: boolean;\n};\n\ntype ICompositeUnitProps = BaseUnitProps & {\n gutterWidth?: number;\n labelOffset?: number;\n paddingLeft?: number;\n nameForDivision?: (division: BaseUnit) => string;\n children?: React.ReactNode;\n unitComponent?: React.FC<any>;\n unitComponentProps?: any;\n noteMode?: \"labeled\" | \"unlabeled\";\n showLabelColumn?: boolean;\n noteComponent?: React.FC<any>;\n shouldRenderNote?: (d: any) => boolean;\n};\n\ninterface CompositeUnitProps {\n unitComponent: React.FC<any>;\n unitComponentProps?: any;\n width: number;\n showLabels?: boolean;\n clipToFrame?: boolean;\n}\n\nexport function CompositeUnitsColumn(props: CompositeUnitProps) {\n /*\n A column with units and names either\n overlapping or offset to the right\n */\n const {\n width,\n unitComponent = TrackedLabeledUnit,\n unitComponentProps,\n clipToFrame,\n ...rest\n } = props;\n\n return h(LithologyColumn, { width, clipToFrame }, [\n h(UnitBoxes, {\n unitComponent,\n unitComponentProps,\n ...rest,\n }),\n ]);\n}\n\nexport function AnnotatedUnitsColumn(props: ICompositeUnitProps) {\n useEffect(() => {\n console.warn(\n \"AnnotatedUnitsColumn is deprecated and currently renders a no-op for transition purposes\",\n );\n }, []);\n return null;\n}\n\nexport function SectionLabelsColumn(props: ICompositeUnitProps) {\n // Section with \"squishy\" time scale\n const {\n width = 300,\n noteMode = \"unlabeled\",\n labelOffset = 30,\n noteComponent,\n shouldRenderNote,\n } = props;\n\n const { totalHeight, axisType } = useMacrostratColumnData();\n const _compositeScale = useCompositeScale();\n\n const unlabeledUnits = useContext(UnlabeledDivisionsContext);\n const unitsToLabel = noteMode == \"unlabeled\" ? unlabeledUnits : undefined;\n\n const selectUnit = useUnitSelectionDispatch();\n\n return h(\"div.section-labels-column\", [\n h(\n ColumnNotesProvider,\n {\n units: [],\n scale: _compositeScale,\n totalHeight,\n axisType,\n },\n h(\n SVG,\n {\n height: totalHeight,\n innerWidth: width - 4,\n paddingH: 1,\n paddingLeft: 3,\n },\n h(UnitNamesColumn, {\n divisions: unitsToLabel,\n paddingLeft: labelOffset,\n width,\n noteComponent,\n shouldRenderNote,\n scale: _compositeScale,\n onClickNote(note) {\n selectUnit(note.data, null, null);\n },\n }),\n ),\n ),\n ]);\n}\n\nexport function ColumnNotesProvider(props) {\n // A fake column axis provider that allows scales to cross\n const { children, scale, totalHeight, pixelScale } = props;\n\n const { axisType } = useMacrostratColumnData();\n\n return h(\n ColumnContext.Provider,\n {\n value: {\n divisions: [],\n scale,\n scaleClamped: scale,\n pixelHeight: totalHeight,\n pixelsPerMeter: pixelScale,\n axisType,\n zoom: 1,\n },\n },\n children,\n );\n}\n\nexport { TrackedLabeledUnit, ICompositeUnitProps };\n"],"names":["hyperStyled","styles","createContext","useState","useRef","useCallback","useEffect","defaultNameFunction","useContext","LabeledUnit","LithologyColumn","UnitBoxes","useMacrostratColumnData","useCompositeScale","useUnitSelectionDispatch","SVG","UnitNamesColumn","ColumnContext"],"mappings":";;;;;;;;;;AAwBA,MAAM,IAAIA,IAAAA,YAAYC,gBAAM;AAM5B,MAAM,sBAAsBC,MAAAA,cAAc,IAAI;AAC9C,MAAM,4BAA4BA,MAAAA,cAAc,IAAI;AAEpD,MAAM,uBAAu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AAAA,UAClC;AAAA,QAAA,CACD;AAAA,MAAA;AAAA,IACH;AAAA,EACF,CACD;AACH;AAEO,SAAS,oBAAoB,OAAO;AAEzC,QAAM,EAAE,UAAU,OAAO,aAAa,eAAe;AAErD,QAAM,EAAE,SAAA,IAAaJ,8BAAA;AAErB,SAAO;AAAA,IACLK,iBAAAA,cAAc;AAAA,IACd;AAAA,MACE,OAAO;AAAA,QACL,WAAW,CAAA;AAAA,QACX;AAAA,QACA,cAAc;AAAA,QACd,aAAa;AAAA,QACb,gBAAgB;AAAA,QAChB;AAAA,QACA,MAAM;AAAA,MAAA;AAAA,IACR;AAAA,IAEF;AAAA,EAAA;AAEJ;;;;;;;;"}
@@ -14,22 +14,22 @@ function LabelTrackerProvider(props) {
14
14
  const { children, units, findUnitID = findMacrostratUnitID } = props;
15
15
  const [unlabeledDivisions, setUnlabeledDivisions] = useState(null);
16
16
  const labelTrackerRef = useRef({});
17
+ const recompute = useCallback(() => {
18
+ const tracker = labelTrackerRef.current;
19
+ const allReported = units.every((d) => findUnitID(d) in tracker);
20
+ if (!allReported) return;
21
+ setUnlabeledDivisions(units.filter((d) => tracker[findUnitID(d)] === false));
22
+ }, [units, findUnitID]);
17
23
  const trackLabelVisibility = useCallback(
18
24
  (div, visible) => {
19
- const id = findUnitID(div);
20
- labelTrackerRef.current[id] = visible;
21
- if (Object.keys(labelTrackerRef.current).length == units.length) {
22
- setUnlabeledDivisions(
23
- // @ts-ignore
24
- units.filter((d) => {
25
- const id2 = findUnitID(d);
26
- return labelTrackerRef.current[id2] == false;
27
- })
28
- );
29
- }
25
+ labelTrackerRef.current[findUnitID(div)] = visible;
26
+ recompute();
30
27
  },
31
- [labelTrackerRef, units, findUnitID]
28
+ [recompute, findUnitID]
32
29
  );
30
+ useEffect(() => {
31
+ recompute();
32
+ }, [recompute]);
33
33
  const value = trackLabelVisibility;
34
34
  return h(
35
35
  LabelTrackerContext.Provider,
@@ -1 +1 @@
1
- {"version":3,"file":"composite.js","sources":["../../src/units/composite.ts"],"sourcesContent":["import { hyperStyled } from \"@macrostrat/hyper\";\nimport {\n ColumnContext,\n LithologyColumn,\n SVG,\n} from \"@macrostrat/column-components\";\nimport { defaultNameFunction, UnitNamesColumn } from \"./names\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { BaseUnit } from \"@macrostrat/api-types\";\nimport { LabeledUnit, UnitBoxes } from \"./boxes\";\nimport styles from \"./composite.module.sass\";\nimport {\n useCompositeScale,\n useMacrostratColumnData,\n useUnitSelectionDispatch,\n} from \"../data-provider\";\n\nconst h = hyperStyled(styles);\n\ninterface LabelTracker {\n [key: number]: boolean;\n}\n\nconst LabelTrackerContext = createContext(null);\nconst UnlabeledDivisionsContext = createContext(null);\n\nconst findMacrostratUnitID = (u) => u.unit_id;\n\nexport function LabelTrackerProvider(props) {\n /** Tracker for units to handle state for whether their labels fit inline or not.\n * Designed to work for single or composite columns.\n */\n const { children, units, findUnitID = findMacrostratUnitID } = props;\n const [unlabeledDivisions, setUnlabeledDivisions] = useState<\n BaseUnit[] | null\n >(null);\n const labelTrackerRef = useRef<LabelTracker>({});\n const trackLabelVisibility = useCallback(\n (div, visible) => {\n const id = findUnitID(div);\n labelTrackerRef.current[id] = visible;\n if (Object.keys(labelTrackerRef.current).length == units.length) {\n setUnlabeledDivisions(\n // @ts-ignore\n units.filter((d) => {\n const id = findUnitID(d);\n return labelTrackerRef.current[id] == false;\n }),\n );\n }\n },\n [labelTrackerRef, units, findUnitID],\n );\n\n const value = trackLabelVisibility;\n return h(\n LabelTrackerContext.Provider,\n { value },\n h(\n UnlabeledDivisionsContext.Provider,\n { value: unlabeledDivisions },\n children,\n ),\n );\n}\n\nfunction TrackedLabeledUnit({\n division,\n nameForDivision = defaultNameFunction,\n ...rest\n}) {\n const trackLabelVisibility = useContext(LabelTrackerContext);\n return h(LabeledUnit, {\n division,\n label: nameForDivision(division),\n onLabelUpdated(label, visible) {\n // If there is al LabelTrackerContext, update the label visibility\n trackLabelVisibility?.(division, visible);\n },\n ...rest,\n });\n}\n\nexport const CompositeUnitComponent = TrackedLabeledUnit;\n\ntype BaseUnitProps = {\n width: number;\n showLabels?: boolean;\n columnWidth?: number;\n clipToFrame?: boolean;\n};\n\ntype ICompositeUnitProps = BaseUnitProps & {\n gutterWidth?: number;\n labelOffset?: number;\n paddingLeft?: number;\n nameForDivision?: (division: BaseUnit) => string;\n children?: React.ReactNode;\n unitComponent?: React.FC<any>;\n unitComponentProps?: any;\n noteMode?: \"labeled\" | \"unlabeled\";\n showLabelColumn?: boolean;\n noteComponent?: React.FC<any>;\n shouldRenderNote?: (d: any) => boolean;\n};\n\ninterface CompositeUnitProps {\n unitComponent: React.FC<any>;\n unitComponentProps?: any;\n width: number;\n showLabels?: boolean;\n clipToFrame?: boolean;\n}\n\nexport function CompositeUnitsColumn(props: CompositeUnitProps) {\n /*\n A column with units and names either\n overlapping or offset to the right\n */\n const {\n width,\n unitComponent = TrackedLabeledUnit,\n unitComponentProps,\n clipToFrame,\n ...rest\n } = props;\n\n return h(LithologyColumn, { width, clipToFrame }, [\n h(UnitBoxes, {\n unitComponent,\n unitComponentProps,\n ...rest,\n }),\n ]);\n}\n\nexport function AnnotatedUnitsColumn(props: ICompositeUnitProps) {\n useEffect(() => {\n console.warn(\n \"AnnotatedUnitsColumn is deprecated and currently renders a no-op for transition purposes\",\n );\n }, []);\n return null;\n}\n\nexport function SectionLabelsColumn(props: ICompositeUnitProps) {\n // Section with \"squishy\" time scale\n const {\n width = 300,\n noteMode = \"unlabeled\",\n labelOffset = 30,\n noteComponent,\n shouldRenderNote,\n } = props;\n\n const { totalHeight, axisType } = useMacrostratColumnData();\n const _compositeScale = useCompositeScale();\n\n const unlabeledUnits = useContext(UnlabeledDivisionsContext);\n const unitsToLabel = noteMode == \"unlabeled\" ? unlabeledUnits : undefined;\n\n const selectUnit = useUnitSelectionDispatch();\n\n return h(\"div.section-labels-column\", [\n h(\n ColumnNotesProvider,\n {\n units: [],\n scale: _compositeScale,\n totalHeight,\n axisType,\n },\n h(\n SVG,\n {\n height: totalHeight,\n innerWidth: width - 4,\n paddingH: 1,\n paddingLeft: 3,\n },\n h(UnitNamesColumn, {\n divisions: unitsToLabel,\n paddingLeft: labelOffset,\n width,\n noteComponent,\n shouldRenderNote,\n scale: _compositeScale,\n onClickNote(note) {\n selectUnit(note.data, null, null);\n },\n }),\n ),\n ),\n ]);\n}\n\nexport function ColumnNotesProvider(props) {\n // A fake column axis provider that allows scales to cross\n const { children, scale, totalHeight, pixelScale } = props;\n\n const { axisType } = useMacrostratColumnData();\n\n return h(\n ColumnContext.Provider,\n {\n value: {\n divisions: [],\n scale,\n scaleClamped: scale,\n pixelHeight: totalHeight,\n pixelsPerMeter: pixelScale,\n axisType,\n zoom: 1,\n },\n },\n children,\n );\n}\n\nexport { TrackedLabeledUnit, ICompositeUnitProps };\n"],"names":["styles","id"],"mappings":";;;;;;;;AAwBA,MAAM,IAAI,YAAYA,GAAM;AAM5B,MAAM,sBAAsB,cAAc,IAAI;AAC9C,MAAM,4BAA4B,cAAc,IAAI;AAEpD,MAAM,uBAAuB,CAAC,MAAM,EAAE;AAE/B,SAAS,qBAAqB,OAAO;AAI1C,QAAM,EAAE,UAAU,OAAO,aAAa,yBAAyB;AAC/D,QAAM,CAAC,oBAAoB,qBAAqB,IAAI,SAElD,IAAI;AACN,QAAM,kBAAkB,OAAqB,EAAE;AAC/C,QAAM,uBAAuB;AAAA,IAC3B,CAAC,KAAK,YAAY;AAChB,YAAM,KAAK,WAAW,GAAG;AACzB,sBAAgB,QAAQ,EAAE,IAAI;AAC9B,UAAI,OAAO,KAAK,gBAAgB,OAAO,EAAE,UAAU,MAAM,QAAQ;AAC/D;AAAA;AAAA,UAEE,MAAM,OAAO,CAAC,MAAM;AAClB,kBAAMC,MAAK,WAAW,CAAC;AACvB,mBAAO,gBAAgB,QAAQA,GAAE,KAAK;AAAA,UACxC,CAAC;AAAA,QAAA;AAAA,MAEL;AA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iBAAiB;AAEhE,QAAM,aAAa,yBAAA;AAEnB,SAAO,EAAE,6BAA6B;AAAA,IACpC;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO,CAAA;AAAA,QACP,OAAO;AAAA,QACP;AAAA,QACA;AAAA,MAAA;AAAA,MAEF;AAAA,QACE;AAAA,QACA;AAAA,UACE,QAAQ;AAAA,UACR,YAAY,QAAQ;AAAA,UACpB,UAAU;AAAA,UACV,aAAa;AAAA,QAAA;AAAA,QAEf,EAAE,iBAAiB;AAAA,UACjB,WAAW;AAAA,UACX,aAAa;AAAA,UACb;AAAA,UACA;AAAA,UACA;AAAA,UACA,OAAO;AAAA,UACP,YAAY,MAAM;AAChB,uBAAW,KAAK,MAAM,MAAM,IAAI;AAAA,UAClC;AAAA,QAAA,CACD;AAAA,MAAA;AAAA,IACH;AAAA,EACF,CACD;AACH;AAEO,SAAS,oBAAoB,OAAO;AAEzC,QAAM,EAAE,UAAU,OAAO,aAAa,eAAe;AAErD,QAAM,EAAE,SAAA,IAAa,wBAAA;AAErB,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,MACE,OAAO;AAAA,QACL,WAAW,CAAA;AAAA,QACX;AAAA,QACA,cAAc;AAAA,QACd,aAAa;AAAA,QACb,gBAAgB;AAAA,QAChB;AAAA,QACA,MAAM;AAAA,MAAA;AAAA,IACR;AAAA,IAEF;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"composite.js","sources":["../../src/units/composite.ts"],"sourcesContent":["import { hyperStyled } from \"@macrostrat/hyper\";\nimport {\n ColumnContext,\n LithologyColumn,\n SVG,\n} from \"@macrostrat/column-components\";\nimport { defaultNameFunction, UnitNamesColumn } from \"./names\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { BaseUnit } from \"@macrostrat/api-types\";\nimport { LabeledUnit, UnitBoxes } from \"./boxes\";\nimport styles from \"./composite.module.sass\";\nimport {\n useCompositeScale,\n useMacrostratColumnData,\n useUnitSelectionDispatch,\n} from \"../data-provider\";\n\nconst h = hyperStyled(styles);\n\ninterface LabelTracker {\n [key: number]: boolean;\n}\n\nconst LabelTrackerContext = createContext(null);\nconst UnlabeledDivisionsContext = createContext(null);\n\nconst findMacrostratUnitID = (u) => u.unit_id;\n\nexport function LabelTrackerProvider(props) {\n /** Tracker for units to handle state for whether their labels fit inline or not.\n * Designed to work for single or composite columns.\n */\n const { children, units, findUnitID = findMacrostratUnitID } = props;\n const [unlabeledDivisions, setUnlabeledDivisions] = useState<\n BaseUnit[] | null\n >(null);\n const labelTrackerRef = useRef<LabelTracker>({});\n\n const recompute = useCallback(() => {\n // Recompute over the *current* unit set (which changes as the column zooms).\n // The tracker ref accumulates entries for units seen at any zoom level, so\n // we gate on whether every currently-visible unit has reported — not on the\n // total number of tracked units, which would go stale and freeze the notes.\n const tracker = labelTrackerRef.current;\n const allReported = units.every((d) => findUnitID(d) in tracker);\n if (!allReported) return;\n setUnlabeledDivisions(units.filter((d) => tracker[findUnitID(d)] === false));\n }, [units, findUnitID]);\n\n const trackLabelVisibility = useCallback(\n (div, visible) => {\n labelTrackerRef.current[findUnitID(div)] = visible;\n recompute();\n },\n [recompute, findUnitID],\n );\n\n // Re-sync when the visible unit set changes (e.g. on zoom), so a unit whose\n // label now fits inline stops also rendering as a note, and vice versa.\n useEffect(() => {\n recompute();\n }, [recompute]);\n\n const value = trackLabelVisibility;\n return h(\n LabelTrackerContext.Provider,\n { value },\n h(\n UnlabeledDivisionsContext.Provider,\n { value: unlabeledDivisions },\n children,\n ),\n );\n}\n\nfunction TrackedLabeledUnit({\n division,\n nameForDivision = defaultNameFunction,\n ...rest\n}) {\n const trackLabelVisibility = useContext(LabelTrackerContext);\n return h(LabeledUnit, {\n division,\n label: nameForDivision(division),\n onLabelUpdated(label, visible) {\n // If there is al LabelTrackerContext, update the label visibility\n trackLabelVisibility?.(division, visible);\n },\n ...rest,\n });\n}\n\nexport const CompositeUnitComponent = TrackedLabeledUnit;\n\ntype BaseUnitProps = {\n width: number;\n showLabels?: boolean;\n columnWidth?: number;\n clipToFrame?: boolean;\n};\n\ntype ICompositeUnitProps = BaseUnitProps & {\n gutterWidth?: number;\n labelOffset?: number;\n paddingLeft?: number;\n nameForDivision?: (division: BaseUnit) => string;\n children?: React.ReactNode;\n unitComponent?: React.FC<any>;\n unitComponentProps?: any;\n noteMode?: \"labeled\" | \"unlabeled\";\n showLabelColumn?: boolean;\n noteComponent?: React.FC<any>;\n shouldRenderNote?: (d: any) => boolean;\n};\n\ninterface CompositeUnitProps {\n unitComponent: React.FC<any>;\n unitComponentProps?: any;\n width: number;\n showLabels?: boolean;\n clipToFrame?: boolean;\n}\n\nexport function CompositeUnitsColumn(props: CompositeUnitProps) {\n /*\n A column with units and names either\n overlapping or offset to the right\n */\n const {\n width,\n unitComponent = TrackedLabeledUnit,\n unitComponentProps,\n clipToFrame,\n ...rest\n } = props;\n\n return h(LithologyColumn, { width, clipToFrame }, [\n h(UnitBoxes, {\n unitComponent,\n unitComponentProps,\n ...rest,\n }),\n ]);\n}\n\nexport function AnnotatedUnitsColumn(props: ICompositeUnitProps) {\n useEffect(() => {\n console.warn(\n \"AnnotatedUnitsColumn is deprecated and currently renders a no-op for transition purposes\",\n );\n }, []);\n return null;\n}\n\nexport function SectionLabelsColumn(props: ICompositeUnitProps) {\n // Section with \"squishy\" time scale\n const {\n width = 300,\n noteMode = \"unlabeled\",\n labelOffset = 30,\n noteComponent,\n shouldRenderNote,\n } = props;\n\n const { totalHeight, axisType } = useMacrostratColumnData();\n const _compositeScale = useCompositeScale();\n\n const unlabeledUnits = useContext(UnlabeledDivisionsContext);\n const unitsToLabel = noteMode == \"unlabeled\" ? unlabeledUnits : undefined;\n\n const selectUnit = useUnitSelectionDispatch();\n\n return h(\"div.section-labels-column\", [\n h(\n ColumnNotesProvider,\n {\n units: [],\n scale: _compositeScale,\n totalHeight,\n axisType,\n },\n h(\n SVG,\n {\n height: totalHeight,\n innerWidth: width - 4,\n paddingH: 1,\n paddingLeft: 3,\n },\n h(UnitNamesColumn, {\n divisions: unitsToLabel,\n paddingLeft: labelOffset,\n width,\n noteComponent,\n shouldRenderNote,\n scale: _compositeScale,\n onClickNote(note) {\n selectUnit(note.data, null, null);\n },\n }),\n ),\n ),\n ]);\n}\n\nexport function ColumnNotesProvider(props) {\n // A fake column axis provider that allows scales to cross\n const { children, scale, totalHeight, pixelScale } = props;\n\n const { axisType } = useMacrostratColumnData();\n\n return h(\n ColumnContext.Provider,\n {\n value: {\n divisions: [],\n scale,\n scaleClamped: scale,\n pixelHeight: totalHeight,\n pixelsPerMeter: pixelScale,\n axisType,\n zoom: 1,\n },\n },\n children,\n );\n}\n\nexport { TrackedLabeledUnit, ICompositeUnitProps };\n"],"names":["styles"],"mappings":";;;;;;;;AAwBA,MAAM,IAAI,YAAYA,GAAM;AAM5B,MAAM,sBAAsB,cAAc,IAAI;AAC9C,MAAM,4BAA4B,cAAc,IAAI;AAEpD,MAAM,uBAAuB,CAAC,MAAM,EAAE;AAE/B,SAAS,qBAAqB,OAAO;AAI1C,QAAM,EAAE,UAAU,OAAO,aAAa,yBAAyB;AAC/D,QAAM,CAAC,oBAAoB,qBAAqB,IAAI,SAElD,IAAI;AACN,QAAM,kBAAkB,OAAqB,EAAE;AAE/C,QAAM,YAAY,YAAY,MAAM;AAKlC,UAAM,UAAU,gBAAgB;AAChC,UAAM,cAAc,MAAM,MAAM,CAAC,MAAM,WAAW,CAAC,KAAK,OAAO;AAC/D,QAAI,CAAC,YAAa;AAClB,0BAAsB,MAAM,OAAO,CAAC,MAAM,QAAQ,WAAW,CAAC,CAAC,MAAM,KAAK,CAAC;AAAA,EAC7E,GAAG,CAAC,OAAO,UAAU,CAAC;AAEtB,QAAM,uBAAuB;AAAA,IAC3B,CAAC,KAAK,YAAY;AAChB,sBAAgB,QAAQ,WAAW,GAAG,CAAC,IAAI;AAC3C,gBAAA;AAAA,IACF;AAAA,IACA,CAAC,WAAW,UAAU;AAAA,EAAA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,cAAc,iBAAiB;AAEhE,QAAM,aAAa,yBAAA;AAEnB,SAAO,EAAE,6BAA6B;AAAA,IACpC;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO,CAAA;AAAA,QACP,OAAO;AAAA,QACP;AAAA,QACA;AAAA,MAAA;AAAA,MAEF;AAAA,QACE;AAAA,QACA;AAAA,UACE,QAAQ;AAAA,UACR,YAAY,QAAQ;AAAA,UACpB,UAAU;AAAA,UACV,aAAa;AAAA,QAAA;AAAA,QAEf,EAAE,iBAAiB;AAAA,UACjB,WAAW;AAAA,UACX,aAAa;AAAA,UACb;AAAA,UACA;AAAA,UACA;AAAA,UACA,OAAO;AAAA,UACP,YAAY,MAAM;AAChB,uBAAW,KAAK,MAAM,MAAM,IAAI;AAAA,UAClC;AAAA,QAAA,CACD;AAAA,MAAA;AAAA,IACH;AAAA,EACF,CACD;AACH;AAEO,SAAS,oBAAoB,OAAO;AAEzC,QAAM,EAAE,UAAU,OAAO,aAAa,eAAe;AAErD,QAAM,EAAE,SAAA,IAAa,wBAAA;AAErB,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,MACE,OAAO;AAAA,QACL,WAAW,CAAA;AAAA,QACX;AAAA,QACA,cAAc;AAAA,QACd,aAAa;AAAA,QACb,gBAAgB;AAAA,QAChB;AAAA,QACA,MAAM;AAAA,MAAA;AAAA,IACR;AAAA,IAEF;AAAA,EAAA;AAEJ;"}
@@ -5,11 +5,10 @@ const columnComponents = require("@macrostrat/column-components");
5
5
  const names = require("./names.cjs");
6
6
  const boxes = require("./boxes.cjs");
7
7
  const uiComponents = require("@macrostrat/ui-components");
8
- const colors = require("./colors.cjs");
8
+ const stratigraphyUtils = require("@macrostrat/stratigraphy-utils");
9
9
  const composite = require("./composite.cjs");
10
10
  const dataProvider = require("@macrostrat/data-provider");
11
11
  const React = require("react");
12
- const resolvers = require("./resolvers.cjs");
13
12
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
13
  const h__default = /* @__PURE__ */ _interopDefault(h);
15
14
  function UnitsColumn({ width = 100 }) {
@@ -51,7 +50,7 @@ function UnitComponent({
51
50
  let reducedWidth = _nColumns;
52
51
  if ("layout" in division) {
53
52
  const layout = division.layout;
54
- _nColumns = Math.min(_nColumns, layout.totalColumns);
53
+ _nColumns = layout.totalColumns;
55
54
  columnIx = layout.column;
56
55
  reducedWidth = width / layout.totalColumns / layout.nColumns;
57
56
  x = columnIx * width / _nColumns;
@@ -69,13 +68,13 @@ function useUnitColor(unit, opts = {}) {
69
68
  const { asBackground = true } = opts;
70
69
  return React.useMemo(() => {
71
70
  if (unit == null || lithMap == null) return null;
72
- return colors.getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);
71
+ return stratigraphyUtils.getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);
73
72
  }, [unit?.unit_id, lithMap, inDarkMode, asBackground]);
74
73
  }
75
74
  function ColoredUnitComponent(props) {
76
75
  const backgroundColor = useUnitColor(props.division);
77
76
  const patternID = React.useMemo(() => {
78
- return resolvers.resolveID(props.division);
77
+ return stratigraphyUtils.getBestFGDCPatternForUnit(props.division);
79
78
  }, [props.division?.unit_id]);
80
79
  const fill = columnComponents.useGeologicPattern(patternID);
81
80
  return h__default.default(UnitComponent, {
@@ -91,20 +90,20 @@ function useUnitColorByEnvironment(unit, opts = {}) {
91
90
  const { asBackground = true } = opts;
92
91
  return React.useMemo(() => {
93
92
  if (unit == null || environmentMap == null) return null;
94
- let c = colors.getMixedUnitColor(unit, environmentMap, inDarkMode, asBackground, {
93
+ let c = stratigraphyUtils.getMixedUnitColor(unit, environmentMap, inDarkMode, asBackground, {
95
94
  key: "environ",
96
95
  id_key: "environ_id"
97
96
  });
98
97
  if (c != null) {
99
98
  return c;
100
99
  }
101
- return colors.getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);
100
+ return stratigraphyUtils.getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);
102
101
  }, [unit?.unit_id, environmentMap, lithMap, inDarkMode, asBackground]);
103
102
  }
104
103
  function EnvironmentColoredUnitComponent(props) {
105
104
  const backgroundColor = useUnitColorByEnvironment(props.division);
106
105
  const patternID = React.useMemo(() => {
107
- return resolvers.resolveID(props.division);
106
+ return stratigraphyUtils.getBestFGDCPatternForUnit(props.division);
108
107
  }, [props.division?.unit_id]);
109
108
  const fill = columnComponents.useGeologicPattern(patternID);
110
109
  return h__default.default(UnitComponent, {
@@ -113,9 +112,6 @@ function EnvironmentColoredUnitComponent(props) {
113
112
  ...props
114
113
  });
115
114
  }
116
- exports.flattenLithologies = colors.flattenLithologies;
117
- exports.getMixedColorForData = colors.getMixedColorForData;
118
- exports.getMixedUnitColor = colors.getMixedUnitColor;
119
115
  exports.AnnotatedUnitsColumn = composite.AnnotatedUnitsColumn;
120
116
  exports.ColumnNotesProvider = composite.ColumnNotesProvider;
121
117
  exports.CompositeUnitComponent = composite.CompositeUnitComponent;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/units/index.ts"],"sourcesContent":["import h from \"@macrostrat/hyper\";\nimport {\n LithologyColumn,\n useGeologicPattern,\n} from \"@macrostrat/column-components\";\nimport { UnitNamesColumn } from \"./names\";\nimport { ICompositeUnitProps } from \"./composite\";\nimport { UnitBoxes, UnitProps } from \"./boxes\";\nimport { useColumnLayout } from \"@macrostrat/column-components\";\nimport { useInDarkMode } from \"@macrostrat/ui-components\";\nimport { getMixedUnitColor } from \"./colors\";\nimport { TrackedLabeledUnit } from \"./composite\";\nimport { useEnvironments, useLithologies } from \"@macrostrat/data-provider\";\nimport { useMemo } from \"react\";\nimport { resolveID } from \"./resolvers\";\nimport { BaseUnit, Lithology } from \"@macrostrat/api-types\";\nimport { UnitWithLayoutParameters } from \"../prepare-units/helpers.ts\";\n\nexport * from \"./composite\";\nexport * from \"./types\";\nexport * from \"./colors\";\n\nexport function UnitsColumn({ width = 100 }) {\n /*\n A column showing units with USGS color fill\n */\n return h(LithologyColumn, { width }, h(UnitBoxes));\n}\n\nexport function SimpleUnitsColumn(props: ICompositeUnitProps) {\n /*\n A column with units and names either\n overlapping or offset to the right\n */\n const { columnWidth, width, gutterWidth = 0, labelOffset = 30 } = props;\n\n return h([\n h(UnitsColumn, {\n width: columnWidth,\n }),\n h(UnitNamesColumn, {\n transform: `translate(${columnWidth + gutterWidth})`,\n paddingLeft: labelOffset,\n width: width - columnWidth - gutterWidth,\n }),\n ]);\n}\n\nexport function BasicUnitComponent({ division, ...rest }) {\n /** A unit that allows directly setting colors and patterns. */\n\n return h(UnitComponent, {\n division,\n ...rest,\n backgroundColor: division.color,\n patternID: division.patternID,\n });\n}\n\ninterface UnitComponentProps<T extends BaseUnit> {\n division: UnitWithLayoutParameters<T> | T;\n nColumns: number;\n width?: number;\n}\n\nexport function UnitComponent<T extends BaseUnit>({\n division,\n nColumns = 2,\n ...rest\n}: UnitComponentProps<T>) {\n const width = rest.width ?? useColumnLayout()?.width;\n\n let _nColumns = nColumns;\n if (isNaN(_nColumns)) {\n _nColumns = 2;\n }\n let columnIx = 0;\n let x = 0;\n\n let reducedWidth = _nColumns;\n if (\"layout\" in division) {\n const layout = division.layout;\n _nColumns = Math.min(_nColumns, layout.totalColumns);\n columnIx = layout.column;\n reducedWidth = width / layout.totalColumns / layout.nColumns;\n x = (columnIx * width) / _nColumns;\n }\n return h(TrackedLabeledUnit, {\n division,\n ...rest,\n width: reducedWidth,\n x,\n });\n}\n\ninterface UnitColorOptions {\n asBackground?: boolean;\n}\n\nexport function useUnitColor(unit, opts: UnitColorOptions = {}): string | null {\n /** Get the color for a unit based on its lithology */\n const lithMap = useLithologies();\n const inDarkMode = useInDarkMode();\n const { asBackground = true } = opts;\n\n return useMemo(() => {\n if (unit == null || lithMap == null) return null;\n return getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);\n }, [unit?.unit_id, lithMap, inDarkMode, asBackground]);\n}\n\nexport function ColoredUnitComponent(props) {\n /** A unit component that is colored using a mixture of lithologies.\n * This is a separate component because it depends on more providers/contexts to determine coloring. */\n const backgroundColor = useUnitColor(props.division);\n\n const patternID = useMemo(() => {\n return resolveID(props.division); // ?? getPatternID(props.division.lith, lithMap);\n }, [props.division?.unit_id]);\n\n const fill = useGeologicPattern(patternID);\n\n return h(UnitComponent, {\n fill,\n backgroundColor,\n ...props,\n });\n}\n\nexport function useUnitColorByEnvironment(\n unit,\n opts: UnitColorOptions = {},\n): string | null {\n /** Get the color for a unit based on its lithology */\n const environmentMap = useEnvironments();\n const lithMap = useLithologies();\n const inDarkMode = useInDarkMode();\n const { asBackground = true } = opts;\n\n return useMemo(() => {\n if (unit == null || environmentMap == null) return null;\n let c = getMixedUnitColor(unit, environmentMap, inDarkMode, asBackground, {\n key: \"environ\",\n id_key: \"environ_id\",\n });\n if (c != null) {\n return c;\n }\n // Fallback to lithology color if no environment color is found\n return getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);\n }, [unit?.unit_id, environmentMap, lithMap, inDarkMode, asBackground]);\n}\n\nexport function EnvironmentColoredUnitComponent(props) {\n /** A unit component that is colored using a mixture of lithologies.\n * This is a separate component because it depends on more providers/contexts to determine coloring. */\n const backgroundColor = useUnitColorByEnvironment(props.division);\n\n const patternID = useMemo(() => {\n return resolveID(props.division); // ?? getPatternID(props.division.lith, lithMap);\n }, [props.division?.unit_id]);\n\n const fill = useGeologicPattern(patternID);\n\n return h(UnitComponent, {\n fill,\n backgroundColor,\n ...props,\n });\n}\n\nfunction getPatternID(\n liths: Array<Lithology>,\n lithMap: Map<number, Lithology>,\n): string | null {\n if (lithMap == null || liths == null || liths.length == 0) {\n return null;\n }\n const patternIDs = new Set<string>();\n for (const lith of liths) {\n const lithData = lithMap.get(lith.lith_id);\n if (lithData) {\n patternIDs.add(`${lithData.fill}`);\n }\n }\n let id = patternIDs.values()[0];\n if (id == \"0\") return null;\n return id;\n}\n"],"names":["h","LithologyColumn","UnitBoxes","UnitNamesColumn","useColumnLayout","TrackedLabeledUnit","useLithologies","useInDarkMode","useMemo","getMixedUnitColor","resolveID","useGeologicPattern","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E;AAEO,SAAS,gCAAgC,OAAO;AAGrD,QAAM,kBAAkB,0BAA0B,MAAM,QAAQ;AAEhE,QAAM,YAAYD,MAAAA,QAAQ,MAAM;AAC9B,WAAOE,UAAAA,UAAU,MAAM,QAAQ;AAAA,EACjC,GAAG,CAAC,MAAM,UAAU,OAAO,CAAC;AAE5B,QAAM,OAAOC,iBAAAA,mBAAmB,SAAS;AAEzC,SAAOX,WAAAA,QAAE,eAAe;AAAA,IACtB;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,CACJ;AACH;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/units/index.ts"],"sourcesContent":["import h from \"@macrostrat/hyper\";\nimport {\n LithologyColumn,\n useGeologicPattern,\n} from \"@macrostrat/column-components\";\nimport { UnitNamesColumn } from \"./names\";\nimport { ICompositeUnitProps } from \"./composite\";\nimport { UnitBoxes } from \"./boxes\";\nimport { useColumnLayout } from \"@macrostrat/column-components\";\nimport { useInDarkMode } from \"@macrostrat/ui-components\";\nimport {\n getBestFGDCPatternForUnit,\n getMixedUnitColor,\n} from \"@macrostrat/stratigraphy-utils\";\nimport { TrackedLabeledUnit } from \"./composite\";\nimport { useEnvironments, useLithologies } from \"@macrostrat/data-provider\";\nimport { useMemo } from \"react\";\nimport { BaseUnit, Lithology } from \"@macrostrat/api-types\";\nimport { UnitWithLayoutParameters } from \"../prepare-units/helpers.ts\";\n\nexport * from \"./composite\";\nexport * from \"./types\";\n\nexport function UnitsColumn({ width = 100 }) {\n /*\n A column showing units with USGS color fill\n */\n return h(LithologyColumn, { width }, h(UnitBoxes));\n}\n\nexport function SimpleUnitsColumn(props: ICompositeUnitProps) {\n /*\n A column with units and names either\n overlapping or offset to the right\n */\n const { columnWidth, width, gutterWidth = 0, labelOffset = 30 } = props;\n\n return h([\n h(UnitsColumn, {\n width: columnWidth,\n }),\n h(UnitNamesColumn, {\n transform: `translate(${columnWidth + gutterWidth})`,\n paddingLeft: labelOffset,\n width: width - columnWidth - gutterWidth,\n }),\n ]);\n}\n\nexport function BasicUnitComponent({ division, ...rest }) {\n /** A unit that allows directly setting colors and patterns. */\n\n return h(UnitComponent, {\n division,\n ...rest,\n backgroundColor: division.color,\n patternID: division.patternID,\n });\n}\n\ninterface UnitComponentProps<T extends BaseUnit> {\n division: UnitWithLayoutParameters<T> | T;\n nColumns: number;\n width?: number;\n}\n\nexport function UnitComponent<T extends BaseUnit>({\n division,\n nColumns = 2,\n ...rest\n}: UnitComponentProps<T>) {\n const width = rest.width ?? useColumnLayout()?.width;\n\n let _nColumns = nColumns;\n if (isNaN(_nColumns)) {\n _nColumns = 2;\n }\n let columnIx = 0;\n let x = 0;\n\n let reducedWidth = _nColumns;\n if (\"layout\" in division) {\n const layout = division.layout;\n _nColumns = layout.totalColumns;\n columnIx = layout.column;\n reducedWidth = width / layout.totalColumns / layout.nColumns;\n x = (columnIx * width) / _nColumns;\n }\n\n return h(TrackedLabeledUnit, {\n division,\n ...rest,\n width: reducedWidth,\n x,\n });\n}\n\ninterface UnitColorOptions {\n asBackground?: boolean;\n}\n\nexport function useUnitColor(unit, opts: UnitColorOptions = {}): string | null {\n /** Get the color for a unit based on its lithology */\n const lithMap = useLithologies();\n const inDarkMode = useInDarkMode();\n const { asBackground = true } = opts;\n\n return useMemo(() => {\n if (unit == null || lithMap == null) return null;\n return getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);\n }, [unit?.unit_id, lithMap, inDarkMode, asBackground]);\n}\n\nexport function ColoredUnitComponent(props) {\n /** A unit component that is colored using a mixture of lithologies.\n * This is a separate component because it depends on more providers/contexts to determine coloring. */\n const backgroundColor = useUnitColor(props.division);\n\n const patternID = useMemo(() => {\n return getBestFGDCPatternForUnit(props.division); // ?? getPatternID(props.division.lith, lithMap);\n }, [props.division?.unit_id]);\n\n const fill = useGeologicPattern(patternID);\n\n return h(UnitComponent, {\n fill,\n backgroundColor,\n ...props,\n });\n}\n\nexport function useUnitColorByEnvironment(\n unit,\n opts: UnitColorOptions = {},\n): string | null {\n /** Get the color for a unit based on its lithology */\n const environmentMap = useEnvironments();\n const lithMap = useLithologies();\n const inDarkMode = useInDarkMode();\n const { asBackground = true } = opts;\n\n return useMemo(() => {\n if (unit == null || environmentMap == null) return null;\n let c = getMixedUnitColor(unit, environmentMap, inDarkMode, asBackground, {\n key: \"environ\",\n id_key: \"environ_id\",\n });\n if (c != null) {\n return c;\n }\n // Fallback to lithology color if no environment color is found\n return getMixedUnitColor(unit, lithMap, inDarkMode, asBackground);\n }, [unit?.unit_id, environmentMap, lithMap, inDarkMode, asBackground]);\n}\n\nexport function EnvironmentColoredUnitComponent(props) {\n /** A unit component that is colored using a mixture of lithologies.\n * This is a separate component because it depends on more providers/contexts to determine coloring. */\n const backgroundColor = useUnitColorByEnvironment(props.division);\n\n const patternID = useMemo(() => {\n return getBestFGDCPatternForUnit(props.division); // ?? getPatternID(props.division.lith, lithMap);\n }, [props.division?.unit_id]);\n\n const fill = useGeologicPattern(patternID);\n\n return h(UnitComponent, {\n fill,\n backgroundColor,\n ...props,\n });\n}\n"],"names":["h","LithologyColumn","UnitBoxes","UnitNamesColumn","useColumnLayout","TrackedLabeledUnit","useLithologies","useInDarkMode","useMemo","getMixedUnitColor","getBestFGDCPatternForUnit","useGeologicPattern","useEnvironments"],"mappings":";;;;;;;;;;;;;AAuBO,SAAS,YAAY,EAAE,QAAQ,OAAO;AAI3C,SAAOA,WAAAA,QAAEC,iBAAAA,iBAAiB,EAAE,SAASD,WAAAA,QAAEE,MAAAA,SAAS,CAAC;AACnD;AAEO,SAAS,kBAAkB,OAA4B;AAK5D,QAAM,EAAE,aAAa,OAAO,cAAc,GAAG,cAAc,OAAO;AAElE,SAAOF,mBAAE;AAAA,IACPA,WAAAA,QAAE,aAAa;AAAA,MACb,OAAO;AAAA,IAAA,CACR;AAAA,IACDA,WAAAA,QAAEG,MAAAA,iBAAiB;AAAA,MACjB,WAAW,aAAa,cAAc,WAAW;AAAA,MACjD,aAAa;AA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ers.ts';
4
4
  export * from './composite';
5
5
  export * from './types';
6
- export * from './colors';
7
6
  export declare function UnitsColumn({ width }: {
8
7
  width?: number | undefined;
9
8
  }): import('react').FunctionComponentElement<import('@macrostrat/column-components').LithologyColumnProps>;
@@ -3,13 +3,11 @@ import { useGeologicPattern, useColumnLayout, LithologyColumn } from "@macrostra
3
3
  import { UnitNamesColumn } from "./names.js";
4
4
  import { UnitBoxes } from "./boxes.js";
5
5
  import { useInDarkMode } from "@macrostrat/ui-components";
6
- import { getMixedUnitColor } from "./colors.js";
7
- import { flattenLithologies, getMixedColorForData } from "./colors.js";
6
+ import { getBestFGDCPatternForUnit, getMixedUnitColor } from "@macrostrat/stratigraphy-utils";
8
7
  import { TrackedLabeledUnit } from "./composite.js";
9
8
  import { AnnotatedUnitsColumn, ColumnNotesProvider, CompositeUnitComponent, CompositeUnitsColumn, LabelTrackerProvider, SectionLabelsColumn } from "./composite.js";
10
9
  import { useLithologies, useEnvironments } from "@macrostrat/data-provider";
11
10
  import { useMemo } from "react";
12
- import { resolveID } from "./resolvers.js";
13
11
  function UnitsColumn({ width = 100 }) {
14
12
  return h(LithologyColumn, { width }, h(UnitBoxes));
15
13
  }
@@ -49,7 +47,7 @@ function UnitComponent({
49
47
  let reducedWidth = _nColumns;
50
48
  if ("layout" in division) {
51
49
  const layout = division.layout;
52
- _nColumns = Math.min(_nColumns, layout.totalColumns);
50
+ _nColumns = layout.totalColumns;
53
51
  columnIx = layout.column;
54
52
  reducedWidth = width / layout.totalColumns / layout.nColumns;
55
53
  x = columnIx * width / _nColumns;
@@ -73,7 +71,7 @@ function useUnitColor(unit, opts = {}) {
73
71
  function ColoredUnitComponent(props) {
74
72
  const backgroundColor = useUnitColor(props.division);
75
73
  const patternID = useMemo(() => {
76
- return resolveID(props.division);
74
+ return getBestFGDCPatternForUnit(props.division);
77
75
  }, [props.division?.unit_id]);
78
76
  const fill = useGeologicPattern(patternID);
79
77
  return h(UnitComponent, {
@@ -102,7 +100,7 @@ function useUnitColorByEnvironment(unit, opts = {}) {
102
100
  function EnvironmentColoredUnitComponent(props) {
103
101
  const backgroundColor = useUnitColorByEnvironment(props.division);
104
102
  const patternID = useMemo(() => {
105
- return resolveID(props.division);
103
+ return getBestFGDCPatternForUnit(props.division);
106
104
  }, [props.division?.unit_id]);
107
105
  const fill = useGeologicPattern(patternID);
108
106
  return h(UnitComponent, {
@@ -125,9 +123,6 @@ export {
125
123
  TrackedLabeledUnit,
126
124
  UnitComponent,
127
125
  UnitsColumn,
128
- flattenLithologies,
129
- getMixedColorForData,
130
- getMixedUnitColor,
131
126
  useUnitColor,
132
127
  useUnitColorByEnvironment
133
128
  };