dagre-d3流程圖

<!doctype html>

<meta charset="utf-8">
<title>Dagre D3 Demo: Arrows</title>

<link rel="stylesheet" href="demo.css">
<script src="https://d3js.org/d3.v5.min.js" charset="utf-8"></script>
<script src="../dagre-d3.js"></script>

<style id="css">
body {
  font: 300 14px 'Helvetica Neue', Helvetica;
}

.node rect,
.node circle,
.node ellipse {
  stroke: #333;
  fill: #fff;
  stroke-width: 1px;
}

.edgePath path {
  stroke: #333;
  fill: #333;
  stroke-width: 1.5px;
}

.node rect {
  background: lightblue;
  font-size: 16px;
  color: white;
  width: 50px;
  height: 50px;
}

</style>

<h1>Dagre D3 Demo: Arrows</h1>

<svg width=960 height=600><g/></svg>

<section>
<p>A sample that shows the different arrows available in dagre-d3.
</section>

<script id="js">
// Create a new directed graph
var g = new dagreD3.graphlib.Graph().setGraph({});

g.setGraph({
    nodesep: 70,
    ranksep: 50,
    rankdir: "LR", // 流程方向
    marginx: 20,
    marginy: 20
  });

  
// 設置節點
g.setNode('p2', { label: 'p'});
g.setNode('p', { label: 'p'});
g.setNode('c', { label: 'c'});

var html = `<div style="color: white;background-color: red;">html</div>`
g.setNode('p1', { 
  labelType: 'html',
  label: html,
  rx: 0, // 圓角
  ry: 0,
  // padding: 0,
});
g.setNode('c1', { label: 'c'});
// 連接線 (start, end, lineStyle)
g.setEdge('c', 'p', {
  arrowhead: 'normal',
  label: ''
});
g.setEdge('c', 'p2', {
  arrowhead: 'normal',
  label: ''
});

var svg = d3.select('svg'),
  inner = svg.select('g');

// 可以收縮放大
var zoom = d3.zoom().on("zoom", function() {
      inner.attr("transform", d3.event.transform);
    });
svg.call(zoom);
// 渲染到頁面
var render = new dagreD3.render();
render(inner, g);

var initialScale = 0.75;
svg.call(zoom.transform, d3.zoomIdentity.translate((svg.attr("width") - g.graph().width * initialScale) / 2, 20).scale(initialScale));
svg.attr('height', g.graph().height * initialScale + 40);

</script>

<script src="demo.js"></script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章