Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resizable canvas option #117

Open
vinothpandian opened this issue Feb 20, 2023 · 3 comments
Open

Add resizable canvas option #117

vinothpandian opened this issue Feb 20, 2023 · 3 comments

Comments

@vinothpandian
Copy link
Owner

The withViewBox property works to scale everything up/down on resize. but then when you add another stroke to the canvas after resizing, all strokes on the canvas "shift" and I encounter the same problem where the strokes all get cut off

Originally posted by @dereklance in #116 (reply in thread)

@suciueus
Copy link

suciueus commented Jul 3, 2024

is there a plan to solve this one?

@xjamundx
Copy link

Just running into this today

@eusebiusuciuengage
Copy link

@xjamundx Going to react-sketch-canvas/src/Canvas/index.tsx and changing method getCoordinates to this (below) will fix it. But I didn't investigate what impact it has on other features etc. so use with caution:

  const getCoordinates = useCallback(
    (pointerEvent: React.PointerEvent<HTMLDivElement>): Point => {
      const boundingArea = canvasRef.current?.getBoundingClientRect();
      canvasSizeRef.current = boundingArea
        ? {
          width: boundingArea.width,
          height: boundingArea.height,
        }
        : null;

      if (!boundingArea) {
        return { x: 0, y: 0 };
      }

      if (!canvasRef.current) {
        return { x: 0, y: 0 };
      }

      const svgCanvas = canvasRef?.current?.firstChild as SVGSVGElement;
      let point = svgCanvas?.createSVGPoint();

      if (!point) {
        return { x: 0, y: 0 };
      }

      point.x = pointerEvent.pageX;
      point.y = pointerEvent.pageY;
      point = point.matrixTransform(svgCanvas?.getScreenCTM()?.inverse());

      return {
        x: point.x,
        y: point.y
      };
    },
    []
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants