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

Fix Some edges not being displayed in the SVG #96

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import i5.las2peer.services.ocd.graphs.CustomGraph;
import org.graphstream.stream.file.FileSinkSVG;

//TODO: Check whether graphstream output acts similarly enough to yFiles output
public class SvgVisualOutputAdapter extends AbstractVisualOutputAdapter {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* @author Sebastian
*
*/
//TODO: Set that edges are always rendered before nodes (previously done in viewer defaults, now those methods arent needed except this one part)
//TODO: text-mode: normal to print labels
//TODO: Currently we need to work solely with the ui.style attribute of elements since the SVG visualization of graphstream refuses to look at other attributes, we should change to use single attributes when it it is possible
public class LayoutHandler {
private static final Color CENTRALITY_COLOR = Color.BLUE;
Expand Down Expand Up @@ -81,7 +79,8 @@ private void setLayoutDefaults(CustomGraph graph, double minNodeSize, double max
*/
double minDegree = graph.getMinWeightedInDegree();
double maxDegree = graph.getMaxWeightedInDegree();
double scalingFactor = (maxNodeSize - minNodeSize) / (maxDegree - minDegree);
double degreeDifference = (maxDegree == minDegree) ? 1.0 : (maxDegree - minDegree);
double scalingFactor = (maxNodeSize - minNodeSize) / degreeDifference;
while(nodesIt.hasNext()) {
node = nodesIt.next();
double curNodeSize = minNodeSize + (graph.getWeightedInDegree(node) - minDegree) * scalingFactor;
Expand Down Expand Up @@ -216,18 +215,13 @@ private void setCentralityLayoutDefaults(CustomGraph graph) {
* Sets the view default attributes, such as the rendering order.
* @param graph the graph view
*/
//TODO: Check if yFiles viewer defaults are mimicked closely enough and add extra styling if not.
private void setViewDefaults(CustomGraph graph) {
// DefaultGraph2DRenderer renderer = new DefaultGraph2DRenderer();
// graph.setGraph2DRenderer(renderer);
// renderer.setDrawEdgesFirst(true);
// graph.fitContent();
graph.setAttribute("ui.stylesheet",
"node {" +
" z-index: 1;" +
" z-index: 2;" +
"}" +
"edge {" +
" z-index: 0;" +
" z-index: 1;" +
"}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public class OrganicGraphLayouter implements GraphLayouter {

@Override
public void doLayout(CustomGraph graph) {
// SmartOrganicLayouter layouter = new SmartOrganicLayouter();
// layouter.setMinimalNodeDistance(45);
// layouter.setConsiderNodeLabelsEnabled(true);
// layouter.setNodeOverlapsAllowed(false);
// layouter.setCompactness(0.2);
graph.setAttribute("ui.stylesheet",
"graph {" +
" padding: 2;" +
Expand All @@ -47,38 +42,25 @@ public void doLayout(CustomGraph graph) {
Edge edge = edgesIt.next();
edge.setAttribute("ui.style", edge.getAttribute("ui.style") + "fill-color: black; shape: line; size: 1.5;");
}
// ParallelEdgeLayouter parallelLayouter = new ParallelEdgeLayouter(layouter);
// parallelLayouter.setDirectedModeEnabled(true);
// parallelLayouter.setLineDistance(10);
// parallelLayouter.setLeadingEdgeAdjustmentEnabled(false);
// parallelLayouter.doLayout(graph);
} else {
Iterator<Edge> edgesIt = graph.edges().iterator();
while(edgesIt.hasNext()) {
Edge edge = edgesIt.next();
edge.setAttribute("ui.style", edge.getAttribute("ui.style") + "fill-color: black; shape: line; size: 1.5;");
}
// OrganicEdgeRouter router = new OrganicEdgeRouter();
// router.setCoreLayouter(layouter);
// router.setEdgeNodeOverlapAllowed(false);
// router.setMinimalDistance(5);
// router.setRoutingAll(true);
// router.setUsingBends(false);
// router.doLayout(graph);
}

//graph.layout.addAttributeSink(graph);
graph.layout.shake();
graph.layout.compute();

while (graph.layout.getStabilization() < 1.0) {
while (graph.layout.getStabilization() < 0.95) {
graph.layout.compute();
}
//TODO:REMOVE
//For Debugging
//System.setProperty("org.graphstream.ui", "swing");
//graph.display();

//while(true);
//TODO:REMOVE
//For Debugging
}
};