code: def truncate_str(text, maxlen=40):
      """
      truncate a string
  
      Parameters
      ----------
      text : string
          string to check in order to add line break
      maxlen : int
          number of characters before truncation
  
      Returns
      -------
      string
          truncated text
      """
      if isinstance(text, str) and len(text) > maxlen:
          tot_length = 0
          input_words = text.split()
          output_words = []
          for word in input_words[:-1]:
              tot_length = tot_length + len(word)
              if tot_length <= maxlen:
                  output_words.append(word)
  
          text = " ".join(output_words)
          if len(input_words) > len(output_words):
              text = text + "..."
      return text
  
file_path: shapash/shapash/utils/utils.py
imports: import numpy
  import pandas
  import socket
  import math
  from shapash.explainer.smart_state import SmartState
  from shapash.explainer.multi_decorator import MultiDecorator
label_desc: Use image node_id 6 for calling a global function with example usage: truncate_str(text, maxlen) and returns: text