graph.cloneCells(cells)
Clone all the cells (elements and/or links) from the cells
array and return an
object that maps the original cell ID to the clone (i.e. an object of the form { [original cell ID]: [clone] }
).
The reason why this object is returned instead of an array of clones is that it is very useful to know which object the clone
was created for.
The number of clones returned equals cells.length
. This function does not simply
clone all the cells but it also reconstructs all the source/target and parent/embed references
within cells
. This is very useful. For example, for a graph A --- L ---> B
,
cloneCells([A, L, B])
returns { A.id: A2, L.id: L2, B.id: B2 }
resulting
in a graph A2 --- L2 ---> B2
, i.e. the source and target of the link L2
is changed to point to A2
and B2
(in contrast to just looping over cells
and calling cell.clone()
on each item).