blob: a94914dadad37119810e12c251ad6eabc0195e9b [file] [log] [blame]
Sean Condon50855cf2018-12-23 15:37:42 +00001<!--
2~ Copyright 2018-present Open Networking Foundation
3~
4~ Licensed under the Apache License, Version 2.0 (the "License");
5~ you may not use this file except in compliance with the License.
6~ You may obtain a copy of the License at
7~
8~ http://www.apache.org/licenses/LICENSE-2.0
9~
10~ Unless required by applicable law or agreed to in writing, software
11~ distributed under the License is distributed on an "AS IS" BASIS,
12~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13~ See the License for the specific language governing permissions and
14~ limitations under the License.
15-->
16<svg:defs xmlns:svg="http://www.w3.org/2000/svg">
17 <svg:filter id="glow">
18 <svg:feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0.9 0 0 0 0 0.9 0 0 0 0 1 0" />
19 <svg:feGaussianBlur stdDeviation="2.5" result="coloredBlur" />
20 <svg:feMerge>
21 <svg:feMergeNode in="coloredBlur" />
22 <svg:feMergeNode in="SourceGraphic"/>
23 </svg:feMerge>
24 </svg:filter>
25</svg:defs>
26<!-- Template explanation: Creates an SVG Line and in
27 line 1) transform end A to the position calculated by the d3 force graph engine
28 line 2) transform end B to the position calculated by the d3 force graph engine
29 line 3) Give it various CSS styles depending on attributes
Sean Condon1ae15802019-03-02 09:07:18 +000030 ling 4) Change the line width depending on the scale
Sean Condon50855cf2018-12-23 15:37:42 +000031 line 4) When it is clicked, call the method that toggles the selection and
32 emits an event.
33 line 5) When the mouse is moved over call on enhance() function. This will
34 flash up the port labels, and display the link in blue for 1 second
35 Other child objects have their own description
36-->
37<svg:line xmlns:svg="http://www.w3.org/2000/svg"
38 [attr.x1]="link.source?.x" [attr.y1]="link.source?.y"
39 [attr.x2]="link.target?.x" [attr.y2]="link.target?.y"
40 [ngClass]="['link', selected?'selected':'', enhanced?'enhanced':'', highlighted]"
Sean Condon1ae15802019-03-02 09:07:18 +000041 [ngStyle]="{'stroke-width': (enhanced ? 4 : 2) * scale + 'px'}"
Sean Condond88f3662019-04-03 16:35:30 +010042 (click)="toggleSelected(link, $event)"
Sean Condon50855cf2018-12-23 15:37:42 +000043 (mouseover)="enhance()"
44 [attr.filter]="highlighted?'url(#glow)':'none'">
45</svg:line>
Sean Condon1ae15802019-03-02 09:07:18 +000046<svg:g xmlns:svg="http://www.w3.org/2000/svg"
47 [ngClass]="['linkLabel']"
48 [attr.transform]="'scale(' + scale + ')'">
49 <!-- Template explanation: Creates SVG Text in the middle of the link to
50 show traffic and in:
Sean Condon50855cf2018-12-23 15:37:42 +000051 line 1) Performs the animation 'linkLabelVisible' whenever the isHighlighted
52 boolean value changes
53 line 2 & 3) Sets the text at half way between the 2 end points of the line
54 Note: we do not use an *ngIf to enable or disable this, because that would
55 cause the fade out of the text to not work
56 -->
57 <svg:text xmlns:svg="http://www.w3.org/2000/svg"
58 [@linkLabelVisible]="isHighlighted"
59 [attr.x]="link.source?.x + (link.target?.x - link.source?.x)/2"
60 [attr.y]="link.source?.y + (link.target?.y - link.source?.y)/2"
61 >{{ label }}</svg:text>
62</svg:g>
63<!-- Template explanation: Creates an SVG Group if
64 line 1) 'enhanced' is active and port text exists
65 line 2) assigns classes to it
66-->
67<svg:g xmlns:svg="http://www.w3.org/2000/svg"
68 *ngIf="enhanced && link.portA"
Sean Condon1ae15802019-03-02 09:07:18 +000069 class="portLabel"
70 [attr.transform]="'translate(' + labelPosSrc.x + ',' + labelPosSrc.y + '),scale(' + scale + ')'">
Sean Condon50855cf2018-12-23 15:37:42 +000071 <!-- Template explanation: Creates an SVG Rectangle and in
72 line 1) transform end A to the position calculated by the d3 force graph engine
73 line 2) assigns classes to it
74 -->
75 <svg:rect
Sean Condon1ae15802019-03-02 09:07:18 +000076 [attr.x]="2 - textLength(link.portA)/2" y="-8"
Sean Condon50855cf2018-12-23 15:37:42 +000077 [attr.width]="4 + textLength(link.portA)" height="16" >
78 </svg:rect>
79 <!-- Template explanation: Creates SVG Text and in
80 line 1) transform it to the position calculated by the method labelPosSrc()
81 line 2) centre aligns it
82 line 3) ensures that the text fills the rectangle by adjusting spacing
83 -->
Sean Condon1ae15802019-03-02 09:07:18 +000084 <svg:text y="2" text-anchor="middle"
Sean Condon50855cf2018-12-23 15:37:42 +000085 [attr.textLength]= "textLength(link.portA)" lengthAdjust="spacing"
86 >{{ link.portA }}</svg:text>
87</svg:g>
88<!-- A repeat of the above, but for the other end of the line -->
89<svg:g xmlns:svg="http://www.w3.org/2000/svg"
90 *ngIf="enhanced && link.portB"
Sean Condon1ae15802019-03-02 09:07:18 +000091 class="portLabel"
92 [attr.transform]="'translate(' + labelPosTgt.x + ',' + labelPosTgt.y + '),scale(' + scale + ')'">
Sean Condon50855cf2018-12-23 15:37:42 +000093 <svg:rect
Sean Condon1ae15802019-03-02 09:07:18 +000094 [attr.x]="2 - textLength(link.portB)/2" y="-8"
Sean Condon50855cf2018-12-23 15:37:42 +000095 [attr.width]="4 + textLength(link.portB)" height="16">
96 </svg:rect>
Sean Condon1ae15802019-03-02 09:07:18 +000097 <svg:text x="2" y="2" text-anchor="middle"
Sean Condon50855cf2018-12-23 15:37:42 +000098 [attr.textLength]= "textLength(link.portB)" lengthAdjust="spacing"
99 >{{ link.portB }}</svg:text>
100</svg:g>