Skip to content

Commit

Permalink
8344204: IGV: Button to enable/disable cutting of long edges
Browse files Browse the repository at this point in the history
Reviewed-by: rcastanedalo, chagedorn
  • Loading branch information
tobiasholenstein committed Nov 18, 2024
1 parent 4a7ce1d commit 6c2ae44
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public HierarchicalCFGLayoutManager() {
fontMetrics = canvas.getFontMetrics(font);
}

@Override
public void setCutEdges(boolean enable) {
subManager.setCutEdges(enable);
manager.setCutEdges(enable);
}

public void setSubManager(LayoutManager manager) {
this.subManager = manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public HierarchicalClusterLayoutManager(HierarchicalLayoutManager.Combine combin
this.combine = combine;
}

@Override
public void setCutEdges(boolean enable) {
subManager.setCutEdges(enable);
manager.setCutEdges(enable);
}

public void doLayout(LayoutGraph graph, Set<? extends Link> importantLinks) {
doLayout(graph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ public void setLayerOffset(int layerOffset) {
this.layerOffset = layerOffset;
}

public void setMaxLayerLength(int v) {
maxLayerLength = v;
@Override
public void setCutEdges(boolean enable) {
maxLayerLength = enable ? 10 : -1;
}

public void setMinLayerDifference(int v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class HierarchicalStableLayoutManager {
public static final int X_OFFSET = 8;
public static final int LAYER_OFFSET = 8;
// Algorithm global data structures
private HashSet<? extends Vertex> currentVertices;
private HashSet<? extends Link> currentLinks;
private Set<? extends Vertex> currentVertices;
private Set<? extends Link> currentLinks;
private Set<Link> reversedLinks;
private List<LayoutNode> nodes;
private final HashMap<Vertex, LayoutNode> vertexToLayoutNode;
Expand All @@ -51,10 +51,19 @@ public class HierarchicalStableLayoutManager {
private HashMap<Vertex, VertexAction> vertexToAction;
private List<VertexAction> vertexActions;
private List<LinkAction> linkActions;
private HashSet<? extends Vertex> oldVertices;
private HashSet<? extends Link> oldLinks;
private Set<? extends Vertex> oldVertices;
private Set<? extends Link> oldLinks;
private boolean shouldRedrawLayout = true;
private boolean shouldRemoveEmptyLayers = true;
private boolean cutEdges = false;

public void doLayout(LayoutGraph layoutGraph) {
boolean oldShouldRedrawLayout = shouldRedrawLayout;
setShouldRedrawLayout(true);
updateLayout(layoutGraph.getVertices(), layoutGraph.getLinks());
setShouldRedrawLayout(oldShouldRedrawLayout);
}


enum Action {
ADD,
Expand Down Expand Up @@ -90,6 +99,15 @@ public HierarchicalStableLayoutManager() {
nodes = new ArrayList<>();
}

public void setCutEdges(boolean enable) {
cutEdges = enable;
manager.setCutEdges(enable);
}

public boolean getCutEdges() {
return cutEdges;
}

private int calculateOptimalBoth(LayoutNode n) {
if (n.preds.isEmpty() && n.succs.isEmpty()) {
return n.x;
Expand Down Expand Up @@ -396,7 +414,7 @@ public void setShouldRedrawLayout(boolean shouldRedrawLayout) {
this.shouldRedrawLayout = shouldRedrawLayout;
}

public void updateLayout(HashSet<? extends Vertex> vertices, HashSet<? extends Link> links) {
public void updateLayout(Set<? extends Vertex> vertices, Set<? extends Link> links) {
currentVertices = vertices;
currentLinks = links;
reversedLinks = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public LinearLayoutManager(Map<? extends Vertex, Integer> vertexRank) {
this.vertexRank = vertexRank;
}

@Override
public void setCutEdges(boolean enable) {}

@Override
public void doLayout(LayoutGraph graph) {
doLayout(graph, new HashSet<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
public interface LayoutManager {

void setCutEdges(boolean enable);

void doLayout(LayoutGraph graph);

void doLayout(LayoutGraph graph, Set<? extends Link> importantLinks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,20 +700,27 @@ private boolean isVisible(Connection c) {
}

private void doStableSeaLayout(HashSet<Figure> visibleFigures, HashSet<Connection> visibleConnections) {
hierarchicalStableLayoutManager.updateLayout(visibleFigures, visibleConnections);
boolean enable = model.getCutEdges();
boolean previous = hierarchicalStableLayoutManager.getCutEdges();
hierarchicalStableLayoutManager.setCutEdges(enable);
if (enable != previous) {
hierarchicalStableLayoutManager.doLayout(new LayoutGraph(visibleConnections, visibleFigures));
} else {
hierarchicalStableLayoutManager.updateLayout(visibleFigures, visibleConnections);
}
}

private void doSeaLayout(HashSet<Figure> figures, HashSet<Connection> edges) {
HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
manager.setMaxLayerLength(10);
manager.setCutEdges(model.getCutEdges());
manager.doLayout(new LayoutGraph(edges, figures));
hierarchicalStableLayoutManager.setShouldRedrawLayout(true);
}

private void doClusteredLayout(HashSet<Connection> edges) {
HierarchicalClusterLayoutManager m = new HierarchicalClusterLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
manager.setMaxLayerLength(9);
manager.setCutEdges(model.getCutEdges());
manager.setMinLayerDifference(3);
m.setManager(manager);
m.setSubManager(new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS));
Expand All @@ -724,7 +731,7 @@ private void doCFGLayout(HashSet<Figure> figures, HashSet<Connection> edges) {
Diagram diagram = getModel().getDiagram();
HierarchicalCFGLayoutManager m = new HierarchicalCFGLayoutManager();
HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
manager.setMaxLayerLength(9);
manager.setCutEdges(model.getCutEdges());
manager.setMinLayerDifference(1);
manager.setLayoutSelfEdges(true);
manager.setXOffset(25);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.sun.hotspot.igv.graph.MatcherSelector;
import com.sun.hotspot.igv.settings.Settings;
import com.sun.hotspot.igv.util.RangeSliderModel;
import com.sun.hotspot.igv.view.actions.CutEdgesAction;
import com.sun.hotspot.igv.view.actions.GlobalSelectionAction;
import java.awt.Color;
import java.util.*;
Expand Down Expand Up @@ -68,8 +69,8 @@ public class DiagramViewModel extends RangeSliderModel implements ChangedListene
private boolean showCFG;
private boolean showNodeHull;
private boolean showEmptyBlocks;
private boolean hideDuplicates;
private static boolean globalSelection = false;
private static boolean cutEdges = false;

private final ChangedListener<FilterChain> filterChainChangedListener = changedFilterChain -> {
assert filterChain == changedFilterChain;
Expand All @@ -80,6 +81,18 @@ public Group getGroup() {
return group;
}

public boolean getCutEdges() {
return cutEdges;
}

public void setCutEdges(boolean enable, boolean fire) {
boolean prevEnable = cutEdges;
cutEdges = enable;
if (fire && prevEnable != enable) {
diagramChangedEvent.fire();
}
}

public boolean getGlobalSelection() {
return globalSelection;
}
Expand Down Expand Up @@ -154,25 +167,6 @@ public void setShowEmptyBlocks(boolean b) {
diagramChangedEvent.fire();
}

public void setHideDuplicates(boolean hideDuplicates) {
this.hideDuplicates = hideDuplicates;
InputGraph currentGraph = getFirstGraph();
if (hideDuplicates) {
// Back up to the unhidden equivalent graph
int index = graphs.indexOf(currentGraph);
while (graphs.get(index).getProperties().get("_isDuplicate") != null) {
index--;
}
currentGraph = graphs.get(index);
}
filterGraphs();
selectGraph(currentGraph);
}

public boolean getHideDuplicates() {
return hideDuplicates;
}

private void initGroup() {
group.getChangedEvent().addListener(g -> {
assert g == group;
Expand All @@ -191,6 +185,7 @@ private void initGroup() {
public DiagramViewModel(DiagramViewModel model) {
super(model);
globalSelection = false;
cutEdges = false;
group = model.getGroup();
initGroup();
graphs = new ArrayList<>(model.graphs);
Expand All @@ -205,12 +200,12 @@ public DiagramViewModel(DiagramViewModel model) {
filtersOrder = provider.getAllFiltersOrdered();

globalSelection = GlobalSelectionAction.get(GlobalSelectionAction.class).isSelected();
cutEdges = CutEdgesAction.get(CutEdgesAction.class).isSelected();
showCFG = model.getShowCFG();
showSea = model.getShowSea();
showBlocks = model.getShowBlocks();
showNodeHull = model.getShowNodeHull();
showEmptyBlocks = model.getShowEmptyBlocks();
hideDuplicates = model.getHideDuplicates();

hiddenNodes = new HashSet<>(model.getHiddenNodes());
selectedNodes = new HashSet<>();
Expand All @@ -228,13 +223,13 @@ public DiagramViewModel(InputGraph graph) {
filtersOrder = provider.getAllFiltersOrdered();

globalSelection = GlobalSelectionAction.get(GlobalSelectionAction.class).isSelected();
cutEdges = CutEdgesAction.get(CutEdgesAction.class).isSelected();
showStableSea = Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.STABLE_SEA_OF_NODES;
showSea = Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.SEA_OF_NODES;
showBlocks = Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.CLUSTERED_SEA_OF_NODES;
showCFG = Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.CONTROL_FLOW_GRAPH;
showNodeHull = true;
showEmptyBlocks = true;
hideDuplicates = false;

hiddenNodes = new HashSet<>();
selectedNodes = new HashSet<>();
Expand Down Expand Up @@ -422,11 +417,8 @@ private void filterGraphs() {
ArrayList<InputGraph> result = new ArrayList<>();
List<String> positions = new ArrayList<>();
for (InputGraph graph : group.getGraphs()) {
String duplicate = graph.getProperties().get("_isDuplicate");
if (duplicate == null || !hideDuplicates) {
result.add(graph);
positions.add(graph.getName());
}
result.add(graph);
positions.add(graph.getName());
}
this.graphs = result;
setPositions(positions);
Expand Down Expand Up @@ -460,22 +452,12 @@ public InputGraph getSecondGraph() {

public void selectGraph(InputGraph graph) {
int index = graphs.indexOf(graph);
if (index == -1 && hideDuplicates) {
// A graph was selected that's currently hidden, so unhide and select it.
setHideDuplicates(false);
index = graphs.indexOf(graph);
}
assert index != -1;
setPositions(index, index);
}

public void selectDiffGraph(InputGraph graph) {
int index = graphs.indexOf(graph);
if (index == -1 && hideDuplicates) {
// A graph was selected that's currently hidden, so unhide and select it.
setHideDuplicates(false);
index = graphs.indexOf(graph);
}
assert index != -1;
int firstIndex = getFirstPosition();
int secondIndex = getSecondPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public void mouseMoved(MouseEvent e) {}
toolBar.addSeparator();
toolBar.add(new JToggleButton(new PredSuccAction(diagramViewModel.getShowNodeHull())));
toolBar.add(new JToggleButton(new ShowEmptyBlocksAction(cfgLayoutAction, diagramViewModel.getShowEmptyBlocks())));
toolBar.add(new JToggleButton(new HideDuplicatesAction(diagramViewModel.getHideDuplicates())));

toolBar.addSeparator();
UndoAction undoAction = UndoAction.get(UndoAction.class);
Expand All @@ -221,6 +220,11 @@ public void mouseMoved(MouseEvent e) {}
toolBar.add(redoAction);

toolBar.addSeparator();

JToggleButton cutEdgesButton = new JToggleButton(CutEdgesAction.get(CutEdgesAction.class));
cutEdgesButton.setHideActionText(true);
toolBar.add(cutEdgesButton);

JToggleButton globalSelectionButton = new JToggleButton(GlobalSelectionAction.get(GlobalSelectionAction.class));
globalSelectionButton.setHideActionText(true);
toolBar.add(globalSelectionButton);
Expand Down Expand Up @@ -453,6 +457,7 @@ public TopComponent cloneComponent() {
}
etc.addSelectedNodes(selectedNodes, false);
model.setGlobalSelection(GlobalSelectionAction.get(GlobalSelectionAction.class).isSelected(), false);
model.setCutEdges(CutEdgesAction.get(CutEdgesAction.class).isSelected(), false);
etc.resetUndoRedo();

int currentZoomLevel = scene.getZoomPercentage();
Expand Down
Loading

1 comment on commit 6c2ae44

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.