diagram.js 988 B

1234567891011121314151617181920212223242526272829
  1. // This is not included in the core application.js bundle.
  2. $(function () {
  3. const svg = document.querySelector(".agent-diagram svg.diagram");
  4. const overlay = document.querySelector(".agent-diagram .overlay");
  5. $(overlay).width($(svg).width()).height($(svg).height());
  6. const getTopLeft = function (node) {
  7. const bbox = node.getBBox();
  8. const point = svg.createSVGPoint();
  9. point.x = bbox.x + bbox.width;
  10. point.y = bbox.y;
  11. return point.matrixTransform(node.getCTM());
  12. };
  13. return $(svg)
  14. .find("g.node[data-badge-id]")
  15. .each(function () {
  16. const tl = getTopLeft(this);
  17. $("#" + this.getAttribute("data-badge-id"), overlay).each(function () {
  18. const badge = $(this);
  19. badge
  20. .css({
  21. left: tl.x - badge.outerWidth() * (2 / 3),
  22. top: tl.y - badge.outerHeight() * (1 / 3),
  23. "background-color": badge.find(".label").css("background-color"),
  24. })
  25. .show();
  26. });
  27. });
  28. });