Skip to content

Commit e4ec833

Browse files
author
John Simons
committed
Word wrapping sequence diagram endpoint names
Fixes #469
1 parent 63d5e70 commit e4ec833

File tree

6 files changed

+93
-11
lines changed

6 files changed

+93
-11
lines changed

src/ServiceInsight/App.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<cnv:PopupMenuItemCountVisibleConverter x:Key="PopupMenuItemCountVisibleConverter" />
3030
<cnv:CompositeCollectionConverter x:Key="CompositeCollectionConverter" />
3131
<cnv:TimeSpanHumanizedConverter x:Key="TimeSpanHumanizedConverter" />
32+
<cnv:SmartWrapConverter x:Key="SmartWrapConverter" />
33+
<cnv:CenterToolTipConverter x:Key="CenterToolTipConverter" />
3234

3335
<!-- Colors and Brushes -->
3436
<SolidColorBrush x:Key="ControlBackgroundColor" Color="#FFCED4DF" />

src/ServiceInsight/SequenceDiagram/EndpointInfo.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Particular.ServiceInsight.Desktop.SequenceDiagram
44
{
55
using System.Diagnostics;
6-
using System.Linq;
76
using Models;
87

98
[DebuggerDisplay("{Name}")]
@@ -16,16 +15,13 @@ protected EndpointInfo()
1615
public EndpointInfo(Endpoint endpoint, string version)
1716
{
1817
if (endpoint == null)
19-
throw new ArgumentNullException("endpoint", "endpoint is null.");
20-
21-
Name = string.Join(".", endpoint.Name.Split('.').Skip(1));
22-
if (string.IsNullOrEmpty(Name))
2318
{
24-
Name = endpoint.Name;
19+
throw new ArgumentNullException("endpoint", "endpoint is null.");
2520
}
26-
FullName = endpoint.Name;
21+
22+
FullName = Name = endpoint.Name;
2723
Version = version;
28-
Host = endpoint.Host ?? "";
24+
Host = endpoint.Host ?? String.Empty;
2925
}
3026

3127
public string Name { get; protected set; }

src/ServiceInsight/SequenceDiagram/SequenceDiagramView.xaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020
<ResourceDictionary>
2121
<Style x:Key="EndpointTooltipStyle" TargetType="ToolTip">
2222
<Setter Property="OverridesDefaultStyle" Value="true" />
23-
<Setter Property="Placement" Value="Center" />
24-
<Setter Property="VerticalOffset" Value="54" />
23+
<Setter Property="Placement" Value="Bottom" />
24+
<Setter Property="HorizontalOffset">
25+
<Setter.Value>
26+
<MultiBinding Converter="{StaticResource CenterToolTipConverter}">
27+
<Binding RelativeSource="{RelativeSource Self}" Path="PlacementTarget.ActualWidth"/>
28+
<Binding RelativeSource="{RelativeSource Self}" Path="ActualWidth"/>
29+
</MultiBinding>
30+
</Setter.Value>
31+
</Setter>
2532
<Setter Property="Template">
2633
<Setter.Value>
2734
<ControlTemplate TargetType="ToolTip">
@@ -136,7 +143,8 @@
136143
<TextBlock Grid.Column="1"
137144
HorizontalAlignment="Center"
138145
VerticalAlignment="Center"
139-
Text="{Binding Name}"
146+
Text="{Binding Name, Converter={StaticResource SmartWrapConverter}}"
147+
TextWrapping="Wrap"
140148
TextTrimming="CharacterEllipsis" />
141149
</Grid>
142150
</Border>

src/ServiceInsight/ServiceInsight.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,13 @@
503503
<Compile Include="ValueConverters\BoolToBrushConverter.cs" />
504504
<Compile Include="ValueConverters\ByteToCharConverter.cs" />
505505
<Compile Include="ValueConverters\ByteToHexConverter.cs" />
506+
<Compile Include="ValueConverters\CenterToolTipConverter.cs" />
506507
<Compile Include="ValueConverters\CompositeCollectionConverter.cs" />
507508
<Compile Include="ValueConverters\EndSegmentValueConverter.cs" />
508509
<Compile Include="ValueConverters\MessageDateTimeFormatProvider.cs" />
509510
<Compile Include="ValueConverters\MiddlePointValueConverter.cs" />
510511
<Compile Include="ValueConverters\PopupMenuItemCountVisibleConverter.cs" />
512+
<Compile Include="ValueConverters\SmartWrapConverter.cs" />
511513
<Compile Include="ValueConverters\StartSegmentValueConverter.cs" />
512514
<Compile Include="ValueConverters\StatusToBrushConverter.cs" />
513515
<Compile Include="ValueConverters\StringEmptyOrNullToVisibilityConverter.cs" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Particular.ServiceInsight.Desktop.ValueConverters
2+
{
3+
using System;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Windows;
7+
using System.Windows.Data;
8+
9+
public class CenterToolTipConverter : IMultiValueConverter
10+
{
11+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (values.FirstOrDefault(v => v == DependencyProperty.UnsetValue) != null)
14+
{
15+
return double.NaN;
16+
}
17+
double placementTargetWidth = (double)values[0];
18+
double toolTipWidth = (double)values[1];
19+
return (placementTargetWidth / 2.0) - (toolTipWidth / 2.0);
20+
}
21+
22+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
23+
{
24+
throw new NotSupportedException();
25+
}
26+
}
27+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace Particular.ServiceInsight.Desktop.ValueConverters
2+
{
3+
using System;
4+
using System.Text.RegularExpressions;
5+
using System.Windows;
6+
using System.Windows.Data;
7+
8+
public class SmartWrapConverter : IValueConverter
9+
{
10+
private static readonly Regex PascalCaseWordPartsRegex;
11+
12+
static SmartWrapConverter()
13+
{
14+
PascalCaseWordPartsRegex = new Regex(@"[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?=[A-Z][a-z]|[0-9]|\b)",
15+
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
16+
}
17+
18+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
19+
{
20+
var result = value as string;
21+
22+
if (result == null)
23+
{
24+
return DependencyProperty.UnsetValue;
25+
}
26+
27+
result = result.Replace(".", ".\u200B");
28+
result = result.Replace("-", "-\u200B");
29+
result = result.Replace("_", "_\u200B");
30+
31+
return AddUnicodeZeroWidthSpaceBasedOnPascalCase(result);
32+
}
33+
34+
static string AddUnicodeZeroWidthSpaceBasedOnPascalCase(string input)
35+
{
36+
var result = PascalCaseWordPartsRegex
37+
.Replace(input, match => "\u200B" + match.Value);
38+
39+
return result;
40+
}
41+
42+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
43+
{
44+
throw new NotImplementedException();
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)