     edges[node_id] = _(edge_labels).map (label) ->
       { label: label, dest: dotty.get(data, label).$oid }
 
+was_seen = (node_id) ->
+  _.some _.values(collections).concat([default_collection]), (c) ->
+    _.contains c.nodes, node_id
+
 process.stdin.pipe(JSONStream.parse()).on 'data', (data) ->
   # sometimes we get piped arrays, sometimes we get one json obj per line
   if _(data).isArray()


# collect __collection metadata attached to each object in order to draw subgraphs
collections = {} # e.g. # { "collection_name": { fillcolor: "...", nodes: [...] } ... }"

rnd_color = () ->
  #("#{srand.random().toFixed(2)}" for i in [0..2]).join(' ')
  COLORS[Math.floor(srand.random() * COLORS.length)]
DEFAULT_FILL=rnd_color()

# store all edge info for writing/coloring correctly at the very end
# edges are colored w/ the same color as their dest node

.on 'end', () ->
  # draw edges
  for source, edgeinfos of edges
    # skipping any edges to nodes that we've never seen
    for edge in edgeinfos when was_seen edge.dest
      stream.write "  \"#{source}\" -> \"#{edge.dest}\" [style=solid, label=\"#{edge.label}\", color=\"#{colors[edge.dest]}\", fontcolor=\"#{colors[edge.dest]}\"];\n"

  # group together nodes in the same collection
