Hi, I'm trying to make the HTML5 canvas responsive to changes in its container element's size.
Setting the canvas width to 100% via CSS achieves the desired effect, however, I cannot figure out how to reset the zoom scale of the MindFusion diagram so the ShapeNodes on the canvas look crisp. The canvas will resize, but all of the MF elements look fuzzy and the zooming behavior gets messed up. I've tried using `canvas.setBounds()` and various other methods in the `diagram` class, but haven't been successful.
Here's some code that I am using to achieve the resizing effect. Using MVC 5, Angular 1.5.8, and latest MindFusion builds.
#my-canvas {
width: 100%;
}
function scaleCanvas (scale) {
scale = scale || 1;
var viewport = angular.element('#viewport');
var point = canvas.clientToDoc({ x: viewport.width() * scale, y: viewport.height() * scale });
var dim = {
width: point.x,
height: point.y
};
var rect = new MindFusion.Drawing.Rect(0, 0, Math.floor(dim.width), Math.floor(dim.height));
canvas.setBounds(rect); // Instance of MindFusion Diagram fed in via Angular service, code omitted
canvas.setZoomToRect(rect);
}
Thank you!