Skip to content

Commit

Permalink
Change 'domain' property in "OfX/OfY" components to be a tuple (match…
Browse files Browse the repository at this point in the history
…ing current 't' property).
  • Loading branch information
Mark Fitzgerald committed Jun 27, 2024
1 parent dbb3ec3 commit 5253d7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/display/Plot/OfX.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { vec } from "../../vec"

export interface OfXProps extends Omit<ParametricProps, "xy" | "domain" | "t"> {
y: (x: number) => number
domain?: {min?: number, max?: number}
domain?: vec.Vector2
svgPathProps?: React.SVGProps<SVGPathElement>
}

export function OfX({ y, domain, ...props }: OfXProps) {
const [xuMin, xuMax] = domain ?? [-Infinity, Infinity]
const {
xPaneRange: [xpMin, xpMax],
} = usePaneContext()
// Determine the most restrictive range values (either user-provided or the pane context)
const xMin = Math.max(xpMin, domain?.min ?? -Infinity)
const xMax = Math.min(xpMax, domain?.max ?? Infinity)
const xMin = Math.max(xuMin, xpMin)
const xMax = Math.min(xuMax, xpMax)

const xy = React.useCallback<ParametricProps["xy"]>((x) => [x, y(x)], [y])
const parametricDomain = React.useMemo<vec.Vector2>(() => [xMin, xMax], [xMin, xMax])
Expand Down
7 changes: 4 additions & 3 deletions src/display/Plot/OfY.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { vec } from "../../vec"

export interface OfYProps extends Omit<ParametricProps, "xy" | "domain" | "t"> {
x: (y: number) => number
domain?: {min?: number, max?: number}
domain?: vec.Vector2
svgPathProps?: React.SVGProps<SVGPathElement>
}

export function OfY({ x, domain, ...props }: OfYProps) {
const [yuMin, yuMax] = domain ?? [-Infinity, Infinity]
const {
yPaneRange: [ypMin, ypMax],
} = usePaneContext()
// Determine the most restrictive range values (either user-provided or the pane context)
const yMin = Math.max(ypMin, domain?.min ?? -Infinity)
const yMax = Math.min(ypMax, domain?.max ?? Infinity)
const yMin = Math.max(yuMin, ypMin)
const yMax = Math.min(yuMax, ypMax)

const xy = React.useCallback<ParametricProps["xy"]>((y) => [x(y), y], [x])
const parametricDomain = React.useMemo<vec.Vector2>(() => [yMin, yMax], [yMin, yMax])
Expand Down

0 comments on commit 5253d7f

Please sign in to comment.