Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended property change support in Neuroglia.Blazor.Dagre #16

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions src/Blazor/Neuroglia.Blazor.Dagre/Models/GraphElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,103 @@ public abstract class GraphElement
/// <inheritdoc />
public virtual Guid Id { get; set; } = Guid.NewGuid();

/// <summary>
/// Stores the element's label
/// </summary>
protected string? _label;
/// <inheritdoc />
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual string? Label { get; set; }
public virtual string? Label
{
get => this._label;
set
{
this._label = value;
this.OnChange();
}
}

/// <summary>
/// Stores the element's component type
/// </summary>
protected Type? _componentType;
/// <inheritdoc />
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public virtual Type? ComponentType { get; set; }
public virtual Type? ComponentType
{
get => this._componentType;
set
{
this._componentType = value;
this.OnChange();
}
}

/// <summary>
/// Stores the element's css class
/// </summary>
protected string? _cssClass;
/// <inheritdoc />
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual string? CssClass { get; set; }
public virtual string? CssClass
{
get => this._cssClass;
set
{
this._cssClass = value;
this.OnChange();
}
}


/// <summary>
/// Stores the element's metadata
/// </summary>
protected IDictionary<string, object>? _metadata = null;
/// <inheritdoc />
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonExtensionData]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonExtensionData]
public virtual IDictionary<string, object>? Metadata { get; set; }
public virtual IDictionary<string, object>? Metadata
{
get => this._metadata;
set
{
this._metadata = value;
this.OnChange();
}
}

/// <summary>
/// The action tiggered when a property changes
/// </summary>
public virtual event Action? Changed;

/// <summary>
/// Constructs a new <see cref="GraphElement"/>
/// </summary>
protected GraphElement()
{ }

/// <summary>
/// Constructs a new <see cref="GraphElement"/>
/// </summary>
/// <param name="label">The element's label</param>
/// <param name="cssClass">The element's css class(es)</param>
/// <param name="componentType">The element's component(template) type</param>
protected GraphElement(string? label = "", string? cssClass = null, Type? componentType = null) {
this.Label = label;
this.CssClass = cssClass;
this.ComponentType = componentType;
}

/// <summary>
/// Invokes the change action
/// </summary>
protected virtual void OnChange()
{
this.Changed?.Invoke();
Expand Down
11 changes: 10 additions & 1 deletion src/Blazor/Neuroglia.Blazor.Dagre/Models/GraphViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ public virtual decimal Scale
protected readonly Collection<Type> _svgDefinitionComponents;
public virtual IReadOnlyCollection<Type> SvgDefinitionComponents => this._svgDefinitionComponents;

public virtual bool EnableProfiling { get; set; }
protected bool _enableProfiling = false;
public virtual bool EnableProfiling
{
get => this._enableProfiling;
set
{
this._enableProfiling = value;
this.OnChange();
}
}

/// <summary>
/// The map of node type and their component type
Expand Down
54 changes: 45 additions & 9 deletions src/Blazor/Neuroglia.Blazor.Dagre/Models/NodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class NodeViewModel
: GraphElement, INodeViewModel
{
protected double? _x { get; set; }
protected double? _x = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual double? X {
Expand All @@ -15,7 +15,7 @@ public virtual double? X {
}
}

protected double? _y { get; set; }
protected double? _y = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual double? Y
Expand All @@ -28,7 +28,7 @@ public virtual double? Y
}
}

protected double? _width { get; set; }
protected double? _width = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual double? Width
Expand All @@ -41,7 +41,7 @@ public virtual double? Width
}
}

protected double? _height { get; set; }
protected double? _height = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual double? Height
Expand All @@ -54,23 +54,59 @@ public virtual double? Height
}
}

protected double? _radiusX = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual double? RadiusX { get; set; }
public virtual double? RadiusX
{
get => this._radiusX;
set
{
this._radiusX = value;
this.OnChange();
}
}

protected double? _radiusY = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual double? RadiusY { get; set; }
public virtual double? RadiusY
{
get => this._radiusY;
set
{
this._radiusY = value;
this.OnChange();
}
}

protected Guid? _parentId = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual Guid? ParentId { get; set; }
public virtual Guid? ParentId
{
get => this._parentId;
set
{
this._parentId = value;
this.OnChange();
}
}

protected string? _shape = null;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual string? Shape { get; set; }
public virtual string? Shape
{
get => this._shape;
set
{
this._shape = value;
this.OnChange();
}
}

protected IBoundingBox _bbox { get; set; }
protected IBoundingBox _bbox = null!;
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public virtual IBoundingBox? BBox => this._bbox;
Expand Down