How to scale the rendered SVG relative to parent elements dimensions ? #1426
-
How to scale the rendered music staff SVG relative to parent elements dimension ? I want to render a bigger image of the music staff. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Do you mean scaling (more notes fit in the same measure) or zooming (changing the size of the music, notes and staff proportionally). Either way you can get it by changing the svg view box. If you want to fit more music in the same space, you need to do this pre-rendering and set scale to something < 1.0. If you just want to zoom, keep 'scaling' value = 1.0 and change zoom value.
// assuming your application set up width/height and svg parent element is #boo
const renderer = new VF.Renderer('boo', VF.Renderer.Backends.SVG);
const context = renderer.getContext();
const svg = context.svg;
const xOffset = 0;
const yOffset = 0;
const zoom = 2.0;
const scale = 1.0;
svg.setAttributeNS('', 'width', '' + width * zoom);
svg.setAttributeNS('', 'height', '' + height * zoom);
svg.setAttributeNS('', 'viewBox', '' + xOffset + ' ' + yOffset + ' ' + Math.round((width * zoom) / scale) + ' ' +
Math.round((height * zoom) / scale)); |
Beta Was this translation helpful? Give feedback.
-
setAttributeNS is a native SVG DOM call. It is not part of Vex (I assume you're running in a browser and not nodejs). Here is a demo. I had the zoom value backwards - smaller zoom = larger output. Same with scale, you can play around with those. |
Beta Was this translation helpful? Give feedback.
setAttributeNS is a native SVG DOM call. It is not part of Vex (I assume you're running in a browser and not nodejs).
Here is a demo. I had the zoom value backwards - smaller zoom = larger output. Same with scale, you can play around with those.
https://jsfiddle.net/AaronDavidNewman/bsgc07pj/