forked from michaelknoch/ng2-cytoscape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng2-cytoscape.ts
92 lines (81 loc) · 2.57 KB
/
ng2-cytoscape.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {Component, OnChanges, ElementRef, Input} from '@angular/core';
declare var jQuery: any;
declare var cytoscape: any;
@Component({
selector: 'ng2-cytoscape',
template: '<div id="cy"></div>',
styles: [`#cy {
height: 100%;
width: 100%;
position: absolute;
left: 0;
top: 0;
}`]
})
export class NgCytoscape implements OnChanges {
@Input() public elements: any;
@Input() public style: any;
@Input() public layout: any;
@Input() public zoom: any;
public constructor(private el: ElementRef) {
this.layout = this.layout || {
name: 'grid',
directed: true,
padding: 0
};
this.zoom = this.zoom || {
min: 0.1,
max: 1.5
};
this.style = this.style || cytoscape.stylesheet()
.selector('node')
.css({
'content': 'data(name)',
'shape': 'rectangle',
'text-valign': 'center',
'background-color': 'data(faveColor)',
'width': '200px',
'height': '100px',
'color': 'black'
})
.selector(':selected')
.css({
'border-width': 3,
'border-color': '#333'
})
.selector('edge')
.css({
'label': 'data(label)',
'color': 'black',
'curve-style': 'bezier',
'opacity': 0.666,
'width': 'mapData(strength, 70, 100, 2, 6)',
'target-arrow-shape': 'triangle',
'line-color': 'data(faveColor)',
'source-arrow-color': 'data(faveColor)',
'target-arrow-color': 'data(faveColor)'
})
.selector('edge.questionable')
.css({
'line-style': 'dotted',
'target-arrow-shape': 'diamond'
})
.selector('.faded')
.css({
'opacity': 0.25,
'text-opacity': 0
});
}
public ngOnChanges(): any {
this.render();
}
public render() {
jQuery(this.el.nativeElement).cytoscape({
layout: this.layout,
minZoom: this.zoom.min,
maxZoom: this.zoom.max,
style: this.style,
elements: this.elements,
});
}
}