blob: 2013a632cb8345533b07548e3c12d1f07a8c99e5 [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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
17/*
18 ONOS GUI -- SVG -- Icon Service
19
20 @author Simon Hunt
21 */
22(function () {
23 'use strict';
24
Simon Hunt7f172cc2015-01-16 17:43:00 -080025 var $log, fs;
26
27 var viewBoxDim = 50,
28 viewBox = '0 0 ' + viewBoxDim + ' ' + viewBoxDim;
29
30 // maps icon id to the glyph id it uses.
31 // note: icon id maps to a CSS class for styling that icon
32 var glyphMapping = {
33 deviceOnline: 'checkMark',
34 deviceOffline: 'xMark'
35 };
Simon Hunt7ac7be92015-01-06 10:47:56 -080036
37 angular.module('onosSvg')
Simon Hunt7f172cc2015-01-16 17:43:00 -080038 .factory('IconService', ['$log', 'FnService', function (_$log_, _fs_) {
Simon Hunt7ac7be92015-01-06 10:47:56 -080039 $log = _$log_;
Simon Hunt7f172cc2015-01-16 17:43:00 -080040 fs = _fs_;
41
42 // div is a D3 selection of the <DIV> element into which icon should load
43 // iconCls is the CSS class used to identify the icon
44 // size is dimension of icon in pixels. Defaults to 20.
45 function loadIcon(div, iconCls, size) {
46 var dim = size || 20,
47 gid = glyphMapping[iconCls] || 'unknown';
48
49 var svg = div.append('svg').attr({
50 width: dim,
51 height: dim,
52 viewBox: viewBox
53 });
54 var g = svg.append('g').attr({
55 'class': 'icon ' + iconCls
56 });
57 g.append('rect').attr({
58 width: viewBoxDim,
59 height: viewBoxDim,
60 rx: 4
61 });
62 g.append('use').attr({
63 width: viewBoxDim,
64 height: viewBoxDim,
65 'class': 'glyph',
66 'xlink:href': '#' + gid
67 });
68 }
Simon Hunt7ac7be92015-01-06 10:47:56 -080069
70 return {
Simon Hunt7f172cc2015-01-16 17:43:00 -080071 loadIcon: loadIcon
Simon Hunt7ac7be92015-01-06 10:47:56 -080072 };
73 }]);
74
75}());