addon/utils/data-processor.js
function _normalizeRawData(data) {
  var EmObj = Ember.Object,
      vertices,          // Hash of vertices
      edges,             // Hash of edges
      rootVertices = []; // Vertices without out-edges are considered root vertices

  vertices = data.vertices.reduce(function (obj, vertex) {
    vertex = VertexDataNode.create(vertex);
    if(!vertex.outEdgeIds) {
      rootVertices.push(vertex);
    }
    obj[vertex.vertexName] = vertex;
    return obj;
  }, {});

  edges = !data.edges ? [] : data.edges.reduce(function (obj, edge) {
    obj[edge.edgeId] = EmObj.create(edge);
    return obj;
  }, {});

  if(data.vertexGroups) {
    data.vertexGroups.forEach(function (group) {
      group.groupMembers.forEach(function (vertex) {
        vertices[vertex].vertexGroup = EmObj.create(group);
      });
    });
  }

  return {
    vertices: EmObj.create(vertices),
    edges: EmObj.create(edges),
    rootVertices: rootVertices
  };
}
function _normalizeRawData(data) {
  var EmObj = Ember.Object,
      vertices,          // Hash of vertices
      edges,             // Hash of edges
      rootVertices = []; // Vertices without out-edges are considered root vertices

  vertices = data.vertices.reduce(function (obj, vertex) {
    vertex = VertexDataNode.create(vertex);
    if(!vertex.outEdgeIds) {
      rootVertices.push(vertex);
    }
    obj[vertex.vertexName] = vertex;
    return obj;
  }, {});

  edges = !data.edges ? [] : data.edges.reduce(function (obj, edge) {
    obj[edge.edgeId] = EmObj.create(edge);
    return obj;
  }, {});

  if(data.vertexGroups) {
    data.vertexGroups.forEach(function (group) {
      group.groupMembers.forEach(function (vertex) {
        vertices[vertex].vertexGroup = EmObj.create(group);
      });
    });
  }

  return {
    vertices: EmObj.create(vertices),
    edges: EmObj.create(edges),
    rootVertices: rootVertices
  };
}
function _normalizeRawData ( data ) { var EmObj = Ember . Object , vertices , // Hash of vertices edges , // Hash of edges rootVertices = [ ] ; // Vertices without out-edges are considered root vertices vertices = data . vertices . reduce ( function ( obj , vertex ) { vertex = VertexDataNode . create ( vertex ) ; if ( ! vertex . outEdgeIds ) { rootVertices . push ( vertex ) ; } obj [ vertex . vertexName ] = vertex ; return obj ; } , { } ) ; edges = ! data . edges ? [ ] : data . edges . reduce ( function ( obj , edge ) { obj [ edge . edgeId ] = EmObj . create ( edge ) ; return obj ; } , { } ) ; if ( data . vertexGroups ) { data . vertexGroups . forEach ( function ( group ) { group . groupMembers . forEach ( function ( vertex ) { vertices [ vertex ] . vertexGroup = EmObj . create ( group ) ; } ) ; } ) ; } return { vertices : EmObj . create ( vertices ) , edges : EmObj . create ( edges ) , rootVertices : rootVertices } ; }
Converts vertices & edges into hashes for easy access.
Makes vertexGroup a property of the respective vertices.
@param data {Object}
@return {Object} An object with vertices hash, edges hash and array of root vertices.
Converts vertices & edges into hashes for easy access . Makes vertexGroup a property of the respective vertices .