如何使用 NGX-Graph 创建具有不同形状的 DAG(图)

How to create DAG (Graph) with different shapes using NGX-Graph

我想创建具有自定义节点形状和自定义颜色的图表。我还想在边缘上贴上标签。我如何使用 NGX-Graph (https://swimlane.github.io/ngx-graph/)

执行此操作

例如

您可以为节点定义自己的模板并根据需要对其进行自定义:

<ngx-graph [legend]="false" [links]="graph.links" [scheme]="colorScheme" [nodes]="graph.nodes" [nodeWidth]="70" [nodeHeight]="70" [orientation]="'LR'" [curve]="curve">
  <ng-template #nodeTemplate let-node>
    <svg:g class="node">
      <svg:rect [attr.width]="node.width" [attr.height]="node.height" stroke="#3d465a" fill="#262C38" stroke-width="2" rx="15" ry="15" />
      <svg:rect [attr.width]="node.width - 10" [attr.height]="node.height - 10" [attr.fill]="node.options.color" rx="10" ry="10" x="5" y="5" />
      <svg:text class="node-type" alignment-baseline="central" [attr.x]="16" [attr.y]="15">
        {{node.type}}
      </svg:text>
      <svg:image alignment-baseline="central" [attr.x]="(node.width / 2) - 16" [attr.y]="25" [attr.width]="32" [attr.height]="32" [attr.xlink:href]="getImageForNode(node)" />
      <svg:text class="node-label" alignment-baseline="central" [attr.x]="(node.width / 2) - ((node.label.length * 5) / 2)" [attr.y]="85">
        {{node.label}}
      </svg:text>
    </svg:g>
  </ng-template>
</ngx-graph>

您可以访问该模板中的节点数据,因此您可以根据节点的属性绘制不同的形状。