Skip to content

Commit

Permalink
Word wrapping sequence diagram endpoint names
Browse files Browse the repository at this point in the history
Fixes #469
  • Loading branch information
John Simons committed Jun 15, 2015
1 parent 63d5e70 commit e4ec833
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/ServiceInsight/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<cnv:PopupMenuItemCountVisibleConverter x:Key="PopupMenuItemCountVisibleConverter" />
<cnv:CompositeCollectionConverter x:Key="CompositeCollectionConverter" />
<cnv:TimeSpanHumanizedConverter x:Key="TimeSpanHumanizedConverter" />
<cnv:SmartWrapConverter x:Key="SmartWrapConverter" />
<cnv:CenterToolTipConverter x:Key="CenterToolTipConverter" />

<!-- Colors and Brushes -->
<SolidColorBrush x:Key="ControlBackgroundColor" Color="#FFCED4DF" />
Expand Down
12 changes: 4 additions & 8 deletions src/ServiceInsight/SequenceDiagram/EndpointInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Particular.ServiceInsight.Desktop.SequenceDiagram
{
using System.Diagnostics;
using System.Linq;
using Models;

[DebuggerDisplay("{Name}")]
Expand All @@ -16,16 +15,13 @@ protected EndpointInfo()
public EndpointInfo(Endpoint endpoint, string version)
{
if (endpoint == null)
throw new ArgumentNullException("endpoint", "endpoint is null.");

Name = string.Join(".", endpoint.Name.Split('.').Skip(1));
if (string.IsNullOrEmpty(Name))
{
Name = endpoint.Name;
throw new ArgumentNullException("endpoint", "endpoint is null.");
}
FullName = endpoint.Name;

FullName = Name = endpoint.Name;
Version = version;
Host = endpoint.Host ?? "";
Host = endpoint.Host ?? String.Empty;
}

public string Name { get; protected set; }
Expand Down
14 changes: 11 additions & 3 deletions src/ServiceInsight/SequenceDiagram/SequenceDiagramView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
<ResourceDictionary>
<Style x:Key="EndpointTooltipStyle" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Placement" Value="Center" />
<Setter Property="VerticalOffset" Value="54" />
<Setter Property="Placement" Value="Bottom" />
<Setter Property="HorizontalOffset">
<Setter.Value>
<MultiBinding Converter="{StaticResource CenterToolTipConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="PlacementTarget.ActualWidth"/>
<Binding RelativeSource="{RelativeSource Self}" Path="ActualWidth"/>
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
Expand Down Expand Up @@ -136,7 +143,8 @@
<TextBlock Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Name}"
Text="{Binding Name, Converter={StaticResource SmartWrapConverter}}"
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis" />
</Grid>
</Border>
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceInsight/ServiceInsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,13 @@
<Compile Include="ValueConverters\BoolToBrushConverter.cs" />
<Compile Include="ValueConverters\ByteToCharConverter.cs" />
<Compile Include="ValueConverters\ByteToHexConverter.cs" />
<Compile Include="ValueConverters\CenterToolTipConverter.cs" />
<Compile Include="ValueConverters\CompositeCollectionConverter.cs" />
<Compile Include="ValueConverters\EndSegmentValueConverter.cs" />
<Compile Include="ValueConverters\MessageDateTimeFormatProvider.cs" />
<Compile Include="ValueConverters\MiddlePointValueConverter.cs" />
<Compile Include="ValueConverters\PopupMenuItemCountVisibleConverter.cs" />
<Compile Include="ValueConverters\SmartWrapConverter.cs" />
<Compile Include="ValueConverters\StartSegmentValueConverter.cs" />
<Compile Include="ValueConverters\StatusToBrushConverter.cs" />
<Compile Include="ValueConverters\StringEmptyOrNullToVisibilityConverter.cs" />
Expand Down
27 changes: 27 additions & 0 deletions src/ServiceInsight/ValueConverters/CenterToolTipConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Particular.ServiceInsight.Desktop.ValueConverters
{
using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;

public class CenterToolTipConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.FirstOrDefault(v => v == DependencyProperty.UnsetValue) != null)
{
return double.NaN;
}
double placementTargetWidth = (double)values[0];
double toolTipWidth = (double)values[1];
return (placementTargetWidth / 2.0) - (toolTipWidth / 2.0);
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
47 changes: 47 additions & 0 deletions src/ServiceInsight/ValueConverters/SmartWrapConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace Particular.ServiceInsight.Desktop.ValueConverters
{
using System;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Data;

public class SmartWrapConverter : IValueConverter
{
private static readonly Regex PascalCaseWordPartsRegex;

static SmartWrapConverter()
{
PascalCaseWordPartsRegex = new Regex(@"[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?=[A-Z][a-z]|[0-9]|\b)",
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
}

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var result = value as string;

if (result == null)
{
return DependencyProperty.UnsetValue;
}

result = result.Replace(".", ".\u200B");
result = result.Replace("-", "-\u200B");
result = result.Replace("_", "_\u200B");

return AddUnicodeZeroWidthSpaceBasedOnPascalCase(result);
}

static string AddUnicodeZeroWidthSpaceBasedOnPascalCase(string input)
{
var result = PascalCaseWordPartsRegex
.Replace(input, match => "\u200B" + match.Value);

return result;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

0 comments on commit e4ec833

Please sign in to comment.