Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 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 | import { Injectable } from '@angular/core'; |
| 17 | import { GlyphService } from './glyph.service'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 18 | import { LogService } from '../log.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 19 | import { SvgUtilService } from './svgutil.service'; |
| 20 | import * as d3 from 'd3'; |
| 21 | |
| 22 | const vboxSize = 50; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 23 | |
| 24 | export 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 Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 28 | ['inactive', 'xMark'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 29 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 30 | ['plus', 'plus'], |
| 31 | ['minus', 'minus'], |
| 32 | ['play', 'play'], |
| 33 | ['stop', 'stop'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 34 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 35 | ['upload', 'upload'], |
| 36 | ['download', 'download'], |
| 37 | ['delta', 'delta'], |
| 38 | ['nonzero', 'nonzero'], |
| 39 | ['close', 'xClose'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 40 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 41 | ['m_cloud', 'm_cloud'], |
| 42 | ['m_map', 'm_map'], |
| 43 | ['m_selectMap', 'm_selectMap'], |
| 44 | ['thatsNoMoon', 'thatsNoMoon'], |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 45 | ['m_ports', 'm_ports'], |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 46 | ['m_switch', 'm_switch'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 47 | ['switch', 'm_switch'], |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 48 | ['m_roadm', 'm_roadm'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 49 | ['roadm', 'm_roadm'], |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 50 | ['m_router', 'm_router'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 51 | ['router', 'm_router'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 52 | ['m_uiAttached', 'm_uiAttached'], |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 53 | ['m_endstation', 'm_endstation'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 54 | ['endstation', 'm_endstation'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 55 | ['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 Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 60 | ['m_cycleGridDisplay', 'm_cycleGridDisplay'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 61 | ['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 Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 74 | ['bgpSpeaker', 'm_bgpSpeaker'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 75 | ['m_otn', 'm_otn'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 76 | ['otn', 'm_otn'], |
| 77 | ['m_terminal_device', 'm_otn'], |
| 78 | ['m_ols', 'm_roadm'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 79 | ['m_roadm_otn', 'm_roadm_otn'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 80 | ['roadm_otn', 'm_roadm_otn'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 81 | ['m_fiberSwitch', 'm_fiberSwitch'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 82 | ['fiber_switch', 'm_fiberSwitch'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 83 | ['m_microwave', 'm_microwave'], |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 84 | ['microwave', 'm_microwave'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 85 | ['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 Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 101 | ['virtual', 'cord'], |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 102 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 103 | ['topo', 'topo'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 104 | ['bird', 'bird'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 105 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 106 | ['refresh', 'refresh'], |
| 107 | ['query', 'query'], |
| 108 | ['garbage', 'garbage'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 109 | |
| 110 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 111 | ['upArrow', 'triangleUp'], |
| 112 | ['downArrow', 'triangleDown'], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 113 | ['triangleLeft', 'triangleLeft'], |
| 114 | ['triangleRight', 'triangleRight'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 115 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 116 | ['appInactive', 'unknown'], |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 117 | ['uiAttached', 'uiAttached'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 118 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 119 | ['node', 'node'], |
| 120 | ['devIcon_SWITCH', 'switch'], |
| 121 | ['devIcon_ROADM', 'roadm'], |
| 122 | ['devIcon_OTN', 'otn'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 123 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 124 | ['portIcon_DEFAULT', 'm_ports'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 125 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 126 | ['meter', 'meterTable'], // TODO: m_meter icon? |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 127 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 128 | ['deviceTable', 'switch'], |
| 129 | ['flowTable', 'flowTable'], |
| 130 | ['portTable', 'portTable'], |
| 131 | ['groupTable', 'groupTable'], |
| 132 | ['meterTable', 'meterTable'], |
| 133 | ['pipeconfTable', 'pipeconfTable'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 134 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 135 | ['hostIcon_endstation', 'endstation'], |
| 136 | ['hostIcon_router', 'router'], |
| 137 | ['hostIcon_bgpSpeaker', 'bgpSpeaker'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 138 | |
| 139 | // navigation menu icons... |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 140 | ['nav_apps', 'bird'], |
| 141 | ['nav_settings', 'cog'], |
| 142 | ['nav_cluster', 'node'], |
| 143 | ['nav_processors', 'allTraffic'], |
Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +0530 | [diff] [blame] | 144 | ['nav_partitions', 'unknown'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 145 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 146 | ['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 Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 154 | ['clock', 'clock'], |
| 155 | ['clocks', 'clocks'], |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 156 | ]); |
| 157 | |
| 158 | /** |
| 159 | * ONOS GUI -- SVG -- Icon Service |
| 160 | */ |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 161 | @Injectable({ |
| 162 | providedIn: 'root', |
| 163 | }) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 164 | export 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 Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 176 | const body = d3.select('body'); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 177 | 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 186 | * 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 Condon | 59d3137 | 2019-02-02 20:07:00 +0000 | [diff] [blame] | 195 | let glyphName: string = glyphMapping.get(iconCls); |
| 196 | if (!glyphName) { |
| 197 | glyphName = iconCls; |
| 198 | } |
Sean Condon | 4747ece | 2019-05-04 20:17:02 +0100 | [diff] [blame] | 199 | this.gs.loadDefs(this.ensureIconLibDefs(), [glyphName], true, [iconCls]); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 200 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 201 | } |