Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Typography

Various functions to support typography

Hierarchy

  • Typography

Index

Methods

Static fontSizeToBox

  • fontSizeToBox(box: GroupLike, ratio?: number, byHeight?: boolean): function
  • Get a function to scale font size proportionally to text box size changes.

    Parameters

    • box: GroupLike

      Initial box as a Group

    • Default value ratio: number = 1

      font-size change ratio. Default is 1.

    • Default value byHeight: boolean = true

    Returns function

    a function where input parameter is a new box, and returns the new font size value

      • (GroupLike: any): number
      • Parameters

        • GroupLike: any

        Returns number

Static fontSizeToThreshold

  • fontSizeToThreshold(threshold: number, direction?: number): function
  • Get a function to scale font size based on a threshold value

    Parameters

    • threshold: number

      threshold value

    • Default value direction: number = 0

      if negative, get a font size <= defaultSize; if positive, get a font size >= defaultSize; Default is 0 which will scale font without min or max limits.

    Returns function

    a function where input parameter is the default font size and a value to compare with threshold, and returns new font size value

      • (a: number, b: number): number
      • Parameters

        • a: number
        • b: number

        Returns number

Static textWidthEstimator

  • textWidthEstimator(fn: function, samples?: string[], distribution?: number[]): function
  • Create a heuristic text width estimate function. It will be less accurate but faster.

    Parameters

    • fn: function

      a reference function that can measure text width accurately

        • (string: any): number
        • Parameters

          • string: any

          Returns number

    • Default value samples: string[] = ["M", "n", "."]

      a list of string samples. Default is ["M", "n", "."]

    • Default value distribution: number[] = [0.06, 0.8, 0.14]

      a list of the samples' probability distribution. Default is [0.06, 0.8, 0.14].

    Returns function

    a function that can estimate text width

      • (string: any): number
      • Parameters

        • string: any

        Returns number

Static truncate

  • truncate(fn: function, str: string, width: number, tail?: string): [string, number]
  • Truncate text to fit width

    Parameters

    • fn: function

      a function that can measure text width

        • (string: any): number
        • Parameters

          • string: any

          Returns number

    • str: string

      text to truncate

    • width: number

      width to fit

    • Default value tail: string = ""

      text to indicate overflow such as "...". Default is empty "".

    Returns [string, number]

Generated using TypeDoc