Source code for viiapackage.pictures.result_pictures.helper_functions.get_legend_values

### ===================================================================================================================
###  FUNCTION: Get legend values for VIIA pictures
### ===================================================================================================================
# Copyright ©VIIA 2024

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from typing import List


### ===================================================================================================================
###   2. Function to get the legend values for result pictures
### ===================================================================================================================

[docs]def viia_get_legend_values( max_value: float, min_value: float, pic_type: str, nr_level: int = 9, fraction_digits: int = 4) -> List[float]: """ Function to get the values for the legend. Input: - max_value (float): Maximum value of the legend. - min_value (float): Minimum value of the legend. - pic_type (str): The result type of the result picture, this is defined in the viia-result_pictures yaml file. Used to check for maximum or minimum critical boundary (or crackwidth). - nr_level (int): Number of levels to be applied in the picture. Default value is 9 levels. - fraction_digits (int): Precision for the rounding of the values of the legend. Output: - Returns list with values for the legend of the picture. """ # Divide the range by the number of levels interval = (max_value - min_value) / (nr_level - 1) if any(['max' in pic_type.lower(), 'crackwidth' in pic_type.lower()]): return list(sorted(set([round(min_value + interval * i, fraction_digits) for i in range(nr_level + 1)]))) elif 'min' in pic_type.lower(): return list(sorted(set([round(max_value - interval * i, fraction_digits) for i in range(nr_level + 1)]))) raise ValueError( f"ERROR: The picture type of {pic_type} is neither the result of maximum or minimum, the legend values cannot " f"be decided in this case.")
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================