 # edges are colored w/ the same color as their dest node
 edges = {} # e.g. { "<source_node_id>": [{label: "...", dest: "..."} ... ], ... }
 
-# store mapping from node -> color for edge drawing at the very end
-colors = {}
+# mapping from collection -> edge label -> color
+edge_colors = {} # e.g. { "collection_name": { "im.a.nested.path": "#color", ... } ... }
+default_edge_colors = {} # backup for when there's no collection name
+# get a color for (collection, label) pairing, picking a new one if it hasn't
+# already been picked
+edge_color = (collection, label) ->
+  label_map = 
+    if collection?
+      edge_colors[collection] ?= {}
+      edge_colors[collection]
+    else default_edge_colors
+  label_map[label] ?= rnd_color()
 
 handle_data = (data) ->
   # all nodes keyed on objectid

    .value()
  if edge_labels.length
    edges[node_id] = _(edge_labels).map (label) ->
      { label: label, dest: dotty.get(data, label).$oid }

process.stdin.pipe(JSONStream.parse()).on 'data', (data) ->
  # sometimes we get piped arrays, sometimes we get one json obj per line

  # draw edges
  for source, edgeinfos of edges
    for edge in edgeinfos
      stream.write "  \"#{source}\" -> \"#{edge.dest}\" [style=solid, label=\"#{edge.label}\", color=\"#{edge.color}\", fontcolor=\"#{edge.color}\"];\n"

  # group together nodes in the same collection
  for cname, cinfo of collections
