style-attrs.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!doctype html>
  2. <meta charset="utf-8">
  3. <title>Dagre D3 Demo: Style Attributes</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: Style Attributes</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.path {
  21. stroke: #333;
  22. fill: none;
  23. stroke-width: 1.5px;
  24. }
  25. .arrowhead {
  26. stroke: blue;
  27. fill: blue;
  28. stroke-width: 1.5px;
  29. }
  30. </style>
  31. <svg id="svg" width=960 height=600></svg>
  32. <section>
  33. <p>An example showing how styles that are set in the input graph can be applied
  34. to nodes, node labels, edges, and edge labels in the rendered graph.
  35. </section>
  36. <script id="js">
  37. // Create the input graph
  38. var g = new graphlib.Graph().setGraph({});
  39. // Fill node "A" with the color green
  40. g.setNode("A", { style: "fill: #afa" });
  41. // Make the label for node "B" bold
  42. g.setNode("B", { labelStyle: "font-weight: bold" });
  43. // Double the size of the font for node "C"
  44. g.setNode("C", { labelStyle: "font-size: 2em" });
  45. g.setNode("D", {});
  46. g.setNode("E", {});
  47. // Make the edge from "A" to "B" red, thick, and dashed
  48. g.setEdge("A", "B", {
  49. style: "stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;",
  50. arrowheadStyle: "fill: #f66"
  51. });
  52. // Make the label for the edge from "C" to "B" italic and underlined
  53. g.setEdge("C", "B", {
  54. label: "A to C",
  55. labelStyle: "font-style: italic; text-decoration: underline;"
  56. });
  57. // Make the edge between A and D smoother.
  58. // see available options for lineInterpolate here: https://github.com/mbostock/d3/wiki/SVG-Shapes#line_interpolate
  59. g.setEdge("A", "D", {
  60. label: "line interpolation different",
  61. curve: d3.curveBasis
  62. });
  63. g.setEdge("E", "D", {});
  64. // Make the arrowhead blue
  65. g.setEdge("A", "E", {
  66. label: "Arrowhead class",
  67. arrowheadClass: 'arrowhead'
  68. });
  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. inner = svg.append("g");
  74. // Run the renderer. This is what draws the final graph.
  75. render(inner, g);
  76. // Center the graph
  77. var xCenterOffset = (svg.attr("width") - g.graph().width) / 2;
  78. inner.attr("transform", "translate(" + xCenterOffset + ", 20)");
  79. svg.attr("height", g.graph().height + 40);
  80. </script>
  81. <script src="demo.js"></script>