index.js 626 B

12345678910111213141516171819202122232425262728
  1. import _ from 'lodash'
  2. import util from '../util'
  3. import { positionX } from './bk'
  4. function position (g) {
  5. g = util.asNonCompoundGraph(g)
  6. positionY(g)
  7. _.forEach(positionX(g), function (x, v) {
  8. g.node(v).x = x
  9. })
  10. }
  11. function positionY (g) {
  12. const layering = util.buildLayerMatrix(g)
  13. const rankSep = g.graph().ranksep
  14. let prevY = 0
  15. _.forEach(layering, function (layer) {
  16. const maxHeight = _.max(_.map(layer, function (v) { return g.node(v).height }))
  17. _.forEach(layer, function (v) {
  18. g.node(v).y = prevY + maxHeight / 2
  19. })
  20. prevY += maxHeight + rankSep
  21. })
  22. }
  23. export default position