Hi Craig -- it depends on what sort of resizing you want to do. If you want to change layouts within VexFlow (how much white space there is between notes, or how many measures are displayed on each staff system, for instance), that would involve how you configure the size of each measure (or Stave in VexFlow speak), and whether you're manually setting the X positions of each element in the measure, or letting the Formatter handle it for you. This gets into some pretty high level programming and depends a lot on the application needs you have. If you're building an in-browser GUI music notation program, you'll end up spending a lot of time on exactly this, and the Formatter.preCalculateMinTotalWidth() function will become a dear friend of yours.
Method for Canvas, SVG, and Raphael Contexts:
If you don't need that functionality, and just want the image of the music to be sized to the width of the container, then the best (current) bet without hacking the VexFlow rendering engines, is to add a listener for window.resize events. When they happen:
- Clear your VexFlow canvas
- Resize your VexFlow canvas to the new dimensions you want
- Figure out how that container size compares to the width you've imagined as your default (basically, the width of all your measures combined). For instance, if you'd imagined you'd have 500px width, but you actually have 750px available, you'd want to scale the rendering to 1.5 times the original.
- Call ctx.scale(width, height) with whatever the scale factor you calculated was
- Redraw your VexFlow notation.
Responsive Kluge for SVG Context Only:
You can leave the sizing to the browser in the new SVG context, but it takes a little bit of hacking. If you're ok with that, reach into the SVG itself and set its style.width & style.height elements as a percentage to make the SVG automatically resize to its container width:
ctx.svg.style.width = "100%";
ctx.svg.style.height = "100%";
If you do this, to keep the image from stretching horizontally or vertically, you may also want to add a preserveAspectRatio = "xMinYMin meet" (note the capitalization of xMin vs YMin!!!) to the SVG. You can do this by calling:
ctx.svg.setAttribute("preserveAspectRatio", "xMinYMin meet");
Note that any time you call ctx.clear() you'd also need to set the preserveAspectRatio again, since it would be removed from with all of the other elements from the SVG.
Hope this helps -- sorry there's not an easier answer!
Greg