@macrostrat/column-views 3.12.0 → 3.12.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.
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  DataField,
3
+ IntervalProportion,
3
4
  IntervalShort,
4
5
  IntervalTag,
5
6
  type IntervalTagProps,
@@ -8,9 +9,17 @@ import {
8
9
  } from "@macrostrat/data-components";
9
10
  import { useMacrostratDefs } from "@macrostrat/data-provider";
10
11
  import h from "./age-range.module.sass";
11
- import { formatProportion, formatRange } from "./utils";
12
+ import { formatRange } from "./utils";
12
13
  import classNames from "classnames";
13
- import { ReactNode, useMemo } from "react";
14
+ import { useMemo } from "react";
15
+
16
+ // The interval tag, its proportion and single-age label live in
17
+ // `@macrostrat/data-components`; re-exported under their names here.
18
+ export {
19
+ AgeLabel,
20
+ getAge,
21
+ IntervalProportion as Proportion,
22
+ } from "@macrostrat/data-components";
14
23
 
15
24
  export function AgeField({ unit, children, ...rest }) {
16
25
  const [_b_age, _t_age, _unit] = getAgeRange(unit);
@@ -46,30 +55,6 @@ export function AgeRange({
46
55
  });
47
56
  }
48
57
 
49
- export function AgeLabel({
50
- age,
51
- maximumFractionDigits = 2,
52
- minimumFractionDigits = 0,
53
- className,
54
- }: {
55
- age: number;
56
- className?: string;
57
- maximumFractionDigits?: number;
58
- minimumFractionDigits?: number;
59
- }) {
60
- /** Component to display a single age value with unit conversion from
61
- * Ma to ka or Ga as appropriate.
62
- */
63
- const [value, unit] = getAge(age);
64
-
65
- const _value = value.toLocaleString("en-US", {
66
- maximumFractionDigits,
67
- minimumFractionDigits,
68
- });
69
-
70
- return h(Value, { value: _value, unit, className });
71
- }
72
-
73
58
  export function Duration({
74
59
  value,
75
60
  maximumFractionDigits = 2,
@@ -179,11 +164,11 @@ export function IntervalProportions({
179
164
  let p1: any = null;
180
165
 
181
166
  if (_showProps !== false) {
182
- p1 = h(Proportion, { value: t_prop });
167
+ p1 = h(IntervalProportion, { value: t_prop });
183
168
 
184
169
  if (i0 !== i1 || b_prop !== 0 || t_prop !== 1) {
185
170
  // We have a single interval with undefined proportions
186
- p0 = h(Proportion, { value: b_prop });
171
+ p0 = h(IntervalProportion, { value: b_prop });
187
172
  }
188
173
 
189
174
  if (i0 === i1 && (b_prop !== 0 || t_prop !== 1)) {
@@ -221,19 +206,6 @@ function getProportion(age: number, interval: IntervalShort): number | null {
221
206
  return (interval.b_age - age) / (interval.b_age - interval.t_age);
222
207
  }
223
208
 
224
- export function Proportion({ value }: { value: number }) {
225
- let content: ReactNode | null = null;
226
- if (value == 0) {
227
- content = "base";
228
- } else if (value == 1) {
229
- content = "top";
230
- } else {
231
- content = formatProportion(value * 100) + "%";
232
- }
233
-
234
- return h("span.proportion", content);
235
- }
236
-
237
209
  export function getAgeRange(_unit) {
238
210
  let b_age = _unit.b_age;
239
211
  let t_age = _unit.t_age;
@@ -251,21 +223,3 @@ export function getAgeRange(_unit) {
251
223
 
252
224
  return [b_age, t_age, unit];
253
225
  }
254
-
255
- export function getAge(value) {
256
- /** Get the age value in Ma, ka, or Ga as appropriate */
257
- let unit = "Ma";
258
- if (value < 0.8) {
259
- unit = "ka";
260
- value *= 1000;
261
- if (value < 5) {
262
- unit = "yr";
263
- value *= 1000;
264
- }
265
- } else if (value > 1000) {
266
- unit = "Ga";
267
- value /= 1000;
268
- }
269
-
270
- return [value, unit];
271
- }