Skip to content

Commit f5ef029

Browse files
committed
Revert station types to avoid dep
1 parent 5e2c634 commit f5ef029

7 files changed

Lines changed: 76 additions & 66 deletions

File tree

packages/react/src/components/TideGraph/TideGraph.tsx

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
11
import { useNeapsConfig } from "../../provider.js";
22
import { TideGraphScroll } from "./TideGraphScroll.js";
3-
import { TideGraphStatic } from "./TideGraphStatic.js";
43
import { PX_PER_DAY_DEFAULT } from "./constants.js";
5-
import type { TimelineEntry, Extreme, Units } from "../../types.js";
64

7-
export interface TideGraphDataProps {
8-
timeline: TimelineEntry[];
9-
extremes?: Extreme[];
10-
timezone?: string;
11-
units?: Units;
12-
}
13-
14-
export interface TideGraphFetchProps {
5+
export interface TideGraphProps {
156
id: string;
16-
timeline?: undefined;
17-
}
18-
19-
export type TideGraphProps = (TideGraphDataProps | TideGraphFetchProps) & {
207
pxPerDay?: number;
218
className?: string;
22-
};
9+
}
2310

2411
export function TideGraph(props: TideGraphProps) {
2512
const config = useNeapsConfig();
2613

27-
if (props.timeline) {
28-
return (
29-
<TideGraphStatic
30-
timeline={props.timeline}
31-
extremes={props.extremes}
32-
timezone={props.timezone}
33-
units={props.units ?? config.units}
34-
locale={config.locale}
35-
className={props.className}
36-
/>
37-
);
38-
}
39-
4014
return (
4115
<TideGraphScroll
4216
id={props.id}

packages/react/src/components/TideGraph/TideGraphChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useTideScales } from "../../hooks/use-tide-scales.js";
1111
import { NightBands } from "./NightBands.js";
1212
import { HEIGHT, MARGIN } from "./constants.js";
1313
import type { TimelineEntry, Extreme, Units } from "../../types.js";
14+
import { useNeapsConfig } from "../../provider.js";
1415

1516
const timelineBisector = bisector<TimelineEntry, number>((d) => d.time.getTime()).left;
1617

@@ -19,7 +20,6 @@ export function TideGraphChart({
1920
extremes,
2021
timezone,
2122
units,
22-
locale,
2323
svgWidth,
2424
yDomainOverride,
2525
latitude,
@@ -32,7 +32,6 @@ export function TideGraphChart({
3232
extremes: Extreme[];
3333
timezone: string;
3434
units: Units;
35-
locale: string;
3635
svgWidth: number;
3736
yDomainOverride?: [number, number];
3837
latitude?: number;
@@ -42,6 +41,7 @@ export function TideGraphChart({
4241
onSelect: (entry: TimelineEntry | null, sticky?: boolean) => void;
4342
}) {
4443
const gradientId = useId();
44+
const { locale } = useNeapsConfig();
4545

4646
const { xScale, yScale, innerW, innerH } = useTideScales({
4747
timeline,

packages/react/src/components/TideGraph/TideGraphScroll.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import type { TimelineEntry } from "../../types.js";
1212
export function TideGraphScroll({
1313
id,
1414
pxPerDay,
15-
locale,
1615
className,
1716
}: {
1817
id: string;
1918
pxPerDay: number;
20-
locale: string;
2119
className?: string;
2220
}) {
2321
const scrollRef = useRef<HTMLDivElement>(null);
@@ -221,7 +219,6 @@ export function TideGraphScroll({
221219
extremes={extremes}
222220
timezone={timezone}
223221
units={units}
224-
locale={locale}
225222
svgWidth={svgWidth}
226223
yDomainOverride={yDomain}
227224
latitude={station?.latitude}

packages/react/src/components/TideGraph/TideGraphStatic.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ import { useTooltip } from "@visx/tooltip";
44
import { useContainerWidth } from "../../hooks/use-container-width.js";
55
import { useCurrentLevel } from "../../hooks/use-current-level.js";
66
import { TideGraphChart } from "./TideGraphChart.js";
7-
import type { TideGraphDataProps } from "./TideGraph.js";
8-
import type { TimelineEntry } from "../../types.js";
7+
import type { TimelineEntry, Extreme, Units } from "../../types.js";
8+
9+
export interface TideGraphStaticProps {
10+
timeline: TimelineEntry[];
11+
extremes?: Extreme[];
12+
timezone?: string;
13+
units?: Units;
14+
locale?: string;
15+
className?: string;
16+
}
917

1018
export function TideGraphStatic({
1119
timeline,
1220
extremes = [],
1321
timezone = "UTC",
1422
units = "feet",
15-
locale,
23+
locale = "en",
1624
className,
17-
}: TideGraphDataProps & { locale: string; className?: string }) {
25+
}: TideGraphStaticProps) {
1826
const { ref: containerRef, width: containerWidth } = useContainerWidth();
1927
const currentLevel = useCurrentLevel(timeline);
2028
const { tooltipData, showTooltip, hideTooltip } = useTooltip<TimelineEntry>();

packages/react/src/types.ts

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
export type Units = "meters" | "feet";
2-
import type { Station as BaseStation } from "@neaps/tide-database";
32

4-
export interface Station extends BaseStation {
5-
defaultDatum: string;
3+
export interface StationSummary {
4+
id: string;
5+
name: string;
6+
latitude: number;
7+
longitude: number;
8+
region: string;
9+
country: string;
10+
continent: string;
11+
timezone: string;
12+
type: "reference" | "subordinate";
13+
distance?: number;
614
}
715

8-
export type StationSummary = Pick<
9-
Station,
10-
| "id"
11-
| "name"
12-
| "latitude"
13-
| "longitude"
14-
| "region"
15-
| "country"
16-
| "continent"
17-
| "timezone"
18-
| "type"
19-
> & {
20-
distance?: number;
21-
};
16+
export interface Station extends StationSummary {
17+
source: {
18+
id: string;
19+
name: string;
20+
url: string;
21+
};
22+
license: {
23+
type: string;
24+
commercial_use: boolean;
25+
url?: string;
26+
notes?: string;
27+
};
28+
disclaimers?: string;
29+
datums: Record<string, number>;
30+
defaultDatum?: string;
31+
harmonic_constituents: {
32+
name: string;
33+
amplitude: number;
34+
phase: number;
35+
}[];
36+
offsets?: {
37+
reference: string;
38+
height?: {
39+
high: number;
40+
low: number;
41+
type: "ratio" | "fixed";
42+
};
43+
time?: {
44+
high: number;
45+
low: number;
46+
};
47+
};
48+
}
2249

2350
export interface Extreme {
2451
time: Date;

packages/react/test/a11y.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TideTable } from "../src/components/TideTable.js";
55
import { StationSearch } from "../src/components/StationSearch.js";
66
import { NearbyStations } from "../src/components/NearbyStations.js";
77
import { TideStation } from "../src/components/TideStation.js";
8-
import { TideGraph } from "../src/components/TideGraph/index.js";
8+
import { TideGraphStatic } from "../src/components/TideGraph/index.js";
99
import { createTestWrapper } from "./helpers.js";
1010

1111
async function checkA11y(container: HTMLElement) {
@@ -83,9 +83,12 @@ describe("accessibility", () => {
8383
{ time: new Date("2025-12-17T18:00:00Z"), level: 1.4 },
8484
];
8585

86-
const { container } = render(<TideGraph timeline={timeline} timezone="UTC" units="meters" />, {
87-
wrapper: createTestWrapper(),
88-
});
86+
const { container } = render(
87+
<TideGraphStatic timeline={timeline} timezone="UTC" units="meters" />,
88+
{
89+
wrapper: createTestWrapper(),
90+
},
91+
);
8992

9093
await checkA11y(container);
9194
});

packages/react/test/components/TideGraph.test.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, test, expect } from "vitest";
22
import { render, waitFor } from "@testing-library/react";
3-
import { TideGraph } from "../../src/components/TideGraph/index.js";
3+
import { TideGraphStatic } from "../../src/components/TideGraph/index.js";
44
import { createTestWrapper } from "../helpers.js";
55

66
const timeline = [
@@ -19,10 +19,10 @@ const extremes = [
1919
{ time: new Date("2025-12-17T12:00:00Z"), level: 0.3, high: false, low: true, label: "Low" },
2020
];
2121

22-
describe("TideGraph", () => {
23-
test("renders a canvas element in data-driven mode", async () => {
22+
describe("TideGraphStatic", () => {
23+
test("renders an svg element", async () => {
2424
const { container } = render(
25-
<TideGraph timeline={timeline} extremes={extremes} timezone="UTC" units="meters" />,
25+
<TideGraphStatic timeline={timeline} extremes={extremes} timezone="UTC" units="meters" />,
2626
{ wrapper: createTestWrapper() },
2727
);
2828

@@ -32,9 +32,10 @@ describe("TideGraph", () => {
3232
});
3333

3434
test("renders with empty extremes", async () => {
35-
const { container } = render(<TideGraph timeline={timeline} timezone="UTC" units="meters" />, {
36-
wrapper: createTestWrapper(),
37-
});
35+
const { container } = render(
36+
<TideGraphStatic timeline={timeline} timezone="UTC" units="meters" />,
37+
{ wrapper: createTestWrapper() },
38+
);
3839

3940
await waitFor(() => {
4041
expect(container.querySelector("svg")).not.toBeNull();
@@ -43,7 +44,7 @@ describe("TideGraph", () => {
4344

4445
test("applies className", () => {
4546
const { container } = render(
46-
<TideGraph timeline={timeline} timezone="UTC" units="meters" className="my-graph" />,
47+
<TideGraphStatic timeline={timeline} timezone="UTC" units="meters" className="my-graph" />,
4748
{ wrapper: createTestWrapper() },
4849
);
4950

0 commit comments

Comments
 (0)