public void setZoomToFit ( double drawWidth , double drawHeight , double diagramWidth , double diagramHeight ) { double margin = rendererModel . getParameter ( Margin . class ) . getValue ( ) ; // determine the zoom needed to fit the diagram to the screen double widthRatio = drawWidth / ( diagramWidth + ( 2 * margin ) ) ; double heightRatio = drawHeight / ( diagramHeight + ( 2 * margin ) ) ; double zoom = Math . min ( widthRatio , heightRatio ) ; this . fontManager . setFontForZoom ( zoom ) ; // record the zoom in the model, so that generators can use it rendererModel . getParameter ( ZoomFactor . class ) . setValue ( zoom ) ; }
Calculate and set the zoom factor needed to completely fit the diagram onto the screen bounds .