Skip to content

Commit

Permalink
Update fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpetryk committed Oct 20, 2024
1 parent f5f551c commit 941bf82
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 45 deletions.
25 changes: 23 additions & 2 deletions .api-report/mafs.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
```ts

/// <reference types="react" />

import { JSX as JSX_2 } from 'react/jsx-runtime';
import { KatexOptions } from 'katex';
import * as React_2 from 'react';
Expand Down Expand Up @@ -82,6 +80,29 @@ export interface Filled {
weight?: number;
}

// @public (undocumented)
function Image_2({ href, x, y, width, height, anchor, preserveAspectRatio, svgImageProps, }: ImageProps): JSX_2.Element;
export { Image_2 as Image }

// @public (undocumented)
export interface ImageProps {
// Warning: (ae-forgotten-export) The symbol "Anchor" needs to be exported by the entry point index.d.ts
anchor?: Anchor;
// (undocumented)
height: number;
// (undocumented)
href: string;
preserveAspectRatio?: string;
// (undocumented)
svgImageProps?: React.SVGProps<SVGImageElement>;
// (undocumented)
width: number;
// (undocumented)
x: number;
// (undocumented)
y: number;
}

// @public (undocumented)
export type Interval = [min: number, max: number];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@ import {
useMovablePoint,
} from "mafs"

import mafs from "./mafs.png"
import image from "./mafs.png"

Check failure on line 10 in docs/components/guide-examples/display/images/ImageAnchorExample.tsx

View workflow job for this annotation

GitHub Actions / tsc

Cannot find module './mafs.png' or its corresponding type declarations.

export default function VectorExample() {
const center = useMovablePoint([2, 2])
return (
<Mafs viewBox={{ x: [-1, 7], y: [-1, 5] }}>
<Coordinates.Cartesian />
<Image
src={mafs.src}
href={image.src ?? image}
anchor="tl"
x={center.x + 0.1}
y={center.y - 0.1}
width={1}
height={1}
/>
<Image
src={mafs.src}
href={image.src ?? image}
anchor="tr"
x={center.x - 0.1}
y={center.y - 0.1}
width={1}
height={1}
/>
<Image
src={mafs.src}
href={image.src ?? image}
anchor="bl"
x={center.x + 0.1}
y={center.y + 0.1}
width={1}
height={1}
/>
<Image
src={mafs.src}
href={image.src ?? image}
anchor="br"
x={center.x - 0.1}
y={center.y + 0.1}
Expand Down
11 changes: 5 additions & 6 deletions docs/components/guide-examples/display/images/ImageExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import {
Coordinates,
Debug,
Image,
Mafs,
useMovablePoint,
} from "mafs"

import mafs from "./mafs.png"
import image from "./mafs.png"

Check failure on line 10 in docs/components/guide-examples/display/images/ImageExample.tsx

View workflow job for this annotation

GitHub Actions / tsc

Cannot find module './mafs.png' or its corresponding type declarations.

export default function ImageExample() {
const origin = useMovablePoint([3, 3])
Expand All @@ -18,31 +17,31 @@ export default function ImageExample() {
<Mafs viewBox={{ x: [-1, 7], y: [-1, 5] }}>
<Coordinates.Cartesian />
<Image
src={mafs.src}
href={image.src ?? image}
anchor="tl"
x={origin.x + padding}
y={origin.y - padding}
width={2}
height={2}
/>
<Image
src={mafs.src}
href={image.src ?? image}
anchor="tr"
x={origin.x - padding}
y={origin.y - padding}
width={2}
height={2}
/>
<Image
src={mafs.src}
href={image.src ?? image}
anchor="bl"
x={origin.x + padding}
y={origin.y + padding}
width={2}
height={2}
/>
<Image
src={mafs.src}
href={image.src ?? image}
anchor="br"
x={origin.x - padding}
y={origin.y + padding}
Expand Down
20 changes: 20 additions & 0 deletions e2e/generated-vrt.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import SimpleTransform from "../docs/components/guide-examples/utility/SimpleTra
import CartesianCoordinatesConfigExample from "../docs/components/guide-examples/display/coordinates/CartesianCoordinatesConfigExample"
import CartesianCoordinatesExample from "../docs/components/guide-examples/display/coordinates/CartesianCoordinatesExample"
import PolarCoordinatesExample from "../docs/components/guide-examples/display/coordinates/PolarCoordinatesExample"
import ImageAnchorExample from "../docs/components/guide-examples/display/images/ImageAnchorExample"
import ImageExample from "../docs/components/guide-examples/display/images/ImageExample"
import VectorExample from "../docs/components/guide-examples/display/vectors/VectorExample"
import ContainViewbox from "../docs/components/guide-examples/display/viewbox/ContainViewbox"
import StretchViewbox from "../docs/components/guide-examples/display/viewbox/StretchViewbox"
Expand Down Expand Up @@ -381,6 +383,24 @@ test("guide-examples/display/coordinates/PolarCoordinatesExample", async ({ moun
</TestContextProvider>,
))

test("guide-examples/display/images/ImageAnchorExample", async ({ mount, page }) =>
await visualTest(
mount,
page,
<TestContextProvider value={{ overrideHeight: 500 }}>
<ImageAnchorExample />
</TestContextProvider>,
))

test("guide-examples/display/images/ImageExample", async ({ mount, page }) =>
await visualTest(
mount,
page,
<TestContextProvider value={{ overrideHeight: 500 }}>
<ImageExample />
</TestContextProvider>,
))

test("guide-examples/display/vectors/VectorExample", async ({ mount, page }) =>
await visualTest(
mount,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 30 additions & 31 deletions src/display/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { Anchor, computeAnchor } from "../math"

export interface ImageProps {
src: string
href: string
x: number
y: number
/**
* Indicate where, in the image (top, bottom, left, right, center), the x and
* y coordinate refers to.
*/
anchor?: Anchor
width: number
height: number
anchor?: Anchor
/**
* Whether to preserve the aspect ratio of the image. By default, the image
* will be centered and scaled to fit the width and height. If you want to
* squish the image to be the same shape as the box, set this to "none".
*
* This is passed directly to the `preserveAspectRatio` attribute of the SVG
* `<image>` element.
*
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
*/
preserveAspectRatio?: string

svgImageProps?: React.SVGProps<SVGImageElement>
}

export function Image({
src,
href,
x,
y,
width,
Expand All @@ -26,37 +41,21 @@ export function Image({
const transform = [
"var(--mafs-view-transform)",
"var(--mafs-user-transform)",
// Ensure the image is not upside down (since Mafs has the y-axis pointing,
// while SVG has it pointing down)
// Ensure the image is not upside down (since Mafs has the y-axis pointing
// up, while SVG has it pointing down).
"scaleY(-1)",
].join(" ")

const debug = false

return (
<>
{debug && (
<rect
x={anchorX}
y={-anchorY}
width={width}
height={height}
fill="none"
stroke="red"
vectorEffect={"non-scaling-stroke"}
style={{ transform }}
/>
)}
<image
href={src}
x={anchorX}
y={-anchorY}
width={width}
height={height}
preserveAspectRatio={preserveAspectRatio}
{...svgImageProps}
style={{ transform }}
/>
</>
<image
href={href}
x={anchorX}
y={-anchorY}
width={width}
height={height}
preserveAspectRatio={preserveAspectRatio}
{...svgImageProps}
style={{ transform }}
/>
)
}
2 changes: 1 addition & 1 deletion tests/frameworks/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 941bf82

Please sign in to comment.