Skip to content

Instantly share code, notes, and snippets.

@starakaj
Created April 16, 2021 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starakaj/d9d2c5ed42874e940a6d4b002fb14595 to your computer and use it in GitHub Desktop.
Save starakaj/d9d2c5ed42874e940a6d4b002fb14595 to your computer and use it in GitHub Desktop.
// This is what the scaling code should actually look like
if (viewBox !== undefined) {
let x = t.numericLiteral(
2 * Number.parseFloat(attribs.x || "0") / viewBox[2] - 1
);
let y = t.numericLiteral(
1 - 2 * Number.parseFloat(attribs.y || "0") / viewBox[3]
);
let w = t.numericLiteral(
2 * Number.parseFloat(attribs.width || "0") / viewBox[2]
);
let h = t.numericLiteral(
2 * Number.parseFloat(attribs.height || "0") / viewBox[3]
);
const rectStatements = makeRectDrawStatements({ x, y, w, h });
paintStatements = paintStatements.concat(rectStatements);
} else {
console.warn("rect tag outside of svg parent tag with defined viewBox, skipping");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment