-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3501d8d
commit 551b0fa
Showing
7 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PropTable } from "components/PropTable" | ||
|
||
import CodeAndExample from "components/CodeAndExample" | ||
import ImageExample from "guide-examples/display/images/ImageExample" | ||
import type { Metadata } from "next" | ||
|
||
export const metadata: Metadata = { | ||
title: "Vectors", | ||
} | ||
|
||
function Vectors() { | ||
return ( | ||
<> | ||
<p> | ||
Images in Mafs are just wrappers around the SVG <code>image</code> element, with some | ||
improvements. For exa | ||
</p> | ||
|
||
<CodeAndExample example={ImageExample} /> | ||
|
||
<PropTable of={"Vector"} /> | ||
</> | ||
) | ||
} | ||
|
||
export default Vectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
docs/components/guide-examples/display/images/ImageExample.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use client" | ||
|
||
import { | ||
Coordinates, | ||
Debug, | ||
Image, | ||
Mafs, | ||
useMovablePoint, | ||
} from "mafs" | ||
|
||
import mafs from "./mafs.png" | ||
|
||
export default function VectorExample() { | ||
return ( | ||
<Mafs viewBox={{ x: [-1, 7], y: [-1, 5] }}> | ||
<Coordinates.Cartesian /> | ||
<Image | ||
src={mafs.src} | ||
anchor="cc" | ||
x={2} | ||
y={2} | ||
width={2} | ||
height={2} | ||
/> | ||
</Mafs> | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Anchor, computeAnchor } from "../math" | ||
|
||
export interface ImageProps { | ||
src: string | ||
x: number | ||
y: number | ||
width: number | ||
height: number | ||
anchor?: Anchor | ||
preserveAspectRatio?: string | ||
svgImageProps?: React.SVGProps<SVGImageElement> | ||
} | ||
|
||
export function Image({ | ||
src, | ||
x, | ||
y, | ||
width, | ||
height, | ||
anchor = "bl", | ||
preserveAspectRatio, | ||
svgImageProps, | ||
}: ImageProps) { | ||
const [actualX, actualY] = computeAnchor(anchor, x, y, width, height) | ||
|
||
const scaleX = width < 0 ? -1 : 1 | ||
const scaleY = height < 0 ? -1 : 1 | ||
|
||
console.log(actualX - (width < 0 ? -width : 0)) | ||
|
||
return ( | ||
<image | ||
href={src} | ||
x={actualX - (width < 0 ? -width : 0)} | ||
y={actualY - (height < 0 ? -height : 0)} | ||
width={Math.abs(width)} | ||
height={Math.abs(height)} | ||
preserveAspectRatio={preserveAspectRatio} | ||
{...svgImageProps} | ||
style={{ | ||
transform: [`var(--mafs-view-transform)`, `var(--mafs-user-transform)`, `scaleY(-1) `].join( | ||
" ", | ||
), | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters