dom.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!doctype html>
  2. <meta charset="utf-8">
  3. <title>Dagre D3 Demo: DOM Example</title>
  4. <link rel="stylesheet" href="demo.css">
  5. <script src="../../node_modules/graphlibrary/dist/graphlib.js"></script>
  6. <script src="../../node_modules/d3/build/d3.js"></script>
  7. <script src="../dagre-d3.js"></script>
  8. <h1>Dagre D3 Demo: DOM Example</h1>
  9. <style id="css">
  10. text {
  11. font-weight: 300;
  12. font-family: "Helvetica Neue", Helvetica, Arial, sans-serf;
  13. font-size: 14px;
  14. }
  15. .node rect {
  16. stroke: #333;
  17. fill: #fff;
  18. stroke-width: 1.5px;
  19. }
  20. .edgePath path {
  21. stroke: #333;
  22. stroke-width: 1.5px;
  23. }
  24. table {
  25. border-spacing: 0;
  26. }
  27. table td {
  28. padding: 7px;
  29. }
  30. table td:first-child {
  31. background-color: #afa;
  32. border-top: 1px solid #333;
  33. border-left: 1px solid #333;
  34. border-bottom: 1px solid #333;
  35. border-radius: 5px 0 0 5px;
  36. }
  37. table td:last-child {
  38. background-color: #faa;
  39. border-top: 1px solid #333;
  40. border-right: 1px solid #333;
  41. border-bottom: 1px solid #333;
  42. border-radius: 0 5px 5px 0;
  43. }
  44. </style>
  45. <svg width=960 height=600></svg>
  46. <section>
  47. <p>A sample showing how to use DOM nodes in a graph. Note that IE does not
  48. support this technique.
  49. </section>
  50. <script id="js">
  51. // Create a new directed graph
  52. var g = new graphlib.Graph().setGraph({});
  53. g.setNode("root", {
  54. label: function() {
  55. var table = document.createElement("table"),
  56. tr = d3.select(table).append("tr");
  57. tr.append("td").text("A");
  58. tr.append("td").text("B");
  59. return table;
  60. },
  61. padding: 0,
  62. rx: 5,
  63. ry: 5
  64. });
  65. g.setNode("A", { label: "A", fill: "#afa" });
  66. g.setNode("B", { label: "B", fill: "#faa" });
  67. g.setEdge("root", "A", {});
  68. g.setEdge("root", "B", {});
  69. // Create the renderer
  70. var render = new dagreD3.render();
  71. // Set up an SVG group so that we can translate the final graph.
  72. var svg = d3.select('svg'),
  73. svgGroup = svg.append('g');
  74. // Run the renderer. This is what draws the final graph.
  75. render(svgGroup, g);
  76. // Center the graph
  77. var xCenterOffset = (svg.attr('width') - g.graph().width) / 2;
  78. svgGroup.attr('transform', 'translate(' + xCenterOffset + ', 20)');
  79. svg.attr('height', g.graph().height + 40);
  80. </script>
  81. <script src="demo.js"></script>