addranks 830 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* Assuming nodes have been positioned by dot, this adds a rank
  2. * attribute by placing all nodes with the same y value on a specific
  3. * integer rank.
  4. * If the graph has rankdir=LR, x and y are flipped.
  5. */
  6. BEG_G {
  7. double x,y;
  8. int lv[double];
  9. int r, rk[double];
  10. int flip;
  11. if (isAttr($,"G","rankdir") && $.rankdir=="LR") flip = 1;
  12. }
  13. N {
  14. sscanf($.pos,"%f,%f",&x,&y);
  15. if (flip) lv[x] = 1;
  16. else lv[y] = 1;
  17. }
  18. BEG_G {
  19. r = 0;
  20. if (flip)
  21. forr (lv[x]) {
  22. rk[x] = r++;
  23. /* printf (2, "rk[%f] = %d\n", y, rk[y]); */
  24. }
  25. else
  26. forr (lv[y]) {
  27. rk[y] = r++;
  28. /* printf (2, "rk[%f] = %d\n", y, rk[y]); */
  29. }
  30. }
  31. N {
  32. sscanf($.pos,"%f,%f",&x,&y);
  33. /* printf(2, "node %s y %f rk %d\n", $.name, y, rk[y]); */
  34. if (flip) $.rank = sprintf("%d", rk[x]);
  35. else $.rank = sprintf("%d", rk[y]);
  36. }