Search in sources :

Example 1 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class AbstractPrintElementGenerator method getPrintElements.

@NotNull
public Collection<PrintElementWithGraphElement> getPrintElements(int rowIndex) {
    Collection<PrintElementWithGraphElement> result = new ArrayList<>();
    Collection<SimpleRowElement> simpleRowElements = getSimpleRowElements(rowIndex);
    Map<GraphEdge, SimpleRowElement> arrows = ContainerUtil.newHashMap();
    for (SimpleRowElement rowElement : simpleRowElements) {
        if (!rowElement.myType.equals(RowElementType.NODE)) {
            arrows.put((GraphEdge) rowElement.myElement, rowElement);
        }
    }
    if (rowIndex < myLinearGraph.nodesCount() - 1) {
        for (ShortEdge shortEdge : getDownShortEdges(rowIndex)) {
            RowElementType rowElementType = RowElementType.NODE;
            if ((arrows.get(shortEdge.myEdge) != null) && RowElementType.DOWN_ARROW.equals(arrows.get(shortEdge.myEdge).myType)) {
                rowElementType = RowElementType.DOWN_ARROW;
                arrows.remove(shortEdge.myEdge);
            }
            result.add(createEdgePrintElement(rowIndex, shortEdge, EdgePrintElement.Type.DOWN, !rowElementType.equals(RowElementType.NODE)));
        }
    }
    if (rowIndex > 0) {
        for (ShortEdge shortEdge : getDownShortEdges(rowIndex - 1)) {
            RowElementType rowElementType = RowElementType.NODE;
            if ((arrows.get(shortEdge.myEdge) != null) && RowElementType.UP_ARROW.equals(arrows.get(shortEdge.myEdge).myType)) {
                rowElementType = RowElementType.UP_ARROW;
                arrows.remove(shortEdge.myEdge);
            }
            result.add(createEdgePrintElement(rowIndex, shortEdge, EdgePrintElement.Type.UP, !rowElementType.equals(RowElementType.NODE)));
        }
    }
    for (SimpleRowElement arrow : arrows.values()) {
        result.add(new TerminalEdgePrintElement(rowIndex, arrow.myPosition, arrow.myType == RowElementType.UP_ARROW ? EdgePrintElement.Type.UP : EdgePrintElement.Type.DOWN, (GraphEdge) arrow.myElement, myPrintElementManager));
    }
    for (SimpleRowElement rowElement : simpleRowElements) {
        if (rowElement.myType.equals(RowElementType.NODE)) {
            result.add(createSimplePrintElement(rowIndex, rowElement));
        }
    }
    return result;
}
Also used : PrintElementWithGraphElement(com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement) ArrayList(java.util.ArrayList) TerminalEdgePrintElement(com.intellij.vcs.log.graph.impl.print.elements.TerminalEdgePrintElement) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class ColorGetterByLayoutIndex method getColorId.

public int getColorId(@NotNull GraphElement element) {
    int upNodeIndex, downNodeIndex;
    if (element instanceof GraphNode) {
        upNodeIndex = ((GraphNode) element).getNodeIndex();
        downNodeIndex = upNodeIndex;
    } else {
        GraphEdge edge = (GraphEdge) element;
        NormalEdge normalEdge = LinearGraphUtils.asNormalEdge(edge);
        if (normalEdge != null) {
            upNodeIndex = normalEdge.up;
            downNodeIndex = normalEdge.down;
        } else {
            upNodeIndex = LinearGraphUtils.getNotNullNodeIndex(edge);
            downNodeIndex = upNodeIndex;
        }
    }
    int upLayoutIndex = getLayoutIndex(upNodeIndex);
    int downLayoutIndex = getLayoutIndex(downNodeIndex);
    CommitId headCommitId = getOneOfHeads(upNodeIndex);
    if (upLayoutIndex != downLayoutIndex) {
        return myColorManager.getColorOfFragment(headCommitId, Math.max(upLayoutIndex, downLayoutIndex));
    }
    if (upLayoutIndex == myPermanentGraphInfo.getPermanentGraphLayout().getLayoutIndex(getHeadNodeId(upNodeIndex))) {
        return myColorManager.getColorOfBranch(headCommitId);
    } else {
        return myColorManager.getColorOfFragment(headCommitId, upLayoutIndex);
    }
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 3 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class GraphElementComparatorByLayoutIndex method compare.

@Override
public int compare(@NotNull GraphElement o1, @NotNull GraphElement o2) {
    if (o1 instanceof GraphEdge && o2 instanceof GraphEdge) {
        GraphEdge edge1 = (GraphEdge) o1;
        GraphEdge edge2 = (GraphEdge) o2;
        NormalEdge normalEdge1 = asNormalEdge(edge1);
        NormalEdge normalEdge2 = asNormalEdge(edge2);
        if (normalEdge1 == null)
            return -compare2(edge2, new GraphNode(getNotNullNodeIndex(edge1)));
        if (normalEdge2 == null)
            return compare2(edge1, new GraphNode(getNotNullNodeIndex(edge2)));
        if (normalEdge1.up == normalEdge2.up) {
            if (getLayoutIndex(normalEdge1.down) != getLayoutIndex(normalEdge2.down)) {
                return getLayoutIndex(normalEdge1.down) - getLayoutIndex(normalEdge2.down);
            } else {
                return normalEdge1.down - normalEdge2.down;
            }
        }
        if (normalEdge1.up < normalEdge2.up) {
            return compare2(edge1, new GraphNode(normalEdge2.up));
        } else {
            return -compare2(edge2, new GraphNode(normalEdge1.up));
        }
    }
    if (o1 instanceof GraphEdge && o2 instanceof GraphNode)
        return compare2((GraphEdge) o1, (GraphNode) o2);
    if (o1 instanceof GraphNode && o2 instanceof GraphEdge)
        return -compare2((GraphEdge) o2, (GraphNode) o1);
    // both GraphNode
    assert false;
    return 0;
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) LinearGraphUtils.asNormalEdge(com.intellij.vcs.log.graph.utils.LinearGraphUtils.asNormalEdge) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 4 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class PrintElementGeneratorImpl method getRecommendedWidth.

public int getRecommendedWidth() {
    if (myRecommendedWidth <= 0) {
        int n = Math.min(SAMPLE_SIZE, myLinearGraph.nodesCount());
        double sum = 0;
        double sumSquares = 0;
        int edgesCount = 0;
        Set<NormalEdge> currentNormalEdges = ContainerUtil.newHashSet();
        for (int i = 0; i < n; i++) {
            List<GraphEdge> adjacentEdges = myLinearGraph.getAdjacentEdges(i, EdgeFilter.ALL);
            int upArrows = 0;
            int downArrows = 0;
            for (GraphEdge e : adjacentEdges) {
                NormalEdge normalEdge = asNormalEdge(e);
                if (normalEdge != null) {
                    if (isEdgeUp(e, i)) {
                        currentNormalEdges.remove(normalEdge);
                    } else {
                        currentNormalEdges.add(normalEdge);
                    }
                } else {
                    if (e.getType() == GraphEdgeType.DOTTED_ARROW_UP) {
                        upArrows++;
                    } else {
                        downArrows++;
                    }
                }
            }
            int newEdgesCount = 0;
            for (NormalEdge e : currentNormalEdges) {
                if (isEdgeVisibleInRow(e, i)) {
                    newEdgesCount++;
                } else {
                    RowElementType arrow = getArrowType(e, i);
                    if (arrow == RowElementType.DOWN_ARROW) {
                        downArrows++;
                    } else if (arrow == RowElementType.UP_ARROW) {
                        upArrows++;
                    }
                }
            }
            int width = Math.max(edgesCount + upArrows, newEdgesCount + downArrows);
            /*
         * 0 <= K < 1; weight is an arithmetic progression, starting at 2 / ( n * (k + 1)) ending at k * 2 / ( n * (k + 1))
         * this formula ensures that sum of all weights is 1
         */
            double weight = 2 / (n * (K + 1)) * (1 + (K - 1) * i / (n - 1));
            sum += width * weight;
            sumSquares += width * width * weight;
            edgesCount = newEdgesCount;
        }
        /*
      weighted variance calculation described here:
      http://stackoverflow.com/questions/30383270/how-do-i-calculate-the-standard-deviation-between-weighted-measurements
       */
        double average = sum;
        double deviation = Math.sqrt(sumSquares - average * average);
        myRecommendedWidth = (int) Math.round(average + deviation);
    }
    return myRecommendedWidth;
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 5 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class LinearFragmentGenerator method getRelativeFragment.

@Nullable
public GraphFragment getRelativeFragment(@NotNull GraphElement element) {
    int upNodeIndex;
    int downNodeIndex;
    if (element instanceof GraphNode) {
        upNodeIndex = ((GraphNode) element).getNodeIndex();
        downNodeIndex = upNodeIndex;
    } else {
        NormalEdge graphEdge = LinearGraphUtils.asNormalEdge(((GraphEdge) element));
        if (graphEdge == null)
            return null;
        upNodeIndex = graphEdge.up;
        downNodeIndex = graphEdge.down;
    }
    for (int i = 0; i < MAX_SEARCH_SIZE; i++) {
        GraphFragment graphFragment = getDownFragment(upNodeIndex);
        if (graphFragment != null && graphFragment.downNodeIndex >= downNodeIndex)
            return graphFragment;
        List<Integer> upNodes = myLinearGraph.getNodes(upNodeIndex, UP);
        if (upNodes.size() != 1) {
            break;
        }
        upNodeIndex = upNodes.get(0);
    }
    return null;
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GraphEdge (com.intellij.vcs.log.graph.api.elements.GraphEdge)15 GraphNode (com.intellij.vcs.log.graph.api.elements.GraphNode)9 GraphElement (com.intellij.vcs.log.graph.api.elements.GraphElement)5 NormalEdge (com.intellij.vcs.log.graph.utils.NormalEdge)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 PrintElementWithGraphElement (com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement)2 ArrayList (java.util.ArrayList)2 Pair (com.intellij.openapi.util.Pair)1 SmartList (com.intellij.util.SmartList)1 GraphEdgeType (com.intellij.vcs.log.graph.api.elements.GraphEdgeType)1 TerminalEdgePrintElement (com.intellij.vcs.log.graph.impl.print.elements.TerminalEdgePrintElement)1 EdgeNodeCharConverter.parseGraphEdgeType (com.intellij.vcs.log.graph.parser.EdgeNodeCharConverter.parseGraphEdgeType)1 LinearGraphUtils.asNormalEdge (com.intellij.vcs.log.graph.utils.LinearGraphUtils.asNormalEdge)1 List (java.util.List)1 PriorityQueue (java.util.PriorityQueue)1