GUI -- Augment sprite definitions to include subpaths and fills.
- Added sample segment routing sprite layer. Change-Id: I531992754632255ca9156b536cb08386816add16
Showing
3 changed files
with
103 additions
and
12 deletions
... | @@ -586,3 +586,18 @@ | ... | @@ -586,3 +586,18 @@ |
586 | fill: #444; | 586 | fill: #444; |
587 | } | 587 | } |
588 | 588 | ||
589 | +/* fills */ | ||
590 | +.light #ov-topo svg #topo-sprites use.fill-gray2 { | ||
591 | + fill: #eee; | ||
592 | +} | ||
593 | +.dark #ov-topo svg #topo-sprites use.fill-gray2 { | ||
594 | + fill: #444; | ||
595 | +} | ||
596 | + | ||
597 | +.light #ov-topo svg #topo-sprites use.fill-blue2 { | ||
598 | + fill: #bce; | ||
599 | +} | ||
600 | +.dark #ov-topo svg #topo-sprites use.fill-blue2 { | ||
601 | + fill: #447; | ||
602 | +} | ||
603 | + | ... | ... |
... | @@ -58,9 +58,24 @@ | ... | @@ -58,9 +58,24 @@ |
58 | gs.loadDefs(defsElement, ids, true); | 58 | gs.loadDefs(defsElement, ids, true); |
59 | } | 59 | } |
60 | 60 | ||
61 | + function applyStrokeStyle(s, use) { | ||
62 | + var style; | ||
63 | + if (s) { | ||
64 | + style = {}; | ||
65 | + angular.forEach(s, function (value, key) { | ||
66 | + style['stroke-' + key] = value; | ||
67 | + }); | ||
68 | + use.style(style); | ||
69 | + } | ||
70 | + } | ||
61 | 71 | ||
62 | - function doSprite(spr, def, pmeta) { | 72 | + function applyFillClass(f, use) { |
63 | - var c = spr.class || 'gray1', | 73 | + use.classed('fill-' + f, true); |
74 | + } | ||
75 | + | ||
76 | + function doSprite(spr, def, pathmeta) { | ||
77 | + var pmeta = pathmeta[def.path], | ||
78 | + c = spr.class || 'gray1', | ||
64 | p = spr.pos || [0,0], | 79 | p = spr.pos || [0,0], |
65 | lab = spr.label, | 80 | lab = spr.label, |
66 | dim = def.dim || [40,40], | 81 | dim = def.dim || [40,40], |
... | @@ -69,7 +84,7 @@ | ... | @@ -69,7 +84,7 @@ |
69 | dy = def.labelyoff || 1, | 84 | dy = def.labelyoff || 1, |
70 | sc = def.scale, | 85 | sc = def.scale, |
71 | xfm = sus.translate(p), | 86 | xfm = sus.translate(p), |
72 | - g, attr, use, style; | 87 | + g, attr, use; |
73 | 88 | ||
74 | if (sc) { | 89 | if (sc) { |
75 | xfm += sus.scale(sc, sc); | 90 | xfm += sus.scale(sc, sc); |
... | @@ -86,13 +101,24 @@ | ... | @@ -86,13 +101,24 @@ |
86 | }; | 101 | }; |
87 | 102 | ||
88 | use = g.append('use').attr(attr); | 103 | use = g.append('use').attr(attr); |
89 | - | 104 | + applyStrokeStyle(pmeta.s, use); |
90 | - if (pmeta.s) { | 105 | + applyFillClass(def.fill, use); |
91 | - style = {}; | 106 | + |
92 | - angular.forEach(pmeta.s, function (value, key) { | 107 | + |
93 | - style['stroke-' + key] = value; | 108 | + // add subpaths if they have been defined |
109 | + if (fs.isA(def.subpaths)) { | ||
110 | + def.subpaths.forEach(function (v) { | ||
111 | + pmeta = pathmeta[v.path]; | ||
112 | + attr = { | ||
113 | + width: w, | ||
114 | + height: h, | ||
115 | + 'xlink:href': '#' + pmeta.u, | ||
116 | + transform: sus.translate(v.pos) | ||
117 | + }; | ||
118 | + use = g.append('use').attr(attr); | ||
119 | + applyStrokeStyle(pmeta.s, use); | ||
120 | + applyFillClass(def.subpathfill, use); | ||
94 | }); | 121 | }); |
95 | - use.style(style); | ||
96 | } | 122 | } |
97 | 123 | ||
98 | if (lab) { | 124 | if (lab) { |
... | @@ -188,9 +214,8 @@ | ... | @@ -188,9 +214,8 @@ |
188 | 214 | ||
189 | if (sprites) { | 215 | if (sprites) { |
190 | sprites.forEach(function (spr) { | 216 | sprites.forEach(function (spr) { |
191 | - var def = defs[spr.id], | 217 | + var def = defs[spr.id]; |
192 | - pmeta = pathmeta[def.path]; | 218 | + doSprite(spr, def, pathmeta); |
193 | - doSprite(spr, def, pmeta); | ||
194 | }); | 219 | }); |
195 | } | 220 | } |
196 | 221 | ... | ... |
1 | +{ | ||
2 | + "defn_name": "segmentRouting", | ||
3 | + "defn_desc": "Schematic of Data Center", | ||
4 | + | ||
5 | + "paths": [ | ||
6 | + { | ||
7 | + "tag": "chassis", | ||
8 | + "stroke": { | ||
9 | + "width": 3.5 | ||
10 | + }, | ||
11 | + "viewbox": "0 0 120 170", | ||
12 | + "d": "M10,10h80v150h-80z" | ||
13 | + }, | ||
14 | + { | ||
15 | + "tag": "module", | ||
16 | + "stroke": { | ||
17 | + "width": 2 | ||
18 | + }, | ||
19 | + "viewbox": "0 0 120 20", | ||
20 | + "d": "M15,5h70v12h-70z" | ||
21 | + } | ||
22 | + ], | ||
23 | + | ||
24 | + "defn": [ | ||
25 | + { | ||
26 | + "id": "rack", | ||
27 | + "path": "chassis", | ||
28 | + "fill": "gray2", | ||
29 | + "subpathfill": "blue2", | ||
30 | + "subpaths": [ | ||
31 | + { "path": "module", "pos": [0, 0]}, | ||
32 | + { "path": "module", "pos": [0, 20]}, | ||
33 | + { "path": "module", "pos": [0, 40]}, | ||
34 | + { "path": "module", "pos": [0, 60]} | ||
35 | + ], | ||
36 | + "dim":[120,170] | ||
37 | + } | ||
38 | + ], | ||
39 | + | ||
40 | + "load": { | ||
41 | + "alpha": 0.9, | ||
42 | + "sprites": [ | ||
43 | + { "id": "rack", "pos":[300,600], "class":"blue1" }, | ||
44 | + { "id": "rack", "pos":[500,600], "class":"blue1" }, | ||
45 | + { "id": "rack", "pos":[700,600], "class":"blue1" } | ||
46 | + ], | ||
47 | + "labels": [ | ||
48 | + { "pos":[550,80], "text":"Segment Routing Demo", "class":"blue1", "size":1.4 } | ||
49 | + ] | ||
50 | + } | ||
51 | +} |
-
Please register or login to post a comment