MAIDR Documentation - v3.46.2
    Preparing search index...

    Class FormatterService

    Service for managing value formatting across all layers in a MAIDR figure.

    The FormatterService extracts format configurations from layer definitions and provides methods to format values consistently throughout the application.

    // In Controller
    const formatterService = new FormatterService(maidrData);

    // Format a value
    const formatted = formatterService.formatValue(128.47, 'layer-1', 'y');
    // Returns "$128.47" if layer has currency formatter

    // Format an array (e.g., boxplot outliers)
    const formattedArray = formatterService.formatValue(
    [-9.795, 6.057, 14.736],
    'layer-1',
    'y'
    );
    // Returns ["-9.80", "6.06", "14.74"] if layer has 2-decimal formatter

    Implements

    Index

    Constructors

    Methods

    • Checks if a layer has a custom formatter for the specified axis.

      Parameters

      • layerId: string

        The ID of the layer

      • axis: AxisType

        The axis type ('x', 'y', or 'fill')

      Returns boolean

      True if a custom formatter is configured

    • Formats a value (single or array) using the formatter for the specified layer and axis.

      This is the primary method for formatting values in the application. It handles both single values and arrays (e.g., boxplot outliers).

      Parameters

      • value: FormattableValue

        The value or array of values to format

      • layerId: string

        The ID of the layer

      • axis: AxisType

        The axis type ('x', 'y', or 'fill')

      Returns string | string[]

      Formatted string or array of formatted strings

      // Single value
      formatValue(128.47, 'layer-1', 'y') // "$128.47"

      // Array of values (boxplot outliers)
      formatValue([-9.795, 6.057], 'layer-1', 'y') // ["-9.80", "6.06"]
    • Formats a single value (not an array) and always returns a string. Use this when you're certain the value is not an array.

      Parameters

      • value: string | number

        The single value to format

      • layerId: string

        The ID of the layer

      • axis: AxisType

        The axis type ('x', 'y', or 'fill')

      Returns string

      Formatted string

    • Formats an array of values and always returns a string array. Use this when you're certain the value is an array.

      Parameters

      • values: (string | number)[]

        The array of values to format

      • layerId: string

        The ID of the layer

      • axis: AxisType

        The axis type ('x', 'y', or 'fill')

      Returns string[]

      Array of formatted strings