use of com.intellij.vcs.log.graph.utils.NormalEdge 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);
}
}
use of com.intellij.vcs.log.graph.utils.NormalEdge 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;
}
use of com.intellij.vcs.log.graph.utils.NormalEdge 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;
}
use of com.intellij.vcs.log.graph.utils.NormalEdge 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;
}
use of com.intellij.vcs.log.graph.utils.NormalEdge in project intellij-community by JetBrains.
the class GraphElementComparatorByLayoutIndex method compare2.
private int compare2(@NotNull GraphEdge edge, @NotNull GraphNode node) {
NormalEdge normalEdge = asNormalEdge(edge);
if (normalEdge == null) {
return getLayoutIndex(getNotNullNodeIndex(edge)) - getLayoutIndex(node.getNodeIndex());
}
int upEdgeLI = getLayoutIndex(normalEdge.up);
int downEdgeLI = getLayoutIndex(normalEdge.down);
int nodeLI = getLayoutIndex(node.getNodeIndex());
if (Math.max(upEdgeLI, downEdgeLI) != nodeLI) {
return Math.max(upEdgeLI, downEdgeLI) - nodeLI;
} else {
return normalEdge.up - node.getNodeIndex();
}
}
Aggregations