code: 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);
  
      }
docs: Calculate and set the zoom factor needed to completely fit the diagram
  onto the screen bounds.
  
  @param drawWidth the width of the area to draw onto
  @param drawHeight the height of the area to draw onto
  @param diagramWidth the width of the diagram
  @param diagramHeight the height of the diagram