getAdjMatrix = (data, directed) => {
  const { nodes, edges } = data;
  const matrix = [];
  // map node with index in data.nodes
  const nodeMap = {};

  if (!nodes) {
    throw new Error('invalid nodes data!');
  }
  if (nodes) {
    nodes.forEach((node, i) => {
      nodeMap[node.id] = i;
      const row = [];
      matrix.push(row);
    });
  }

  if (edges) {
    edges.forEach(e => {
      const { source, target } = e;
      const sIndex = nodeMap[source];
      const tIndex = nodeMap[target];
      matrix[sIndex][tIndex] = 1;
      if (!directed) {
        matrix[tIndex][sIndex] = 1;
      }
    });
  }

  return matrix;
}
get adjacency matrix
@param data graph data
@param directed whether it's a directed graph