@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
@@ -1,22 +1,93 @@
1
1
  import chroma from "chroma-js";
2
- import { UnitLong } from "@macrostrat/api-types";
2
+ import {
3
+ Environment,
4
+ Lithology,
5
+ UnitLithology,
6
+ UnitLong,
7
+ } from "@macrostrat/api-types";
3
8
 
4
9
  interface KeyOptions {
5
- key?: string;
6
- id_key?: string;
10
+ key?: "lith" | "environ";
11
+ id_key?: "lith_id" | "environ_id";
7
12
  }
8
13
 
9
14
  export function getMixedUnitColor(
10
15
  unit: UnitLong,
11
- lithMap,
16
+ lithMap: Map<number, { color: string }>,
12
17
  inDarkMode = false,
13
18
  asBackground = true,
14
19
  keyOpts: KeyOptions = null,
15
20
  ): string | null {
16
21
  const { key = "lith", id_key = "lith_id" } = keyOpts ?? {};
17
22
  const liths = unit[key];
18
- if (liths == null) {
19
- return "gray";
23
+ const getColor = (data: UnitLithology): string | null => {
24
+ return lithMap?.get(data[id_key])?.color ?? null;
25
+ };
26
+
27
+ return getMixedColorForData(liths, getColor, {
28
+ inDarkMode,
29
+ asBackground,
30
+ key: id_key,
31
+ });
32
+ }
33
+
34
+ interface ColorBuilderOptions {
35
+ key?: "lith_id" | "environ_id";
36
+ inDarkMode?: boolean;
37
+ asBackground?: boolean;
38
+ }
39
+
40
+ export function flattenLithologies<
41
+ T extends { prop: number | null; lith_id?: number; environ_id?: number },
42
+ >(liths: T[][], normalize: boolean = true): T[] {
43
+ /** Unify proportions in lithology/environment data across several units, normalizing if needed.
44
+ * If normalize is true, proportions are scaled to sum to 1 within each unit (with remaining proportions
45
+ * distributed equally among liths without specified proportions). This helps ensure that units with a
46
+ * few lithologies with specified proportions don't skew the color mixing.
47
+ *
48
+ * Lithologies are deduplicated based on their identifying property (lith_id or environ_id) if that is present.
49
+ */
50
+ if (liths == null || liths.length === 0) {
51
+ return [];
52
+ }
53
+
54
+ const unitCount = liths.length;
55
+
56
+ let newLiths: T[] = [];
57
+ for (const unitLiths of liths) {
58
+ let l1 = unitLiths;
59
+ if (normalize) {
60
+ l1 = addProportionsToAllData(unitLiths);
61
+ }
62
+ // Divide proportions by number of units to balance influence
63
+ for (const lith of l1) {
64
+ if (lith.prop == null || isNaN(lith.prop) || lith.prop <= 0) {
65
+ continue;
66
+ }
67
+ lith.prop = lith.prop / unitCount;
68
+ }
69
+ newLiths.push(...l1);
70
+ }
71
+ if (newLiths[0]?.lith_id != null) {
72
+ newLiths = mergeLikeData(newLiths, "lith_id");
73
+ } else if (newLiths[0]?.environ_id != null) {
74
+ newLiths = mergeLikeData(newLiths, "environ_id");
75
+ }
76
+ // Sort by proportion descending
77
+ newLiths.sort((a, b) => b.prop - a.prop);
78
+ return newLiths;
79
+ }
80
+
81
+ export function getMixedColorForData<
82
+ T extends UnitLithology | Lithology | Environment,
83
+ >(
84
+ liths: T[] | null,
85
+ getColor: (val: T) => string | null,
86
+ options: ColorBuilderOptions = {},
87
+ ): string | null {
88
+ const { inDarkMode = false, asBackground = true } = options;
89
+ if (liths == null || liths.length === 0) {
90
+ return null;
20
91
  }
21
92
  const lithData = liths
22
93
  .map((d) => {
@@ -25,33 +96,19 @@ export function getMixedUnitColor(
25
96
  prop = null;
26
97
  }
27
98
  return {
28
- lith_id: d[id_key],
99
+ ...d,
29
100
  prop,
30
- color: lithMap?.get(d[id_key])?.color,
101
+ color: getColor?.(d) ?? d.color,
31
102
  };
32
103
  })
33
104
  .filter((d) => d.color != null);
34
105
 
35
- const lithsWithProp = lithData.filter((d) => d.prop != null);
36
- const lithsWithoutProp = lithData.filter((d) => d.prop == null);
37
-
38
- const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
39
- if (totalProp < 1 && lithsWithoutProp.length > 0) {
40
- const remainingProp = 1 - totalProp;
41
- // Distribute remaining proportion equally among liths without prop
42
- const equalProp = remainingProp / lithsWithoutProp.length;
43
- lithsWithoutProp.forEach((d) => {
44
- lithsWithProp.push({
45
- ...d,
46
- prop: equalProp,
47
- });
48
- });
49
- }
50
-
51
- if (lithsWithProp.length == 0) {
106
+ if (lithData.length == 0) {
52
107
  return null;
53
108
  }
54
109
 
110
+ const lithsWithProp = addProportionsToAllData(lithData);
111
+
55
112
  // Mix colors proportionally
56
113
  const baseColor = chroma.average(
57
114
  lithsWithProp.map((d) => d.color),
@@ -69,3 +126,58 @@ export function getMixedUnitColor(
69
126
  return baseColor.set("hsl.l", 0.9).hex();
70
127
  }
71
128
  }
129
+
130
+ function addProportionsToAllData<T extends { prop?: number }>(liths: T[]): T[] {
131
+ /** Make sure that all lithologies/environments have a defined proportion,
132
+ * and that proportions sum to 1. If some liths lack a defined proportion,
133
+ * the remaining proportion is distributed equally among them.
134
+ *
135
+ * NOTE: This function does not normalize proportions if they already sum to more than 1.
136
+ */
137
+ const lithsWithProp = liths.filter((d) => d.prop != null);
138
+ const lithsWithoutProp = liths.filter((d) => d.prop == null);
139
+
140
+ const totalProp = lithsWithProp.reduce((sum, d) => sum + d.prop, 0);
141
+ let overallTotal = 1;
142
+
143
+ if (totalProp < overallTotal && lithsWithoutProp.length > 0) {
144
+ const remainingProp = overallTotal - totalProp;
145
+ // Distribute remaining proportion equally among liths without prop
146
+ const equalProp = remainingProp / lithsWithoutProp.length;
147
+ lithsWithoutProp.forEach((d) => {
148
+ lithsWithProp.push({
149
+ ...d,
150
+ prop: equalProp,
151
+ } as T);
152
+ });
153
+ }
154
+ return lithsWithProp as T[];
155
+ }
156
+
157
+ function mergeLikeData<
158
+ T extends { prop: number; lith_id?: number; environ_id?: number },
159
+ >(liths: T[], key: "lith_id" | "environ_id"): T[] {
160
+ /** Merge lithology/environment data with the same identifying property (lith_id or environ_id),
161
+ * summing their proportions.
162
+ *
163
+ * TODO: handle attribute merging
164
+ */
165
+ const mergedMap: Map<number, T> = new Map();
166
+
167
+ for (const lith of liths) {
168
+ const id = lith[key];
169
+ if (id == null) continue;
170
+
171
+ if (mergedMap.has(id)) {
172
+ const existing = mergedMap.get(id);
173
+ mergedMap.set(id, {
174
+ ...existing,
175
+ prop: existing.prop + lith.prop,
176
+ });
177
+ } else {
178
+ mergedMap.set(id, { ...lith });
179
+ }
180
+ }
181
+
182
+ return Array.from(mergedMap.values());
183
+ }
@@ -1,3 +1,6 @@
1
+ import { Lithology, UnitLithology } from "@macrostrat/api-types";
2
+ import { LithologyCore } from "@macrostrat/api-types/src/lithologies";
3
+
1
4
  const symbolIndex = {
2
5
  "dolomite-limestone": 641,
3
6
  lime_mudstone: 627,
@@ -54,6 +57,19 @@ const symbolIndex = {
54
57
  diamictite: 681,
55
58
  };
56
59
 
60
+ export function getBestFGDCPatternForLithologyList<
61
+ T extends UnitLithology | Lithology,
62
+ >(liths: T[]): { lith: T; patternID: string } | null {
63
+ let lithsSorted = [...liths];
64
+ lithsSorted.sort((a, b) => b.prop - a.prop);
65
+ let firstLith = lithsSorted[0];
66
+ let sym = symbolIndex[firstLith.name];
67
+ if (sym != null) {
68
+ return { lith: firstLith, patternID: `${sym}` };
69
+ }
70
+ return null;
71
+ }
72
+
57
73
  const resolveID = (d: any) => {
58
74
  if (d.lith == null || d.lith.length == 0) {
59
75
  return null;