-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
3aee37d
commit a54d3d2
Showing
2 changed files
with
56 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
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,54 @@ | ||
<script lang="ts"> | ||
import { getContext } from 'svelte'; | ||
import { zoomIdentity } from 'd3-zoom'; | ||
import type { LayerCakeContext } from '$lib/types'; | ||
export let transform = zoomIdentity; | ||
$: cursorX = 0; | ||
$: cursorY = 0; | ||
const { xScale, yScale, width, height } = getContext<LayerCakeContext>('LayerCake'); | ||
function updateCoordinates(event: PointerEvent) { | ||
if (!$xScale || !$yScale) return; | ||
const svgElement = event.currentTarget as SVGElement; | ||
const rect = svgElement.getBoundingClientRect(); | ||
const x = event.clientX - rect.left - 16; | ||
const y = event.clientY - rect.top - 16; | ||
const transformedX = (x - transform.x) / transform.k; | ||
const transformedY = (y - transform.y) / transform.k; | ||
cursorX = $xScale.invert(transformedX); | ||
cursorY = $yScale.invert(transformedY); | ||
} | ||
</script> | ||
|
||
<rect | ||
x="0" | ||
y="0" | ||
width={$width} | ||
height={$height} | ||
fill="transparent" | ||
on:pointermove={updateCoordinates} | ||
/> | ||
|
||
<g transform="translate({$width - 120}, {$height - 40})"> | ||
<rect | ||
width="110" | ||
height="30" | ||
rx="4" | ||
fill="#2563eb" | ||
class="shadow-lg" | ||
/> | ||
<text | ||
x="55" | ||
y="19" | ||
text-anchor="middle" | ||
fill="white" | ||
font-size="12" | ||
> | ||
X: {cursorX.toFixed(2)}, Y: {cursorY.toFixed(2)} | ||
</text> | ||
</g> |