in tools/Graph Explorer/GraphExplorer/Models/Model.cs [528:721]
public static string GenerateHtml(List<IRecord> records)
{
static void GeneratePath(StringBuilder b, int indent, IPath value)
{
var indentString = new string(' ', indent);
b.AppendLine(indentString + "{");
b.Append(indentString + " start:");
GenerateNode(b, indent + 2, value.Start);
b.Append(indentString + " end:");
GenerateNode(b, indent + 2, value.End);
b.AppendLine(indentString + " segments: [");
var firstSegment = true;
foreach(var relation in value.Relationships)
{
if (!firstSegment)
b.AppendLine(",");
else
firstSegment = false;
b.AppendLine(indentString + " {");
b.AppendLine(indentString + " start: " + relation.StartNodeId.ToString() + ",");
b.AppendLine(indentString + " relationship: {");
b.AppendLine(indentString + " id: " + relation.Id.ToString() + ",");
b.AppendLine(indentString + " type: " + relation.Type + ",");
b.AppendLine(indentString + " start: " + relation.StartNodeId.ToString() + ",");
b.AppendLine(indentString + " end: " + relation.EndNodeId.ToString() + ",");
b.AppendLine(indentString + " properties: {");
var first = true;
foreach (var prop in relation.Properties.OrderBy(p => p.Key))
{
if (!first)
b.AppendLine(",");
else
first = false;
b.Append(indentString + " " + prop.Key + ": " + prop.Value.ToString());
}
b.AppendLine();
b.AppendLine(indentString + " }");
b.AppendLine(indentString + " },");
b.AppendLine(indentString + " end: " + relation.EndNodeId.ToString());
b.Append(" }");
}
b.AppendLine();
b.AppendLine(indentString + " ],");
b.AppendLine(indentString + " length: " + value.Relationships.Count());
b.AppendLine("}");
}
static void GenerateNode(StringBuilder b, int indent, INode node)
{
var indentString = new string(' ', indent);
b.AppendLine(indentString + "{");
b.AppendLine(indentString + " id: " + node.Id.ToString() + ",");
b.AppendLine(indentString + " labels: [");
bool first = true;
foreach (var label in node.Labels)
{
if (!first)
b.AppendLine(",");
else
first = false;
b.Append(indentString + " " + label);
}
b.AppendLine();
b.AppendLine(indentString + " ],");
b.AppendLine(indentString + " properties: {");
first = true;
foreach (var prop in node.Properties.OrderBy(p => p.Key))
{
if (!first)
b.AppendLine(",");
else
first = false;
b.Append(indentString + " " + prop.Key + ": " + prop.Value.ToString());
}
b.AppendLine();
b.AppendLine(indentString + " }");
b.AppendLine(indentString + "}");
}
static void GenerateRelationship(StringBuilder b, int indent, IRelationship relationship)
{
var indentString = new string(' ', indent);
b.AppendLine(indentString + "{");
b.AppendLine(indentString + " id: " + relationship.Id.ToString() + ",");
b.AppendLine(indentString + " type: " + relationship.Type + ",");
b.AppendLine(indentString + " start: " + relationship.StartNodeId.ToString() + ", ");
b.AppendLine(indentString + " end: " + relationship.EndNodeId.ToString() + ", ");
b.AppendLine(indentString + " properties: {");
var first = true;
foreach (var prop in relationship.Properties.OrderBy(p => p.Key))
{
if (!first)
b.AppendLine(",");
else
first = false;
b.Append(indentString + " " + prop.Key + ": " + prop.Value.ToString());
}
b.AppendLine();
b.AppendLine(indentString + " }");
}
static void GenerateList(StringBuilder b, List<object> l)
{
bool first = true;
b.Append("[");
foreach (var element in l)
{
if (!first)
b.Append(", ");
Generate(b, 0, element);
first = false;
}
b.Append("]");
}
static void GenerateString(StringBuilder b, string s)
{
b.Append(s);
}
static void Generate(StringBuilder b, int indent, object value)
{
if (value is IPath)
GeneratePath(b, indent, value as IPath);
else if (value is INode)
GenerateNode(b, indent, value as INode);
else if (value is IRelationship)
GenerateRelationship(b, indent, value as IRelationship);
else if (value is List<object>)
GenerateList(b, value as List<object>);
else
GenerateString(b, value.ToString());
}
var builder = new StringBuilder();
builder.AppendLine("<html>");
builder.AppendLine("<style>");
builder.AppendLine(" table, th, td {");
builder.AppendLine(" border: 1px solid black;");
builder.AppendLine(" font-size: " + Properties.Settings.Default.TextResultsFontSize.ToString() + ";");
builder.AppendLine(" border-collapse: collapse;");
builder.AppendLine(" }");
builder.AppendLine("</style>");
builder.AppendLine("<body>");
builder.AppendLine("<table style='width:100%;'>");
builder.AppendLine(" <tr>");
if (records.Any())
{
foreach (var heading in records.First().Keys)
{
builder.AppendLine(" <th>" + heading + "</th>");
}
}
builder.AppendLine(" </tr>");
foreach (var record in records)
{
builder.AppendLine(" <tr>");
var keys = record.Values.Keys.GetEnumerator();
var values = record.Values.Values;
foreach (var value in values)
{
builder.AppendLine(" <td><pre>");
if (value != null)
{
Generate(builder, 0, value);
keys.MoveNext();
string key = keys.Current;
}
builder.AppendLine(" </pre></td>");
}
builder.AppendLine(" </tr>");
}
builder.AppendLine("</table>");
builder.AppendLine("</body>");
builder.AppendLine("</html>");
return builder.ToString();
}