private void configureViewerPreferredSize() {
		int vertexCount = graph.vertexSet().size();

		Dimension viewSize = viewer.getPreferredSize();

		// set the layoutModel's initials size to a minimal value. Not sure this should be necessary
		// but it makes the initial scaling look better for small graphs. Otherwise it seems
		// to use a very large area to layout the graph, resulting in tiny nodes that are spaced
		// very far apart. This might just be a work around for a bug in some of the layout
		// algorithms that don't seem to properly compute a good layout size.
		viewer.getVisualizationModel().getLayoutModel().setSize(1, 1);

		if (vertexCount < 100) {
			viewer.getVisualizationModel()
					.getLayoutModel()
					.setPreferredSize(viewSize.width, viewSize.height);
		}
		else {
			int newSize = viewSize.width + 5 * (vertexCount - 100);
			viewer.getVisualizationModel().getLayoutModel().setPreferredSize(newSize, newSize);
		}
	}
configure a preferred size based on the size of the graph to display
Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java