code: def get_sort_order(
      dist, clust_order, cluster_threshold, feature_order
  ):
      """Returns a sorted order of the values where we respect the clustering order when dist[i,j] < cluster_threshold"""
  
      # feature_imp = np.abs(values)
  
      # if partition_tree is not None:
      #     new_tree = fill_internal_max_values(partition_tree, shap_values)
      #     clust_order = sort_inds(new_tree, np.abs(shap_values))
      clust_inds = np.argsort(clust_order)
  
      feature_order = (
          feature_order.copy()
      )  # order.apply(Explanation(shap_values))
      # print("feature_order", feature_order)
      for i in range(len(feature_order) - 1):
          ind1 = feature_order[i]
          next_ind = feature_order[i + 1]
          next_ind_pos = i + 1
          for j in range(i + 1, len(feature_order)):
              ind2 = feature_order[j]
  
              # if feature_imp[ind] >
              # if ind1 == 2:
              #     print(ind1, ind2, dist[ind1,ind2])
              if dist[ind1, ind2] <= cluster_threshold:
                  # if ind1 == 2:
                  #     print(clust_inds)
                  #     print(ind1, ind2, next_ind, dist[ind1,ind2], clust_inds[ind2], clust_inds[next_ind])
                  if (
                      dist[ind1, next_ind] > cluster_threshold
                      or clust_inds[ind2] < clust_inds[next_ind]
                  ):
                      next_ind = ind2
                      next_ind_pos = j
              # print("next_ind", next_ind)
              # print("next_ind_pos", next_ind_pos)
  
          # insert the next_ind next
          for j in range(next_ind_pos, i + 1, -1):
              # print("j", j)
              feature_order[j] = feature_order[j - 1]
          feature_order[i + 1] = next_ind
          # print(feature_order)
  
      return feature_order
  
file_path: shap/shap/plots/_utils.py
imports: import matplotlib.pyplot
  import numpy
  from ..None import Explanation
  from ..utils import OpChain
  from .None import colors
label_desc: Use image node_id 3 for calling a global function with example usage: get_sort_order(dist, clust_order, cluster_threshold, feature_order) and returns: feature_order