File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
visualizer/IdealGraphVisualizer/Graph/src/main/java/org/graalvm/visualizer/graph Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments