blob: e87e1a8379a776d9cd621a2cfb56d1216aeea235 [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
Sean Condon1ae15802019-03-02 09:07:18 +000018 line 0) creates a box big enough to accommodate the drop shadow
Sean Condon50855cf2018-12-23 15:37:42 +000019 line 1) render the target object in to a bit map and apply a blur to it
20 based on its alpha channel
21 line 2) take that blurred layer and shift it down and to the right by 4
22 line 3) Merge this blurred and shifted layer and overlay it with the
23 original target object
24 -->
Sean Condonb2c483c2019-01-16 20:28:55 +000025 <svg:filter id="drop-shadow" x="-25%" y="-25%" width="200%" height="200%">
26 <svg:feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur" />
Sean Condon50855cf2018-12-23 15:37:42 +000027 <svg:feOffset in="blur" dx="4" dy="4" result="offsetBlur"/>
28 <svg:feMerge >
29 <svg:feMergeNode in="offsetBlur" />
30 <svg:feMergeNode in="SourceGraphic" />
31 </svg:feMerge>
32 </svg:filter>
Sean Condon1ae15802019-03-02 09:07:18 +000033 <!-- Template explanation: Define a colour gradient that can be used in icons -->
Sean Condon50855cf2018-12-23 15:37:42 +000034 <svg:linearGradient id="diagonal_blue" x1="0%" y1="0%" x2="100%" y2="100%">
Sean Condonb2c483c2019-01-16 20:28:55 +000035 <svg:stop offset= "0%" style="stop-color: #7fabdb;" />
36 <svg:stop offset= "100%" style="stop-color: #5b99d2;" />
Sean Condon50855cf2018-12-23 15:37:42 +000037 </svg:linearGradient>
38</svg:defs>
39<!-- Template explanation: Creates an SVG Group and in
40 line 1) transform it to the position calculated by the d3 force graph engine
Sean Condon1ae15802019-03-02 09:07:18 +000041 and scale it inversely to the zoom level
Sean Condon50855cf2018-12-23 15:37:42 +000042 line 2) Give it various CSS styles depending on attributes
43 line 3) When it is clicked, call the method that toggles the selection and
44 emits an event.
45 Other child objects have their own description
46-->
47<svg:g xmlns:svg="http://www.w3.org/2000/svg"
Sean Condon0c577f62018-11-18 22:40:05 +000048 [attr.transform]="'translate(' + device?.x + ',' + device?.y + '), scale(' + scale + ')'"
49 [ngClass]="['node', 'device', device.online?'online':'', selected?'selected':'']"
Sean Condond88f3662019-04-03 16:35:30 +010050 (click)="toggleSelected(device, $event)">
Sean Condon50855cf2018-12-23 15:37:42 +000051 <svg:desc>Device {{device.id}}</svg:desc>
52 <!-- Template explanation: Creates an SVG Rectangle and in
53 line 1) set a css style and shift so that it's centred
54 line 2) set the initial width and height - width changes with label
55 line 3) link to the animation 'deviceLabelToggle', pass in to it a width
56 calculated from the width of the text, and additional padding at the end
57 line 4) Apply the filter defined above to this rectangle (even as its
58 width changes
59 -->
60 <svg:rect
61 class="node-container" x="-18" y="-18"
62 width="36" height="36"
Sean Condonb2c483c2019-01-16 20:28:55 +000063 [@deviceLabelToggle]="{ value: labelToggle, params: {txtWidth: (36 + labelTextLen() * 1.1)+'px' }}"
Sean Condon50855cf2018-12-23 15:37:42 +000064 filter= "url(#drop-shadow)">
Sean Condon0c577f62018-11-18 22:40:05 +000065 </svg:rect>
Sean Condon50855cf2018-12-23 15:37:42 +000066 <!-- Template explanation: Creates an SVG Rectangle slightly smaller and
67 overlaid on the above. This is the blue box, and its width and height does
68 not change
69 -->
70 <svg:rect x="-16" y="-16" width="32" height="32" style="fill: url(#diagonal_blue)">
Sean Condon0c577f62018-11-18 22:40:05 +000071 </svg:rect>
Sean Condon50855cf2018-12-23 15:37:42 +000072 <!-- Template explanation: Creates an SVG Text element and in
73 line 1) make it left aligned and slightly down and to the right of the last rect
74 line 2) set its text length to be the calculated value - see that function
75 line 3) because of kerning the actual text might be shorter or longer than
76 the pre-calculated value - if so change the spacing between the letters
77 (and not the letter width to compensate)
78 line 4) link to the animation deviceLabelToggleTxt, so that the text appears
79 in gently
80 line 5) The text will be one of 3 values - blank, the id or the name
81 -->
82 <svg:text
83 text-anchor="start" y="0.3em" x="22"
84 [attr.textLength]= "labelTextLen()"
85 lengthAdjust= "spacing"
Sean Condon50855cf2018-12-23 15:37:42 +000086 [@deviceLabelToggleTxt]="labelToggle">
Sean Condon0c577f62018-11-18 22:40:05 +000087 {{ labelToggle == 0 ? '': labelToggle == 1 ? device.id:device.props.name }}
88 </svg:text>
Sean Condon59d31372019-02-02 20:07:00 +000089 <svg:use [attr.xlink:href]="'#' + deviceIcon()" width="36" height="36" x="-18" y="-18">
Sean Condon021f0fa2018-12-06 23:31:11 -080090 </svg:use>
Sean Condond88f3662019-04-03 16:35:30 +010091</svg:g>