blob: 60cbe9d60aa56e73f8e12c85e1b830baa09f4675 [file] [log] [blame]
Simon Hunt25248912014-11-04 11:25:48 -08001/*
2 * Copyright 2014 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/*
Simon Hunte7f4bb02014-11-04 15:51:54 -080018 Alternate sample module file to illustrate framework integration.
Simon Hunt25248912014-11-04 11:25:48 -080019
20 @author Simon Hunt
21 */
22
23(function (onos) {
24 'use strict';
25
26 var svg;
27
28
29 function sizeSvg(view) {
30 svg.attr({
31 width: view.width(),
32 height: view.height()
33 });
34 }
35
Simon Hunt25248912014-11-04 11:25:48 -080036 // gets invoked only the first time the view is loaded
37 function preload(view, ctx) {
38 svg = view.$div.append('svg');
39 sizeSvg(view);
40 }
41
42 function reset(view) {
43 // clear our svg of all objects
44 svg.html('');
45 }
46
47 function load(view, ctx) {
Simon Hunte7f4bb02014-11-04 15:51:54 -080048 var fill = 'teal',
49 stroke = 'black';
Simon Hunt25248912014-11-04 11:25:48 -080050
51 svg.append('circle')
52 .attr({
53 cx: view.width() / 2,
54 cy: view.height() / 2,
55 r: 30
56 })
57 .style({
58 fill: fill,
59 stroke: stroke,
Simon Hunte7f4bb02014-11-04 15:51:54 -080060 'stroke-width': 1.5,
61 opacity: 0.5
Simon Hunt25248912014-11-04 11:25:48 -080062 });
63 }
64
65 function resize(view, ctx) {
66 sizeSvg(view);
67 svg.selectAll('circle')
68 .attr({
69 cx: view.width() / 2,
70 cy: view.height() / 2
71 });
72 }
73
74 // == register views here, with links to lifecycle callbacks
75
76 onos.ui.addView('sampleAlt', {
77 preload: preload,
78 reset: reset,
79 load: load,
80 resize: resize
81 });
82
83
84}(ONOS));