test.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!doctype html>
  2. <meta charset="utf-8">
  3. <title>Dagre D3 Demo: Arrows</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. <style id="css">
  9. body {
  10. font: 300 14px 'Helvetica Neue', Helvetica;
  11. }
  12. .node rect,
  13. .node circle,
  14. .node ellipse {
  15. stroke: #333;
  16. fill: #fff;
  17. stroke-width: 1px;
  18. }
  19. .edgePath path {
  20. stroke: #333;
  21. fill: #333;
  22. stroke-width: 1.5px;
  23. }
  24. </style>
  25. <h1>Dagre D3 Demo: Arrows</h1>
  26. <svg width=960 height=600><g/></svg>
  27. <section>
  28. <p>A sample that shows the different arrows available in dagre-d3.
  29. </section>
  30. <script id="js">
  31. // Create a new directed graph
  32. var g = new graphlib.Graph().setGraph({});
  33. g.setNode("A", { label: "A" });
  34. g.setNode("B", { label: "B" });
  35. g.setNode("C", { label: "C" });
  36. g.setNode("Z", { label: "Z" });
  37. g.setNode("Y", { label: "Y" });
  38. g.setEdge("A", "B", { arrowhead: 'normal' });
  39. g.setEdge("A", "C", { arrowhead: 'normal' });
  40. g.setEdge("A", "Z", { arrowhead: 'normal' });
  41. g.setEdge("A", "Y", { arrowhead: 'normal' });
  42. g.setEdge("B", "Y", { arrowhead: 'normal' });
  43. g.setEdge("Z", "Y", { arrowhead: 'normal' });
  44. g.setEdge("Y", "A", { arrowhead: 'normal' });
  45. var svg = d3.select("svg"),
  46. inner = svg.select("g");
  47. // Set up zoom support
  48. var zoom = d3.zoom().on("zoom", function() {
  49. inner.attr("transform", d3.event.transform);
  50. });
  51. svg.call(zoom);
  52. // Create the renderer
  53. var render = new dagreD3.render();
  54. // Run the renderer. This is what draws the final graph.
  55. render(inner, g);
  56. // Center the graph
  57. var initialScale = 0.75;
  58. svg.call(zoom.transform, d3.zoomIdentity.translate((svg.attr("width") - g.graph().width * initialScale) / 2, 20).scale(initialScale));
  59. svg.attr('height', g.graph().height * initialScale + 40);
  60. </script>
  61. <script src="demo.js"></script>