Table of Contents

Class ElementCollection

Namespace
FlowGraph.Core.Elements
Assembly
FlowGraph.Core.dll

An observable collection of canvas elements with typed accessors and lookup methods.

public class ElementCollection : ObservableCollection<ICanvasElement>, IList<ICanvasElement>, ICollection<ICanvasElement>, IReadOnlyList<ICanvasElement>, IReadOnlyCollection<ICanvasElement>, IEnumerable<ICanvasElement>, IList, ICollection, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
Inheritance
ElementCollection
Implements
Inherited Members

Remarks

This collection is the core data structure for the canvas-first architecture. It holds all elements (nodes, edges, shapes, etc.) and provides efficient lookup and filtering methods.

Supports batch operations via AddRange(IEnumerable<ICanvasElement>) for efficient bulk updates.

Properties

ByZIndex

Gets all elements sorted by Z-index (rendering order).

public IEnumerable<ICanvasElement> ByZIndex { get; }

Property Value

IEnumerable<ICanvasElement>

EdgeCount

Gets the count of edges in the collection. O(1) operation.

public int EdgeCount { get; }

Property Value

int

Edges

Gets all edge elements in the collection. PERFORMANCE: Returns cached list for O(1) access instead of O(n) OfType filtering.

public IReadOnlyList<Edge> Edges { get; }

Property Value

IReadOnlyList<Edge>

NodeCount

Gets the count of nodes in the collection. O(1) operation.

public int NodeCount { get; }

Property Value

int

Nodes

Gets all node elements in the collection. PERFORMANCE: Returns cached list for O(1) access instead of O(n) OfType filtering.

public IReadOnlyList<Node> Nodes { get; }

Property Value

IReadOnlyList<Node>

Selected

Gets all selected elements.

public IEnumerable<ICanvasElement> Selected { get; }

Property Value

IEnumerable<ICanvasElement>

ShapeCount

Gets the count of shapes in the collection. O(1) operation.

public int ShapeCount { get; }

Property Value

int

Shapes

Gets all shape elements in the collection. PERFORMANCE: Returns cached list for O(1) access instead of O(n) OfType filtering.

public IReadOnlyList<ShapeElement> Shapes { get; }

Property Value

IReadOnlyList<ShapeElement>

Visible

Gets all visible elements.

public IEnumerable<ICanvasElement> Visible { get; }

Property Value

IEnumerable<ICanvasElement>

Methods

AddRange(IEnumerable<ICanvasElement>)

Adds a range of elements without firing individual notifications. A single Reset notification is fired after all elements are added.

public void AddRange(IEnumerable<ICanvasElement> elements)

Parameters

elements IEnumerable<ICanvasElement>

The elements to add.

ClearItems()

Removes all items from the collection.

protected override void ClearItems()

ContainsId(string)

Determines whether an element with the specified ID exists.

public bool ContainsId(string id)

Parameters

id string

The element ID to check.

Returns

bool

FindById(string)

Finds an element by its ID.

public ICanvasElement? FindById(string id)

Parameters

id string

The element ID to search for.

Returns

ICanvasElement

The element if found; otherwise, null.

FindById<T>(string)

Finds an element by its ID and casts to the specified type.

public T? FindById<T>(string id) where T : class, ICanvasElement

Parameters

id string

The element ID to search for.

Returns

T

The element if found and of the correct type; otherwise, null.

Type Parameters

T

The expected element type.

FindInBounds(Rect, bool)

Finds all elements within the specified bounds.

public IEnumerable<ICanvasElement> FindInBounds(Rect bounds, bool includePartial = false)

Parameters

bounds Rect

The bounds to search within.

includePartial bool

If true, includes elements that partially intersect the bounds.

Returns

IEnumerable<ICanvasElement>

GetEdgesForNode(string)

Gets all edges connected to a specific node (either as source or target). PERFORMANCE: O(1) lookup using edge index instead of O(n) iteration.

public IEnumerable<Edge> GetEdgesForNode(string nodeId)

Parameters

nodeId string

The ID of the node to find edges for.

Returns

IEnumerable<Edge>

Enumerable of edges connected to the node.

GetEdgesForNodes(IEnumerable<string>)

Gets all edges connected to any of the specified nodes. PERFORMANCE: O(k) where k is number of connected edges, instead of O(n) iteration over all edges.

public List<Edge> GetEdgesForNodes(IEnumerable<string> nodeIds)

Parameters

nodeIds IEnumerable<string>

The IDs of nodes to find edges for.

Returns

List<Edge>

List of distinct edges connected to any of the specified nodes.

InsertItem(int, ICanvasElement)

Inserts an item into the collection at the specified index.

protected override void InsertItem(int index, ICanvasElement item)

Parameters

index int

The zero-based index at which item should be inserted.

item ICanvasElement

The object to insert.

OfElementType<T>()

Gets all elements of the specified type.

public IEnumerable<T> OfElementType<T>() where T : ICanvasElement

Returns

IEnumerable<T>

Type Parameters

T

The element type to filter by.

OnCollectionChanged(NotifyCollectionChangedEventArgs)

Raises the CollectionChanged event with the provided arguments.

protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)

Parameters

e NotifyCollectionChangedEventArgs

Arguments of the event being raised.

RemoveItem(int)

Removes the item at the specified index of the collection.

protected override void RemoveItem(int index)

Parameters

index int

The zero-based index of the element to remove.

RemoveRange(IEnumerable<ICanvasElement>)

Removes a range of elements without firing individual notifications. A single Reset notification is fired after all elements are removed.

public void RemoveRange(IEnumerable<ICanvasElement> elements)

Parameters

elements IEnumerable<ICanvasElement>

The elements to remove.

ReplaceAll(IEnumerable<ICanvasElement>)

Clears all elements and adds the specified elements.

public void ReplaceAll(IEnumerable<ICanvasElement> elements)

Parameters

elements IEnumerable<ICanvasElement>

The elements to set.

SetItem(int, ICanvasElement)

Replaces the element at the specified index.

protected override void SetItem(int index, ICanvasElement item)

Parameters

index int

The zero-based index of the element to replace.

item ICanvasElement

The new value for the element at the specified index.