blob: f0e662eecf8766ba65acd0b034bc836aa6d34d30 [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 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 = 'blue',
56 stroke = 'grey';
57
58 svg.append('circle')
59 .attr({
60 cx: view.width() / 2,
61 cy: view.height() / 2,
62 r: 30
63 })
64 .style({
65 fill: fill,
66 stroke: stroke,
67 'stroke-width': 3.5
68 });
69 }
70
71 function resize(view, ctx) {
72 sizeSvg(view);
73 svg.selectAll('circle')
74 .attr({
75 cx: view.width() / 2,
76 cy: view.height() / 2
77 });
78 }
79
80 // == register views here, with links to lifecycle callbacks
81
82 onos.ui.addView('sampleAlt', {
83 preload: preload,
84 reset: reset,
85 load: load,
86 resize: resize
87 });
88
89
90}(ONOS));