Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
rohittcodes committed Nov 8, 2024
1 parent dc6e8e3 commit 6156101
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/components/CircuitToSvgWithMouseControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { type AnyCircuitElement } from "circuit-json"
import { useMouseMatrixTransform } from "use-mouse-matrix-transform"
import { convertCircuitJsonToSchematicSvg } from "circuit-to-svg"
import { useEffect, useMemo, useRef, useState, useCallback } from "react"
import {
toString as transformToString,
import {
toString as transformToString,
Matrix,
scale,
translate,
compose
compose,
} from "transformation-matrix"

interface Props {
Expand All @@ -19,8 +19,8 @@ export const CircuitToSvgWithMouseControl = ({ circuitJson }: Props) => {
const [containerWidth, setContainerWidth] = useState(0)
const containerBoundsRef = useRef({ width: 0, x: 0, y: 0 })

const {
ref: containerRef,
const {
ref: containerRef,
transform: currentTransform,
setTransform,
} = useMouseMatrixTransform({
Expand All @@ -29,11 +29,11 @@ export const CircuitToSvgWithMouseControl = ({ circuitJson }: Props) => {

// Get the current container bounds
const bounds = containerBoundsRef.current

if (event) {
const mousePoint = {
x: event.clientX - bounds.x,
y: event.clientY - bounds.y
y: event.clientY - bounds.y,
}

const prevScale = currentTransform.a
Expand All @@ -45,7 +45,7 @@ export const CircuitToSvgWithMouseControl = ({ circuitJson }: Props) => {
translate(mousePoint.x, mousePoint.y),
scale(scaleFactor, scaleFactor),
translate(-mousePoint.x, -mousePoint.y),
currentTransform
currentTransform,
)

svgDivRef.current.style.transform = transformToString(zoomTransform)
Expand All @@ -63,26 +63,26 @@ export const CircuitToSvgWithMouseControl = ({ circuitJson }: Props) => {
containerBoundsRef.current = {
width: rect.width,
x: rect.left,
y: rect.top
y: rect.top,
}
setContainerWidth(rect.width)
}, [])

useEffect(() => {
if (!containerRef.current) return

updateContainerBounds()

const resizeObserver = new ResizeObserver(() => {
updateContainerBounds()
})

resizeObserver.observe(containerRef.current)
window.addEventListener('resize', updateContainerBounds)
window.addEventListener("resize", updateContainerBounds)

return () => {
resizeObserver.disconnect()
window.removeEventListener('resize', updateContainerBounds)
window.removeEventListener("resize", updateContainerBounds)
}
}, [updateContainerBounds])

Expand Down Expand Up @@ -117,4 +117,4 @@ export const CircuitToSvgWithMouseControl = ({ circuitJson }: Props) => {
/>
</div>
)
}
}

0 comments on commit 6156101

Please sign in to comment.