code: def largest_category_index_up_to_ratio(
      histogram, max_segments, max_cat_proportions
  ):
      """Decide which categorical values are big enough to display individually.
  
      First check how many of the biggest categories needed in order to occupy `max_cat_proportions`% of the data. If
      the number is less than max_segments than return it, else return max_segments or number of unique values.
      """
      total_values = sum(histogram.values)
      first_less_then_max_cat_proportions_idx = np.argwhere(
          histogram.values.cumsum()
          >= total_values * max_cat_proportions
      )[0][0]
  
      # Get index of last value in histogram to show
      return min(
          max_segments,
          histogram.size,
          first_less_then_max_cat_proportions_idx + 1,
      )
  
imports: from collections import defaultdict
  from copy import deepcopy
  from typing import Callable, List, Optional, Tuple, Union
  import numpy
  import pandas
  from sklearn.tree import _tree
  from deepchecks.tabular.dataset import Dataset
  from deepchecks.utils.strings import format_number
  from deepchecks.utils.typing import Hashable
label_desc: Use image node_id 4 for calling a global function with example usage: largest_category_index_up_to_ratio(histogram, max_segments, max_cat_proportions) and returns: min