Steven Burrows
Committed by Thomas Vachuska

Topojsons have all been formatted with jsonlint

Added topojson files for all supportted maps, optimised the countries topojson files to remove unused properties.

Added Javadocs for UiTopoMap

Refactored Topo Maps to use UiTopoMapFactory, UiTopoMap classes.

Change-Id: I976137baa7f62a81e48231e1612b967d39dc641d

Refactored Topo Maps to use UiTopoMapFactory, UiTopoMap classes.

Change-Id: I976137baa7f62a81e48231e1612b967d39dc641d

Added Copyright

Change-Id: Ie62171ba6ab08bbf955bc444cd2db41d0c30baaa

Added file path for topojson or svg

Change-Id: Ib1fc79672079ec4c6e2cd35bc39a28abeafca297

Line break to account for the soft limit

Change-Id: Ib2b57ceee139b20a73d7ad0110b37fc1b5326ed7

Added File Path to the Map Class

Change-Id: Ic6ae4ca507e58155bb106ad46be14e048dc3a95c

Added File Path to the Map Class

Change-Id: Ib2200b0bf315f9dccb581447ddb4b6f6669e34ff
...@@ -44,18 +44,21 @@ public final class UiExtension { ...@@ -44,18 +44,21 @@ public final class UiExtension {
44 private final List<UiView> views; 44 private final List<UiView> views;
45 private final UiMessageHandlerFactory messageHandlerFactory; 45 private final UiMessageHandlerFactory messageHandlerFactory;
46 private final UiTopoOverlayFactory topoOverlayFactory; 46 private final UiTopoOverlayFactory topoOverlayFactory;
47 + private final UiTopoMapFactory topoMapFactory;
47 48
48 private boolean isValid = true; 49 private boolean isValid = true;
49 50
50 // private constructor - only the builder calls this 51 // private constructor - only the builder calls this
51 private UiExtension(ClassLoader cl, String path, List<UiView> views, 52 private UiExtension(ClassLoader cl, String path, List<UiView> views,
52 UiMessageHandlerFactory mhFactory, 53 UiMessageHandlerFactory mhFactory,
53 - UiTopoOverlayFactory toFactory) { 54 + UiTopoOverlayFactory toFactory,
55 + UiTopoMapFactory tmFactory) {
54 this.classLoader = cl; 56 this.classLoader = cl;
55 this.resourcePath = path; 57 this.resourcePath = path;
56 this.views = views; 58 this.views = views;
57 this.messageHandlerFactory = mhFactory; 59 this.messageHandlerFactory = mhFactory;
58 this.topoOverlayFactory = toFactory; 60 this.topoOverlayFactory = toFactory;
61 + this.topoMapFactory = tmFactory;
59 } 62 }
60 63
61 64
...@@ -115,6 +118,15 @@ public final class UiExtension { ...@@ -115,6 +118,15 @@ public final class UiExtension {
115 return topoOverlayFactory; 118 return topoOverlayFactory;
116 } 119 }
117 120
121 + /**
122 + * Returns the topology map factory, if one was defined.
123 + *
124 + * @return topology map factory
125 + */
126 + public UiTopoMapFactory topoMapFactory() {
127 + return topoMapFactory;
128 + }
129 +
118 130
119 // Returns the resource input stream from the specified class-loader. 131 // Returns the resource input stream from the specified class-loader.
120 private InputStream getStream(String path) { 132 private InputStream getStream(String path) {
...@@ -137,6 +149,7 @@ public final class UiExtension { ...@@ -137,6 +149,7 @@ public final class UiExtension {
137 private List<UiView> views = new ArrayList<>(); 149 private List<UiView> views = new ArrayList<>();
138 private UiMessageHandlerFactory messageHandlerFactory = null; 150 private UiMessageHandlerFactory messageHandlerFactory = null;
139 private UiTopoOverlayFactory topoOverlayFactory = null; 151 private UiTopoOverlayFactory topoOverlayFactory = null;
152 + private UiTopoMapFactory topoMapFactory = null;
140 153
141 /** 154 /**
142 * Create a builder with the given class loader. 155 * Create a builder with the given class loader.
...@@ -189,13 +202,25 @@ public final class UiExtension { ...@@ -189,13 +202,25 @@ public final class UiExtension {
189 } 202 }
190 203
191 /** 204 /**
205 + * Sets the topology map factory for this extension.
206 + *
207 + * @param tmFactory topology map factory
208 + * @return self, for chaining
209 + */
210 + public Builder topoMapFactory(UiTopoMapFactory tmFactory) {
211 + this.topoMapFactory = tmFactory;
212 + return this;
213 + }
214 +
215 + /**
192 * Builds the UI extension. 216 * Builds the UI extension.
193 * 217 *
194 * @return UI extension instance 218 * @return UI extension instance
195 */ 219 */
196 public UiExtension build() { 220 public UiExtension build() {
197 return new UiExtension(classLoader, resourcePath, views, 221 return new UiExtension(classLoader, resourcePath, views,
198 - messageHandlerFactory, topoOverlayFactory); 222 + messageHandlerFactory, topoOverlayFactory,
223 + topoMapFactory);
199 } 224 }
200 225
201 } 226 }
......
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ui;
18 +
19 +/**
20 + * Represents user interface topology view overlay.
21 + */
22 +public class UiTopoMap {
23 +
24 + private final String id;
25 + private final String description;
26 + private final String filePath;
27 + private final double scale;
28 +
29 +
30 + /**
31 + * Creates a new topology map.
32 + *
33 + * @param id map identifier
34 + * @param description map description
35 + * @param filePath map filePath,
36 + * @param scale map scale,
37 + */
38 + public UiTopoMap(String id, String description, String filePath, double scale) {
39 + this.id = id;
40 + this.description = description;
41 + this.filePath = filePath;
42 + this.scale = scale;
43 + }
44 +
45 + /**
46 + * Returns the identifier for this map.
47 + *
48 + * @return the identifier
49 + */
50 + public String getId() {
51 + return this.id;
52 + }
53 +
54 + /**
55 + * Returns the description for this map.
56 + *
57 + * @return the description
58 + */
59 + public String getDescription() {
60 + return this.description;
61 + }
62 +
63 + /**
64 + * Returns the filePath for this map.
65 + *
66 + * @return the filePath
67 + */
68 + public String getFilePath() {
69 + return this.filePath;
70 + }
71 +
72 + /**
73 + * Returns the scale for this map.
74 + *
75 + * @return the scale
76 + */
77 + public double getScale() {
78 + return this.scale;
79 + }
80 +
81 +}
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ui;
18 +
19 +import java.util.List;
20 +
21 +/**
22 + * Abstraction of an entity capable of producing one or more topology
23 + * map topologies.
24 + */
25 +public interface UiTopoMapFactory {
26 +
27 + /**
28 + * Produces a list of new maps.
29 + *
30 + * @return list of new maps
31 + */
32 + List<UiTopoMap> newMaps();
33 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -18,10 +18,12 @@ package org.onosproject.ui.impl; ...@@ -18,10 +18,12 @@ package org.onosproject.ui.impl;
18 18
19 import com.fasterxml.jackson.databind.node.ArrayNode; 19 import com.fasterxml.jackson.databind.node.ArrayNode;
20 import com.fasterxml.jackson.databind.node.ObjectNode; 20 import com.fasterxml.jackson.databind.node.ObjectNode;
21 -import com.google.common.collect.ImmutableList;
22 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
23 import org.onosproject.ui.RequestHandler; 22 import org.onosproject.ui.RequestHandler;
24 import org.onosproject.ui.UiMessageHandler; 23 import org.onosproject.ui.UiMessageHandler;
24 +import org.onosproject.ui.UiExtensionService;
25 +import org.onosproject.ui.UiTopoMapFactory;
26 +import org.onosproject.ui.UiTopoMap;
25 27
26 import java.util.Collection; 28 import java.util.Collection;
27 import java.util.List; 29 import java.util.List;
...@@ -38,21 +40,9 @@ class MapSelectorMessageHandler extends UiMessageHandler { ...@@ -38,21 +40,9 @@ class MapSelectorMessageHandler extends UiMessageHandler {
38 private static final String MAPS = "maps"; 40 private static final String MAPS = "maps";
39 private static final String MAP_ID = "id"; 41 private static final String MAP_ID = "id";
40 private static final String DESCRIPTION = "description"; 42 private static final String DESCRIPTION = "description";
43 + private static final String FILE_PATH = "filePath";
41 private static final String SCALE = "scale"; 44 private static final String SCALE = "scale";
42 45
43 - private static final List<Map> SUPPORTED_MAPS =
44 - ImmutableList.of(new Map("australia", "Australia", 1.0),
45 - new Map("ns_america", "North, Central and South America", 0.7),
46 - new Map("s_america", "South America", 0.9),
47 - new Map("usa", "United States", 1.0),
48 - new Map("bayarea", "Bay Area, California", 1.0),
49 - new Map("europe", "Europe", 2.5),
50 - new Map("italy", "Italy", 0.8),
51 - new Map("uk", "United Kingdom and Ireland", 0.6),
52 - new Map("japan", "Japan", 0.8),
53 - new Map("s_korea", "South Korea", 0.75),
54 - new Map("taiwan", "Taiwan", 0.7));
55 -
56 @Override 46 @Override
57 protected Collection<RequestHandler> createRequestHandlers() { 47 protected Collection<RequestHandler> createRequestHandlers() {
58 return ImmutableSet.of( 48 return ImmutableSet.of(
...@@ -72,30 +62,30 @@ class MapSelectorMessageHandler extends UiMessageHandler { ...@@ -72,30 +62,30 @@ class MapSelectorMessageHandler extends UiMessageHandler {
72 } 62 }
73 63
74 private ObjectNode mapsJson() { 64 private ObjectNode mapsJson() {
65 +
75 ObjectNode payload = objectNode(); 66 ObjectNode payload = objectNode();
76 ArrayNode order = arrayNode(); 67 ArrayNode order = arrayNode();
77 ObjectNode maps = objectNode(); 68 ObjectNode maps = objectNode();
78 payload.set(ORDER, order); 69 payload.set(ORDER, order);
79 payload.set(MAPS, maps); 70 payload.set(MAPS, maps);
80 - SUPPORTED_MAPS.forEach(m -> {
81 - maps.set(m.id, objectNode().put(MAP_ID, m.id)
82 - .put(DESCRIPTION, m.description)
83 - .put(SCALE, m.scale));
84 - order.add(m.id);
85 - });
86 - return payload;
87 - }
88 71
89 - private static final class Map { 72 + UiExtensionService service = get(UiExtensionService.class);
90 - private final String id; 73 + service.getExtensions().forEach(ext -> {
91 - private final String description; 74 + UiTopoMapFactory mapFactory = ext.topoMapFactory();
92 - private final double scale;
93 75
94 - private Map(String id, String description, double scale) { 76 + if (mapFactory != null) {
95 - this.id = id; 77 + List<UiTopoMap> topoMaps = mapFactory.newMaps();
96 - this.description = description; 78 +
97 - this.scale = scale; 79 + topoMaps.forEach(m -> {
98 - } 80 + maps.set(m.getId(), objectNode().put(MAP_ID, m.getId())
81 + .put(DESCRIPTION, m.getDescription())
82 + .put(FILE_PATH, m.getFilePath())
83 + .put(SCALE, m.getScale()));
84 + order.add(m.getId());
85 + });
99 } 86 }
87 + });
100 88
89 + return payload;
90 + }
101 } 91 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -52,8 +52,10 @@ import org.onosproject.ui.UiExtensionService; ...@@ -52,8 +52,10 @@ import org.onosproject.ui.UiExtensionService;
52 import org.onosproject.ui.UiMessageHandlerFactory; 52 import org.onosproject.ui.UiMessageHandlerFactory;
53 import org.onosproject.ui.UiPreferencesService; 53 import org.onosproject.ui.UiPreferencesService;
54 import org.onosproject.ui.UiTopoOverlayFactory; 54 import org.onosproject.ui.UiTopoOverlayFactory;
55 +import org.onosproject.ui.UiTopoMapFactory;
55 import org.onosproject.ui.UiView; 56 import org.onosproject.ui.UiView;
56 import org.onosproject.ui.UiViewHidden; 57 import org.onosproject.ui.UiViewHidden;
58 +import org.onosproject.ui.UiTopoMap;
57 import org.slf4j.Logger; 59 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory; 60 import org.slf4j.LoggerFactory;
59 61
...@@ -165,9 +167,29 @@ public class UiExtensionManager ...@@ -165,9 +167,29 @@ public class UiExtensionManager
165 new TrafficOverlay() 167 new TrafficOverlay()
166 ); 168 );
167 169
170 + UiTopoMapFactory topoMapFactory =
171 + () -> ImmutableList.of(
172 + new UiTopoMap("australia", "Australia", "*australia", 1.0),
173 + new UiTopoMap("americas", "North, Central and South America", "*americas", 0.7),
174 + new UiTopoMap("n_america", "North America", "*n_america", 0.9),
175 + new UiTopoMap("s_america", "South America", "*s_america", 0.9),
176 + new UiTopoMap("usa", "United States", "*continental_us", 1.0),
177 + new UiTopoMap("bayareaGEO", "Bay Area, California", "*bayarea", 1.0),
178 + new UiTopoMap("europe", "Europe", "*europe", 2.5),
179 + new UiTopoMap("italy", "Italy", "*italy", 0.8),
180 + new UiTopoMap("uk", "United Kingdom and Ireland", "*uk", 0.6),
181 + new UiTopoMap("japan", "Japan", "*japan", 0.8),
182 + new UiTopoMap("s_korea", "South Korea", "*s_korea", 0.75),
183 + new UiTopoMap("taiwan", "Taiwan", "*taiwan", 0.7),
184 + new UiTopoMap("africa", "Africa", "*africa", 0.7),
185 + new UiTopoMap("oceania", "Oceania", "*oceania", 0.7),
186 + new UiTopoMap("asia", "Asia", "*asia", 0.7)
187 + );
188 +
168 return new UiExtension.Builder(CL, coreViews) 189 return new UiExtension.Builder(CL, coreViews)
169 .messageHandlerFactory(messageHandlerFactory) 190 .messageHandlerFactory(messageHandlerFactory)
170 .topoOverlayFactory(topoOverlayFactory) 191 .topoOverlayFactory(topoOverlayFactory)
192 + .topoMapFactory(topoMapFactory)
171 .resourcePath(CORE) 193 .resourcePath(CORE)
172 .build(); 194 .build();
173 } 195 }
......
...@@ -42,16 +42,24 @@ ...@@ -42,16 +42,24 @@
42 // mapping to ~/data/map/continental_us.topojson contains 42 // mapping to ~/data/map/continental_us.topojson contains
43 // exactly the paths for the continental US. 43 // exactly the paths for the continental US.
44 44
45 - function loadMapInto(mapLayer, id, opts) { 45 + function loadMapInto(mapLayer, mapPath, id, opts) {
46 - var promise = gds.fetchTopoData(id), 46 + var promise = gds.fetchTopoData(mapPath),
47 deferredProjection = $q.defer(); 47 deferredProjection = $q.defer();
48 48
49 if (!promise) { 49 if (!promise) {
50 - $log.warn('Failed to load map: ' + id); 50 + $log.warn('Failed to load map: ' + mapPath);
51 return false; 51 return false;
52 } 52 }
53 53
54 promise.then(function () { 54 promise.then(function () {
55 +
56 + // NOTE: This finds the topo object within the topojson file
57 + var topoObjects = promise.topodata.objects;
58 +
59 + if (topoObjects.hasOwnProperty(id)) {
60 + opts.objectTag = id;
61 + }
62 +
55 var gen = gds.createPathGenerator(promise.topodata, opts); 63 var gen = gds.createPathGenerator(promise.topodata, opts);
56 64
57 deferredProjection.resolve(gen.settings.projection); 65 deferredProjection.resolve(gen.settings.projection);
......
...@@ -376,7 +376,12 @@ ...@@ -376,7 +376,12 @@
376 function currentMap() { 376 function currentMap() {
377 return ps.getPrefs( 377 return ps.getPrefs(
378 'topo_mapid', 378 'topo_mapid',
379 - { mapid: 'usa', mapscale: 1, tint: 'off'}, 379 + {
380 + mapid: 'usa',
381 + mapscale: 1,
382 + mapfilepath: '*continental_us',
383 + tint: 'off'
384 + },
380 $loc.search() 385 $loc.search()
381 ); 386 );
382 } 387 }
...@@ -384,6 +389,7 @@ ...@@ -384,6 +389,7 @@
384 function setUpMap() { 389 function setUpMap() {
385 var prefs = currentMap(), 390 var prefs = currentMap(),
386 mapId = prefs.mapid, 391 mapId = prefs.mapid,
392 + mapFilePath = prefs.mapfilepath,
387 mapScale = prefs.mapscale, 393 mapScale = prefs.mapscale,
388 tint = prefs.tint, 394 tint = prefs.tint,
389 promise, 395 promise,
...@@ -402,35 +408,24 @@ ...@@ -402,35 +408,24 @@
402 d3.selectAll(this.childNodes).remove(); 408 d3.selectAll(this.childNodes).remove();
403 }); 409 });
404 } 410 }
405 - if (mapId === 'usa') { 411 +
406 - shadeFlip = 0; 412 + if (mapFilePath === '*countries') {
407 - promise = ms.loadMapInto(mapG, '*continental_us', { 413 +
408 - adjustScale: mapScale, 414 + cfilter = countryFilters[mapId] || countryFilters.uk;
409 - shading: shading() 415 +
410 - }); 416 + promise = ms.loadMapRegionInto(mapG, {
411 - } else if (mapId === 'bayarea') { 417 + countryFilter: cfilter,
412 - shadeFlip = 1;
413 - promise = ms.loadMapInto(mapG, '*bayarea', {
414 - objectTag: 'bayareaGEO',
415 adjustScale: mapScale, 418 adjustScale: mapScale,
416 shading: shading() 419 shading: shading()
417 }); 420 });
418 - } else if (mapId === 'taiwan') {
419 - shadeFlip = 0;
420 - promise = ms.loadMapInto(mapG, '*taiwan', {
421 - objectTag: 'taiwan',
422 - adjustScale: mapScale,
423 - shading: shading()
424 - })
425 } else { 421 } else {
426 - shadeFlip = 0; 422 +
427 - cfilter = countryFilters[mapId] || countryFilters.uk; 423 + promise = ms.loadMapInto(mapG, mapFilePath, mapId, {
428 - promise = ms.loadMapRegionInto(mapG, {
429 - countryFilter: cfilter,
430 adjustScale: mapScale, 424 adjustScale: mapScale,
431 shading: shading() 425 shading: shading()
432 }); 426 });
433 } 427 }
428 +
434 ps.setPrefs('topo_mapid', prefs); 429 ps.setPrefs('topo_mapid', prefs);
435 return promise; 430 return promise;
436 } 431 }
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
59 var p = { 59 var p = {
60 mapid: map.id, 60 mapid: map.id,
61 mapscale: map.scale, 61 mapscale: map.scale,
62 + mapfilepath: map.filePath,
62 tint: tintCheck.property('checked') ? 'on' : 'off' 63 tint: tintCheck.property('checked') ? 'on' : 'off'
63 }; 64 };
64 setMap(p); 65 setMap(p);
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.