From 0ab8a73d9522c4ff584f4ff7ad212d27f53ebe7c Mon Sep 17 00:00:00 2001 From: simplejason Date: Mon, 19 Apr 2021 15:25:18 +0800 Subject: [PATCH] feat(module:graph): support edge style with line and curev --- components/graph/graph-edge.component.ts | 19 ++++++++++++++----- components/graph/graph.component.ts | 9 +++++++-- components/graph/interface.ts | 8 ++++++++ package.json | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/components/graph/graph-edge.component.ts b/components/graph/graph-edge.component.ts index ff6cd94c83c..f68f0d0c45e 100644 --- a/components/graph/graph-edge.component.ts +++ b/components/graph/graph-edge.component.ts @@ -15,9 +15,9 @@ import { SimpleChanges, TemplateRef } from '@angular/core'; -import { curveBasis, line } from 'd3-shape'; +import { curveBasis, curveLinear, line } from 'd3-shape'; import { take } from 'rxjs/operators'; -import { NzGraphEdge } from './interface'; +import { NzGraphEdge, NzGraphEdgeType } from './interface'; @Component({ selector: '[nz-graph-edge]', @@ -34,6 +34,8 @@ import { NzGraphEdge } from './interface'; }) export class NzGraphEdgeComponent implements OnInit, OnChanges { @Input() edge!: NzGraphEdge; + @Input() edgeType?: NzGraphEdgeType; + @Input() customTemplate?: TemplateRef<{ $implicit: NzGraphEdge; }>; @@ -44,10 +46,10 @@ export class NzGraphEdgeComponent implements OnInit, OnChanges { private el!: SVGGElement; private path!: SVGPathElement; - private readonly line = line<{ x: number; y: number }>() + private line = line<{ x: number; y: number }>() .x(d => d.x) .y(d => d.y) - .curve(curveBasis); + .curve(curveLinear); constructor(private elementRef: ElementRef, private ngZone: NgZone, private cdr: ChangeDetectorRef) { this.el = this.elementRef.nativeElement; @@ -58,7 +60,7 @@ export class NzGraphEdgeComponent implements OnInit, OnChanges { } ngOnChanges(changes: SimpleChanges): void { - const { edge, customTemplate } = changes; + const { edge, customTemplate, edgeType } = changes; if (edge) { this.ngZone.onStable.pipe(take(1)).subscribe(() => { // Update path element if customTemplate set @@ -70,6 +72,13 @@ export class NzGraphEdgeComponent implements OnInit, OnChanges { this.cdr.markForCheck(); }); } + if (edgeType) { + const type = this.edgeType === NzGraphEdgeType.CURVE ? curveBasis : curveLinear; + this.line = line<{ x: number; y: number }>() + .x(d => d.x) + .y(d => d.y) + .curve(type); + } } initElementStyle(): void { diff --git a/components/graph/graph.component.ts b/components/graph/graph.component.ts index 98ad4ea30e2..ec7e5921811 100644 --- a/components/graph/graph.component.ts +++ b/components/graph/graph.component.ts @@ -88,7 +88,13 @@ export function isDataSource(value: NzSafeAny): value is NzGraphData { - + @@ -203,7 +209,6 @@ export class NzGraphComponent implements OnInit, OnChanges, AfterViewInit, After const { nzAutoFit, nzRankDirection, nzGraphData, nzGraphLayoutConfig } = changes; if (nzGraphLayoutConfig) { this.layoutSetting = this.mergeConfig(nzGraphLayoutConfig.currentValue); - // Object.assign(this.layoutSetting, this.nzGraphLayoutSetting || {}); } if (nzGraphData) { diff --git a/components/graph/interface.ts b/components/graph/interface.ts index 01d939c4ab1..9ec7ec818d7 100644 --- a/components/graph/interface.ts +++ b/components/graph/interface.ts @@ -15,6 +15,11 @@ import { } from 'dagre-compound'; import { NzSafeAny } from 'ng-zorro-antd/core/types'; +export enum NzGraphEdgeType { + LINE = 'line', + CURVE = 'curve' +} + export interface NzGraphDataDef extends HierarchyGraphDef { nodes: NzGraphNodeDef[]; edges: NzGraphEdgeDef[]; @@ -80,6 +85,9 @@ export interface NzGraphBaseLayout { labelOffset: number; maxLabelWidth: number; }; + defaultEdge: { + type: NzGraphEdgeType | string; // Need to support extensions + }; } export function nzTypeDefinition(): (item: unknown) => T { diff --git a/package.json b/package.json index 4966ee0a9e6..2e53ab82562 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "conventional-changelog-cli": "^2.1.1", "d3": "^6.3.1", "dagre": "^0.8.5", - "dagre-compound": "0.0.4", + "dagre-compound": "0.0.8", "detect-port": "^1.3.0", "fs-extra": "^9.0.1", "gulp": "^4.0.2",