Distance-preserving orderings in graphs