Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [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 | |
| 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, |
Simon Hunt | c4c5a07 | 2015-03-25 15:32:19 -0700 | [diff] [blame] | 32 | texty = 30, |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 33 | 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 Hunt | c4c5a07 | 2015-03-25 15:32:19 -0700 | [diff] [blame] | 41 | height: dim + texty, |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 42 | 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 Hunt | c4c5a07 | 2015-03-25 15:32:19 -0700 | [diff] [blame] | 62 | 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 Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 72 | |
Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 73 | angular.module('showIconsTest', ['onosSvg']) |
| 74 | |
| 75 | .controller('OvShowIconsTest', ['$log', 'GlyphService', 'IconService', |
| 76 | function ($log, gs, icns) { |
| 77 | var self = this; |
Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 78 | |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 79 | gs.init(); |
| 80 | |
| 81 | var div = d3.select('#showIcons'); |
| 82 | |
| 83 | // show device online and offline icons |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 84 | icns.loadEmbeddedIcon(div, 'active', 50); |
Simon Hunt | c4c5a07 | 2015-03-25 15:32:19 -0700 | [diff] [blame] | 85 | div.append('span').style('padding-left', '15px'); |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 86 | icns.loadEmbeddedIcon(div, 'inactive', 50); |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 87 | |
| 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 Hunt | c4c5a07 | 2015-03-25 15:32:19 -0700 | [diff] [blame] | 98 | if (ctr%6 > 0) { |
| 99 | gDiv.append('span').style('padding-left', '15px'); |
| 100 | } else { |
| 101 | gDiv.append('br'); |
Bri Prebilic Cole | c006eef | 2015-01-20 11:42:05 -0800 | [diff] [blame] | 102 | } |
| 103 | }); |
Bri Prebilic Cole | 17a18b2 | 2015-01-19 17:15:59 -0800 | [diff] [blame] | 104 | |
| 105 | $log.log('OvShowIconsTest has been created'); |
| 106 | }]); |
Bri Prebilic Cole | b07c279 | 2015-01-20 09:58:09 -0800 | [diff] [blame] | 107 | }()); |