Skip to content

Axes.MaxTickLabelWidth

Estimates the maximum Y-axis tick label width for layout reservation

DaxLib.SVG.Axes.MaxTickLabelWidth( axisMin, axisMax, tickCount, axisFontSize, labelWidthFactor, axisIsDate )
Parameter Type Required Description
axisMin NUMERIC VAL Axis minimum value
axisMax NUMERIC VAL Axis maximum value
tickCount INT64 Optional: Number of ticks to estimate. Defaults to 1
axisFontSize INT64 Optional: Axis font size. Defaults to 10
labelWidthFactor DECIMAL Optional: Font width factor. Defaults to 0.56 (Segoe UI)
axisIsDate BOOLEAN Optional: Whether the axis values represent dates. Defaults to FALSE

NUMERIC Estimated max label width in pixels

DaxLib.SVG.Axes.MaxTickLabelWidth(
    0,              // axisMin
    1000,           // axisMax
    5,              // tickCount
    10,             // axisFontSize
    0.56,           // labelWidthFactor (Segoe UI default)
    FALSE           // axisIsDate
)
// Returns estimated max label width in pixels
// Used to reserve space for Y-axis labels in Axes.Layout
function 'DaxLib.SVG.Axes.MaxTickLabelWidth' =
        (
            axisMin: NUMERIC VAL,
            axisMax: NUMERIC VAL,
            tickCount: INT64,
            axisFontSize: INT64,
            labelWidthFactor: DOUBLE,
            axisIsDate: BOOLEAN
        ) =>

            VAR _TickCount = IF( ISBLANK( tickCount ) || tickCount < 1, 1, tickCount )
            VAR _AxisFontSize = IF( ISBLANK( axisFontSize ), 10, axisFontSize )
            VAR _LabelWidthFactor = IF( ISBLANK( labelWidthFactor ), 0.56, labelWidthFactor )
            VAR _AxisIsDate = IF( ISBLANK( axisIsDate ), FALSE(), axisIsDate )
            VAR _NumericSpan = ABS( axisMax - axisMin )
            VAR _NumericDecimals = IF( _NumericSpan >= 100, 0, IF( _NumericSpan >= 10, 1, 2 ) )

            VAR _TickBase =
                ADDCOLUMNS(
                    GENERATESERIES( 0, _TickCount - 1, 1 ),
                    "@TickValue",
                        IF(
                            _TickCount = 1,
                            axisMin,
                            axisMin + DIVIDE( [Value], _TickCount - 1, 0 ) * ( axisMax - axisMin )
                        )
                )

            VAR _LabelTable =
                ADDCOLUMNS(
                    _TickBase,
                    "@Label",
                        FORMAT(
                            IF(
                                _AxisIsDate,
                                [@TickValue],
                                ROUND( [@TickValue], _NumericDecimals )
                            ),
                            IF( _AxisIsDate, "dd-mmm-yy", "General Number" )
                        )
                )

            VAR _MeasuredLabelTable =
                ADDCOLUMNS(
                    _LabelTable,
                    "@EstimatedWidth", LEN( [@Label] ) * _AxisFontSize * _LabelWidthFactor
                )

            RETURN
                MAXX( _MeasuredLabelTable, [@EstimatedWidth] )