nextspace
    Preparing search index...

    Function computeFitTransform

    • Works out the transform that brings a whole laid-out graph inside the canvas.

      A force simulation spreads as far as its nodes push each other and knows nothing about the size of the box it is drawn in, so without this the graph simply runs off the edges. This measures what was actually laid out — pill widths and the labels hanging below nodes included — and centres it at the largest scale that still fits. A graph too vast to fit even at minScale stops shrinking there instead: it is left to be panned rather than squeezed down to dust.

      Parameters

      • extents: NodeExtent[]

        Every placed node. An empty list has nothing to frame and returns null.

      • width: number
      • height: number
      • margin: { margin?: number; maxScale?: number; minScale?: number } = {}

        Fraction of the canvas to fill, leaving a little air around the graph.

      Returns FitTransform | null

      The transform, or null when there is nothing to frame.