blob: 915e0168b794ca92b49b81be71c0a52306149fd7 [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,
Simon Huntc4c5a072015-03-25 15:32:19 -070032 texty = 30,
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080033 gid = id || 'unknown',
34 rx = rer || 4,
35 svgCls = svgClass || 'embeddedGlyph',
36 svg, g;
37
38 svg = div.append('svg').attr({
39 'class': svgCls,
40 width: dim,
Simon Huntc4c5a072015-03-25 15:32:19 -070041 height: dim + texty,
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080042 viewBox: '0 0 ' + dim + ' ' + dim
43 });
44
45 g = svg.append('g').attr({
46 'class': 'glyph'
47 });
48
49 g.append('rect').attr({
50 width: dim,
51 height: dim,
52 rx: rx
53 });
54
55 g.append('use').attr({
56 width: dim,
57 height: dim,
58 'class': 'glyph',
59 'xlink:href': '#' + gid
60 });
61
Simon Huntc4c5a072015-03-25 15:32:19 -070062 g.append('text')
63 .attr({
64 'text-anchor': 'left',
65 y: '1em',
66 x: 0,
67 transform: 'translate(0, ' + dim + ')scale(0.8)'
68 })
69 .style('fill', '#800')
70 .text(id);
71 }
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080072
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -080073 angular.module('showIconsTest', ['onosSvg'])
74
75 .controller('OvShowIconsTest', ['$log', 'GlyphService', 'IconService',
76 function ($log, gs, icns) {
77 var self = this;
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -080078
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080079 gs.init();
80
81 var div = d3.select('#showIcons');
82
83 // show device online and offline icons
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070084 icns.loadEmbeddedIcon(div, 'active', 50);
Simon Huntc4c5a072015-03-25 15:32:19 -070085 div.append('span').style('padding-left', '15px');
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070086 icns.loadEmbeddedIcon(div, 'inactive', 50);
Bri Prebilic Colec006eef2015-01-20 11:42:05 -080087
88 var defs = d3.select('defs');
89
90 // show all glyphs in glyph library
91 gs.loadDefs(defs, null, true);
92 var list = gs.ids(),
93 gDiv = d3.select('#showGlyphs'),
94 ctr = 0;
95 list.forEach(function (id) {
96 createGlyph(gDiv, 50, id);
97 ctr += 1;
Simon Huntc4c5a072015-03-25 15:32:19 -070098 if (ctr%6 > 0) {
99 gDiv.append('span').style('padding-left', '15px');
100 } else {
101 gDiv.append('br');
Bri Prebilic Colec006eef2015-01-20 11:42:05 -0800102 }
103 });
Bri Prebilic Cole17a18b22015-01-19 17:15:59 -0800104
105 $log.log('OvShowIconsTest has been created');
106 }]);
Bri Prebilic Coleb07c2792015-01-20 09:58:09 -0800107}());