From a27db5bb6e15ad80a7452abeab7e88b8f9af49ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kon=C3=AD=C4=8Dek?= Date: Fri, 12 Jun 2009 15:47:56 +0000 Subject: [PATCH] Object graph visualizer - all doubles for communication with Graphviz's Neato are formatted to 3 decimal places - Neato crashed on some inputs, hopefully fixed now. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4281 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Debugger.AddIn.csproj | 1 + .../Graph/Layout/Tree/BoxDotFormatter.cs | 2 +- .../Graph/Layout/Tree/DotFormatter.cs | 6 +-- .../Graph/Layout/Tree/NeatoDoubleFormatter.cs | 39 +++++++++++++++++++ .../Graph/Layout/Tree/RecordDotFormatter.cs | 6 +-- 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/NeatoDoubleFormatter.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj index 98b28217fe..be68efe0ea 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj @@ -185,6 +185,7 @@ + diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/BoxDotFormatter.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/BoxDotFormatter.cs index 58b7e007c6..e374a7d3fa 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/BoxDotFormatter.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/BoxDotFormatter.cs @@ -27,7 +27,7 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout Rect neatoInput = transform.NodeToNeatoInput(node); string dotFormatNode = - string.Format(formatCulture, + string.Format(this.neatoDoubleFormatter, "{0} [pos=\"{1},{2}!\" width=\"{3}\" height=\"{4}\"];", nodeName, neatoInput.Location.X, neatoInput.Location.Y, neatoInput.Width, neatoInput.Height); builder.AppendLine(dotFormatNode); diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/DotFormatter.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/DotFormatter.cs index 3413bbf077..e2ba4e05db 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/DotFormatter.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/DotFormatter.cs @@ -23,12 +23,12 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout protected NeatoPositionTransform transform; + protected NeatoDoubleFormatter neatoDoubleFormatter = new NeatoDoubleFormatter(); + // state (node and edge names) needed for parsing back protected Dictionary nodeNames = new Dictionary(); protected Dictionary edgeNames = new Dictionary(); - protected CultureInfo formatCulture = CultureInfo.GetCultureInfo("en-US"); - /// /// Used for generating node and edge names. /// @@ -136,7 +136,7 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout private double readDouble(TextReader reader) { - return double.Parse(readWord(reader), formatCulture); + return double.Parse(readWord(reader), this.neatoDoubleFormatter.DoubleCulture); } private int readInt(TextReader reader) diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/NeatoDoubleFormatter.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/NeatoDoubleFormatter.cs new file mode 100644 index 0000000000..3628834ed9 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/NeatoDoubleFormatter.cs @@ -0,0 +1,39 @@ +// +// +// +// +// $Revision$ +// +using System; +using System.Globalization; + +namespace Debugger.AddIn.Visualizers.Graph.Layout +{ + /// + /// When used as IFormatProvider in string.Format, formats doubles to be suitable for Neato. + /// + public class NeatoDoubleFormatter : IFormatProvider, ICustomFormatter + { + private CultureInfo doubleCulture = CultureInfo.GetCultureInfo("en-US"); + /// + /// CultureInfo used for formatting and parsing doubles (en-US). + /// + public CultureInfo DoubleCulture + { + get { return this.doubleCulture; } + } + + public object GetFormat(Type formatType) + { + if (formatType == typeof(ICustomFormatter)) + return this; + else + return null; + } + + public string Format(string format, object arg, IFormatProvider formatProvider) + { + return string.Format(doubleCulture, "{0:0.000}", arg); + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/RecordDotFormatter.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/RecordDotFormatter.cs index d853abafee..fd83305b30 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/RecordDotFormatter.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Graph/Layout/Tree/RecordDotFormatter.cs @@ -12,7 +12,7 @@ using System.Windows; namespace Debugger.AddIn.Visualizers.Graph.Layout { /// - /// that treats nodes as records of properties. + /// that treats nodes as records of properties. /// Edges start at property, end at node. /// public class RecordDotFormatter : DotFormatter @@ -48,9 +48,9 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout } string dotFormatNode = - string.Format(formatCulture, + string.Format(this.neatoDoubleFormatter, "{0} [pos=\"{1},{2}!\" width=\"{3}\" height=\"{4}\" label=\"{5}\"];", - nodeName, + nodeName, neatoInput.Location.X, neatoInput.Location.Y, neatoInput.Width, neatoInput.Height, recordLabel.ToString()); builder.AppendLine(dotFormatNode);