code: def task_group_to_dict(task_item_or_group):
      """Create a nested dict representation of this TaskGroup and its children used to construct the Graph."""
      from airflow.models.abstractoperator import AbstractOperator
  
      if isinstance(task := task_item_or_group, AbstractOperator):
          setup_teardown_type = {}
          if task.is_setup is True:
              setup_teardown_type["setupTeardownType"] = "setup"
          elif task.is_teardown is True:
              setup_teardown_type["setupTeardownType"] = "teardown"
          return {
              "id": task.task_id,
              "value": {
                  "label": task.label,
                  "labelStyle": f"fill:{task.ui_fgcolor};",
                  "style": f"fill:{task.ui_color};",
                  "rx": 5,
                  "ry": 5,
                  **setup_teardown_type,
              },
          }
      task_group = task_item_or_group
      is_mapped = isinstance(task_group, MappedTaskGroup)
      children = [
          task_group_to_dict(child)
          for child in sorted(
              task_group.children.values(), key=lambda t: t.label
          )
      ]
  
      if task_group.upstream_group_ids or task_group.upstream_task_ids:
          children.append(
              {
                  "id": task_group.upstream_join_id,
                  "value": {
                      "label": "",
                      "labelStyle": f"fill:{task_group.ui_fgcolor};",
                      "style": f"fill:{task_group.ui_color};",
                      "shape": "circle",
                  },
              }
          )
  
      if (
          task_group.downstream_group_ids
          or task_group.downstream_task_ids
      ):
          # This is the join node used to reduce the number of edges between two TaskGroup.
          children.append(
              {
                  "id": task_group.downstream_join_id,
                  "value": {
                      "label": "",
                      "labelStyle": f"fill:{task_group.ui_fgcolor};",
                      "style": f"fill:{task_group.ui_color};",
                      "shape": "circle",
                  },
              }
          )
  
      return {
          "id": task_group.group_id,
          "value": {
              "label": task_group.label,
              "labelStyle": f"fill:{task_group.ui_fgcolor};",
              "style": f"fill:{task_group.ui_color}",
              "rx": 5,
              "ry": 5,
              "clusterLabelPos": "top",
              "tooltip": task_group.tooltip,
              "isMapped": is_mapped,
          },
          "children": children,
      }
  
imports: from __future__ import annotations
  import copy
  import functools
  import operator
  import weakref
  from typing import TYPE_CHECKING, Any, Generator, Iterator, Sequence
  import re2
  from airflow.compat.functools import cache
  from airflow.exceptions import AirflowDagCycleException, AirflowException, DuplicateTaskIdFound, TaskAlreadyInTaskGroup
  from airflow.models.taskmixin import DAGNode
  from airflow.serialization.enums import DagAttributeTypes
  from airflow.utils.helpers import validate_group_key
label_desc: Use image node_id 1 for calling a global function with example usage: task_group_to_dict(task_item_or_group) and returns: dict, dict