code: def build_final_chart_code(code):
      is_charts = (
          next(
              (
                  c
                  for c in make_list(code)
                  if c.startswith("figure = go.Figure(data=charts,")
              ),
              None,
          )
          is not None
      )
      return "\n".join(
          make_list(code)
          + [CHARTS_EXPORT_CODE if is_charts else CHART_EXPORT_CODE]
      )
  
imports: import dtale.global_state
  from dtale.utils import make_list, triple_quote
  from dtale.query import build_query
label_desc: Use image node_id 1 for calling a global function with example usage: build_final_chart_code(code) and returns: str