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
(cherry picked from commit 3a9a6447)
......@@ -44,18 +44,21 @@ public final class UiExtension {
private final List<UiView> views;
private final UiMessageHandlerFactory messageHandlerFactory;
private final UiTopoOverlayFactory topoOverlayFactory;
private final UiTopoMapFactory topoMapFactory;
private boolean isValid = true;
// private constructor - only the builder calls this
private UiExtension(ClassLoader cl, String path, List<UiView> views,
UiMessageHandlerFactory mhFactory,
UiTopoOverlayFactory toFactory) {
UiTopoOverlayFactory toFactory,
UiTopoMapFactory tmFactory) {
this.classLoader = cl;
this.resourcePath = path;
this.views = views;
this.messageHandlerFactory = mhFactory;
this.topoOverlayFactory = toFactory;
this.topoMapFactory = tmFactory;
}
......@@ -115,6 +118,15 @@ public final class UiExtension {
return topoOverlayFactory;
}
/**
* Returns the topology map factory, if one was defined.
*
* @return topology map factory
*/
public UiTopoMapFactory topoMapFactory() {
return topoMapFactory;
}
// Returns the resource input stream from the specified class-loader.
private InputStream getStream(String path) {
......@@ -137,6 +149,7 @@ public final class UiExtension {
private List<UiView> views = new ArrayList<>();
private UiMessageHandlerFactory messageHandlerFactory = null;
private UiTopoOverlayFactory topoOverlayFactory = null;
private UiTopoMapFactory topoMapFactory = null;
/**
* Create a builder with the given class loader.
......@@ -189,13 +202,25 @@ public final class UiExtension {
}
/**
* Sets the topology map factory for this extension.
*
* @param tmFactory topology map factory
* @return self, for chaining
*/
public Builder topoMapFactory(UiTopoMapFactory tmFactory) {
this.topoMapFactory = tmFactory;
return this;
}
/**
* Builds the UI extension.
*
* @return UI extension instance
*/
public UiExtension build() {
return new UiExtension(classLoader, resourcePath, views,
messageHandlerFactory, topoOverlayFactory);
messageHandlerFactory, topoOverlayFactory,
topoMapFactory);
}
}
......
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui;
/**
* Represents user interface topology view overlay.
*/
public class UiTopoMap {
private final String id;
private final String description;
private final String filePath;
private final double scale;
/**
* Creates a new topology map.
*
* @param id map identifier
* @param description map description
* @param filePath map filePath,
* @param scale map scale,
*/
public UiTopoMap(String id, String description, String filePath, double scale) {
this.id = id;
this.description = description;
this.filePath = filePath;
this.scale = scale;
}
/**
* Returns the identifier for this map.
*
* @return the identifier
*/
public String getId() {
return this.id;
}
/**
* Returns the description for this map.
*
* @return the description
*/
public String getDescription() {
return this.description;
}
/**
* Returns the filePath for this map.
*
* @return the filePath
*/
public String getFilePath() {
return this.filePath;
}
/**
* Returns the scale for this map.
*
* @return the scale
*/
public double getScale() {
return this.scale;
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui;
import java.util.List;
/**
* Abstraction of an entity capable of producing one or more topology
* map topologies.
*/
public interface UiTopoMapFactory {
/**
* Produces a list of new maps.
*
* @return list of new maps
*/
List<UiTopoMap> newMaps();
}
\ No newline at end of file
......@@ -18,10 +18,12 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.UiExtensionService;
import org.onosproject.ui.UiTopoMapFactory;
import org.onosproject.ui.UiTopoMap;
import java.util.Collection;
import java.util.List;
......@@ -38,21 +40,9 @@ class MapSelectorMessageHandler extends UiMessageHandler {
private static final String MAPS = "maps";
private static final String MAP_ID = "id";
private static final String DESCRIPTION = "description";
private static final String FILE_PATH = "filePath";
private static final String SCALE = "scale";
private static final List<Map> SUPPORTED_MAPS =
ImmutableList.of(new Map("australia", "Australia", 1.0),
new Map("ns_america", "North, Central and South America", 0.7),
new Map("s_america", "South America", 0.9),
new Map("usa", "United States", 1.0),
new Map("bayarea", "Bay Area, California", 1.0),
new Map("europe", "Europe", 2.5),
new Map("italy", "Italy", 0.8),
new Map("uk", "United Kingdom and Ireland", 0.6),
new Map("japan", "Japan", 0.8),
new Map("s_korea", "South Korea", 0.75),
new Map("taiwan", "Taiwan", 0.7));
@Override
protected Collection<RequestHandler> createRequestHandlers() {
return ImmutableSet.of(
......@@ -72,30 +62,30 @@ class MapSelectorMessageHandler extends UiMessageHandler {
}
private ObjectNode mapsJson() {
ObjectNode payload = objectNode();
ArrayNode order = arrayNode();
ObjectNode maps = objectNode();
payload.set(ORDER, order);
payload.set(MAPS, maps);
SUPPORTED_MAPS.forEach(m -> {
maps.set(m.id, objectNode().put(MAP_ID, m.id)
.put(DESCRIPTION, m.description)
.put(SCALE, m.scale));
order.add(m.id);
});
return payload;
}
private static final class Map {
private final String id;
private final String description;
private final double scale;
UiExtensionService service = get(UiExtensionService.class);
service.getExtensions().forEach(ext -> {
UiTopoMapFactory mapFactory = ext.topoMapFactory();
private Map(String id, String description, double scale) {
this.id = id;
this.description = description;
this.scale = scale;
}
if (mapFactory != null) {
List<UiTopoMap> topoMaps = mapFactory.newMaps();
topoMaps.forEach(m -> {
maps.set(m.getId(), objectNode().put(MAP_ID, m.getId())
.put(DESCRIPTION, m.getDescription())
.put(FILE_PATH, m.getFilePath())
.put(SCALE, m.getScale()));
order.add(m.getId());
});
}
});
return payload;
}
}
\ No newline at end of file
......
......@@ -52,8 +52,10 @@ import org.onosproject.ui.UiExtensionService;
import org.onosproject.ui.UiMessageHandlerFactory;
import org.onosproject.ui.UiPreferencesService;
import org.onosproject.ui.UiTopoOverlayFactory;
import org.onosproject.ui.UiTopoMapFactory;
import org.onosproject.ui.UiView;
import org.onosproject.ui.UiViewHidden;
import org.onosproject.ui.UiTopoMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -165,9 +167,29 @@ public class UiExtensionManager
new TrafficOverlay()
);
UiTopoMapFactory topoMapFactory =
() -> ImmutableList.of(
new UiTopoMap("australia", "Australia", "*australia", 1.0),
new UiTopoMap("americas", "North, Central and South America", "*americas", 0.7),
new UiTopoMap("n_america", "North America", "*n_america", 0.9),
new UiTopoMap("s_america", "South America", "*s_america", 0.9),
new UiTopoMap("usa", "United States", "*continental_us", 1.0),
new UiTopoMap("bayareaGEO", "Bay Area, California", "*bayarea", 1.0),
new UiTopoMap("europe", "Europe", "*europe", 2.5),
new UiTopoMap("italy", "Italy", "*italy", 0.8),
new UiTopoMap("uk", "United Kingdom and Ireland", "*uk", 0.6),
new UiTopoMap("japan", "Japan", "*japan", 0.8),
new UiTopoMap("s_korea", "South Korea", "*s_korea", 0.75),
new UiTopoMap("taiwan", "Taiwan", "*taiwan", 0.7),
new UiTopoMap("africa", "Africa", "*africa", 0.7),
new UiTopoMap("oceania", "Oceania", "*oceania", 0.7),
new UiTopoMap("asia", "Asia", "*asia", 0.7)
);
return new UiExtension.Builder(CL, coreViews)
.messageHandlerFactory(messageHandlerFactory)
.topoOverlayFactory(topoOverlayFactory)
.topoMapFactory(topoMapFactory)
.resourcePath(CORE)
.build();
}
......
......@@ -42,16 +42,24 @@
// mapping to ~/data/map/continental_us.topojson contains
// exactly the paths for the continental US.
function loadMapInto(mapLayer, id, opts) {
var promise = gds.fetchTopoData(id),
function loadMapInto(mapLayer, mapPath, id, opts) {
var promise = gds.fetchTopoData(mapPath),
deferredProjection = $q.defer();
if (!promise) {
$log.warn('Failed to load map: ' + id);
$log.warn('Failed to load map: ' + mapPath);
return false;
}
promise.then(function () {
// NOTE: This finds the topo object within the topojson file
var topoObjects = promise.topodata.objects;
if (topoObjects.hasOwnProperty(id)) {
opts.objectTag = id;
}
var gen = gds.createPathGenerator(promise.topodata, opts);
deferredProjection.resolve(gen.settings.projection);
......
......@@ -376,7 +376,12 @@
function currentMap() {
return ps.getPrefs(
'topo_mapid',
{ mapid: 'usa', mapscale: 1, tint: 'off'},
{
mapid: 'usa',
mapscale: 1,
mapfilepath: '*continental_us',
tint: 'off'
},
$loc.search()
);
}
......@@ -384,6 +389,7 @@
function setUpMap() {
var prefs = currentMap(),
mapId = prefs.mapid,
mapFilePath = prefs.mapfilepath,
mapScale = prefs.mapscale,
tint = prefs.tint,
promise,
......@@ -402,35 +408,24 @@
d3.selectAll(this.childNodes).remove();
});
}
if (mapId === 'usa') {
shadeFlip = 0;
promise = ms.loadMapInto(mapG, '*continental_us', {
adjustScale: mapScale,
shading: shading()
});
} else if (mapId === 'bayarea') {
shadeFlip = 1;
promise = ms.loadMapInto(mapG, '*bayarea', {
objectTag: 'bayareaGEO',
if (mapFilePath === '*countries') {
cfilter = countryFilters[mapId] || countryFilters.uk;
promise = ms.loadMapRegionInto(mapG, {
countryFilter: cfilter,
adjustScale: mapScale,
shading: shading()
});
} else if (mapId === 'taiwan') {
shadeFlip = 0;
promise = ms.loadMapInto(mapG, '*taiwan', {
objectTag: 'taiwan',
adjustScale: mapScale,
shading: shading()
})
} else {
shadeFlip = 0;
cfilter = countryFilters[mapId] || countryFilters.uk;
promise = ms.loadMapRegionInto(mapG, {
countryFilter: cfilter,
promise = ms.loadMapInto(mapG, mapFilePath, mapId, {
adjustScale: mapScale,
shading: shading()
});
}
ps.setPrefs('topo_mapid', prefs);
return promise;
}
......
......@@ -59,6 +59,7 @@
var p = {
mapid: map.id,
mapscale: map.scale,
mapfilepath: map.filePath,
tint: tintCheck.property('checked') ? 'on' : 'off'
};
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.