[vcs-log] more precise graph width calculation appcode/171.139 clion/171.140 phpstorm/171.141
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sun, 16 Oct 2016 05:32:31 +0000 (08:32 +0300)
committerJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sun, 16 Oct 2016 05:32:31 +0000 (08:32 +0300)
Take into account position of the edges on the other row.

platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java

index 1aaf1f8235077c245973eec28b2827c3e9969b44..bf43444298f20c47bd38d493ada16fe6053f7c48 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.util.ui.UIUtil;
 import com.intellij.vcs.log.VcsRef;
 import com.intellij.vcs.log.VcsRefType;
 import com.intellij.vcs.log.data.VcsLogData;
+import com.intellij.vcs.log.graph.EdgePrintElement;
 import com.intellij.vcs.log.graph.PrintElement;
 import com.intellij.vcs.log.graph.VisibleGraph;
 import com.intellij.vcs.log.paint.GraphCellPainter;
@@ -165,19 +166,24 @@ public class GraphCommitCellRenderer extends ColoredTableCellRenderer {
   private PaintInfo getGraphImage(int row) {
     VisibleGraph<Integer> graph = myGraphTable.getVisibleGraph();
     Collection<? extends PrintElement> printElements = graph.getRowInfo(row).getPrintElements();
-    int maxIndex = 0;
+    double maxIndex = 0;
     for (PrintElement printElement : printElements) {
       maxIndex = Math.max(maxIndex, printElement.getPositionInCurrentRow());
+      if (printElement instanceof EdgePrintElement) {
+        maxIndex = Math.max(maxIndex,
+                            (printElement.getPositionInCurrentRow() + ((EdgePrintElement)printElement).getPositionInOtherRow()) / 2.0);
+      }
     }
     maxIndex++;
+
     maxIndex = Math.max(maxIndex, Math.min(MAX_GRAPH_WIDTH, graph.getRecommendedWidth()));
-    final BufferedImage image = UIUtil
-      .createImage(PaintParameters.getNodeWidth(myGraphTable.getRowHeight()) * (maxIndex + 4), myGraphTable.getRowHeight(),
-                   BufferedImage.TYPE_INT_ARGB);
+    BufferedImage image = UIUtil.createImage((int)(PaintParameters.getNodeWidth(myGraphTable.getRowHeight()) * (maxIndex + 2)),
+                                             myGraphTable.getRowHeight(),
+                                             BufferedImage.TYPE_INT_ARGB);
     Graphics2D g2 = image.createGraphics();
     myPainter.draw(g2, printElements);
 
-    int width = maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight());
+    int width = (int)(maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight()));
     return new PaintInfo(image, width);
   }