Fix bug in the `diagrams` tool where some diagram nodes may be placed in the wrong cluster