Initial auto scale horizontal only

I’m looking for a way to scale my diagram upon loading in such a way that it fits horizontally in the viewport. initialAutoScale set to UniformToFill will try to fit vertically in some cases.

Yes, UniformToFill will always make sure the smaller of the width/height fits within the viewport, so if your height is smaller, that is what the scale will be based on.

If you want your initial scale to always be based on the width, you could do something like this:

myDiagram.addDiagramListener("InitialLayoutCompleted", function(e) {
  var dia = e.diagram;
  var scale = dia.viewportBounds.width / dia.documentBounds.width;
  if (scale > dia.defaultScale) scale = dia.defaultScale;
  if (scale < dia.minScale) { scale = dia.minScale; }
  if (scale > dia.maxScale) { scale = dia.maxScale; }
  dia.scale = scale;

Thanks. that worked.