Skip to content

Commit f002da4

Browse files
committed
Avoid wrapping inputs and outputs when computing widths
1 parent 50b2bb7 commit f002da4

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

visualizer/IdealGraphVisualizer/Graph/src/main/java/org/graalvm/visualizer/graph/Figure.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ public static int getSlotsWidth(Collection<? extends Slot> slots) {
152152
return result;
153153
}
154154

155+
public int getSlotsWidthBefore(InputSlot inputSlot) {
156+
int result = Figure.SLOT_OFFSET;
157+
for (Slot s : inputSlots) {
158+
if (s == inputSlot) {
159+
return result;
160+
}
161+
result += s.getWidth() + Figure.SLOT_OFFSET;
162+
}
163+
return result;
164+
}
165+
155166
public static int getSlotsWidth(Slot s) {
156167
if (s == null) {
157168
return Figure.SLOT_OFFSET;
@@ -405,6 +416,10 @@ public List<InputSlot> getInputSlots() {
405416
return Collections.unmodifiableList(inputSlots);
406417
}
407418

419+
int getInputSlotsWidth() {
420+
return Figure.getSlotsWidth(inputSlots);
421+
}
422+
408423
public Set<Slot> getSlots() {
409424
Set<Slot> result = new HashSet<>();
410425
result.addAll(getInputSlots());
@@ -422,6 +437,17 @@ public List<OutputSlot> getOutputSlots() {
422437
}
423438
}
424439

440+
441+
public int getOutputSlotsWidth() {
442+
if (outputSlots != null) {
443+
return Figure.getSlotsWidth(outputSlots);
444+
} else if (singleOutput != null) {
445+
return Figure.getSlotsWidth(Collections.singletonList(singleOutput));
446+
} else {
447+
return 0;
448+
}
449+
}
450+
425451
void removeInputSlot(InputSlot s, HashSet<Object> cleaned) {
426452
s.removeAllConnections(cleaned);
427453
inputSlots.remove(s);

visualizer/IdealGraphVisualizer/Graph/src/main/java/org/graalvm/visualizer/graph/InputSlot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ protected Slot copyInto(Figure f) {
4343

4444
@Override
4545
public Point getRelativePosition() {
46-
int gap = getFigure().getWidth() - Figure.getSlotsWidth(getFigure().getInputSlots());
46+
int gap = getFigure().getWidth() - getFigure().getInputSlotsWidth();
4747
if (gap < 0) {
4848
gap = 0;
4949
}
5050
double gapRatio = (double) gap / (double) (getFigure().getInputSlots().size() + 1);
5151
int gapAmount = (int) ((getPosition() + 1) * gapRatio);
52-
return new Point(gapAmount + Figure.getSlotsWidth(Figure.getAllBefore(getFigure().getInputSlots(), this)) + getWidth() / 2, -Figure.SLOT_START);
52+
return new Point(gapAmount + getFigure().getSlotsWidthBefore(this) + getWidth() / 2, -Figure.SLOT_START);
5353
}
5454

5555
@Override

visualizer/IdealGraphVisualizer/Graph/src/main/java/org/graalvm/visualizer/graph/OutputSlot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected Slot copyInto(Figure f) {
4242

4343
@Override
4444
public Point getRelativePosition() {
45-
int gap = getFigure().getWidth() - Figure.getSlotsWidth(getFigure().getOutputSlots());
45+
int gap = getFigure().getWidth() - getFigure().getOutputSlotsWidth();
4646
if (gap < 0) {
4747
gap = 0;
4848
}

0 commit comments

Comments
 (0)