blob: f3c6432ef331e004eda96885d72e8552d0bf3947 [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
Sean Condon5ca00262018-09-06 17:55:25 +01002 * Copyright 2018-present Open Networking Foundation
Sean Condon83fc39f2018-04-19 18:56:13 +01003 *
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 */
16import { Injectable } from '@angular/core';
17import { GlyphService } from './glyph.service';
Sean Condon5ca00262018-09-06 17:55:25 +010018import { LogService } from '../log.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010019import { SvgUtilService } from './svgutil.service';
20import * as d3 from 'd3';
21
22const vboxSize = 50;
Sean Condon83fc39f2018-04-19 18:56:13 +010023
24export const glyphMapping = new Map<string, string>([
25 // Maps icon ID to the glyph ID it uses.
26 // NOTE: icon ID maps to a CSS class for styling that icon
27 ['active', 'checkMark'],
Sean Condon49e15be2018-05-16 16:58:29 +010028 ['inactive', 'xMark'],
Sean Condon83fc39f2018-04-19 18:56:13 +010029
Sean Condon49e15be2018-05-16 16:58:29 +010030 ['plus', 'plus'],
31 ['minus', 'minus'],
32 ['play', 'play'],
33 ['stop', 'stop'],
Sean Condon83fc39f2018-04-19 18:56:13 +010034
Sean Condon49e15be2018-05-16 16:58:29 +010035 ['upload', 'upload'],
36 ['download', 'download'],
37 ['delta', 'delta'],
38 ['nonzero', 'nonzero'],
39 ['close', 'xClose'],
Sean Condon83fc39f2018-04-19 18:56:13 +010040
Sean Condon91481822019-01-01 13:56:14 +000041 ['m_cloud', 'm_cloud'],
42 ['m_map', 'm_map'],
43 ['m_selectMap', 'm_selectMap'],
44 ['thatsNoMoon', 'thatsNoMoon'],
Bhavesh72ead492018-07-19 16:29:18 +053045 ['m_ports', 'm_ports'],
Sean Condon0c577f62018-11-18 22:40:05 +000046 ['m_switch', 'm_switch'],
Sean Condon4747ece2019-05-04 20:17:02 +010047 ['switch', 'm_switch'],
Sean Condon021f0fa2018-12-06 23:31:11 -080048 ['m_roadm', 'm_roadm'],
Sean Condon4747ece2019-05-04 20:17:02 +010049 ['roadm', 'm_roadm'],
Sean Condon021f0fa2018-12-06 23:31:11 -080050 ['m_router', 'm_router'],
Sean Condon4747ece2019-05-04 20:17:02 +010051 ['router', 'm_router'],
Sean Condon91481822019-01-01 13:56:14 +000052 ['m_uiAttached', 'm_uiAttached'],
Sean Condon021f0fa2018-12-06 23:31:11 -080053 ['m_endstation', 'm_endstation'],
Sean Condon4747ece2019-05-04 20:17:02 +010054 ['endstation', 'm_endstation'],
Sean Condon91481822019-01-01 13:56:14 +000055 ['m_summary', 'm_summary'],
56 ['m_details', 'm_details'],
57 ['m_oblique', 'm_oblique'],
58 ['m_filters', 'm_filters'],
59 ['m_cycleLabels', 'm_cycleLabels'],
Sean Condon71910542019-02-16 18:16:42 +000060 ['m_cycleGridDisplay', 'm_cycleGridDisplay'],
Sean Condon91481822019-01-01 13:56:14 +000061 ['m_prev', 'm_prev'],
62 ['m_next', 'm_next'],
63 ['m_flows', 'm_flows'],
64 ['m_allTraffic', 'm_allTraffic'],
65 ['m_xMark', 'm_xMark'],
66 ['m_resetZoom', 'm_resetZoom'],
67 ['m_eqMaster', 'm_eqMaster'],
68 ['m_unknown', 'm_unknown'],
69 ['m_controller', 'm_controller'],
70 ['m_eqMaster', 'm_eqMaster'],
71 ['m_virtual', 'm_virtual'],
72 ['m_other', 'm_other'],
73 ['m_bgpSpeaker', 'm_bgpSpeaker'],
Sean Condon4747ece2019-05-04 20:17:02 +010074 ['bgpSpeaker', 'm_bgpSpeaker'],
Sean Condon91481822019-01-01 13:56:14 +000075 ['m_otn', 'm_otn'],
Sean Condon4747ece2019-05-04 20:17:02 +010076 ['otn', 'm_otn'],
77 ['m_terminal_device', 'm_otn'],
78 ['m_ols', 'm_roadm'],
Sean Condon91481822019-01-01 13:56:14 +000079 ['m_roadm_otn', 'm_roadm_otn'],
Sean Condon4747ece2019-05-04 20:17:02 +010080 ['roadm_otn', 'm_roadm_otn'],
Sean Condon91481822019-01-01 13:56:14 +000081 ['m_fiberSwitch', 'm_fiberSwitch'],
Sean Condon4747ece2019-05-04 20:17:02 +010082 ['fiber_switch', 'm_fiberSwitch'],
Sean Condon91481822019-01-01 13:56:14 +000083 ['m_microwave', 'm_microwave'],
Sean Condon4747ece2019-05-04 20:17:02 +010084 ['microwave', 'm_microwave'],
Sean Condon91481822019-01-01 13:56:14 +000085 ['m_relatedIntents', 'm_relatedIntents'],
86 ['m_intentTraffic', 'm_intentTraffic'],
87 ['m_firewall', 'm_firewall'],
88 ['m_balancer', 'm_balancer'],
89 ['m_ips', 'm_ips'],
90 ['m_ids', 'm_ids'],
91 ['m_olt', 'm_olt'],
92 ['m_onu', 'm_onu'],
93 ['m_swap', 'm_swap'],
94 ['m_shortestGeoPath', 'm_shortestGeoPath'],
95 ['m_source', 'm_source'],
96 ['m_destination', 'm_destination'],
97 ['m_topo', 'm_topo'],
98 ['m_shortestPath', 'm_shortestPath'],
99 ['m_disjointPaths', 'm_disjointPaths'],
100 ['m_region', 'm_region'],
Sean Condon4747ece2019-05-04 20:17:02 +0100101 ['virtual', 'cord'],
Bhavesh72ead492018-07-19 16:29:18 +0530102
Sean Condon49e15be2018-05-16 16:58:29 +0100103 ['topo', 'topo'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100104 ['bird', 'bird'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100105
Sean Condon49e15be2018-05-16 16:58:29 +0100106 ['refresh', 'refresh'],
107 ['query', 'query'],
108 ['garbage', 'garbage'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100109
110
Sean Condon49e15be2018-05-16 16:58:29 +0100111 ['upArrow', 'triangleUp'],
112 ['downArrow', 'triangleDown'],
Sean Condon91481822019-01-01 13:56:14 +0000113 ['triangleLeft', 'triangleLeft'],
114 ['triangleRight', 'triangleRight'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100115
Sean Condon49e15be2018-05-16 16:58:29 +0100116 ['appInactive', 'unknown'],
Sean Condonaa4366d2018-11-02 14:29:01 +0000117 ['uiAttached', 'uiAttached'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100118
Sean Condon49e15be2018-05-16 16:58:29 +0100119 ['node', 'node'],
120 ['devIcon_SWITCH', 'switch'],
121 ['devIcon_ROADM', 'roadm'],
122 ['devIcon_OTN', 'otn'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100123
Sean Condon49e15be2018-05-16 16:58:29 +0100124 ['portIcon_DEFAULT', 'm_ports'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100125
Sean Condon49e15be2018-05-16 16:58:29 +0100126 ['meter', 'meterTable'], // TODO: m_meter icon?
Sean Condon83fc39f2018-04-19 18:56:13 +0100127
Sean Condon49e15be2018-05-16 16:58:29 +0100128 ['deviceTable', 'switch'],
129 ['flowTable', 'flowTable'],
130 ['portTable', 'portTable'],
131 ['groupTable', 'groupTable'],
132 ['meterTable', 'meterTable'],
133 ['pipeconfTable', 'pipeconfTable'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100134
Sean Condon49e15be2018-05-16 16:58:29 +0100135 ['hostIcon_endstation', 'endstation'],
136 ['hostIcon_router', 'router'],
137 ['hostIcon_bgpSpeaker', 'bgpSpeaker'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100138
139 // navigation menu icons...
Sean Condon49e15be2018-05-16 16:58:29 +0100140 ['nav_apps', 'bird'],
141 ['nav_settings', 'cog'],
142 ['nav_cluster', 'node'],
143 ['nav_processors', 'allTraffic'],
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530144 ['nav_partitions', 'unknown'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100145
Sean Condon49e15be2018-05-16 16:58:29 +0100146 ['nav_topo', 'topo'],
147 ['nav_topo2', 'm_cloud'],
148 ['nav_devs', 'switch'],
149 ['nav_links', 'ports'],
150 ['nav_hosts', 'endstation'],
151 ['nav_intents', 'relatedIntents'],
152 ['nav_tunnels', 'ports'], // TODO: use tunnel glyph, when available
153 ['nav_yang', 'yang'],
Sean Condon590b34b2019-12-04 18:44:37 +0000154 ['clock', 'clock'],
155 ['clocks', 'clocks'],
Sean Condon83fc39f2018-04-19 18:56:13 +0100156]);
157
158/**
159 * ONOS GUI -- SVG -- Icon Service
160 */
Sean Condon5ca00262018-09-06 17:55:25 +0100161@Injectable({
162 providedIn: 'root',
163})
Sean Condon83fc39f2018-04-19 18:56:13 +0100164export class IconService {
165
166 constructor(
167 private gs: GlyphService,
168 private log: LogService,
169 private sus: SvgUtilService
170 ) {
171
172 this.log.debug('IconService constructed');
173 }
174
175 ensureIconLibDefs() {
Sean Condon49e15be2018-05-16 16:58:29 +0100176 const body = d3.select('body');
Sean Condon83fc39f2018-04-19 18:56:13 +0100177 let svg = body.select('svg#IconLibDefs');
178 if (svg.empty()) {
179 svg = body.append('svg').attr('id', 'IconLibDefs');
180 svg.append('defs');
181 }
182 return svg.select('defs');
183 }
184
185 /**
Sean Condon83fc39f2018-04-19 18:56:13 +0100186 * Load an icon only to the svg defs collection
187 *
188 * Note: This is added for use with IconComponent, where the icon's
189 * svg element is defined in the component template (and not built
190 * inline using d3 manipulation
191 *
192 * @param iconCls The icon class as a string
193 */
194 loadIconDef(iconCls: string): void {
Sean Condon59d31372019-02-02 20:07:00 +0000195 let glyphName: string = glyphMapping.get(iconCls);
196 if (!glyphName) {
197 glyphName = iconCls;
198 }
Sean Condon4747ece2019-05-04 20:17:02 +0100199 this.gs.loadDefs(this.ensureIconLibDefs(), [glyphName], true, [iconCls]);
Sean Condon83fc39f2018-04-19 18:56:13 +0100200 }
Sean Condon83fc39f2018-04-19 18:56:13 +0100201}