blob: 747b1bb3ded7e590a5a52792b56c691a01ea1c1f [file] [log] [blame]
Sean Condon0c577f62018-11-18 22:40:05 +00001<!--
Sean Condon91481822019-01-01 13:56:14 +00002~ Copyright 2019-present Open Networking Foundation
Sean Condon0c577f62018-11-18 22:40:05 +00003~
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-->
Sean Condon50855cf2018-12-23 15:37:42 +000016<svg:defs xmlns:svg="http://www.w3.org/2000/svg">
17 <!-- Template explanation: Define an SVG Filter that in
18 line 1) render the target object in to a bit map and apply a blur to it
19 based on its alpha channel
20 line 2) take that blurred layer and shift it down and to the right by 4
21 line 3) Merge this blurred and shifted layer and overlay it with the
22 original target object
23 -->
Sean Condonb2c483c2019-01-16 20:28:55 +000024 <svg:filter id="drop-shadow" x="-25%" y="-25%" width="200%" height="200%">
25 <svg:feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur" />
Sean Condon50855cf2018-12-23 15:37:42 +000026 <svg:feOffset in="blur" dx="4" dy="4" result="offsetBlur"/>
27 <svg:feMerge >
28 <svg:feMergeNode in="offsetBlur" />
29 <svg:feMergeNode in="SourceGraphic" />
30 </svg:feMerge>
31 </svg:filter>
32 <svg:linearGradient id="diagonal_blue" x1="0%" y1="0%" x2="100%" y2="100%">
Sean Condonb2c483c2019-01-16 20:28:55 +000033 <svg:stop offset= "0%" style="stop-color: #7fabdb;" />
34 <svg:stop offset= "100%" style="stop-color: #5b99d2;" />
Sean Condon50855cf2018-12-23 15:37:42 +000035 </svg:linearGradient>
36</svg:defs>
37<!-- Template explanation: Creates an SVG Group and in
38 line 1) transform it to the position calculated by the d3 force graph engine
39 line 2) Give it various CSS styles depending on attributes
40 line 3) When it is clicked, call the method that toggles the selection and
41 emits an event.
42 Other child objects have their own description
43-->
44<svg:g xmlns:svg="http://www.w3.org/2000/svg"
Sean Condon0c577f62018-11-18 22:40:05 +000045 [attr.transform]="'translate(' + device?.x + ',' + device?.y + '), scale(' + scale + ')'"
46 [ngClass]="['node', 'device', device.online?'online':'', selected?'selected':'']"
Sean Condon021f0fa2018-12-06 23:31:11 -080047 (click)="toggleSelected(device)">
Sean Condon50855cf2018-12-23 15:37:42 +000048 <svg:desc>Device {{device.id}}</svg:desc>
49 <!-- Template explanation: Creates an SVG Rectangle and in
50 line 1) set a css style and shift so that it's centred
51 line 2) set the initial width and height - width changes with label
52 line 3) link to the animation 'deviceLabelToggle', pass in to it a width
53 calculated from the width of the text, and additional padding at the end
54 line 4) Apply the filter defined above to this rectangle (even as its
55 width changes
56 -->
57 <svg:rect
58 class="node-container" x="-18" y="-18"
59 width="36" height="36"
Sean Condonb2c483c2019-01-16 20:28:55 +000060 [@deviceLabelToggle]="{ value: labelToggle, params: {txtWidth: (36 + labelTextLen() * 1.1)+'px' }}"
Sean Condon50855cf2018-12-23 15:37:42 +000061 filter= "url(#drop-shadow)">
Sean Condon0c577f62018-11-18 22:40:05 +000062 </svg:rect>
Sean Condon50855cf2018-12-23 15:37:42 +000063 <!-- Template explanation: Creates an SVG Rectangle slightly smaller and
64 overlaid on the above. This is the blue box, and its width and height does
65 not change
66 -->
67 <svg:rect x="-16" y="-16" width="32" height="32" style="fill: url(#diagonal_blue)">
Sean Condon0c577f62018-11-18 22:40:05 +000068 </svg:rect>
Sean Condon50855cf2018-12-23 15:37:42 +000069 <!-- Template explanation: Creates an SVG Text element and in
70 line 1) make it left aligned and slightly down and to the right of the last rect
71 line 2) set its text length to be the calculated value - see that function
72 line 3) because of kerning the actual text might be shorter or longer than
73 the pre-calculated value - if so change the spacing between the letters
74 (and not the letter width to compensate)
75 line 4) link to the animation deviceLabelToggleTxt, so that the text appears
76 in gently
77 line 5) The text will be one of 3 values - blank, the id or the name
78 -->
79 <svg:text
80 text-anchor="start" y="0.3em" x="22"
81 [attr.textLength]= "labelTextLen()"
82 lengthAdjust= "spacing"
83 [ngStyle]="{'transform': 'scale(' + scale + ')'}"
84 [@deviceLabelToggleTxt]="labelToggle">
Sean Condon0c577f62018-11-18 22:40:05 +000085 {{ labelToggle == 0 ? '': labelToggle == 1 ? device.id:device.props.name }}
86 </svg:text>
Sean Condon59d31372019-02-02 20:07:00 +000087 <svg:use [attr.xlink:href]="'#' + deviceIcon()" width="36" height="36" x="-18" y="-18">
Sean Condon021f0fa2018-12-06 23:31:11 -080088 </svg:use>
Sean Condon0c577f62018-11-18 22:40:05 +000089</svg:g>