Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to various visualization problems #126

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion jung-algorithms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<artifactId>jung-algorithms</artifactId>
<name>JUNG - Algorithms</name>
<description>Algorithms for the JUNG project</description>

<dependencies>
<dependency>
<groupId>net.sf.jung</groupId>
Expand Down
1 change: 0 additions & 1 deletion jung-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Sample programs using JUNG. Nearly all JUNG capabilities are demonstrated here.
Please study the source code for these examples prior to asking how to do something.
</description>

<dependencies>
<dependency>
<groupId>net.sf.jung</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.Renderer;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
Expand Down Expand Up @@ -127,17 +128,19 @@ public void actionPerformed(ActionEvent ae) {
switchLayout.setText("Switch to FRLayout");
layout = new SpringLayout<Number>(g.asGraph(), e -> EDGE_LENGTH);
layout.setSize(d);
vv.getModel().setGraphLayout(layout, d);
vv.setLayoutMediator(new LayoutMediator(g, layout), d);
Layout<Number> delegateLayout =
((LayoutDecorator<Number>) vv.getModel().getGraphLayout()).getDelegate();
((LayoutDecorator<Number>) vv.getModel().getLayoutMediator().getLayout())
.getDelegate();
System.err.println("layout: " + delegateLayout.getClass().getName());
// vv.repaint();
} else {
switchLayout.setText("Switch to SpringLayout");
layout = new FRLayout<Number>(g.asGraph(), d);
vv.getModel().setGraphLayout(layout, d);
vv.setLayoutMediator(new LayoutMediator(g, layout), d);
Layout<Number> delegateLayout =
((LayoutDecorator<Number>) vv.getModel().getGraphLayout()).getDelegate();
((LayoutDecorator<Number>) vv.getModel().getLayoutMediator().getLayout())
.getDelegate();
System.err.println("layout: " + delegateLayout.getClass().getName());
// vv.repaint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import edu.uci.ics.jung.visualization.layout.LayoutTransition;
import edu.uci.ics.jung.visualization.renderers.Renderer;
import edu.uci.ics.jung.visualization.util.Animator;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
Expand Down Expand Up @@ -137,7 +138,8 @@ public void actionPerformed(ActionEvent ae) {
relaxer.prerelax();
StaticLayout<Number> staticLayout = new StaticLayout<Number>(g.asGraph(), layout);
LayoutTransition<Number, Number> lt =
new LayoutTransition<Number, Number>(vv, vv.getGraphLayout(), staticLayout);
new LayoutTransition<Number, Number>(
vv, vv.getModel().getLayoutMediator(), new LayoutMediator(g, staticLayout));
Animator animator = new Animator(lt);
animator.start();
vv.repaint();
Expand All @@ -151,7 +153,8 @@ public void actionPerformed(ActionEvent ae) {
relaxer.prerelax();
StaticLayout<Number> staticLayout = new StaticLayout<Number>(g.asGraph(), layout);
LayoutTransition<Number, Number> lt =
new LayoutTransition<Number, Number>(vv, vv.getGraphLayout(), staticLayout);
new LayoutTransition<Number, Number>(
vv, vv.getModel().getLayoutMediator(), new LayoutMediator(g, staticLayout));
Animator animator = new Animator(lt);
animator.start();
vv.repaint();
Expand Down Expand Up @@ -208,7 +211,8 @@ public void process() {
relaxer.prerelax();
StaticLayout<Number> staticLayout = new StaticLayout<Number>(g.asGraph(), layout);
LayoutTransition<Number, Number> lt =
new LayoutTransition<Number, Number>(vv, vv.getGraphLayout(), staticLayout);
new LayoutTransition<Number, Number>(
vv, vv.getModel().getLayoutMediator(), new LayoutMediator(g, staticLayout));
Animator animator = new Animator(lt);
animator.start();
// vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import edu.uci.ics.jung.visualization.transform.shape.HyperbolicShapeTransformer;
import edu.uci.ics.jung.visualization.transform.shape.ViewLensSupport;
import edu.uci.ics.jung.visualization.util.Animator;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
Expand Down Expand Up @@ -147,7 +148,10 @@ public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {

LayoutTransition<String, Integer> lt =
new LayoutTransition<String, Integer>(vv, layout, radialLayout);
new LayoutTransition<String, Integer>(
vv,
vv.getModel().getLayoutMediator(),
new LayoutMediator(graph, radialLayout));
Animator animator = new Animator(lt);
animator.start();
vv.getRenderContext()
Expand All @@ -158,7 +162,8 @@ public void itemStateChanged(ItemEvent e) {
} else {

LayoutTransition<String, Integer> lt =
new LayoutTransition<String, Integer>(vv, radialLayout, layout);
new LayoutTransition<String, Integer>(
vv, vv.getModel().getLayoutMediator(), new LayoutMediator(graph, layout));
Animator animator = new Animator(lt);
animator.start();
vv.getRenderContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private void colorCluster(Set<Number> vertices, Color c) {
}

private void groupCluster(AggregateLayout<Number> layout, Set<Number> vertices) {
if (vertices.size() < vv.getModel().getNetwork().nodes().size()) {
if (vertices.size() < vv.getModel().getLayoutMediator().getLayout().nodes().size()) {
Point2D center = layout.apply(vertices.iterator().next());
MutableNetwork<Number, Number> subGraph = NetworkBuilder.undirected().build();
for (Number v : vertices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.EdgeLabelRenderer;
import edu.uci.ics.jung.visualization.renderers.VertexLabelRenderer;
import edu.uci.ics.jung.visualization.util.Context;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
Expand Down Expand Up @@ -204,7 +205,7 @@ public Dimension getPreferredSize() {
@SuppressWarnings("rawtypes")
public void stateChanged(ChangeEvent e) {
JSlider s = (JSlider) e.getSource();
Function<? super Number, Shape> edgeShapeFunction =
Function<Context<Network, Number>, Shape> edgeShapeFunction =
vv.getRenderContext().getEdgeShapeTransformer();
if (edgeShapeFunction instanceof ParallelEdgeShapeTransformer) {
((ParallelEdgeShapeTransformer) edgeShapeFunction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Number get() {
vv.addGraphMouseListener(new TestGraphMouseListener<Number>());
vv.getRenderer()
.setVertexRenderer(
new GradientVertexRenderer<Number>(
new GradientVertexRenderer<Number, Number>(
vv, Color.white, Color.red, Color.white, Color.blue, false));

// add my listeners for ToolTips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public boolean useTransform() {
vv.addGraphMouseListener(new TestGraphMouseListener<Integer>());
vv.getRenderer()
.setVertexRenderer(
new GradientVertexRenderer<Integer>(
new GradientVertexRenderer<Integer, Number>(
vv, Color.white, Color.red, Color.white, Color.blue, false));
vv.getRenderContext().setEdgeDrawPaintTransformer(e -> Color.lightGray);
vv.getRenderContext().setArrowFillPaintTransformer(a -> Color.lightGray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.layout.LayoutTransition;
import edu.uci.ics.jung.visualization.util.Animator;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
Expand Down Expand Up @@ -133,14 +134,18 @@ public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {

LayoutTransition<String, Integer> lt =
new LayoutTransition<String, Integer>(vv, treeLayout, radialLayout);
new LayoutTransition<String, Integer>(
vv,
vv.getModel().getLayoutMediator(),
new LayoutMediator(graph, radialLayout));
Animator animator = new Animator(lt);
animator.start();
vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
vv.addPreRenderPaintable(rings);
} else {
LayoutTransition<String, Integer> lt =
new LayoutTransition<String, Integer>(vv, radialLayout, treeLayout);
new LayoutTransition<String, Integer>(
vv, vv.getModel().getLayoutMediator(), new LayoutMediator(graph, treeLayout));
Animator animator = new Animator(lt);
animator.start();
vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
Expand All @@ -166,7 +171,7 @@ public void itemStateChanged(ItemEvent e) {
}

private void setLtoR(VisualizationViewer<String, Integer> vv) {
Layout<String> layout = vv.getModel().getGraphLayout();
Layout<String> layout = vv.getModel().getLayoutMediator().getLayout();
Dimension d = layout.getSize();
Point2D center = new Point2D.Double(d.width / 2, d.height / 2);
vv.getRenderContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import edu.uci.ics.jung.visualization.transform.shape.HyperbolicShapeTransformer;
import edu.uci.ics.jung.visualization.transform.shape.MagnifyShapeTransformer;
import edu.uci.ics.jung.visualization.transform.shape.ViewLensSupport;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
Expand Down Expand Up @@ -277,7 +278,7 @@ public void itemStateChanged(ItemEvent e) {

public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
visualizationModel.setGraphLayout(graphLayout);
visualizationModel.setLayoutMediator(new LayoutMediator(graph, graphLayout));
vv.getRenderContext().setVertexShapeTransformer(ovals);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.repaint();
Expand All @@ -290,7 +291,7 @@ public void itemStateChanged(ItemEvent e) {

public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
visualizationModel.setGraphLayout(gridLayout);
visualizationModel.setLayoutMediator(new LayoutMediator(graph, gridLayout));
vv.getRenderContext().setVertexShapeTransformer(squares);
vv.getRenderContext().setVertexLabelTransformer(n -> null);
vv.repaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public Number get() {
edgeFactory,
4,
3);
generator.evolveGraph(20);
generator.evolveGraph(200);
MutableNetwork<Integer, Number> g = generator.get();
for (Number e : g.edges()) {
edge_weight.put(e, Math.random());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public SatelliteViewDemo() {
new PickableVertexPaintTransformer<String>(
vv2.getPickedVertexState(), Color.red, Color.yellow));
vv1.getRenderer()
.setVertexRenderer(new GradientVertexRenderer<String>(vv1, Color.red, Color.white, true));
.setVertexRenderer(
new GradientVertexRenderer<String, Number>(vv1, Color.red, Color.white, true));
vv1.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv1.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void paint(Graphics g) {
p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
Renderer<String, Number> renderer = vv.getRenderer();
renderer.renderEdge(e);
renderer.renderEdge(vv.getRenderContext(), vv.getModel().getLayoutMediator(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import edu.uci.ics.jung.visualization.decorators.PickableVertexPaintTransformer;
import edu.uci.ics.jung.visualization.layout.LayoutTransition;
import edu.uci.ics.jung.visualization.util.Animator;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
Expand Down Expand Up @@ -97,11 +98,16 @@ public void actionPerformed(ActionEvent arg0) {
Layouts layoutType = (Layouts) jcb.getSelectedItem();
try {
// TODO: is this the right input network? or should it be g_array[graph_index]?
Layout<Integer> layout = createLayout(layoutType, vv.getModel().getNetwork());
Network network = g_array[graph_index];
Layout<Integer> layout = createLayout(layoutType, network);
layout.setInitializer(vv.getGraphLayout());
layout.setSize(vv.getSize());
System.err.println("using graph " + graph_names[graph_index]);
System.err.println("using layout: " + layout.getClass());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomnelson I'm a bit puzzled by these System.err.println statements. Did you mean to leave them in? If so, could you explain your reasoning to me?


LayoutTransition<Integer, Number> lt =
new LayoutTransition<>(vv, vv.getGraphLayout(), layout);
new LayoutTransition<Integer, Number>(
vv, vv.getModel().getLayoutMediator(), new LayoutMediator(network, layout));
Animator animator = new Animator(lt);
animator.start();
vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
Expand Down Expand Up @@ -238,20 +244,20 @@ public void start() {
this.getContentPane().add(getGraphPanel());
}

private static <N, E> Layout<N> createLayout(Layouts layoutType, Network<N, E> network) {
private static Layout createLayout(Layouts layoutType, Network network) {
switch (layoutType) {
case CIRCLE:
return new CircleLayout<N>(network.asGraph());
return new CircleLayout(network.asGraph());
case FRUCHTERMAN_REINGOLD:
return new FRLayout<N>(network.asGraph());
return new FRLayout(network.asGraph());
case KAMADA_KAWAI:
return new KKLayout<N>(network.asGraph());
return new KKLayout(network.asGraph());
case SELF_ORGANIZING_MAP:
return new ISOMLayout<N, E>(network);
return new ISOMLayout(network);
case SPRING:
return new SpringLayout<N>(network.asGraph());
return new SpringLayout(network.asGraph());
case SPRING2:
return new SpringLayout2<N>(network.asGraph());
return new SpringLayout2(network.asGraph());
default:
throw new IllegalArgumentException("Unrecognized layout type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
*/
package edu.uci.ics.jung.samples;

import com.google.common.graph.EndpointPair;
import com.google.common.graph.MutableNetwork;
import com.google.common.graph.Network;
import com.google.common.graph.NetworkBuilder;
import com.google.common.graph.*;
import edu.uci.ics.jung.algorithms.layout.AggregateLayout;
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.FRLayout;
Expand All @@ -31,6 +28,7 @@
import edu.uci.ics.jung.visualization.decorators.PickableVertexPaintTransformer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.picking.PickedState;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
Expand Down Expand Up @@ -205,7 +203,7 @@ public void itemStateChanged(ItemEvent e) {
Layout<String> layout = getLayoutFor(clazz, graph);
layout.setInitializer(vv.getGraphLayout());
clusteringLayout.setDelegate(layout);
vv.setGraphLayout(clusteringLayout);
vv.setLayoutMediator(new LayoutMediator(graph, clusteringLayout));
} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down Expand Up @@ -333,8 +331,8 @@ private void heightConstrain(Component component) {
// TODO: needs refactoring to create the layout; see VertexCollapseDemoWithLayouts
private Layout<String> getLayoutFor(
Class<CircleLayout> layoutClass, Network<String, Number> graph) throws Exception {
Object[] args = new Object[] {graph};
Constructor<CircleLayout> constructor = layoutClass.getConstructor(new Class[] {Network.class});
Object[] args = new Object[] {graph.asGraph()};
Constructor<CircleLayout> constructor = layoutClass.getConstructor(Graph.class);
return constructor.newInstance(args);
}

Expand Down Expand Up @@ -383,7 +381,7 @@ private void cluster(boolean state) {
subLayout.setInitializer(vv.getGraphLayout());
subLayout.setSize(subLayoutSize);
clusteringLayout.put(subLayout, center);
vv.setGraphLayout(clusteringLayout);
vv.setLayoutMediator(new LayoutMediator(graph, clusteringLayout));

} catch (Exception e) {
e.printStackTrace();
Expand All @@ -392,7 +390,7 @@ private void cluster(boolean state) {
} else {
// remove all sublayouts
this.clusteringLayout.removeAll();
vv.setGraphLayout(clusteringLayout);
vv.setLayoutMediator(new LayoutMediator(graph, clusteringLayout));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import edu.uci.ics.jung.visualization.decorators.EllipseVertexShapeTransformer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.subLayout.TreeCollapser;
import edu.uci.ics.jung.visualization.util.LayoutMediator;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
Expand Down Expand Up @@ -137,11 +138,11 @@ public void actionPerformed(ActionEvent e) {

public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
vv.setGraphLayout(radialLayout);
vv.setLayoutMediator(new LayoutMediator(graph, radialLayout));
vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
vv.addPreRenderPaintable(rings);
} else {
vv.setGraphLayout(layout);
vv.setLayoutMediator(new LayoutMediator(graph, layout));
vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
vv.removePreRenderPaintable(rings);
}
Expand Down
Loading