docstr: Adds two columns with the connected component id in 'component_id' and the size of this component in 'component_size'.
docstr_tok: ["Adds","two","columns","with","the","connected","component","id","in","'component_id","'","and","the","size","of","this","component","in","'component_size","'","."]
code: def label_components(self):
      """
      Adds two columns with the connected component id in 'component_id' and the size of this component in 'component_size'.
  
      """
      g = self
      g2 = self.materialize_nodes()
      if isinstance(g._edges, pd.DataFrame):
          gg = SugiyamaLayout.graph_from_pandas(
              g._edges,
              source_column=g2._source,
              target_column=g2._destination,
          )
      elif isinstance(g._edges, Graph):
          gg = g._edges
      else:
          raise TypeError
      # the component index used internally is not contingent because of the elimination algorithm used, so we renum here
      comps = {v.component: i for i, v in enumerate(gg.vertices())}
      comps_map = {u: i for i, u in enumerate(comps.values())}
      component_ids = [
          comps_map[comps[gg.get_vertex_from_data(id).component]]
          for id in g2._nodes[g2._node]
      ]
      component_sizes = [
          len(list(gg.get_vertex_from_data(id).component.vertices()))
          for id in g2._nodes[g2._node]
      ]
      g2._nodes["component_id"] = component_ids
      g2._nodes["component_size"] = component_sizes
      g2 = g2.nodes(
          g2._nodes.sort_values(by="component_id", ascending=True)
      )
      return g2
  
file_path: pygraphistry/graphistry/layouts.py
imports: from typing import Any, Callable, cast, Iterable, List, Optional, Set, Union, TYPE_CHECKING
  import math, pandas
  from .Plottable import Plottable
  from .layout import SugiyamaLayout, group_in_a_box_layout
  from .layout.graph import Graph
  from .util import deprecated, setup_logger
label_desc: Use image node_id 5 for calling the LayoutsMixin obj's underlying member method code with example usage: obj.label_components() and returns: g2