docstr: Computes labels for the nodes and adds it to the data.
docstr_tok: ["Computes","labels","for","the","nodes","and","adds","it","to","the","data","."]
code: def _compute_labels(self, element, data, mapping):
      """
      Computes labels for the nodes and adds it to the data.
      """
      if element.vdims:
          edges = Dataset(element)[element[element.vdims[0].name] > 0]
          nodes = list(
              np.unique([edges.dimension_values(i) for i in range(2)])
          )
          nodes = element.nodes.select(
              **{element.nodes.kdims[2].name: nodes}
          )
      else:
          nodes = element
  
      label_dim = nodes.get_dimension(self.label_index)
      labels = self.labels
      if label_dim and labels:
          if self.label_index not in [2, None]:
              self.param.warning(
                  "Cannot declare style mapping for 'labels' option "
                  "and declare a label_index; ignoring the label_index."
              )
      elif label_dim:
          labels = label_dim
      if isinstance(labels, str):
          labels = element.nodes.get_dimension(labels)
  
      if labels is None:
          text = []
      if isinstance(labels, dim):
          text = labels.apply(element, flat=True)
      else:
          text = element.nodes.dimension_values(labels)
          text = [labels.pprint_value(v) for v in text]
  
      ys = nodes.dimension_values(1)
  
      nodes = element._sankey["nodes"]
      if nodes:
          offset = (nodes[0]["x1"] - nodes[0]["x0"]) / 4.0
      else:
          offset = 0
  
      value_dim = element.vdims[0]
      text_labels = []
  
      is_outer_inner = self.label_position in ["outer", "inner"]
  
      # initialize label x-locations
      if self.label_position in ["right", "outer"]:
          xs = np.array([node["x1"] for node in nodes]) + offset
      else:  # ['left', 'inner']
          xs = np.array([node["x0"] for node in nodes]) - offset
  
      for i, node in enumerate(nodes):
          if len(text):
              label = text[i]
          else:
              label = ""
          if self.show_values:
              value = value_dim.pprint_value(
                  node["value"], print_unit=True
              )
              if label:
                  label = f"{label} - {value}"
              else:
                  label = value
          if label:
              text_labels.append(label)
  
      align = (
          "left"
          if self.label_position in ["right", "outer"]
          else "right"
      )
  
      # handle labels that have different alignment due to inner/outer
      if is_outer_inner:
          xs_2 = xs.copy()
          text_labels_2 = text_labels.copy()
          for i, node in enumerate(nodes):
              if self.label_position == "outer" and node["x0"] == 0:
                  text_labels[i] = ""
                  xs_2[i] = node["x0"] - offset
              elif self.label_position == "inner" and node["x0"] == 0:
                  text_labels[i] = ""
                  xs_2[i] = node["x1"] + offset
              else:
                  text_labels_2[i] = ""
  
          align_2 = "right" if align == "left" else "left"
          data["text_2"] = dict(
              x=xs_2, y=ys, text=[str(l) for l in text_labels_2]
          )
          mapping["text_2"] = dict(
              text="text",
              x="x",
              y="y",
              text_baseline="middle",
              text_align=align_2,
          )
  
      data["text_1"] = dict(
          x=xs, y=ys, text=[str(l) for l in text_labels]
      )
      mapping["text_1"] = dict(
          text="text",
          x="x",
          y="y",
          text_baseline="middle",
          text_align=align,
      )
  
file_path: holoviews/holoviews/plotting/bokeh/sankey.py
imports: import numpy
  import param
  from bokeh.models import Patches
  from ...core.data import Dataset
  from ...core.util import dimension_sanitizer, max_range
  from ...util.transform import dim
  from .graphs import GraphPlot
label_desc: Use image node_id 7 for calling the SankeyPlot obj's underlying member method code with example usage: obj._compute_labels(element, data, mapping) without return types