class_docstr: Computes a Sankey diagram from a Graph element for internal use in
  the Sankey element constructor.
  
  Adapted from d3-sankey under BSD-3 license.
  
  Source: https://github.com/d3/d3-sankey/tree/v0.12.3
class_docstr_tok: ["Computes","a","Sankey","diagram","from","a","Graph","element","for","internal","use","in","the","Sankey","element","constructor",".","Adapted","from","d3-sankey","under","BSD-3","license",".","Source",":","https",":","\/\/github.com\/d3\/d3-sankey\/tree\/v0.12.3"]
docstr: Populate the sourceLinks and targetLinks for each node.
  Also, if the source and target are not objects, assume they are indices.
docstr_tok: ["Populate","the","sourceLinks","and","targetLinks","for","each","node",".","Also",",","if","the","source","and","target","are","not","objects",",","assume","they","are","indices","."]
code: def computeNodeLinks(cls, element, graph):
      """
      Populate the sourceLinks and targetLinks for each node.
      Also, if the source and target are not objects, assume they are indices.
      """
      index = element.nodes.kdims[-1]
      node_map = {}
      if element.nodes.vdims:
          values = zip(
              *(
                  element.nodes.dimension_values(d)
                  for d in element.nodes.vdims
              )
          )
      else:
          values = cycle([tuple()])
      for idx, vals in zip(
          element.nodes.dimension_values(index), values
      ):
          node = {
              "index": idx,
              "sourceLinks": [],
              "targetLinks": [],
              "values": vals,
          }
          graph["nodes"].append(node)
          node_map[idx] = node
  
      links = [
          element.dimension_values(d) for d in element.dimensions()[:3]
      ]
      for i, (src, tgt, value) in enumerate(zip(*links)):
          source, target = node_map[src], node_map[tgt]
          link = dict(
              index=i, source=source, target=target, value=value
          )
          graph["links"].append(link)
          source["sourceLinks"].append(link)
          target["targetLinks"].append(link)
  
imports: import math
  from functools import cmp_to_key
  from itertools import cycle
  import numpy
  import param
  from ..core.data import Dataset
  from ..core.dimension import Dimension
  from ..core.operation import Operation
  from ..core.util import get_param_values, unique_array
  from .graphs import EdgePaths, Graph, Nodes
  from .util import quadratic_bezier
label_desc: Use image node_id 3 for calling the _layout_sankey obj's underlying member method code with example usage: obj.computeNodeLinks(cls, element, graph) without return types