Skip to content

Commit

Permalink
gitextensions#5125 RevisionGrid Graph: Nearest branch in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mstv committed Oct 23, 2018
1 parent de336b7 commit ec9a44a
Show file tree
Hide file tree
Showing 12 changed files with 962 additions and 80 deletions.
2 changes: 1 addition & 1 deletion GitCommands/GitCommands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<PackageReference Include="JetBrains.Annotations" Version="11.1.0" />
<PackageReference Include="System.IO.Abstractions" Version="2.0.0.144" />
<PackageReference Include="System.Reactive.Linq" Version="3.1.1" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
Expand Down
2 changes: 1 addition & 1 deletion GitExtUtils/GitExtUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="11.1.0" />
<PackageReference Include="System.ValueTuple">
<Version>4.4.0</Version>
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
2 changes: 2 additions & 0 deletions GitUI/GitUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@
<Compile Include="UserControls\GitItemStatusWithParent.cs" />
<Compile Include="UserControls\RevisionGrid\CellStyle.cs" />
<Compile Include="UserControls\ListViewGroupHitInfo.cs" />
<Compile Include="UserControls\RevisionGrid\Graph\LaneInfoProvider.cs" />
<Compile Include="UserControls\RevisionGrid\Graph\LaneNodeLocator.cs" />
<Compile Include="UserControls\RevisionGrid\Graph\JunctionColorProvider.cs" />
<Compile Include="UserControls\RevisionGrid\Graph\JunctionStyler.cs" />
<Compile Include="UserControls\RevisionGrid\Columns\MultilineIndicator.cs" />
Expand Down
93 changes: 17 additions & 76 deletions GitUI/UserControls/RevisionGrid/Columns/GraphColumnProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GitCommands;
using GitExtUtils.GitUI;
Expand All @@ -17,13 +16,12 @@ namespace GitUI.UserControls.RevisionGrid.Columns
internal sealed class GraphColumnProvider : ColumnProvider
{
private const int MaxLanes = 40;

private static readonly int _nodeDimension = DpiUtil.Scale(10);
private static readonly int _laneWidth = DpiUtil.Scale(16);
private static readonly int _laneLineWidth = DpiUtil.Scale(2);
private static readonly int LaneLineWidth = DpiUtil.Scale(2);
private static readonly int LaneWidth = DpiUtil.Scale(16);
private static readonly int NodeDimension = DpiUtil.Scale(10);

private readonly JunctionStyler _junctionStyler = new JunctionStyler(new JunctionColorProvider());

private readonly LaneInfoProvider _laneInfoProvider;
private readonly RevisionGridControl _grid;
private readonly GraphModel _graphModel;

Expand All @@ -41,6 +39,7 @@ public GraphColumnProvider(RevisionGridControl grid, GraphModel graphModel)
{
_grid = grid;
_graphModel = graphModel;
_laneInfoProvider = new LaneInfoProvider(new LaneNodeLocator(_graphModel));

// TODO is it worth creating a lighter-weight column type?

Expand Down Expand Up @@ -251,7 +250,7 @@ void EnsureCacheIsLargeEnough()
}

_graphBitmap = new Bitmap(
Math.Max(width, _laneWidth * 3),
Math.Max(width, LaneWidth * 3),
height,
PixelFormat.Format32bppPArgb);
_graphBitmapGraphics = Graphics.FromImage(_graphBitmap);
Expand Down Expand Up @@ -286,7 +285,7 @@ bool DrawItem(Graphics g, ILaneRow row)

for (int lane = 0; lane < row.Count; lane++)
{
int mid = g.RenderingOrigin.X + (int)((lane + 0.5) * _laneWidth);
int mid = g.RenderingOrigin.X + (int)((lane + 0.5) * LaneWidth);

for (int item = 0; item < row.LaneInfoCount(lane); item++)
{
Expand All @@ -304,13 +303,13 @@ bool DrawItem(Graphics g, ILaneRow row)
bool sameLane = laneInfo.ConnectLane == lane;
int x0 = mid;
int y0 = top - 1;
int x1 = sameLane ? x0 : mid + ((laneInfo.ConnectLane - lane) * _laneWidth);
int x1 = sameLane ? x0 : mid + ((laneInfo.ConnectLane - lane) * LaneWidth);
int y1 = top + rowHeight;

var p0 = new Point(x0, y0);
var p1 = new Point(x1, y1);

using (var lanePen = new Pen(laneBrush, _laneLineWidth))
using (var lanePen = new Pen(laneBrush, LaneLineWidth))
{
if (sameLane)
{
Expand Down Expand Up @@ -347,10 +346,10 @@ bool DrawItem(Graphics g, ILaneRow row)

// Draw node
var nodeRect = new Rectangle(
g.RenderingOrigin.X + ((_laneWidth - _nodeDimension) / 2) + (row.NodeLane * _laneWidth),
g.RenderingOrigin.Y + ((rowHeight - _nodeDimension) / 2),
_nodeDimension,
_nodeDimension);
g.RenderingOrigin.X + ((LaneWidth - NodeDimension) / 2) + (row.NodeLane * LaneWidth),
g.RenderingOrigin.Y + ((rowHeight - NodeDimension) / 2),
NodeDimension,
NodeDimension);

Color? nodeColor = null;

Expand All @@ -370,7 +369,7 @@ bool DrawItem(Graphics g, ILaneRow row)
}
else //// Circle
{
nodeRect.Width = nodeRect.Height = _nodeDimension - 1;
nodeRect.Width = nodeRect.Height = NodeDimension - 1;

g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillEllipse(nodeBrush, nodeRect);
Expand Down Expand Up @@ -493,7 +492,7 @@ private void UpdateGraphColumnWidth(in VisibleRowRange range)
: MaxLanes;

laneCount = Math.Min(laneCount, maxLanes);
var columnWidth = (_laneWidth * laneCount) + ColumnLeftMargin;
var columnWidth = (LaneWidth * laneCount) + ColumnLeftMargin;
if (Column.Width != columnWidth && columnWidth > Column.MinimumWidth)
{
Column.Width = columnWidth;
Expand All @@ -508,66 +507,8 @@ private void ClearDrawCache()

public override bool TryGetToolTip(DataGridViewCellMouseEventArgs e, GitRevision revision, out string toolTip)
{
if (!revision.IsArtificial)
{
toolTip = GetLaneInfo(e.X - ColumnLeftMargin, e.RowIndex);
return true;
}

toolTip = default;
return false;

string GetLaneInfo(int x, int rowIndex)
{
int lane = x / _laneWidth;
var laneInfoText = new StringBuilder();
lock (_graphModel)
{
ILaneRow laneRow = _graphModel.GetLaneRow(rowIndex);
if (laneRow != null)
{
Node node = null;
if (lane == laneRow.NodeLane)
{
node = laneRow.Node;
if (!node.Revision.IsArtificial)
{
laneInfoText.AppendLine(node.Revision.Guid);
}
}
else if (lane >= 0 && lane < laneRow.Count)
{
for (int laneInfoIndex = 0, laneInfoCount = laneRow.LaneInfoCount(lane); laneInfoIndex < laneInfoCount; ++laneInfoIndex)
{
// search for next node below this row
LaneInfo laneInfo = laneRow[lane, laneInfoIndex];
Junction firstJunction = laneInfo.Junctions.First();
for (int nodeIndex = 0, nodeCount = firstJunction.NodeCount; nodeIndex < nodeCount; ++nodeIndex)
{
Node laneNode = firstJunction[nodeIndex];
if (laneNode.Index > rowIndex)
{
node = laneNode;
break; // from for (nodes)
}
}
}
}

if (node != null)
{
if (laneInfoText.Length > 0)
{
laneInfoText.AppendLine();
}

laneInfoText.Append(node.Revision.Body ?? node.Revision.Subject);
}
}
}

return laneInfoText.ToString();
}
toolTip = _laneInfoProvider.GetLaneInfo(e.X - ColumnLeftMargin, e.RowIndex, LaneWidth);
return true;
}
}
}
7 changes: 6 additions & 1 deletion GitUI/UserControls/RevisionGrid/Graph/GraphModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

namespace GitUI.UserControls.RevisionGrid.Graph
{
internal sealed class GraphModel
internal interface ILaneRowProvider
{
ILaneRow GetLaneRow(int row);
}

internal sealed class GraphModel : ILaneRowProvider
{
public event Action Updated;

Expand Down
Loading

0 comments on commit ec9a44a

Please sign in to comment.