@macrostrat/column-views 3.4.2 → 3.5.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.
- package/CHANGELOG.md +25 -0
- package/dist/column-views.css +7 -7
- package/dist/column.cjs +21 -21
- package/dist/column.cjs.map +1 -1
- package/dist/column.d.ts +3 -1
- package/dist/column.js +4 -4
- package/dist/column.js.map +1 -1
- package/dist/data-provider/store.cjs +26 -3
- package/dist/data-provider/store.cjs.map +1 -1
- package/dist/data-provider/store.d.ts +52 -0
- package/dist/data-provider/store.js +27 -4
- package/dist/data-provider/store.js.map +1 -1
- package/dist/data-provider/unit-selection.cjs +10 -4
- package/dist/data-provider/unit-selection.cjs.map +1 -1
- package/dist/data-provider/unit-selection.d.ts +3 -0
- package/dist/data-provider/unit-selection.js +10 -4
- package/dist/data-provider/unit-selection.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -1
- package/dist/prepare-units/helpers.cjs +58 -36
- package/dist/prepare-units/helpers.cjs.map +1 -1
- package/dist/prepare-units/helpers.d.ts +13 -5
- package/dist/prepare-units/helpers.js +59 -37
- package/dist/prepare-units/helpers.js.map +1 -1
- package/dist/prepare-units/index.cjs +1 -0
- package/dist/prepare-units/index.cjs.map +1 -1
- package/dist/prepare-units/index.d.ts +2 -2
- package/dist/prepare-units/index.js +1 -0
- package/dist/prepare-units/index.js.map +1 -1
- package/dist/unit-details/panel.cjs +1 -1
- package/dist/unit-details/panel.cjs.map +1 -1
- package/dist/unit-details/panel.js +1 -1
- package/dist/unit-details/panel.js.map +1 -1
- package/dist/units/boxes.module.sass.cjs +3 -3
- package/dist/units/boxes.module.sass.js +3 -3
- package/dist/units/index.cjs +5 -5
- package/dist/units/index.cjs.map +1 -1
- package/dist/units/index.d.ts +2 -2
- package/dist/units/index.js +5 -5
- package/dist/units/index.js.map +1 -1
- package/package.json +4 -4
- package/src/column.ts +6 -4
- package/src/correlation-chart/stories/namibia-correlation.stories.ts +151 -0
- package/src/data-provider/store.ts +48 -4
- package/src/data-provider/unit-selection.ts +10 -5
- package/src/prepare-units/helpers.ts +98 -50
- package/src/prepare-units/index.ts +4 -1
- package/src/unit-details/panel.ts +1 -1
- package/src/units/boxes.module.sass +2 -2
- package/src/units/index.ts +7 -7
|
@@ -3,10 +3,10 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
3
3
|
const h$1 = require("@macrostrat/hyper");
|
|
4
4
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
5
5
|
const h__default = /* @__PURE__ */ _interopDefault(h$1);
|
|
6
|
-
const background = "
|
|
6
|
+
const background = "_background_eusyg_20";
|
|
7
7
|
const styles = {
|
|
8
|
-
"unit-label-container": "_unit-label-
|
|
9
|
-
"labeled-unit": "_labeled-
|
|
8
|
+
"unit-label-container": "_unit-label-container_eusyg_1",
|
|
9
|
+
"labeled-unit": "_labeled-unit_eusyg_5",
|
|
10
10
|
background
|
|
11
11
|
};
|
|
12
12
|
let h = h__default.default.styled(styles);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import h$1 from "@macrostrat/hyper";
|
|
2
|
-
const background = "
|
|
2
|
+
const background = "_background_eusyg_20";
|
|
3
3
|
const styles = {
|
|
4
|
-
"unit-label-container": "_unit-label-
|
|
5
|
-
"labeled-unit": "_labeled-
|
|
4
|
+
"unit-label-container": "_unit-label-container_eusyg_1",
|
|
5
|
+
"labeled-unit": "_labeled-unit_eusyg_5",
|
|
6
6
|
background
|
|
7
7
|
};
|
|
8
8
|
let h = h$1.styled(styles);
|
package/dist/units/index.cjs
CHANGED
|
@@ -49,11 +49,11 @@ function UnitComponent({
|
|
|
49
49
|
let columnIx = 0;
|
|
50
50
|
let x = 0;
|
|
51
51
|
let reducedWidth = _nColumns;
|
|
52
|
-
if ("
|
|
53
|
-
const
|
|
54
|
-
_nColumns = Math.min(_nColumns,
|
|
55
|
-
columnIx =
|
|
56
|
-
reducedWidth = width /
|
|
52
|
+
if ("layout" in division) {
|
|
53
|
+
const layout = division.layout;
|
|
54
|
+
_nColumns = Math.min(_nColumns, layout.totalColumns);
|
|
55
|
+
columnIx = layout.column;
|
|
56
|
+
reducedWidth = width / layout.totalColumns / layout.nColumns;
|
|
57
57
|
x = columnIx * width / _nColumns;
|
|
58
58
|
}
|
|
59
59
|
return h__default.default(composite.TrackedLabeledUnit, {
|
package/dist/units/index.cjs.map
CHANGED
|
@@ -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 {
|
|
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","useEnvironments"],"mappings":"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"}
|
package/dist/units/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ICompositeUnitProps } from './composite';
|
|
2
2
|
import { BaseUnit } from '@macrostrat/api-types';
|
|
3
|
-
import {
|
|
3
|
+
import { UnitWithLayoutParameters } from '../prepare-units/helpers.ts';
|
|
4
4
|
export * from './composite';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './colors';
|
|
@@ -13,7 +13,7 @@ export declare function BasicUnitComponent({ division, ...rest }: {
|
|
|
13
13
|
division: any;
|
|
14
14
|
}): import('react').FunctionComponentElement<UnitComponentProps<BaseUnit>>;
|
|
15
15
|
interface UnitComponentProps<T extends BaseUnit> {
|
|
16
|
-
division:
|
|
16
|
+
division: UnitWithLayoutParameters<T> | T;
|
|
17
17
|
nColumns: number;
|
|
18
18
|
width?: number;
|
|
19
19
|
}
|
package/dist/units/index.js
CHANGED
|
@@ -47,11 +47,11 @@ function UnitComponent({
|
|
|
47
47
|
let columnIx = 0;
|
|
48
48
|
let x = 0;
|
|
49
49
|
let reducedWidth = _nColumns;
|
|
50
|
-
if ("
|
|
51
|
-
const
|
|
52
|
-
_nColumns = Math.min(_nColumns,
|
|
53
|
-
columnIx =
|
|
54
|
-
reducedWidth = width /
|
|
50
|
+
if ("layout" in division) {
|
|
51
|
+
const layout = division.layout;
|
|
52
|
+
_nColumns = Math.min(_nColumns, layout.totalColumns);
|
|
53
|
+
columnIx = layout.column;
|
|
54
|
+
reducedWidth = width / layout.totalColumns / layout.nColumns;
|
|
55
55
|
x = columnIx * width / _nColumns;
|
|
56
56
|
}
|
|
57
57
|
return h(TrackedLabeledUnit, {
|
package/dist/units/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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 {
|
|
1
|
+
{"version":3,"file":"index.js","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":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrostrat/column-views",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Data views for Macrostrat stratigraphic columns",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"@macrostrat/api-types": "^1.2.0",
|
|
50
50
|
"@macrostrat/color-utils": "^1.2.2",
|
|
51
51
|
"@macrostrat/column-components": "^2.0.8",
|
|
52
|
-
"@macrostrat/data-components": "^1.1.
|
|
53
|
-
"@macrostrat/data-provider": "^1.0
|
|
52
|
+
"@macrostrat/data-components": "^1.1.12",
|
|
53
|
+
"@macrostrat/data-provider": "^1.1.0",
|
|
54
54
|
"@macrostrat/hyper": "^3.1.1",
|
|
55
55
|
"@macrostrat/map-interface": "^2.2.6",
|
|
56
56
|
"@macrostrat/map-styles": "^2.2.4",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@macrostrat/mapbox-utils": "^1.7.4",
|
|
59
59
|
"@macrostrat/stratigraphy-utils": "^1.3.0",
|
|
60
60
|
"@macrostrat/svg-map-components": "^2.0.3",
|
|
61
|
-
"@macrostrat/timescale": "^3.1.
|
|
61
|
+
"@macrostrat/timescale": "^3.1.5",
|
|
62
62
|
"@macrostrat/ui-components": "^5.0.10",
|
|
63
63
|
"@turf/boolean-point-in-polygon": "^7.3.2",
|
|
64
64
|
"@turf/buffer": "^7.3.2",
|
package/src/column.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ColumnAxisType } from "@macrostrat/column-components";
|
|
2
|
-
import { hyperStyled } from "@macrostrat/hyper";
|
|
3
2
|
import {
|
|
4
3
|
Box,
|
|
5
4
|
extractPadding,
|
|
@@ -12,10 +11,12 @@ import {
|
|
|
12
11
|
useCallback,
|
|
13
12
|
CSSProperties,
|
|
14
13
|
ComponentType,
|
|
14
|
+
RefObject,
|
|
15
15
|
} from "react";
|
|
16
|
-
import
|
|
16
|
+
import h from "./column.module.sass";
|
|
17
17
|
import { UnitComponent } from "./units";
|
|
18
18
|
import {
|
|
19
|
+
ColumnRef,
|
|
19
20
|
UnitKeyboardNavigation,
|
|
20
21
|
useColumnRef,
|
|
21
22
|
useUnitSelectionDispatch,
|
|
@@ -48,8 +49,6 @@ import { NonIdealState } from "@blueprintjs/core";
|
|
|
48
49
|
import { DataField } from "@macrostrat/data-components";
|
|
49
50
|
import { ScaleContinuousNumeric } from "d3-scale";
|
|
50
51
|
|
|
51
|
-
const h = hyperStyled(styles);
|
|
52
|
-
|
|
53
52
|
interface BaseColumnProps extends Omit<
|
|
54
53
|
SectionSharedProps,
|
|
55
54
|
"unconformityLabels"
|
|
@@ -88,6 +87,7 @@ export interface ColumnProps
|
|
|
88
87
|
// Unconformity height in pixels
|
|
89
88
|
unconformityHeight?: number;
|
|
90
89
|
scale?: ScaleContinuousNumeric<number, number>;
|
|
90
|
+
ref?: RefObject<ColumnRef>;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export function Column(props: ColumnProps) {
|
|
@@ -113,6 +113,7 @@ export function Column(props: ColumnProps) {
|
|
|
113
113
|
hybridScale,
|
|
114
114
|
scale,
|
|
115
115
|
axisType,
|
|
116
|
+
ref,
|
|
116
117
|
...rest
|
|
117
118
|
} = props;
|
|
118
119
|
|
|
@@ -178,6 +179,7 @@ export function Column(props: ColumnProps) {
|
|
|
178
179
|
allowUnitSelection: showUnitPopover || allowUnitSelection,
|
|
179
180
|
onUnitSelected,
|
|
180
181
|
selectedUnit,
|
|
182
|
+
ref,
|
|
181
183
|
},
|
|
182
184
|
h(ColumnInner, { ageAxisComponent, ...rest }, [
|
|
183
185
|
children,
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import "@macrostrat/style-system";
|
|
2
|
+
import { MergeSectionsMode, UnitComponent } from "../..";
|
|
3
|
+
import { Meta } from "@storybook/react-vite";
|
|
4
|
+
|
|
5
|
+
import h from "./stories.module.sass";
|
|
6
|
+
import { CorrelationChart } from "../main";
|
|
7
|
+
import { BaseUnit } from "@macrostrat/api-types";
|
|
8
|
+
import { useGeologicPattern } from "@macrostrat/column-components";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: "Column views/Correlation chart",
|
|
12
|
+
component: CorrelationChart,
|
|
13
|
+
parameters: {
|
|
14
|
+
layout: "fullscreen",
|
|
15
|
+
docs: {
|
|
16
|
+
description: {
|
|
17
|
+
component: "Correlation chart for Macrostrat columns",
|
|
18
|
+
},
|
|
19
|
+
story: {
|
|
20
|
+
inline: false,
|
|
21
|
+
iframeHeight: 500,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
args: {},
|
|
26
|
+
} as Meta<typeof CorrelationChart>;
|
|
27
|
+
|
|
28
|
+
const nosib = {
|
|
29
|
+
b_age: 900,
|
|
30
|
+
t_age: 800,
|
|
31
|
+
name: "Nosib",
|
|
32
|
+
color: "#ffd4ba",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const namUnits: (BaseUnit | BaseUnit[])[] = [
|
|
36
|
+
[
|
|
37
|
+
nosib,
|
|
38
|
+
{ b_age: 746, t_age: 720, name: "Chuos", color: "#d0b4ff" },
|
|
39
|
+
{
|
|
40
|
+
b_age: 720,
|
|
41
|
+
t_age: 600,
|
|
42
|
+
name: "Otavi",
|
|
43
|
+
color: "dodgerblue",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
nosib,
|
|
48
|
+
{
|
|
49
|
+
b_age: 740,
|
|
50
|
+
t_age: 600,
|
|
51
|
+
name: "Swakop",
|
|
52
|
+
color: "#aaa",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
nosib,
|
|
57
|
+
{
|
|
58
|
+
b_age: 670,
|
|
59
|
+
t_age: 580,
|
|
60
|
+
name: "Witvlei",
|
|
61
|
+
color: "#fffc4e",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
{
|
|
66
|
+
b_age: 610,
|
|
67
|
+
t_age: 575,
|
|
68
|
+
name: "Zebra Series",
|
|
69
|
+
color: "#fdbcf0",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
b_age: 660,
|
|
73
|
+
t_age: 610,
|
|
74
|
+
name: "Naukluft complex",
|
|
75
|
+
color: "#fdbcbc",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
{
|
|
79
|
+
b_age: 550,
|
|
80
|
+
t_age: 520,
|
|
81
|
+
name: "Nama",
|
|
82
|
+
color: "#baf1a7",
|
|
83
|
+
},
|
|
84
|
+
// {
|
|
85
|
+
// unit_id: 0,
|
|
86
|
+
// b_age: 900,
|
|
87
|
+
// t_age: 0,
|
|
88
|
+
// unit_name: "",
|
|
89
|
+
// column: 8,
|
|
90
|
+
// },
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
export function NamibiaCorrelationChart() {
|
|
94
|
+
return h(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
style: {
|
|
98
|
+
"--column-unit-font-size": "14px",
|
|
99
|
+
"--column-unit-font-style": "bold",
|
|
100
|
+
"--column-text-color": "white",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
[
|
|
104
|
+
h(CorrelationChart, {
|
|
105
|
+
id: 432,
|
|
106
|
+
data: namUnits.map((u, i) => {
|
|
107
|
+
let units: any = null;
|
|
108
|
+
if (Array.isArray(u)) {
|
|
109
|
+
units = u.map((u) => buildUnit(u, i));
|
|
110
|
+
} else {
|
|
111
|
+
units = [buildUnit(u, i)];
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
columnID: i,
|
|
115
|
+
units,
|
|
116
|
+
};
|
|
117
|
+
}),
|
|
118
|
+
columnSpacing: 10,
|
|
119
|
+
t_age: 450,
|
|
120
|
+
b_age: 850,
|
|
121
|
+
//width: 400,
|
|
122
|
+
//columnWidth: 400,
|
|
123
|
+
pixelScale: 2,
|
|
124
|
+
//showLabelColumn: false,
|
|
125
|
+
mergeSections: MergeSectionsMode.ALL,
|
|
126
|
+
unitComponent: ProvidedColorUnitComponent,
|
|
127
|
+
}),
|
|
128
|
+
],
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function buildUnit(unit, i) {
|
|
133
|
+
return {
|
|
134
|
+
unit_id: i,
|
|
135
|
+
col_id: i,
|
|
136
|
+
...unit,
|
|
137
|
+
unit_name: unit.name,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function ProvidedColorUnitComponent(props) {
|
|
142
|
+
/** A unit component that is colored by its own properties. */
|
|
143
|
+
|
|
144
|
+
const fill = useGeologicPattern(props.division.patternID);
|
|
145
|
+
|
|
146
|
+
return h(UnitComponent, {
|
|
147
|
+
fill,
|
|
148
|
+
backgroundColor: props.division.color ?? null,
|
|
149
|
+
...props,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
ReactNode,
|
|
4
|
+
RefObject,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
} from "react";
|
|
2
8
|
import h from "@macrostrat/hyper";
|
|
3
9
|
import {
|
|
4
10
|
CompositeColumnScale,
|
|
@@ -11,13 +17,18 @@ import {
|
|
|
11
17
|
selectedUnitIDAtom,
|
|
12
18
|
UnitSelectionCallbacks,
|
|
13
19
|
UnitSelectionCallbackManager,
|
|
20
|
+
selectedUnitElementAtom,
|
|
14
21
|
} from "./unit-selection";
|
|
15
22
|
import type { BaseUnit } from "@macrostrat/api-types";
|
|
16
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
type AtomMap,
|
|
25
|
+
createScopedStore,
|
|
26
|
+
StateIsolation,
|
|
27
|
+
} from "@macrostrat/data-components";
|
|
17
28
|
import { atom } from "jotai";
|
|
18
29
|
import { useEffect } from "react";
|
|
19
30
|
|
|
20
|
-
export const scope = createScopedStore();
|
|
31
|
+
export const scope: StateIsolation = createScopedStore();
|
|
21
32
|
|
|
22
33
|
export const columnUnitsAtom = atom<BaseUnit[]>();
|
|
23
34
|
|
|
@@ -84,6 +95,13 @@ export function MacrostratColumnStateProvider<T extends BaseUnit>({
|
|
|
84
95
|
);
|
|
85
96
|
}
|
|
86
97
|
|
|
98
|
+
/** Interface for imperative handlers that can
|
|
99
|
+
* be invoked outside of the column's react context
|
|
100
|
+
*/
|
|
101
|
+
export interface ColumnRef {
|
|
102
|
+
scrollSelectedUnitIntoView(): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
87
105
|
export interface MacrostratColumnDataContext<T extends BaseUnit> {
|
|
88
106
|
units: T[];
|
|
89
107
|
sections: PackageLayoutData[];
|
|
@@ -95,6 +113,7 @@ export interface MacrostratColumnDataContext<T extends BaseUnit> {
|
|
|
95
113
|
export interface ColumnDataProviderProps<T extends BaseUnit>
|
|
96
114
|
extends MacrostratColumnDataContext<T>, ColumnStateProviderProps<T> {
|
|
97
115
|
children: ReactNode;
|
|
116
|
+
ref: RefObject<ColumnRef>;
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
const MacrostratColumnDataContext =
|
|
@@ -109,6 +128,7 @@ export function MacrostratColumnDataProvider<T extends BaseUnit>({
|
|
|
109
128
|
allowUnitSelection,
|
|
110
129
|
onUnitSelected,
|
|
111
130
|
selectedUnit,
|
|
131
|
+
ref,
|
|
112
132
|
}: ColumnDataProviderProps<T>) {
|
|
113
133
|
/** Internal provider for Macrostrat column data.
|
|
114
134
|
* As a general rule, we want to provide data and column-axis
|
|
@@ -138,11 +158,35 @@ export function MacrostratColumnDataProvider<T extends BaseUnit>({
|
|
|
138
158
|
allowUnitSelection,
|
|
139
159
|
onUnitSelected,
|
|
140
160
|
selectedUnit,
|
|
161
|
+
ref,
|
|
141
162
|
},
|
|
142
|
-
|
|
163
|
+
[
|
|
164
|
+
h(ColumnRefManager, { ref }),
|
|
165
|
+
h(MacrostratColumnDataContext.Provider, { value }, children),
|
|
166
|
+
],
|
|
143
167
|
);
|
|
144
168
|
}
|
|
145
169
|
|
|
170
|
+
function ColumnRefManager({ ref }: { ref?: RefObject<ColumnRef> }) {
|
|
171
|
+
const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (ref == null) return;
|
|
174
|
+
ref.current = {
|
|
175
|
+
scrollSelectedUnitIntoView(opts?: ScrollIntoViewOptions) {
|
|
176
|
+
selectedUnitElement?.scrollIntoView(
|
|
177
|
+
opts ?? {
|
|
178
|
+
behavior: "smooth",
|
|
179
|
+
block: "center",
|
|
180
|
+
inline: "nearest",
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}, [ref, selectedUnitElement]);
|
|
186
|
+
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
146
190
|
export function UnitSelectionProvider(props: ColumnStateProviderProps<any>) {
|
|
147
191
|
/* A basic unit selection provider without column data context.
|
|
148
192
|
Mostly for use with the CorrelationChart component.
|
|
@@ -48,6 +48,7 @@ export interface UnitSelectionCallbacks {
|
|
|
48
48
|
export const allowUnitSelectionAtom = atom<boolean>(true);
|
|
49
49
|
|
|
50
50
|
export const selectedUnitIDAtom = atom<number | null>();
|
|
51
|
+
export const selectedUnitElementAtom = atom<HTMLElement | null>();
|
|
51
52
|
|
|
52
53
|
const overlayPositionAtom = atom<RectBounds | null>();
|
|
53
54
|
|
|
@@ -113,6 +114,7 @@ const selectedUnitAtom = atom(
|
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
set(selectedUnitElementAtom, target);
|
|
116
118
|
set(selectedUnitIDAtom, unitID);
|
|
117
119
|
set(overlayPositionAtom, overlayPosition);
|
|
118
120
|
|
|
@@ -158,6 +160,7 @@ export function useUnitSelectionTarget(
|
|
|
158
160
|
const ref = useRef<HTMLElement>(null);
|
|
159
161
|
const [selectedUnit, selectUnit] = useUnitSelection();
|
|
160
162
|
const selected = selectedUnit?.unit_id == unit.unit_id;
|
|
163
|
+
const selectedUnitElement = scope.useAtomValue(selectedUnitElementAtom);
|
|
161
164
|
|
|
162
165
|
const onClick = useCallback(
|
|
163
166
|
(evt: Event) => {
|
|
@@ -168,17 +171,19 @@ export function useUnitSelectionTarget(
|
|
|
168
171
|
);
|
|
169
172
|
|
|
170
173
|
useEffect(() => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
selectUnit(unit, ref.current);
|
|
174
|
+
// Sync selection with unit element...
|
|
175
|
+
if (!selected) return;
|
|
176
|
+
selectUnit?.(unit, ref.current);
|
|
177
|
+
}, [ref.current, selected, selectUnit]);
|
|
174
178
|
|
|
179
|
+
useEffect(() => {
|
|
175
180
|
// Scroll the unit into view
|
|
176
|
-
|
|
181
|
+
selectedUnitElement?.scrollIntoView({
|
|
177
182
|
behavior: "smooth",
|
|
178
183
|
block: "center",
|
|
179
184
|
inline: "nearest",
|
|
180
185
|
});
|
|
181
|
-
}, [
|
|
186
|
+
}, [selectedUnitElement]);
|
|
182
187
|
|
|
183
188
|
return [ref, selected, onClick];
|
|
184
189
|
}
|