Refactor GraphVisitor.

* Make def_event_handler available wherever GraphVisitor is included.
* Extract distance map support into a module.