Author: paperwing
Date: 2012-03-23 13:10:50 -0700 (Fri, 23 Mar 2012)
New Revision: 28633
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
Log:
Made recently added NetworkViewLocationTaskFactory accessible to
PopupMenuCreator, in process of creating initial algorithm to distribute
network partitions in 3D space
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
2012-03-23 20:01:13 UTC (rev 28632)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
2012-03-23 20:10:50 UTC (rev 28633)
@@ -8,6 +8,7 @@
import org.cytoscape.service.util.AbstractCyActivator;
import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.task.EdgeViewTaskFactory;
+import org.cytoscape.task.NetworkViewLocationTaskFactory;
import org.cytoscape.task.NetworkViewTaskFactory;
import org.cytoscape.task.NodeViewTaskFactory;
import org.cytoscape.view.layout.CyLayoutAlgorithm;
@@ -55,6 +56,7 @@
registerServiceListener(bc, taskFactoryListener,
"addNodeViewTaskFactory", "removeNodeViewTaskFactory",
NodeViewTaskFactory.class);
registerServiceListener(bc, taskFactoryListener,
"addEdgeViewTaskFactory", "removeEdgeViewTaskFactory",
EdgeViewTaskFactory.class);
registerServiceListener(bc, taskFactoryListener,
"addNetworkViewTaskFactory", "removeNetworkViewTaskFactory",
NetworkViewTaskFactory.class);
+ registerServiceListener(bc, taskFactoryListener,
"addNetworkViewLocationTaskFactory", "removeNetworkViewLocationTaskFactory",
NetworkViewLocationTaskFactory.class);
// Wind Visual Lexicon
WindVisualLexicon windVisualLexicon = new WindVisualLexicon();
@@ -104,7 +106,7 @@
sphericalLayoutAlgorithmProps.setProperty("preferredMenu","Layout.3D Layouts");
sphericalLayoutAlgorithmProps.setProperty("preferredTaskManager","menu");
sphericalLayoutAlgorithmProps.setProperty("title",sphericalLayoutAlgorithm.toString());
- sphericalLayoutAlgorithmProps.setProperty("menuGravity","10.2");
+ sphericalLayoutAlgorithmProps.setProperty("menuGravity","10.5");
registerService(bc,sphericalLayoutAlgorithm,
CyLayoutAlgorithm.class, sphericalLayoutAlgorithmProps);
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
2012-03-23 20:01:13 UTC (rev 28632)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
2012-03-23 20:10:50 UTC (rev 28633)
@@ -43,30 +43,52 @@
System.out.println("Number of partitions: " + numPartitions);
- double xOffsetAmount = 200;
- double yOffsetAmount = 200;
+ double xOffsetAmount = 0;
+ double yOffsetAmount = 0;
+ double largestRadius = -1;
Collection<View<CyNode>> partitionNodeViews;
+ Map<LayoutPartition, Double> partitionRadii = new
HashMap<LayoutPartition, Double>();
+
for (LayoutPartition partition : partitions) {
partitionNodeViews = new HashSet<View<CyNode>>();
for (LayoutNode layoutNode : partition.getNodeList()) {
View<CyNode> nodeView =
layoutNode.getNodeView();
+
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION,
+
nodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION) + xOffsetAmount);
+
+
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION,
+
nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION) + yOffsetAmount);
+
+
partitionNodeViews.add(nodeView);
}
+ arrangeAsSphere(partitionNodeViews);
- partition.offset(count * xOffsetAmount, count *
yOffsetAmount);
+ double subgraphRadius =
findSubgraphRadius(partitionNodeViews);
+ partitionRadii.put(partition, subgraphRadius);
- arrangeAsSphere(partitionNodeViews);
+ xOffsetAmount += subgraphRadius + 50;
+ if (subgraphRadius > largestRadius) {
+ largestRadius = subgraphRadius;
+ }
+
count++;
}
+
// arrangeAsSphere(networkView.getNodeViews());
}
+ private void arrangeAsBox(Collection<View<CyNode>> nodeViews) {
+
+ }
+
private void arrangeAsSphere(Collection<View<CyNode>> nodeViews) {
int nodeCount = nodeViews.size();
int current = 0;
@@ -78,14 +100,24 @@
for (View<CyNode> nodeView : nodeViews) {
- int nodesPerLevel = (int)
Math.max(Math.sqrt(nodeCount), 1);
+ int nodesPerLevel = (int)
Math.max(Math.sqrt(nodeCount), 3);
// The fraction should range from 0 to 1
double levelFraction = Math.floor(current /
nodesPerLevel) * nodesPerLevel / nodeCount;
double thetaLimit = 0.0;
- double phiLimit = 0.05;
+ // Perform a correction for small numbers of nodes
+ double phiLimit = 0.20 - Math.min((double) nodeCount /
125, 1) * 0.15;
+
+ /*
+ if (nodeCount < 25) {
+ phiLimit = 0.15;
+ } else {
+ phiLimit = 0.05;
+ }
+ */
+
// double theta = Math.PI / 2 - (Math.PI * thetaLimit +
(double) level / numLevels * Math.PI * (1 - 2 * thetaLimit));
double theta = Math.PI / 2 - (Math.PI * thetaLimit +
levelFraction * Math.PI * (2 - 2 * thetaLimit));
double phi = Math.PI * phiLimit + (double) (current %
nodesPerLevel) / (nodesPerLevel - 1) * Math.PI * (1 - 2 * phiLimit);
@@ -263,4 +295,32 @@
return null;
}
+
+ /**
+ * Find the radius of the subgraph formed by the given set of nodes.
This radius can be useful
+ * for determining the spacing between graph partitions.
+ * @return
+ */
+ private double findSubgraphRadius(Collection<View<CyNode>> nodeViews) {
+
+ // Obtain the average node position
+ Vector3 averagePosition = findCenter(nodeViews);
+
+ double maxDistanceSquared = -1;
+ View<CyNode> farthestNode = null;
+ double distanceSquared;
+
+ for (View<CyNode> nodeView : nodeViews) {
+ distanceSquared =
Math.pow(nodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION) -
averagePosition.x(), 2)
+ +
Math.pow(nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION) -
averagePosition.y(), 2)
+ +
Math.pow(nodeView.getVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION) -
averagePosition.z(), 2);
+
+ if (distanceSquared > maxDistanceSquared) {
+ maxDistanceSquared = distanceSquared;
+ farthestNode = nodeView;
+ }
+ }
+
+ return Math.sqrt(maxDistanceSquared);
+ }
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
2012-03-23 20:01:13 UTC (rev 28632)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
2012-03-23 20:10:50 UTC (rev 28633)
@@ -15,6 +15,7 @@
import org.cytoscape.model.CyNode;
import org.cytoscape.paperwing.internal.data.GraphicsData;
import org.cytoscape.task.EdgeViewTaskFactory;
+import org.cytoscape.task.NetworkViewLocationTaskFactory;
import org.cytoscape.task.NetworkViewTaskFactory;
import org.cytoscape.task.NodeViewTaskFactory;
import org.cytoscape.task.TunableEdgeViewTaskFactory;
@@ -134,6 +135,28 @@
return popupMenu;
}
+ public JPopupMenu createNetworkLocationMenu(CyNetworkView networkView,
VisualLexicon visualLexicon,
+ Map<NetworkViewLocationTaskFactory, Map<String,
Object>> taskFactories) {
+ JPopupMenu popupMenu = new JPopupMenu();
+ JMenuTracker tracker = new JMenuTracker(popupMenu);
+
+ for (Entry<NetworkViewLocationTaskFactory, Map<String, Object>>
entry : taskFactories.entrySet()) {
+
+ NetworkViewLocationTaskFactory
networkViewLocationTaskFactory = entry.getKey();
+ Map<String, Object> properties = entry.getValue();
+
+ // TODO: Ding implementation for the
NetworkViewLocation Task objects also takes 2D coordinates for
+ // the source of the event. Determine if appropriate to
support NetworkViewLocation Tasks.
+
+ /*
+ TaskFactory taskFactory =
taskFactoryProvider.createFor(networkViewLocationTaskFactory, networkView);
+ createMenuItem(null, visualLexicon, popupMenu,
taskFactory, null, tracker, properties);
+ */
+ }
+
+ return popupMenu;
+ }
+
private void createMenuItem(View<?> view, VisualLexicon visualLexicon,
JPopupMenu popupMenu, TaskFactory taskFactory,
Object context, JMenuTracker tracker,
Map<String, Object> properties) {
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
2012-03-23 20:01:13 UTC (rev 28632)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
2012-03-23 20:10:50 UTC (rev 28633)
@@ -5,6 +5,7 @@
import org.cytoscape.event.CyListener;
import org.cytoscape.task.EdgeViewTaskFactory;
+import org.cytoscape.task.NetworkViewLocationTaskFactory;
import org.cytoscape.task.NetworkViewTaskFactory;
import org.cytoscape.task.NodeViewTaskFactory;
import org.cytoscape.work.TaskFactory;
@@ -18,11 +19,13 @@
private Map<EdgeViewTaskFactory, Map<String, Object>>
edgeViewTaskFactories;
private Map<NetworkViewTaskFactory, Map<String, Object>>
networkViewTaskFactories;
+ private Map<NetworkViewLocationTaskFactory, Map<String, Object>>
networkViewLocationTaskFactories;
public TaskFactoryListener() {
nodeViewTaskFactories = new HashMap<NodeViewTaskFactory,
Map<String, Object>>();
edgeViewTaskFactories = new HashMap<EdgeViewTaskFactory,
Map<String, Object>>();
networkViewTaskFactories = new HashMap<NetworkViewTaskFactory,
Map<String, Object>>();
+ networkViewLocationTaskFactories = new
HashMap<NetworkViewLocationTaskFactory, Map<String, Object>>();
}
public void addNodeViewTaskFactory(NodeViewTaskFactory taskFactory,
Map<String, Object> properties) {
@@ -43,6 +46,10 @@
// printTaskFactoryDetails(taskFactory, properties);
}
+ public void
addNetworkViewLocationTaskFactory(NetworkViewLocationTaskFactory taskFactory,
Map<String, Object> properties) {
+ networkViewLocationTaskFactories.put(taskFactory, properties);
+ }
+
public Map<NodeViewTaskFactory, Map<String, Object>>
getNodeViewTaskFactories() {
return nodeViewTaskFactories;
}
@@ -55,6 +62,10 @@
return networkViewTaskFactories;
}
+ public Map<NetworkViewLocationTaskFactory, Map<String, Object>>
getNetworkViewLocationTaskFactories() {
+ return networkViewLocationTaskFactories;
+ }
+
public void removeNodeViewTaskFactory(NodeViewTaskFactory taskFactory,
Map<String, Object> properties) {
nodeViewTaskFactories.put(taskFactory, properties);
}
@@ -67,6 +78,10 @@
networkViewTaskFactories.put(taskFactory, properties);
}
+ public void
removeNetworkViewLocationTaskFactory(NetworkViewLocationTaskFactory
taskFactory, Map<String, Object> properties) {
+ networkViewLocationTaskFactories.put(taskFactory, properties);
+ }
+
private void printTaskFactoryDetails(TaskFactory taskFactory,
Map<String, String> properties) {
System.out.println("TaskFactory added: " + taskFactory);
System.out.println("Properties: " + properties);
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.