calculateYAxisWidth function

double calculateYAxisWidth(
  1. List<Tick> ticks,
  2. ChartTheme theme,
  3. int pipSize
)

Calculates the appropriate width for the y-axis based on the price values.

This function determines how much horizontal space the y-axis should occupy to properly display price labels. It takes into account the current price values, the theme's styling for y-axis labels, and the precision of price display.

The calculation is based on the width needed to display the last (most recent) price value, plus additional padding specified in the theme. If there are no ticks available, a default width of 60 logical pixels is returned.

@param ticks A list of price ticks from which to determine the y-axis width. The last tick in the list is used for the calculation. @param theme The chart theme, which provides styling information for the y-axis labels. @param pipSize The number of decimal places to display for price values. @return The calculated width for the y-axis in logical pixels.

Implementation

double calculateYAxisWidth(List<Tick> ticks, ChartTheme theme, int pipSize) {
  if (ticks.isEmpty) {
    return 60;
  } else {
    final double width = labelWidth(
      ticks.last.close,
      theme.gridStyle.yLabelStyle,
      pipSize,
    );

    return width + theme.gridStyle.labelHorizontalPadding * 2;
  }
}