query function in diagram graph.

Still needs to do smart clustering (not pure ams)