Working Javascript graph, trying to merge