nextspace
    Preparing search index...

    Function wrapLabel

    • Breaks a label into lines that each fit within maxWidth, so a long one — a leaf's statement, in particular — wraps into a block near its node instead of a single line wide enough to run through whatever else is on the canvas.

      Greedy word wrap: a word is added to the current line as long as the line still fits, and moved to a new one the moment it would not. A single word wider than maxWidth on its own is left whole on its own line rather than split — this wraps prose, not code, and breaking a word mid-letter would read worse than one slightly wide line.

      Parameters

      • text: string

        The label to wrap. An empty string wraps to a single empty line, so the caller always has at least one line to measure and draw.

      • maxWidth: number

        The widest a line may be, in the same screen-pixel units as estimateTextWidth.

      • fontSize: number

        Passed through to estimateTextWidth for each candidate line.

      • ratio: number = 0.55

        Passed through to estimateTextWidth.

      Returns string[]

      One or more lines, in order.