@macrostrat/column-views 3.1.0 → 3.2.1

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 (121) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/age-axis.js +2 -2
  3. package/dist/age-axis.js.map +1 -1
  4. package/dist/age-axis.module.sass.cjs +6 -1
  5. package/dist/age-axis.module.sass.cjs.map +1 -1
  6. package/dist/age-axis.module.sass.js +4 -1
  7. package/dist/age-axis.module.sass.js.map +1 -1
  8. package/dist/age-model-overlay.js +2 -2
  9. package/dist/age-model-overlay.js.map +1 -1
  10. package/dist/age-model-overlay.module.sass.cjs +6 -1
  11. package/dist/age-model-overlay.module.sass.cjs.map +1 -1
  12. package/dist/age-model-overlay.module.sass.js +4 -1
  13. package/dist/age-model-overlay.module.sass.js.map +1 -1
  14. package/dist/column.js +2 -2
  15. package/dist/column.js.map +1 -1
  16. package/dist/column.module.sass.cjs +6 -1
  17. package/dist/column.module.sass.cjs.map +1 -1
  18. package/dist/column.module.sass.js +4 -1
  19. package/dist/column.module.sass.js.map +1 -1
  20. package/dist/correlation-chart/main.js +2 -2
  21. package/dist/correlation-chart/main.js.map +1 -1
  22. package/dist/correlation-chart/main.module.sass.cjs +6 -1
  23. package/dist/correlation-chart/main.module.sass.cjs.map +1 -1
  24. package/dist/correlation-chart/main.module.sass.js +4 -1
  25. package/dist/correlation-chart/main.module.sass.js.map +1 -1
  26. package/dist/data-provider/store.cjs +1 -1
  27. package/dist/data-provider/store.cjs.map +1 -1
  28. package/dist/data-provider/store.js +1 -1
  29. package/dist/data-provider/store.js.map +1 -1
  30. package/dist/facets/carbon-isotopes/isotopes-column.js +2 -2
  31. package/dist/facets/carbon-isotopes/isotopes-column.js.map +1 -1
  32. package/dist/facets/carbon-isotopes/isotopes-column.module.sass.cjs +6 -1
  33. package/dist/facets/carbon-isotopes/isotopes-column.module.sass.cjs.map +1 -1
  34. package/dist/facets/carbon-isotopes/isotopes-column.module.sass.js +4 -1
  35. package/dist/facets/carbon-isotopes/isotopes-column.module.sass.js.map +1 -1
  36. package/dist/facets/detrital-zircon/index.js +2 -2
  37. package/dist/facets/detrital-zircon/index.js.map +1 -1
  38. package/dist/facets/detrital-zircon/index.module.sass.cjs +6 -1
  39. package/dist/facets/detrital-zircon/index.module.sass.cjs.map +1 -1
  40. package/dist/facets/detrital-zircon/index.module.sass.js +4 -1
  41. package/dist/facets/detrital-zircon/index.module.sass.js.map +1 -1
  42. package/dist/facets/fossils/index.js +2 -2
  43. package/dist/facets/fossils/index.js.map +1 -1
  44. package/dist/facets/fossils/taxon-ranges.js +2 -2
  45. package/dist/facets/fossils/taxon-ranges.js.map +1 -1
  46. package/dist/facets/fossils/taxon-ranges.module.sass.cjs +6 -1
  47. package/dist/facets/fossils/taxon-ranges.module.sass.cjs.map +1 -1
  48. package/dist/facets/fossils/taxon-ranges.module.sass.js +4 -1
  49. package/dist/facets/fossils/taxon-ranges.module.sass.js.map +1 -1
  50. package/dist/facets/measurements/base.js +2 -2
  51. package/dist/facets/measurements/base.js.map +1 -1
  52. package/dist/facets/measurements/base.module.sass.cjs +6 -1
  53. package/dist/facets/measurements/base.module.sass.cjs.map +1 -1
  54. package/dist/facets/measurements/base.module.sass.js +4 -1
  55. package/dist/facets/measurements/base.module.sass.js.map +1 -1
  56. package/dist/index.cjs +11 -5
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.js +8 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/maps/_shared/styles.cjs +6 -1
  61. package/dist/maps/_shared/styles.cjs.map +1 -1
  62. package/dist/maps/_shared/styles.js +6 -1
  63. package/dist/maps/_shared/styles.js.map +1 -1
  64. package/dist/maps/column-navigation/mapbox/keyboard-navigation.d.ts +1 -1
  65. package/dist/maps/index.d.ts +1 -0
  66. package/dist/maps/units-overlay/index.cjs +254 -0
  67. package/dist/maps/units-overlay/index.cjs.map +1 -0
  68. package/dist/maps/units-overlay/index.d.ts +14 -0
  69. package/dist/maps/units-overlay/index.js +252 -0
  70. package/dist/maps/units-overlay/index.js.map +1 -0
  71. package/dist/section.js +2 -2
  72. package/dist/section.js.map +1 -1
  73. package/dist/unit-details/panel.cjs +9 -0
  74. package/dist/unit-details/panel.cjs.map +1 -1
  75. package/dist/unit-details/panel.js +11 -2
  76. package/dist/unit-details/panel.js.map +1 -1
  77. package/dist/unit-details/panel.module.sass.cjs +6 -1
  78. package/dist/unit-details/panel.module.sass.cjs.map +1 -1
  79. package/dist/unit-details/panel.module.sass.js +4 -1
  80. package/dist/unit-details/panel.module.sass.js.map +1 -1
  81. package/dist/unit-details/popover.js +2 -2
  82. package/dist/unit-details/popover.js.map +1 -1
  83. package/dist/unit-details/popover.module.sass.cjs +6 -1
  84. package/dist/unit-details/popover.module.sass.cjs.map +1 -1
  85. package/dist/unit-details/popover.module.sass.js +4 -1
  86. package/dist/unit-details/popover.module.sass.js.map +1 -1
  87. package/dist/units/boxes.js +2 -2
  88. package/dist/units/boxes.js.map +1 -1
  89. package/dist/units/boxes.module.sass.cjs +6 -1
  90. package/dist/units/boxes.module.sass.cjs.map +1 -1
  91. package/dist/units/boxes.module.sass.js +4 -1
  92. package/dist/units/boxes.module.sass.js.map +1 -1
  93. package/dist/units/colors.cjs +79 -18
  94. package/dist/units/colors.cjs.map +1 -1
  95. package/dist/units/colors.d.ts +17 -4
  96. package/dist/units/colors.js +79 -18
  97. package/dist/units/colors.js.map +1 -1
  98. package/dist/units/composite.js +2 -2
  99. package/dist/units/composite.js.map +1 -1
  100. package/dist/units/composite.module.sass.cjs +6 -1
  101. package/dist/units/composite.module.sass.cjs.map +1 -1
  102. package/dist/units/composite.module.sass.js +4 -1
  103. package/dist/units/composite.module.sass.js.map +1 -1
  104. package/dist/units/index.cjs +2 -0
  105. package/dist/units/index.cjs.map +1 -1
  106. package/dist/units/index.js +3 -0
  107. package/dist/units/index.js.map +1 -1
  108. package/dist/units/resolvers.cjs +11 -0
  109. package/dist/units/resolvers.cjs.map +1 -1
  110. package/dist/units/resolvers.d.ts +5 -0
  111. package/dist/units/resolvers.js +11 -0
  112. package/dist/units/resolvers.js.map +1 -1
  113. package/package.json +12 -11
  114. package/src/data-provider/store.ts +1 -0
  115. package/src/maps/_shared/styles.ts +10 -3
  116. package/src/maps/index.ts +1 -0
  117. package/src/maps/unit-map.stories.ts +64 -0
  118. package/src/maps/units-overlay/index.ts +336 -0
  119. package/src/unit-details/panel.ts +1 -1
  120. package/src/units/colors.ts +137 -25
  121. package/src/units/resolvers.ts +16 -0
@@ -4,11 +4,11 @@ import h$1 from "@macrostrat/hyper";
4
4
  import { useContext, useMemo, forwardRef } from "react";
5
5
  import { scalePattern, resolveID } from "./resolvers.js";
6
6
  import "@macrostrat/data-provider";
7
- import styles from "./boxes.module.sass.js";
7
+ import h$2 from "./boxes.module.sass.js";
8
8
  import classNames from "classnames";
9
9
  import { getUnitHeightRange } from "../prepare-units/utils.js";
10
10
  import { useUnitSelectionTarget } from "../data-provider/unit-selection.js";
11
- const h = h$1.styled(styles);
11
+ const h = h$1.styled(h$2);
12
12
  function useUnitRect(division, options = {}) {
13
13
  const {
14
14
  widthFraction = 1,
@@ -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] = 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(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] = 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(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"],"mappings":";;;;;;;;;;AAuBA,MAAM,IAAIA,IAAM,OAAO,MAAM;AAkC7B,SAAS,YACP,UACA,UAA2B,IACf;AACZ,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,WAAW,eAAe;AAAA,IAC1B,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,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,IAEL;AAAA,MACE,EAAE,GAAG,SAAS;AAAA,QACZ;AAAA,QACA,EAAE,GAAG,QAAQ,WAAW,uBAAA;AAAA,QACxB,EAAE,gBAAgB;AAAA,UAChB,WAAW;AAAA,UACX,gBAAgB;AAAA,UAChB,OAAO,EAAE,OAAO,OAAA;AAAA,UAChB;AAAA,UACA,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,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,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 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] = 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(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] = 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(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\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ol.toStringTag]: { value: "Module" } });
3
+ const h$1 = require("@macrostrat/hyper");
4
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
5
+ const h__default = /* @__PURE__ */ _interopDefault(h$1);
3
6
  const background = "_background_7b96n_20";
4
7
  const styles = {
5
8
  "unit-label-container": "_unit-label-container_7b96n_1",
6
9
  "labeled-unit": "_labeled-unit_7b96n_5",
7
10
  background
8
11
  };
12
+ let h = h__default.default.styled(styles);
13
+ Object.assign(h, styles);
9
14
  exports.background = background;
10
- exports.default = styles;
15
+ exports.default = h;
11
16
  //# sourceMappingURL=boxes.module.sass.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"boxes.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"boxes.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -1,11 +1,14 @@
1
+ import h$1 from "@macrostrat/hyper";
1
2
  const background = "_background_7b96n_20";
2
3
  const styles = {
3
4
  "unit-label-container": "_unit-label-container_7b96n_1",
4
5
  "labeled-unit": "_labeled-unit_7b96n_5",
5
6
  background
6
7
  };
8
+ let h = h$1.styled(styles);
9
+ Object.assign(h, styles);
7
10
  export {
8
11
  background,
9
- styles as default
12
+ h as default
10
13
  };
11
14
  //# sourceMappingURL=boxes.module.sass.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"boxes.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"boxes.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -6,8 +6,45 @@ const chroma__default = /* @__PURE__ */ _interopDefault(chroma);
6
6
  function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = true, keyOpts = null) {
7
7
  const { key = "lith", id_key = "lith_id" } = keyOpts ?? {};
8
8
  const liths = unit[key];
9
- if (liths == null) {
10
- return "gray";
9
+ const getColor = (data) => {
10
+ return lithMap?.get(data[id_key])?.color ?? null;
11
+ };
12
+ return getMixedColorForData(liths, getColor, {
13
+ inDarkMode,
14
+ asBackground
15
+ });
16
+ }
17
+ function flattenLithologies(liths, normalize = true) {
18
+ if (liths == null || liths.length === 0) {
19
+ return [];
20
+ }
21
+ const unitCount = liths.length;
22
+ let newLiths = [];
23
+ for (const unitLiths of liths) {
24
+ let l1 = unitLiths;
25
+ if (normalize) {
26
+ l1 = addProportionsToAllData(unitLiths);
27
+ }
28
+ for (const lith of l1) {
29
+ if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {
30
+ continue;
31
+ }
32
+ lith.prop = lith.prop / unitCount;
33
+ }
34
+ newLiths.push(...l1);
35
+ }
36
+ if (newLiths[0]?.lith_id != null) {
37
+ newLiths = mergeLikeData(newLiths, "lith_id");
38
+ } else if (newLiths[0]?.environ_id != null) {
39
+ newLiths = mergeLikeData(newLiths, "environ_id");
40
+ }
41
+ newLiths.sort((a, b) => b.prop - a.prop);
42
+ return newLiths;
43
+ }
44
+ function getMixedColorForData(liths, getColor, options = {}) {
45
+ const { inDarkMode = false, asBackground = true } = options;
46
+ if (liths == null || liths.length === 0) {
47
+ return null;
11
48
  }
12
49
  const lithData = liths.map((d) => {
13
50
  let prop = d.prop;
@@ -15,27 +52,15 @@ function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = tru
15
52
  prop = null;
16
53
  }
17
54
  return {
18
- lith_id: d[id_key],
55
+ ...d,
19
56
  prop,
20
- color: lithMap?.get(d[id_key])?.color
57
+ color: getColor?.(d) ?? d.color
21
58
  };
22
59
  }).filter((d) => d.color != null);
23
- const lithsWithProp = lithData.filter((d) => d.prop != null);
24
- const lithsWithoutProp = lithData.filter((d) => d.prop == null);
25
- const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
26
- if (totalProp < 1 && lithsWithoutProp.length > 0) {
27
- const remainingProp = 1 - totalProp;
28
- const equalProp = remainingProp / lithsWithoutProp.length;
29
- lithsWithoutProp.forEach((d) => {
30
- lithsWithProp.push({
31
- ...d,
32
- prop: equalProp
33
- });
34
- });
35
- }
36
- if (lithsWithProp.length == 0) {
60
+ if (lithData.length == 0) {
37
61
  return null;
38
62
  }
63
+ const lithsWithProp = addProportionsToAllData(lithData);
39
64
  const baseColor = chroma__default.default.average(
40
65
  lithsWithProp.map((d) => d.color),
41
66
  "lrgb",
@@ -50,5 +75,41 @@ function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = tru
50
75
  return baseColor.set("hsl.l", 0.9).hex();
51
76
  }
52
77
  }
78
+ function addProportionsToAllData(liths) {
79
+ const lithsWithProp = liths.filter((d) => d.prop != null);
80
+ const lithsWithoutProp = liths.filter((d) => d.prop == null);
81
+ const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
82
+ let overallTotal = 1;
83
+ if (totalProp < overallTotal && lithsWithoutProp.length > 0) {
84
+ const remainingProp = overallTotal - totalProp;
85
+ const equalProp = remainingProp / lithsWithoutProp.length;
86
+ lithsWithoutProp.forEach((d) => {
87
+ lithsWithProp.push({
88
+ ...d,
89
+ prop: equalProp
90
+ });
91
+ });
92
+ }
93
+ return lithsWithProp;
94
+ }
95
+ function mergeLikeData(liths, key) {
96
+ const mergedMap = /* @__PURE__ */ new Map();
97
+ for (const lith of liths) {
98
+ const id = lith[key];
99
+ if (id == null) continue;
100
+ if (mergedMap.has(id)) {
101
+ const existing = mergedMap.get(id);
102
+ mergedMap.set(id, {
103
+ ...existing,
104
+ prop: existing.prop + lith.prop
105
+ });
106
+ } else {
107
+ mergedMap.set(id, { ...lith });
108
+ }
109
+ }
110
+ return Array.from(mergedMap.values());
111
+ }
112
+ exports.flattenLithologies = flattenLithologies;
113
+ exports.getMixedColorForData = getMixedColorForData;
53
114
  exports.getMixedUnitColor = getMixedUnitColor;
54
115
  //# sourceMappingURL=colors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"colors.cjs","sources":["../../src/units/colors.ts"],"sourcesContent":["import chroma from \"chroma-js\";\nimport { UnitLong } from \"@macrostrat/api-types\";\n\ninterface KeyOptions {\n key?: string;\n id_key?: string;\n}\n\nexport function getMixedUnitColor(\n unit: UnitLong,\n lithMap,\n inDarkMode = false,\n asBackground = true,\n keyOpts: KeyOptions = null,\n): string | null {\n const { key = \"lith\", id_key = \"lith_id\" } = keyOpts ?? {};\n const liths = unit[key];\n if (liths == null) {\n return \"gray\";\n }\n const lithData = liths\n .map((d) => {\n let prop = d.prop;\n if (prop == null || isNaN(prop) || prop <= 0) {\n prop = null;\n }\n return {\n lith_id: d[id_key],\n prop,\n color: lithMap?.get(d[id_key])?.color,\n };\n })\n .filter((d) => d.color != null);\n\n const lithsWithProp = lithData.filter((d) => d.prop != null);\n const lithsWithoutProp = lithData.filter((d) => d.prop == null);\n\n const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);\n if (totalProp < 1 && lithsWithoutProp.length > 0) {\n const remainingProp = 1 - totalProp;\n // Distribute remaining proportion equally among liths without prop\n const equalProp = remainingProp / lithsWithoutProp.length;\n lithsWithoutProp.forEach((d) => {\n lithsWithProp.push({\n ...d,\n prop: equalProp,\n });\n });\n }\n\n if (lithsWithProp.length == 0) {\n return null;\n }\n\n // Mix colors proportionally\n const baseColor = chroma.average(\n lithsWithProp.map((d) => d.color),\n \"lrgb\",\n lithsWithProp.map((d) => d.prop),\n );\n\n if (!asBackground) {\n return baseColor.hex();\n }\n\n if (inDarkMode) {\n return baseColor.set(\"hsl.l\", 0.2).hex();\n } else {\n return baseColor.set(\"hsl.l\", 0.9).hex();\n }\n}\n"],"names":["chroma"],"mappings":";;;;;AAQO,SAAS,kBACd,MACA,SACA,aAAa,OACb,eAAe,MACf,UAAsB,MACP;AACf,QAAM,EAAE,MAAM,QAAQ,SAAS,UAAA,IAAc,WAAW,CAAA;AACxD,QAAM,QAAQ,KAAK,GAAG;AACtB,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,MACd,IAA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\nimport {\n Environment,\n Lithology,\n UnitLithology,\n UnitLong,\n} from \"@macrostrat/api-types\";\n\ninterface KeyOptions {\n key?: \"lith\" | \"environ\";\n id_key?: \"lith_id\" | \"environ_id\";\n}\n\nexport function getMixedUnitColor(\n unit: UnitLong,\n lithMap: Map<number, { color: string }>,\n inDarkMode = false,\n asBackground = true,\n keyOpts: KeyOptions = null,\n): string | null {\n const { key = \"lith\", id_key = \"lith_id\" } = keyOpts ?? {};\n const liths = unit[key];\n const getColor = (data: UnitLithology): string | null => {\n return lithMap?.get(data[id_key])?.color ?? null;\n };\n\n return getMixedColorForData(liths, getColor, {\n inDarkMode,\n asBackground,\n key: id_key,\n });\n}\n\ninterface ColorBuilderOptions {\n key?: \"lith_id\" | \"environ_id\";\n inDarkMode?: boolean;\n asBackground?: boolean;\n}\n\nexport function flattenLithologies<\n T extends { prop: number | null; lith_id?: number; environ_id?: number },\n>(liths: T[][], normalize: boolean = true): T[] {\n /** Unify proportions in lithology/environment data across several units, normalizing if needed.\n * If normalize is true, proportions are scaled to sum to 1 within each unit (with remaining proportions\n * distributed equally among liths without specified proportions). This helps ensure that units with a\n * few lithologies with specified proportions don't skew the color mixing.\n *\n * Lithologies are deduplicated based on their identifying property (lith_id or environ_id) if that is present.\n */\n if (liths == null || liths.length === 0) {\n return [];\n }\n\n const unitCount = liths.length;\n\n let newLiths: T[] = [];\n for (const unitLiths of liths) {\n let l1 = unitLiths;\n if (normalize) {\n l1 = addProportionsToAllData(unitLiths);\n }\n // Divide proportions by number of units to balance influence\n for (const lith of l1) {\n if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {\n continue;\n }\n lith.prop = lith.prop / unitCount;\n }\n newLiths.push(...l1);\n }\n if (newLiths[0]?.lith_id != null) {\n newLiths = mergeLikeData(newLiths, \"lith_id\");\n } else if (newLiths[0]?.environ_id != null) {\n newLiths = mergeLikeData(newLiths, \"environ_id\");\n }\n // Sort by proportion descending\n newLiths.sort((a, b) => b.prop - a.prop);\n return newLiths;\n}\n\nexport function getMixedColorForData<\n T extends UnitLithology | Lithology | Environment,\n>(\n liths: T[] | null,\n getColor: (val: T) => string | null,\n options: ColorBuilderOptions = {},\n): string | null {\n const { inDarkMode = false, asBackground = true } = options;\n if (liths == null || liths.length === 0) {\n return null;\n }\n const lithData = liths\n .map((d) => {\n let prop = d.prop;\n if (prop == null || isNaN(prop) || prop <= 0) {\n prop = null;\n }\n return {\n ...d,\n prop,\n color: getColor?.(d) ?? d.color,\n };\n })\n .filter((d) => d.color != null);\n\n if (lithData.length == 0) {\n return null;\n }\n\n const lithsWithProp = addProportionsToAllData(lithData);\n\n // Mix colors proportionally\n const baseColor = chroma.average(\n lithsWithProp.map((d) => d.color),\n \"lrgb\",\n lithsWithProp.map((d) => d.prop),\n );\n\n if (!asBackground) {\n return baseColor.hex();\n }\n\n if (inDarkMode) {\n return baseColor.set(\"hsl.l\", 0.2).hex();\n } else {\n return baseColor.set(\"hsl.l\", 0.9).hex();\n }\n}\n\nfunction addProportionsToAllData<T extends { prop?: number }>(liths: T[]): T[] {\n /** Make sure that all lithologies/environments have a defined proportion,\n * and that proportions sum to 1. If some liths lack a defined proportion,\n * the remaining proportion is distributed equally among them.\n *\n * NOTE: This function does not normalize proportions if they already sum to more than 1.\n */\n const lithsWithProp = liths.filter((d) => d.prop != null);\n const lithsWithoutProp = liths.filter((d) => d.prop == null);\n\n const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);\n let overallTotal = 1;\n\n if (totalProp < overallTotal && lithsWithoutProp.length > 0) {\n const remainingProp = overallTotal - totalProp;\n // Distribute remaining proportion equally among liths without prop\n const equalProp = remainingProp / lithsWithoutProp.length;\n lithsWithoutProp.forEach((d) => {\n lithsWithProp.push({\n ...d,\n prop: equalProp,\n } as T);\n });\n }\n return lithsWithProp as T[];\n}\n\nfunction mergeLikeData<\n T extends { prop: number; lith_id?: number; environ_id?: number },\n>(liths: T[], key: \"lith_id\" | \"environ_id\"): T[] {\n /** Merge lithology/environment data with the same identifying property (lith_id or environ_id),\n * summing their proportions.\n *\n * TODO: handle attribute merging\n */\n const mergedMap: Map<number, T> = new Map();\n\n for (const lith of liths) {\n const id = lith[key];\n if (id == null) continue;\n\n if (mergedMap.has(id)) {\n const existing = mergedMap.get(id);\n mergedMap.set(id, {\n ...existing,\n prop: existing.prop + lith.prop,\n });\n } else {\n mergedMap.set(id, { ...lith });\n }\n }\n\n return Array.from(mergedMap.values());\n}\n"],"names":["chroma"],"mappings":";;;;;AAaO,SAAS,kBACd,MACA,SACA,aAAa,OACb,eAAe,MACf,UAAsB,MACP;AACf,QAAM,EAAE,MAAM,QAAQ,SAAS,UAAA,IAAc,WAAW,CAAA;AACxD,QAAM,QAAQ,KAAK,GAAG;AACtB,QAAM,WAAW,CAAC,SAAuC;AACvD,WAAO,SAAS,IAAI,KAAK,MAAM,CAAC,GAAG,SAAS;AAAA,EAC9C;AAEA,SAAO,qBAAqB,OAAO,UAAU;AAAA,IAC3C;AAAA,IACA;AAAA,EAEF,CAAC;AACH;AAQO,SAAS,mBAEd,OAAc,YAAqB,MAAW;AAQ9C,MAAI,SAAS,QAAQ,MAAM,WAAW,GAAG;AACvC,WAAO,CAAA;AAAA,EACT;AAEA,QAAM,YAAY,MAAM;AAExB,MAAI,WAAgB,CAAA;AACpB,aAAW,aAAa,OAAO;AAC7B,QAAI,KAAK;AACT,QAAI,WAAW;AACb,WAAK,wBAAwB,SAAS;AAAA,IACxC;AAEA,eAAW,QAAQ,IAAI;AACrB,UAAI,KAAK,QAAQ,QAAQ,MAAM,KAAK,IAAI,KAAK,KAAK,QAAQ,GAAG;AAC3D;AAAA,MACF;AACA,WAAK,OAAO,KAAK,OAAO;AAAA,IAC1B;AACA,aAAS,KAAK,GAAG,EAAE;AAAA,EACrB;AACA,MAAI,SAAS,CAAC,GAAG,WAAW,MAAM;AAChC,eAAW,cAAc,UAAU,SAAS;AAAA,EAC9C,WAAW,SAAS,CAAC,GAAG,cAAc,MAAM;AAC1C,eAAW,c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CAAC;AAClE,MAAI,eAAe;AAEnB,MAAI,YAAY,gBAAgB,iBAAiB,SAAS,GAAG;AAC3D,UAAM,gBAAgB,eAAe;AAErC,UAAM,YAAY,gBAAgB,iBAAiB;AACnD,qBAAiB,QAAQ,CAAC,MAAM;AAC9B,oBAAc,KAAK;AAAA,QACjB,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACF;AAAA,IACR,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEA,SAAS,cAEP,OAAY,KAAoC;AAMhD,QAAM,gCAAgC,IAAA;AAEtC,aAAW,QAAQ,OAAO;AACxB,UAAM,KAAK,KAAK,GAAG;AACnB,QAAI,MAAM,KAAM;AAEhB,QAAI,UAAU,IAAI,EAAE,GAAG;AACrB,YAAM,WAAW,UAAU,IAAI,EAAE;AACjC,gBAAU,IAAI,IAAI;AAAA,QAChB,GAAG;AAAA,QACH,MAAM,SAAS,OAAO,KAAK;AAAA,MAAA,CAC5B;AAAA,IACH,OAAO;AACL,gBAAU,IAAI,IAAI,EAAE,GAAG,MAAM;AAAA,IAC/B;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,UAAU,OAAA,CAAQ;AACtC;;;;"}
@@ -1,7 +1,20 @@
1
- import { UnitLong } from '@macrostrat/api-types';
1
+ import { Environment, Lithology, UnitLithology, UnitLong } from '@macrostrat/api-types';
2
2
  interface KeyOptions {
3
- key?: string;
4
- id_key?: string;
3
+ key?: "lith" | "environ";
4
+ id_key?: "lith_id" | "environ_id";
5
5
  }
6
- export declare function getMixedUnitColor(unit: UnitLong, lithMap: any, inDarkMode?: boolean, asBackground?: boolean, keyOpts?: KeyOptions): string | null;
6
+ export declare function getMixedUnitColor(unit: UnitLong, lithMap: Map<number, {
7
+ color: string;
8
+ }>, inDarkMode?: boolean, asBackground?: boolean, keyOpts?: KeyOptions): string | null;
9
+ interface ColorBuilderOptions {
10
+ key?: "lith_id" | "environ_id";
11
+ inDarkMode?: boolean;
12
+ asBackground?: boolean;
13
+ }
14
+ export declare function flattenLithologies<T extends {
15
+ prop: number | null;
16
+ lith_id?: number;
17
+ environ_id?: number;
18
+ }>(liths: T[][], normalize?: boolean): T[];
19
+ export declare function getMixedColorForData<T extends UnitLithology | Lithology | Environment>(liths: T[] | null, getColor: (val: T) => string | null, options?: ColorBuilderOptions): string | null;
7
20
  export {};
@@ -2,8 +2,45 @@ import chroma from "chroma-js";
2
2
  function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = true, keyOpts = null) {
3
3
  const { key = "lith", id_key = "lith_id" } = keyOpts ?? {};
4
4
  const liths = unit[key];
5
- if (liths == null) {
6
- return "gray";
5
+ const getColor = (data) => {
6
+ return lithMap?.get(data[id_key])?.color ?? null;
7
+ };
8
+ return getMixedColorForData(liths, getColor, {
9
+ inDarkMode,
10
+ asBackground
11
+ });
12
+ }
13
+ function flattenLithologies(liths, normalize = true) {
14
+ if (liths == null || liths.length === 0) {
15
+ return [];
16
+ }
17
+ const unitCount = liths.length;
18
+ let newLiths = [];
19
+ for (const unitLiths of liths) {
20
+ let l1 = unitLiths;
21
+ if (normalize) {
22
+ l1 = addProportionsToAllData(unitLiths);
23
+ }
24
+ for (const lith of l1) {
25
+ if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {
26
+ continue;
27
+ }
28
+ lith.prop = lith.prop / unitCount;
29
+ }
30
+ newLiths.push(...l1);
31
+ }
32
+ if (newLiths[0]?.lith_id != null) {
33
+ newLiths = mergeLikeData(newLiths, "lith_id");
34
+ } else if (newLiths[0]?.environ_id != null) {
35
+ newLiths = mergeLikeData(newLiths, "environ_id");
36
+ }
37
+ newLiths.sort((a, b) => b.prop - a.prop);
38
+ return newLiths;
39
+ }
40
+ function getMixedColorForData(liths, getColor, options = {}) {
41
+ const { inDarkMode = false, asBackground = true } = options;
42
+ if (liths == null || liths.length === 0) {
43
+ return null;
7
44
  }
8
45
  const lithData = liths.map((d) => {
9
46
  let prop = d.prop;
@@ -11,27 +48,15 @@ function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = tru
11
48
  prop = null;
12
49
  }
13
50
  return {
14
- lith_id: d[id_key],
51
+ ...d,
15
52
  prop,
16
- color: lithMap?.get(d[id_key])?.color
53
+ color: getColor?.(d) ?? d.color
17
54
  };
18
55
  }).filter((d) => d.color != null);
19
- const lithsWithProp = lithData.filter((d) => d.prop != null);
20
- const lithsWithoutProp = lithData.filter((d) => d.prop == null);
21
- const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
22
- if (totalProp < 1 && lithsWithoutProp.length > 0) {
23
- const remainingProp = 1 - totalProp;
24
- const equalProp = remainingProp / lithsWithoutProp.length;
25
- lithsWithoutProp.forEach((d) => {
26
- lithsWithProp.push({
27
- ...d,
28
- prop: equalProp
29
- });
30
- });
31
- }
32
- if (lithsWithProp.length == 0) {
56
+ if (lithData.length == 0) {
33
57
  return null;
34
58
  }
59
+ const lithsWithProp = addProportionsToAllData(lithData);
35
60
  const baseColor = chroma.average(
36
61
  lithsWithProp.map((d) => d.color),
37
62
  "lrgb",
@@ -46,7 +71,43 @@ function getMixedUnitColor(unit, lithMap, inDarkMode = false, asBackground = tru
46
71
  return baseColor.set("hsl.l", 0.9).hex();
47
72
  }
48
73
  }
74
+ function addProportionsToAllData(liths) {
75
+ const lithsWithProp = liths.filter((d) => d.prop != null);
76
+ const lithsWithoutProp = liths.filter((d) => d.prop == null);
77
+ const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
78
+ let overallTotal = 1;
79
+ if (totalProp < overallTotal && lithsWithoutProp.length > 0) {
80
+ const remainingProp = overallTotal - totalProp;
81
+ const equalProp = remainingProp / lithsWithoutProp.length;
82
+ lithsWithoutProp.forEach((d) => {
83
+ lithsWithProp.push({
84
+ ...d,
85
+ prop: equalProp
86
+ });
87
+ });
88
+ }
89
+ return lithsWithProp;
90
+ }
91
+ function mergeLikeData(liths, key) {
92
+ const mergedMap = /* @__PURE__ */ new Map();
93
+ for (const lith of liths) {
94
+ const id = lith[key];
95
+ if (id == null) continue;
96
+ if (mergedMap.has(id)) {
97
+ const existing = mergedMap.get(id);
98
+ mergedMap.set(id, {
99
+ ...existing,
100
+ prop: existing.prop + lith.prop
101
+ });
102
+ } else {
103
+ mergedMap.set(id, { ...lith });
104
+ }
105
+ }
106
+ return Array.from(mergedMap.values());
107
+ }
49
108
  export {
109
+ flattenLithologies,
110
+ getMixedColorForData,
50
111
  getMixedUnitColor
51
112
  };
52
113
  //# sourceMappingURL=colors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"colors.js","sources":["../../src/units/colors.ts"],"sourcesContent":["import chroma from \"chroma-js\";\nimport { UnitLong } from \"@macrostrat/api-types\";\n\ninterface KeyOptions {\n key?: string;\n id_key?: string;\n}\n\nexport function getMixedUnitColor(\n unit: UnitLong,\n lithMap,\n inDarkMode = false,\n asBackground = true,\n keyOpts: KeyOptions = null,\n): string | null {\n const { key = \"lith\", id_key = \"lith_id\" } = keyOpts ?? {};\n const liths = unit[key];\n if (liths == null) {\n return \"gray\";\n }\n const lithData = liths\n .map((d) => {\n let prop = d.prop;\n if (prop == null || isNaN(prop) || prop <= 0) {\n prop = null;\n }\n return {\n lith_id: d[id_key],\n prop,\n color: lithMap?.get(d[id_key])?.color,\n };\n })\n .filter((d) => d.color != null);\n\n const lithsWithProp = lithData.filter((d) => d.prop != null);\n const lithsWithoutProp = lithData.filter((d) => d.prop == null);\n\n const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);\n if (totalProp < 1 && lithsWithoutProp.length > 0) {\n const remainingProp = 1 - totalProp;\n // Distribute remaining proportion equally among liths without prop\n const equalProp = remainingProp / lithsWithoutProp.length;\n lithsWithoutProp.forEach((d) => {\n lithsWithProp.push({\n ...d,\n prop: equalProp,\n });\n });\n }\n\n if (lithsWithProp.length == 0) {\n return null;\n }\n\n // Mix colors proportionally\n const baseColor = chroma.average(\n lithsWithProp.map((d) => d.color),\n \"lrgb\",\n lithsWithProp.map((d) => d.prop),\n );\n\n if (!asBackground) {\n return baseColor.hex();\n }\n\n if (inDarkMode) {\n return baseColor.set(\"hsl.l\", 0.2).hex();\n } else {\n return baseColor.set(\"hsl.l\", 0.9).hex();\n }\n}\n"],"names":[],"mappings":";AAQO,SAAS,kBACd,MACA,SACA,aAAa,OACb,eAAe,MACf,UAAsB,MACP;AACf,QAAM,EAAE,MAAM,QAAQ,SAAS,UAAA,IAAc,WAAW,CAAA;AACxD,QAAM,QAAQ,KAAK,GAAG;AACtB,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,MACd,IAAI,CAAC,MAAM;AACV,QAAI,OAAO,EAAE;AACb,QAAI,QAAQ,QAAQ,MAAM,IAAI,KAAK,QAAQ,GAAG;AAC5C,aAAO;AAAA,IACT;AACA,WAAO;AAAA,MACL,SAAS,EAAE,MAAM;AAAA,MACjB;AAAA,MACA,OAAO,SAAS,IAAI,EAAE,MAAM,CAAC,GAAG;AAAA,IAAA;AAAA,EAEpC,CAAC,EACA,OAAO,CAAC,MAAM,EAAE,SAAS,IAAI;AAEhC,QAAM,gBAAgB,SAAS,OAAO,CAAC,MAAM,EAAE,QAAQ,IAAI;AAC3D,QAAM,mBAAmB,SAAS,OAAO,CAAC,MAAM,EAAE,QAAQ,IAAI;AAE9D,QAAM,YAAY,cAAc,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,MAAM,CAAC;AAClE,MAAI,YAAY,KAAK,iBAAiB,SAAS,GAAG;AAChD,UAAM,gBAAgB,IAAI;AAE1B,UAAM,YAAY,gBAAgB,iBAAiB;AACnD,qBAAiB,QAAQ,CAAC,MAAM;AAC9B,oBAAc,KAAK;AAAA,QACjB,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAAA,IACH,CAAC;AAAA,EACH;AAEA,MAAI,cAAc,UAAU,GAAG;AAC7B,WAAO;AAAA,EACT;AAGA,QAAM,YAAY,OAAO;AAAA,IACvB,cAAc,IAAI,CAAC,MAAM,EAAE,KAAK;AAAA,IAChC;AAAA,IACA,cAAc,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,EAAA;AAGjC,MAAI,CAAC,cAAc;AACjB,WAAO,UAAU,IAAA;AAAA,EACnB;AAEA,MAAI,YAAY;AACd,WAAO,UAAU,IAAI,SAAS,GAAG,EAAE,IAAA;AAAA,EACrC,OAAO;AACL,WAAO,UAAU,IAAI,SAAS,GAAG,EAAE,IAAA;AAAA,EACrC;AACF;"}
1
+ {"version":3,"file":"colors.js","sources":["../../src/units/colors.ts"],"sourcesContent":["import chroma from \"chroma-js\";\nimport {\n Environment,\n Lithology,\n UnitLithology,\n UnitLong,\n} from \"@macrostrat/api-types\";\n\ninterface KeyOptions {\n key?: \"lith\" | \"environ\";\n id_key?: \"lith_id\" | \"environ_id\";\n}\n\nexport function getMixedUnitColor(\n unit: UnitLong,\n lithMap: Map<number, { color: string }>,\n inDarkMode = false,\n asBackground = true,\n keyOpts: KeyOptions = null,\n): string | null {\n const { key = \"lith\", id_key = \"lith_id\" } = keyOpts ?? {};\n const liths = unit[key];\n const getColor = (data: UnitLithology): string | null => {\n return lithMap?.get(data[id_key])?.color ?? null;\n };\n\n return getMixedColorForData(liths, getColor, {\n inDarkMode,\n asBackground,\n key: id_key,\n });\n}\n\ninterface ColorBuilderOptions {\n key?: \"lith_id\" | \"environ_id\";\n inDarkMode?: boolean;\n asBackground?: boolean;\n}\n\nexport function flattenLithologies<\n T extends { prop: number | null; lith_id?: number; environ_id?: number },\n>(liths: T[][], normalize: boolean = true): T[] {\n /** Unify proportions in lithology/environment data across several units, normalizing if needed.\n * If normalize is true, proportions are scaled to sum to 1 within each unit (with remaining proportions\n * distributed equally among liths without specified proportions). This helps ensure that units with a\n * few lithologies with specified proportions don't skew the color mixing.\n *\n * Lithologies are deduplicated based on their identifying property (lith_id or environ_id) if that is present.\n */\n if (liths == null || liths.length === 0) {\n return [];\n }\n\n const unitCount = liths.length;\n\n let newLiths: T[] = [];\n for (const unitLiths of liths) {\n let l1 = unitLiths;\n if (normalize) {\n l1 = addProportionsToAllData(unitLiths);\n }\n // Divide proportions by number of units to balance influence\n for (const lith of l1) {\n if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {\n continue;\n }\n lith.prop = lith.prop / unitCount;\n }\n newLiths.push(...l1);\n }\n if (newLiths[0]?.lith_id != null) {\n newLiths = mergeLikeData(newLiths, \"lith_id\");\n } else if (newLiths[0]?.environ_id != null) {\n newLiths = mergeLikeData(newLiths, \"environ_id\");\n }\n // Sort by proportion descending\n newLiths.sort((a, b) => b.prop - a.prop);\n return newLiths;\n}\n\nexport function getMixedColorForData<\n T extends UnitLithology | Lithology | Environment,\n>(\n liths: T[] | null,\n getColor: (val: T) => string | null,\n options: ColorBuilderOptions = {},\n): string | null {\n const { inDarkMode = false, asBackground = true } = options;\n if (liths == null || liths.length === 0) {\n return null;\n }\n const lithData = liths\n .map((d) => {\n let prop = d.prop;\n if (prop == null || isNaN(prop) || prop <= 0) {\n prop = null;\n }\n return {\n ...d,\n prop,\n color: getColor?.(d) ?? d.color,\n };\n })\n .filter((d) => d.color != null);\n\n if (lithData.length == 0) {\n return null;\n }\n\n const lithsWithProp = addProportionsToAllData(lithData);\n\n // Mix colors proportionally\n const baseColor = chroma.average(\n lithsWithProp.map((d) => d.color),\n \"lrgb\",\n lithsWithProp.map((d) => d.prop),\n );\n\n if (!asBackground) {\n return baseColor.hex();\n }\n\n if (inDarkMode) {\n return baseColor.set(\"hsl.l\", 0.2).hex();\n } else {\n return baseColor.set(\"hsl.l\", 0.9).hex();\n }\n}\n\nfunction addProportionsToAllData<T extends { prop?: number }>(liths: T[]): T[] {\n /** Make sure that all lithologies/environments have a defined proportion,\n * and that proportions sum to 1. If some liths lack a defined proportion,\n * the remaining proportion is distributed equally among them.\n *\n * NOTE: This function does not normalize proportions if they already sum to more than 1.\n */\n const lithsWithProp = liths.filter((d) => d.prop != null);\n const lithsWithoutProp = liths.filter((d) => d.prop == null);\n\n const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);\n let overallTotal = 1;\n\n if (totalProp < overallTotal && lithsWithoutProp.length > 0) {\n const remainingProp = overallTotal - totalProp;\n // Distribute remaining proportion equally among liths without prop\n const equalProp = remainingProp / lithsWithoutProp.length;\n lithsWithoutProp.forEach((d) => {\n lithsWithProp.push({\n ...d,\n prop: equalProp,\n } as T);\n });\n }\n return lithsWithProp as T[];\n}\n\nfunction mergeLikeData<\n T extends { prop: number; lith_id?: number; environ_id?: number },\n>(liths: T[], key: \"lith_id\" | \"environ_id\"): T[] {\n /** Merge lithology/environment data with the same identifying property (lith_id or environ_id),\n * summing their proportions.\n *\n * TODO: handle attribute merging\n */\n const mergedMap: Map<number, T> = new Map();\n\n for (const lith of liths) {\n const id = lith[key];\n if (id == null) continue;\n\n if (mergedMap.has(id)) {\n const existing = mergedMap.get(id);\n mergedMap.set(id, {\n ...existing,\n prop: existing.prop + lith.prop,\n });\n } else {\n mergedMap.set(id, { ...lith });\n }\n }\n\n return Array.from(mergedMap.values());\n}\n"],"names":[],"mappings":";AAaO,SAAS,kBACd,MACA,SACA,aAAa,OACb,eAAe,MACf,UAAsB,MACP;AACf,QAAM,EAAE,MAAM,QAAQ,SAAS,UAAA,IAAc,WAAW,CAAA;AACxD,QAAM,QAAQ,KAAK,GAAG;AACtB,QAAM,WAAW,CAAC,SAAuC;AACvD,WAAO,SAAS,IAAI,KAAK,MAAM,CAAC,GAAG,SAAS;AAAA,EAC9C;AAEA,SAAO,qBAAqB,OAAO,UAAU;AAAA,IAC3C;AAAA,IACA;AAAA,EAEF,CAAC;AACH;AAQO,SAAS,mBAEd,OAAc,YAAqB,MAAW;AAQ9C,MAAI,SAAS,QAAQ,MAAM,WAAW,GAAG;AACvC,WAAO,CAAA;AAAA,EACT;AAEA,QAAM,YAAY,MAAM;AAExB,MAAI,WAAgB,CAAA;AACpB,aAAW,aAAa,OAAO;AAC7B,QAAI,KAAK;AACT,QAAI,WAAW;AACb,WAAK,wBAAwB,SAAS;AAAA,IACxC;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AS,GAAG,EAAE,IAAA;AAAA,EACrC,OAAO;AACL,WAAO,UAAU,IAAI,SAAS,GAAG,EAAE,IAAA;AAAA,EACrC;AACF;AAEA,SAAS,wBAAqD,OAAiB;AAO7E,QAAM,gBAAgB,MAAM,OAAO,CAAC,MAAM,EAAE,QAAQ,IAAI;AACxD,QAAM,mBAAmB,MAAM,OAAO,CAAC,MAAM,EAAE,QAAQ,IAAI;AAE3D,QAAM,YAAY,cAAc,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,MAAM,CAAC;AAClE,MAAI,eAAe;AAEnB,MAAI,YAAY,gBAAgB,iBAAiB,SAAS,GAAG;AAC3D,UAAM,gBAAgB,eAAe;AAErC,UAAM,YAAY,gBAAgB,iBAAiB;AACnD,qBAAiB,QAAQ,CAAC,MAAM;AAC9B,oBAAc,KAAK;AAAA,QACjB,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACF;AAAA,IACR,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEA,SAAS,cAEP,OAAY,KAAoC;AAMhD,QAAM,gCAAgC,IAAA;AAEtC,aAAW,QAAQ,OAAO;AACxB,UAAM,KAAK,KAAK,GAAG;AACnB,QAAI,MAAM,KAAM;AAEhB,QAAI,UAAU,IAAI,EAAE,GAAG;AACrB,YAAM,WAAW,UAAU,IAAI,EAAE;AACjC,gBAAU,IAAI,IAAI;AAAA,QAChB,GAAG;AAAA,QACH,MAAM,SAAS,OAAO,KAAK;AAAA,MAAA,CAC5B;AAAA,IACH,OAAO;AACL,gBAAU,IAAI,IAAI,EAAE,GAAG,MAAM;AAAA,IAC/B;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,UAAU,OAAA,CAAQ;AACtC;"}
@@ -3,10 +3,10 @@ import { ColumnContext, LithologyColumn, SVG } from "@macrostrat/column-componen
3
3
  import { defaultNameFunction, UnitNamesColumn } from "./names.js";
4
4
  import { useEffect, useContext, useState, useRef, useCallback, createContext } from "react";
5
5
  import { LabeledUnit, UnitBoxes } from "./boxes.js";
6
- import styles from "./composite.module.sass.js";
6
+ import h$1 from "./composite.module.sass.js";
7
7
  import { useUnitSelectionDispatch } from "../data-provider/unit-selection.js";
8
8
  import { useMacrostratColumnData, useCompositeScale } from "../data-provider/store.js";
9
- const h = hyperStyled(styles);
9
+ const h = hyperStyled(h$1);
10
10
  const LabelTrackerContext = createContext(null);
11
11
  const UnlabeledDivisionsContext = createContext(null);
12
12
  const findMacrostratUnitID = (u) => u.unit_id;
@@ -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":["id"],"mappings":";;;;;;;;AAwBA,MAAM,IAAI,YAAY,MAAM;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,uBAA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../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,6 +1,11 @@
1
1
  "use strict";
2
+ const h$1 = require("@macrostrat/hyper");
3
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
+ const h__default = /* @__PURE__ */ _interopDefault(h$1);
2
5
  const styles = {
3
6
  "unit-label": "_unit-label_tidbs_1"
4
7
  };
5
- module.exports = styles;
8
+ let h = h__default.default.styled(styles);
9
+ Object.assign(h, styles);
10
+ module.exports = h;
6
11
  //# sourceMappingURL=composite.module.sass.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"composite.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
1
+ {"version":3,"file":"composite.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -1,7 +1,10 @@
1
+ import h$1 from "@macrostrat/hyper";
1
2
  const styles = {
2
3
  "unit-label": "_unit-label_tidbs_1"
3
4
  };
5
+ let h = h$1.styled(styles);
6
+ Object.assign(h, styles);
4
7
  export {
5
- styles as default
8
+ h as default
6
9
  };
7
10
  //# sourceMappingURL=composite.module.sass.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"composite.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"composite.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -100,6 +100,8 @@ function EnvironmentColoredUnitComponent(props) {
100
100
  ...props
101
101
  });
102
102
  }
103
+ exports.flattenLithologies = colors.flattenLithologies;
104
+ exports.getMixedColorForData = colors.getMixedColorForData;
103
105
  exports.getMixedUnitColor = colors.getMixedUnitColor;
104
106
  exports.AnnotatedUnitsColumn = composite.AnnotatedUnitsColumn;
105
107
  exports.ColumnNotesProvider = composite.ColumnNotesProvider;
@@ -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 { Lithology } from \"@macrostrat/api-types\";\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\nexport function UnitComponent({ division, nColumns = 2, ...rest }) {\n const width = rest.width ?? useColumnLayout()?.width;\n\n const nOverlappingUnits = division.overlappingUnits?.length ?? 0;\n const _nColumns = nOverlappingUnits == 0 ? 1 : nColumns;\n const columnIx = (division.column ?? 0) % _nColumns;\n const reducedWidth = width / _nColumns;\n const 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","useEnvironments"],"mappings":";;;;;;;;;;;;;;AAqBO,SAAS,YAAY,EAAE,QAAQ,OAAO;AAI3C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A,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, 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 { Lithology } from \"@macrostrat/api-types\";\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\nexport function UnitComponent({ division, nColumns = 2, ...rest }) {\n const width = rest.width ?? useColumnLayout()?.width;\n\n const nOverlappingUnits = division.overlappingUnits?.length ?? 0;\n const _nColumns = nOverlappingUnits == 0 ? 1 : nColumns;\n const columnIx = (division.column ?? 0) % _nColumns;\n const reducedWidth = width / _nColumns;\n const 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","useEnvironments"],"mappings":";;;;;;;;;;;;;;AAqBO,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;AAAA,MACb,OAAO,QAAQ,cAAc;AAAA,IAAA,CAC9B;AAAA,EAAA,CACF;AACH;AAEO,SAAS,mBAAmB,EAAE,UAAU,GAAG,QAAQ;AAGxD,SAAOH,WAAAA,QAAE,eAAe;AAAA,IACtB;AAAA,IACA,GAAG;AAAA,IACH,iBAAiB,SAAS;AAAA,IAC1B,WAAW,SAAS;AAAA,EAAA,CACrB;AACH;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AAM,EAAE,eAAe,KAAA,IAAS;AAEhC,SAAOC,MAAAA,QAAQ,MAAM;AACnB,QAAI,QAAQ,QAAQ,kBAAkB,KAAM,QAAO;AACnD,QAAI,IAAIC,OAAAA,kBAAkB,MAAM,gBAAgB,YAAY,cAAc;AAAA,MACxE,KAAK;AAAA,MACL,QAAQ;AAAA,IAAA,CACT;AACD,QAAI,KAAK,MAAM;AACb,aAAO;AAAA,IACT;AAEA,WAAOA,OAAAA,kBAAkB,MAAM,SAAS,YAAY,YAAY;AAAA,EAClE,GAAG,CAAC,MAAM,SAAS,gBAAgB,SAAS,YAAY,YAAY,CAAC;AACvE;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;;;;;;;;;;;;;;;;;;;"}
@@ -4,6 +4,7 @@ import { UnitNamesColumn } from "./names.js";
4
4
  import { UnitBoxes } from "./boxes.js";
5
5
  import { useInDarkMode } from "@macrostrat/ui-components";
6
6
  import { getMixedUnitColor } from "./colors.js";
7
+ import { flattenLithologies, getMixedColorForData } from "./colors.js";
7
8
  import { TrackedLabeledUnit } from "./composite.js";
8
9
  import { AnnotatedUnitsColumn, ColumnNotesProvider, CompositeUnitComponent, CompositeUnitsColumn, LabelTrackerProvider, SectionLabelsColumn } from "./composite.js";
9
10
  import { useLithologies, useEnvironments } from "@macrostrat/data-provider";
@@ -111,6 +112,8 @@ export {
111
112
  TrackedLabeledUnit,
112
113
  UnitComponent,
113
114
  UnitsColumn,
115
+ flattenLithologies,
116
+ getMixedColorForData,
114
117
  getMixedUnitColor,
115
118
  useUnitColor,
116
119
  useUnitColorByEnvironment