blob: 7222452b33219948c6793e9226b4e87fe39d5af7 [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/*
18 Alternate Sample module file to illustrate framework integration.
19
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
36 // NOTE: view is a view-token data structure:
37 // {
38 // vid: 'view-id',
39 // nid: 'nav-id',
40 // $div: ... // d3 selection of dom view div.
41 // }
42
43 // gets invoked only the first time the view is loaded
44 function preload(view, ctx) {
45 svg = view.$div.append('svg');
46 sizeSvg(view);
47 }
48
49 function reset(view) {
50 // clear our svg of all objects
51 svg.html('');
52 }
53
54 function load(view, ctx) {
55 var fill = 'red',
56 stroke = 'black',
57 ctxText = ctx ? 'Context is "' + ctx + '"' : 'No Context';
58
59 svg.append('circle')
60 .attr({
61 cx: view.width() / 2,
62 cy: view.height() / 2,
63 r: 30
64 })
65 .style({
66 fill: fill,
67 stroke: stroke,
68 'stroke-width': 3.5
69 });
70
71 svg.append('text')
72 .text(ctxText)
73 .attr({
74 x: 20,
75 y: '1.5em'
76 })
77 .style({
78 fill: 'darkgreen',
79 'font-size': '20pt'
80 });
81 }
82
83 function resize(view, ctx) {
84 sizeSvg(view);
85 svg.selectAll('circle')
86 .attr({
87 cx: view.width() / 2,
88 cy: view.height() / 2
89 });
90 }
91
92 // == register views here, with links to lifecycle callbacks
93
94 onos.ui.addView('sample', {
95 preload: preload,
96 reset: reset,
97 load: load,
98 resize: resize
99 });
100
101
102}(ONOS));