Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 1 | /* |
| 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 Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 24 | // 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 Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 63 | angular.module('showIconsTest', ['onosSvg']) |
| 64 | |
| 65 | .controller('OvShowIconsTest', ['$log', 'GlyphService', 'IconService', |
| 66 | function ($log, gs, icns) { |
| 67 | var self = this; |
Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 68 | |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 69 | 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 Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 93 | |
| 94 | $log.log('OvShowIconsTest has been created'); |
| 95 | }]); |
Bri Prebilic Cole | b07c279 | 2015-01-20 09:58:09 -0800 | [diff] [blame] | 96 | }()); |