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

panning whole graphics in canvas #93

Open
creativejae opened this issue Feb 13, 2023 · 0 comments
Open

panning whole graphics in canvas #93

creativejae opened this issue Feb 13, 2023 · 0 comments

Comments

@creativejae
Copy link

Hi,
In my code, I used context.translate() function in order to pan all drawings in the canvas. (e.g. dragging)
Since it is to move whole images in canvas, translate() function is being called while context is not in beginPath() mode.
It works perfectly with 2d canvas, but when I tried to export to SVG, intended panning is not applied.
It might be because canvas2svg code applying translate into individual path(?), not to rootGroup in this case. I am not sure.

I made some a temporary workaround solution. It works as I want but it is not much ideal. Here is what I did

var transX = this.boundingBox.translateX; // program tracks canvas level panning
var transY = this.boundingBox.translateY;

var t = "translate(" + transX + "," + transY + ")"; // build translate attribute
var rootGroup = ctx.__root.childNodes[1]; // it might not be ideal to touch __root element from out of canvas2svg ?
var transform = rootGroup.getAttribute("transform");
if (transform) {
transform += " ";
} else {
transform = "";
}
transform += t;
rootGroup.setAttribute("transform", transform);

Any thought?

Expected:
image

Initial result by canvas2svg:
image

Workaround result:
image

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

1 participant