diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml
index 37dd27f..771207c 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml
@@ -2,28 +2,28 @@
-
-
-
+ x:Class="Xamarin.Neo4j.Controls.QueryResultView"
+ x:Name="self">
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml.cs
index 6a51a6b..b1b6244 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Controls/QueryResultView.xaml.cs
@@ -1,43 +1,49 @@
using System;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
using System.Reflection;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
-using Neo4j.Driver;
using Xamarin.Neo4j.Managers;
using Xamarin.Neo4j.Services;
using Xamarin.Neo4j.Models;
-using Xamarin.Neo4j.Pages;
using Xamarin.Neo4j.Utilities;
-using Query = Xamarin.Neo4j.Models.Query;
namespace Xamarin.Neo4j.Controls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class QueryResultView : ContentView
{
- private QueryResult QueryResult => (QueryResult) BindingContext;
+ public static readonly BindableProperty GraphViewHeightProperty =
+ BindableProperty.Create(nameof(GraphViewHeight), typeof(double), typeof(QueryResultView), 300.0);
- public event EventHandler> CloseRequested;
+ public double GraphViewHeight
+ {
+ get => (double)GetValue(GraphViewHeightProperty);
+ set => SetValue(GraphViewHeightProperty, value);
+ }
- private string _neovisHtml;
+ private QueryResult QueryResult => (QueryResult)BindingContext;
public QueryResultView()
{
InitializeComponent();
BindingContextChanged += OnBindingContextChanged;
graphView.Navigating += OnGraphViewNavigating;
+ App.ThemeChanged += OnThemeChanged;
+ }
+
+ private void OnThemeChanged(object sender, EventArgs e)
+ {
+ if (QueryResult == null || graphView == null) return;
+ ParseNeovisHtmlSafe();
+ graphView.Source = new HtmlWebViewSource { Html = QueryResult?.NeovisHtml };
}
private async void OnGraphViewNavigating(object sender, WebNavigatingEventArgs e)
{
- Console.WriteLine($"[Graph] Inline Navigating: {e.Url}");
-
if (!e.Url.Contains("expand") || !e.Url.Contains("nodeId")) return;
e.Cancel = true;
@@ -69,19 +75,11 @@ namespace Xamarin.Neo4j.Controls
private void OnBindingContextChanged(object sender, EventArgs e)
{
- if (BindingContext == null || graphView == null)
- {
- Console.WriteLine($"[Graph] OnBindingContextChanged skipped: BindingContext={BindingContext}, graphView={graphView}");
- return;
- }
-
- Console.WriteLine($"[Graph] OnBindingContextChanged fired, CanDisplayGraph={QueryResult?.CanDisplayGraph}");
+ if (BindingContext == null || graphView == null) return;
ParseNeovisHtmlSafe();
- Console.WriteLine($"[Graph] Setting graphView.Source, html length={_neovisHtml?.Length ?? 0}");
-
- graphView.Source = new HtmlWebViewSource { Html = _neovisHtml };
+ graphView.Source = new HtmlWebViewSource { Html = QueryResult?.NeovisHtml };
}
private void ParseNeovisHtml()
@@ -89,83 +87,46 @@ namespace Xamarin.Neo4j.Controls
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Xamarin.Neo4j.Visualization.visgraph.html";
- var available = string.Join("\n", assembly.GetManifestResourceNames());
- Console.WriteLine($"[Graph] Looking for: {resourceName}");
- Console.WriteLine($"[Graph] Available resources: {available.Replace("\n", ", ")}");
-
var stream = assembly.GetManifestResourceStream(resourceName);
if (stream == null)
{
- _neovisHtml = $"" +
- $"Resource not found:
{resourceName}
" +
- $"Available:
{available.Replace("\n", "
")}";
+ var available = string.Join(", ", assembly.GetManifestResourceNames());
+ QueryResult.NeovisHtml = $"" +
+ $"Resource not found:
{resourceName}
" +
+ $"Available:
{available}";
return;
}
using (stream)
using (var reader = new StreamReader(stream))
{
- var result = reader.ReadToEnd();
+ var html = reader.ReadToEnd();
var connectionId = ConnectionStringManager.ActiveConnectionString?.Id ?? Guid.Empty;
var (nodesJson, edgesJson) = GraphDataHelper.BuildJson(QueryResult.Results, connectionId);
var isDark = Application.Current.RequestedTheme == AppTheme.Dark;
- result = result.Replace("{{nodes}}", nodesJson);
- result = result.Replace("{{edges}}", edgesJson);
- result = result.Replace("{{backgroundColor}}", isDark ? "#292C31" : "#FFFFFF");
- result = result.Replace("{{textColor}}", isDark ? "#FFFFFF" : "#000000");
+ html = html.Replace("{{nodes}}", nodesJson);
+ html = html.Replace("{{edges}}", edgesJson);
+ html = html.Replace("{{backgroundColor}}", isDark ? "#292C31" : "#FFFFFF");
+ html = html.Replace("{{textColor}}", isDark ? "#FFFFFF" : "#000000");
- _neovisHtml = result;
+ QueryResult.NeovisHtml = html;
}
}
private void ParseNeovisHtmlSafe()
{
+ if (QueryResult == null) return;
try
{
ParseNeovisHtml();
}
catch (Exception ex)
{
- Console.WriteLine($"[Graph] ParseNeovisHtml threw: {ex.GetType().Name}: {ex.Message}");
- _neovisHtml = $"" +
- $"{ex.GetType().Name}
{ex.Message}
{ex.StackTrace?.Replace("\n", "
")}";
+ QueryResult.NeovisHtml = $"" +
+ $"{ex.GetType().Name}
{ex.Message}";
}
}
-
- private async void OpenNeovis(object sender, EventArgs e)
- {
- var neo4jService = IPlatformApplication.Current.Services.GetRequiredService();
- var connectionString = ConnectionStringManager.ActiveConnectionString;
- await Application.Current.MainPage.Navigation.PushAsync(new GraphPage(_neovisHtml, connectionString, neo4jService));
- }
-
- private async void SaveQuery(object sender, EventArgs e)
- {
- var name = await Application.Current.MainPage.DisplayPromptAsync("Save Query", "How should the query be called?");
-
- if (!string.IsNullOrWhiteSpace(name))
- {
- var query = new Query()
- {
- Id = Guid.NewGuid(),
- QueryText = QueryResult.Query,
- Name = name,
- };
-
- SavedQueryManager.AddSavedQuery(query);
- }
- }
-
- private void CloseResultView(object sender, EventArgs e)
- {
- CloseRequested?.Invoke(sender, new GenericEventArgs(QueryResult));
- }
-
- private async void OpenTableView(object sender, EventArgs e)
- {
- await Application.Current.MainPage.Navigation.PushAsync(new TablePage(QueryResult));
- }
}
}
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/QueryResult.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/QueryResult.cs
index 29638d9..cf2661a 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/QueryResult.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/QueryResult.cs
@@ -31,5 +31,10 @@ namespace Xamarin.Neo4j.Models
public Neo4jConnectionString ConnectionString { get; set; }
public Dictionary> Results { get; set; }
+
+ /// Cached NeoVis HTML generated by QueryResultView; set when the result is first rendered.
+ public string NeovisHtml { get; set; }
+
+ public bool IsError => !Success;
}
}
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/SessionPage.xaml b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/SessionPage.xaml
index f8c8adc..3f39b6a 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/SessionPage.xaml
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/SessionPage.xaml
@@ -4,7 +4,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:controls="clr-namespace:Xamarin.Neo4j.Controls;assembly=Xamarin.Neo4j"
- x:Class="Xamarin.Neo4j.Pages.SessionPage">
+ x:Class="Xamarin.Neo4j.Pages.SessionPage"
+ x:Name="sessionPage">