/
graph-minimap.component.ts
64 lines (55 loc) · 2.08 KB
/
graph-minimap.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
import { ChangeDetectionStrategy, Component, ElementRef, NgZone, OnDestroy } from '@angular/core';
import { ZoomBehavior } from 'd3-zoom';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { Minimap } from './core/minimap';
import { NzZoomTransform } from './interface';
@Component({
selector: 'nz-graph-minimap',
template: `
<svg>
<defs>
<filter id="minimapDropShadow" x="-20%" y="-20%" width="150%" height="150%">
<feOffset result="offOut" in="SourceGraphic" dx="1" dy="1"></feOffset>
<feColorMatrix
result="matrixOut"
in="offOut"
type="matrix"
values="0.1 0 0 0 0 0 0.1 0 0 0 0 0 0.1 0 0 0 0 0 0.5 0"
></feColorMatrix>
<feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="2"></feGaussianBlur>
<feBlend in="SourceGraphic" in2="blurOut" mode="normal"></feBlend>
</filter>
</defs>
<rect></rect>
</svg>
<canvas class="viewport"></canvas>
<!-- Additional canvas to use as buffer to avoid flickering between updates -->
<canvas class="buffer"></canvas>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'[class.nz-graph-minimap]': 'true'
}
})
export class NzGraphMinimapComponent implements OnDestroy {
minimap?: Minimap;
constructor(private elementRef: ElementRef<HTMLElement>, private ngZone: NgZone) {}
ngOnDestroy(): void {
this.minimap?.destroy();
}
init(containerEle: ElementRef, zoomBehavior: ZoomBehavior<NzSafeAny, NzSafeAny>): void {
const svgEle = containerEle.nativeElement.querySelector('svg');
const zoomEle = containerEle.nativeElement.querySelector('svg > g');
this.minimap = new Minimap(this.ngZone, svgEle, zoomEle, zoomBehavior, this.elementRef.nativeElement, 150, 0);
}
zoom(transform: NzZoomTransform): void {
this.minimap?.zoom(transform);
}
update(): void {
this.minimap?.update();
}
}