Skip to content

panning whole graphics in canvas  #93

@creativejae

Description

@creativejae

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions