blob: 36bb53b6b431077794bd3877b2700b9775d308cb [file] [log] [blame]
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -08001/*
2 * Copyright 2014,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 -- Showing Icons Test Module
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -080019 */
20
21(function () {
22 'use strict';
23
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080024 // assuming the glyph is a square
25 // div is a D3 selection of the <DIV> element into which icon should load
26 // size is the size of the glyph
27 // id is the symbol id
28 // rer is the rectangle the glyph will be in's rounded corners
29 // svgClass is the class name for your glyph
30 function createGlyph(div, size, id, rer, svgClass) {
31 var dim = size || 20,
32 gid = id || 'unknown',
33 rx = rer || 4,
34 svgCls = svgClass || 'embeddedGlyph',
35 svg, g;
36
37 svg = div.append('svg').attr({
38 'class': svgCls,
39 width: dim,
40 height: dim,
41 viewBox: '0 0 ' + dim + ' ' + dim
42 });
43
44 g = svg.append('g').attr({
45 'class': 'glyph'
46 });
47
48 g.append('rect').attr({
49 width: dim,
50 height: dim,
51 rx: rx
52 });
53
54 g.append('use').attr({
55 width: dim,
56 height: dim,
57 'class': 'glyph',
58 'xlink:href': '#' + gid
59 });
60
61}
62
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -080063 angular.module('showIconsTest', ['onosSvg'])
64
65 .controller('OvShowIconsTest', ['$log', 'GlyphService', 'IconService',
66 function ($log, gs, icns) {
67 var self = this;
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -080068
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080069 gs.init();
70
71 var div = d3.select('#showIcons');
72
73 // show device online and offline icons
74 icns.loadEmbeddedIcon(div, 'deviceOnline', 50);
75 div.append('br');
76 icns.loadEmbeddedIcon(div, 'deviceOffline', 50);
77
78 var defs = d3.select('defs');
79
80 // show all glyphs in glyph library
81 gs.loadDefs(defs, null, true);
82 var list = gs.ids(),
83 gDiv = d3.select('#showGlyphs'),
84 ctr = 0;
85 list.forEach(function (id) {
86 createGlyph(gDiv, 50, id);
87 ctr += 1;
88 if(ctr/3 > 1) {
89 ctr = 0;
90 gDiv.append('p');
91 }
92 });
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -080093
94 $log.log('OvShowIconsTest has been created');
95 }]);
Bri Prebilic Coleb07c2792015-01-20 09:58:09 -080096}());