Class GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>

GoDiagram®
v10.0.12
by Northwoods Software®

GraphLinksModels support links between nodes and grouping nodes and links into subgraphs. GraphLinksModels hold node data and link data in separate collections.

Inheritance
Model<TNodeData, TNodeKey, TSharedData>
GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>
Implements
Namespace: Northwoods.Go.Models
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
public class GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort> : Model<TNodeData, TNodeKey, TSharedData>, IModel where TNodeData : class, new() where TNodeKey : IEquatable<TNodeKey> where TLinkData : class, new() where TLinkKey : IEquatable<TLinkKey> where TPort : IEquatable<TPort>
Type Parameters
Name Description
TNodeData
TNodeKey
TSharedData
TLinkData
TLinkKey
TPort
Remarks

Node data is normally represented in a Diagram by instances of Node, but they could be represented by simple Parts or by Groups. Link data should be represented by instances of Link.

Each link data object is assumed to have two values, one referring to the node that the link is coming from and one that the link is going to. The LinkFromKeyProperty property names the property on the link data whose value is the key of the "from" node. The LinkToKeyProperty property names the property on the link data whose value is the key of the "to" node. The default values for these properties are "From" and "To" respectively.

For example, one can define a graph consisting of two nodes with one link connecting them:

model.NodeDataSource = new List<MyNodeData> {
  new MyNodeData { Key = "Alpha" },
  new MyNodeData { Key = "Beta" }
};
model.LinkDataSource = new List<MyLinkData> {
  new MyLinkData { From = "Alpha", To = "Beta" }
};

If you want to have subgraphs in your diagram, where a group node contains some number of nodes and links, you need to declare that some node data actually represent groups, and you need to provide a reference from a member node data to its containing group node data. The NodeIsGroupProperty property names the property on a node data that is true if that node data represents a group. The NodeGroupKeyProperty property names the property on a node data whose value is the key of the containing group's node data. The default values for these properties are "IsGroup" and "Group" respectively.

For example, one can define a graph consisting of one group containing a subgraph of two nodes connected by a link, with a second link from that group to a third node that is not a member of that group:

model.NodeDataSource = new List<MyNodeData> {
  new MyNodeData { Key = "Group1", IsGroup = true },
  new MyNodeData { Key = "Alpha", Group = "Group1" },
  new MyNodeData { Key = "Beta", Group = "Group1" },
  new MyNodeData { Key = "Gamma" }
};
model.LinkDataSource = new List<MyLinkData> {
  new MyLinkData { From = "Alpha", To = "Beta" },
  new MyLinkData { From = "Group1", To = "Gamma" }
];

GraphLinksModels also support distinguishing the "port" element of a node to which a link can connect, at either end of the link. This identification is a string that names the "port" element in the node. However, you need to set the LinkFromPortIdProperty and/or LinkToPortIdProperty properties before the model is able to get the "port id" information from the link data.

For example, one can define a graph consisting of a "subtraction" node and two inputs and one output. The "subtraction" node has two distinct inputs called "subtrahend" and "minuend"; the output is called "difference".

model.LinkFromPortIdProperty = "FromPort";  // necessary to remember port ids
model.LinkToPortIdProperty = "ToPort";
model.NodeDataSource = new List<MyNodeData> {
  new MyNodeData { Key = 1, Constant = 5 },  // a constant input node
  new MyNodeData { Key = 2, Constant = 2 },  // another constant node
  new MyNodeData { Key = 3, Operation = "subtract" },
  new MyNodeData { Key = 4, Value = 3 }  // the output node
};
model.LinkDataSource = new List<MyLinkData> {
  new MyLinkData { From = 1, To = 3, ToPort = "subtrahend" },
  new MyLinkData { From = 2, To = 3, ToPort = "minuend" },
  new MyLinkData { From = 3, To = 4, FromPort = "difference" }
};

In this case links connected to node 3 (which is the subtraction operation) are distinguished by port id. The connections to the other nodes do not have any port identification, presumably because there is only one port on those nodes, representing the node value.

Each link data object is assumed to have a unique key value. The LinkKeyProperty property names the property on the link data whose value is the unique key for that link data object. The default value for this property is "Key". You should not have a TwoWay data binding on the link key property, because that might cause the property value to be set to a duplicate key value.

If the key is undefined, or if there are duplicate key values, the model will automatically try to assign a new unique key value.

Just as with the assignment of node keys, you can customize the assignment of link keys by setting MakeUniqueLinkKeyFunction to a function that returns a unique identifier.

This model does not support the modification of whether a node data object is a group.

This model cannot detect the modification of the LinkDataSource array or the modification of any link data object. If you want to add or remove link data from the LinkDataSource, call the AddLinkData(TLinkData) or RemoveLinkData(TLinkData) methods. If you want to modify the node a link connects to, call the SetFromKeyForLinkData(TLinkData, TNodeKey) and/or SetToKeyForLinkData(TLinkData, TNodeKey) methods. If you want to change the membership of a node data in a group, call the SetGroupKeyForNodeData(TNodeData, TNodeKey) method.

Constructors

GraphLinksModel(GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>)

Constructs a copy of a given GraphLinksModel, without copying the data.

Declaration
protected GraphLinksModel(GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort> model)
Parameters
Type Name Description
GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort> model

GraphLinksModel(IEnumerable<TNodeData>, IEnumerable<TLinkData>)

Constructs an empty GraphLinksModel unless one provides arguments as the initial data collection values for the NodeDataSource and LinkDataSource properties.

Declaration
public GraphLinksModel(IEnumerable<TNodeData> nodedatasource = null, IEnumerable<TLinkData> linkdatasource = null)
Parameters
Type Name Description
IEnumerable<TNodeData> nodedatasource

an optional collection containing objects to be represented by Nodes.

IEnumerable<TLinkData> linkdatasource

an optional collection containing objects to be represented by Links.

Properties

ArchetypeNodeData

Gets or sets a data object that will be copied and added to the model as a new node data each time there is a link reference (either the "to" or the "from" of a link data) to a node key that does not yet exist in the model.

Declaration
public TNodeData ArchetypeNodeData { get; set; }
Property Value
Type Description
TNodeData
Remarks

The default value is null -- node data is not automatically copied and added to the model when there is an unresolved reference in a link data. When adding or modifying a link data if there is a "from" or "to" key value for which FindNodeDataForKey(TNodeKey) returns null, it will call CopyNodeData(TNodeData) on this property value and AddNodeData(TNodeData) on the result.

CopyLinkDataFunction

Gets or sets a function that makes a copy of a link data object.

Declaration
public Func<TLinkData, GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, TLinkData> CopyLinkDataFunction { get; set; }
Property Value
Type Description
Func<TLinkData, GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, TLinkData>
Remarks

You may need to set this property in order to ensure that a copied Link is bound to data that does not share certain data structures between the original link data and the copied link data. This property value may be null in order to cause CopyLinkData(TLinkData) to make a shallow copy of an Object. The default value is null.

LinkCategoryProperty

Gets or sets the name of the data property that returns a string naming that data's category.

Declaration
public string LinkCategoryProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the name "Category", meaning that it expects the data to have a property named "Category" if it cares to name the category for the Link. This is used by the diagram to distinguish between different kinds of links. The name must not be null. If the value is an empty string, GetCategoryForLinkData(TLinkData) will return an empty string for all link data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

LinkDataSource

Gets or sets the collection of link data objects that correspond to Links in the Diagram.

Declaration
public IEnumerable<TLinkData> LinkDataSource { get; set; }
Property Value
Type Description
IEnumerable<TLinkData>
Remarks

The initial value is an empty list.

LinkFromKeyProperty

Gets or sets the name of the data property that returns the key of the node data that the link data is coming from.

Declaration
public string LinkFromKeyProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the name "From", meaning that it expects the data to have a property named "From" to refer to the link's source node. The name must not be null. If the value is an empty string, GetFromKeyForLinkData(TLinkData) will return the default TNodeKey for all link data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

LinkFromPortIdProperty

Gets or sets the name of the data property that returns the optional parameter naming a "port" element on the node that the link data is connected from.

Declaration
public string LinkFromPortIdProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the empty string indicating that one cannot distinguish different logical connection points for any links. The name must not be null nor the value of LinkFromKeyProperty or LinkToKeyProperty. If the value is an empty string, GetFromPortIdForLinkData(TLinkData) will return the default TPort for all link data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

LinkKeyProperty

Gets or sets the name of the data property that returns a unique key for each link data object.

Declaration
public string LinkKeyProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is "Key". The name must not be null.

When this property has a value of an empty string, GetKeyForLinkData(TLinkData) will return the default TLinkKey, and FindLinkDataForKey(TLinkKey) will always return null.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

LinkLabelKeysProperty

Gets or sets the name of the data property that returns a list of keys of node data that are labels on that link data.

Declaration
public string LinkLabelKeysProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the empty string: "", meaning that the model does not support links owning label nodes.

The name must not be null. If the value is an empty string, GetLabelKeysForLinkData(TLinkData) will return an empty list for all link data objects. You will need to set this property in order to support nodes as link labels.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

LinkToKeyProperty

Gets or sets the name of the data property that returns the key of the node data that the link data is going to.

Declaration
public string LinkToKeyProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the name "To", meaning that it expects the data to have a property named "To" to refer to the link's destination node. The name must not be null. If the value is an empty string, GetToKeyForLinkData(TLinkData) will return the default TNodeKey for all link data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

LinkToPortIdProperty

Gets or sets the name of the data property that returns the optional parameter naming a "port" element on the node that the link data is connected to.

Declaration
public string LinkToPortIdProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the empty string indicating that one cannot distinguish different logical connection points for any links. The name must not be null nor the value of LinkFromKeyProperty or LinkToKeyProperty. If the value is an empty string, GetToPortIdForLinkData(TLinkData) will return the default TPort for all link data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

MakeUniqueLinkKeyFunction

Gets or sets a function that returns a unique key for a link data object.

Declaration
public Func<GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, TLinkData, TLinkKey> MakeUniqueLinkKeyFunction { get; set; }
Property Value
Type Description
Func<GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, TLinkData, TLinkKey>
Remarks

This function is called by MakeLinkDataKeyUnique(TLinkData) when a link data object is added to the model, either as part of a new LinkDataSource or by a call to AddLinkData(TLinkData), to make sure the value of GetKeyForLinkData(TLinkData) is unique within the model. However it will not be called when LinkKeyProperty is the empty string.

The value may be null in order to cause MakeLinkDataKeyUnique(TLinkData) behave in the standard manner. (The default value is null.) You may want to supply a function here in order to make sure all of the automatically generated keys are in a particular format. Setting this property after setting LinkDataSource has no real effect until there is a call to AddLinkData(TLinkData).

If a link data object is already in the model and you want to change its key value, call SetKeyForLinkData(TLinkData, TLinkKey) with a new and unique key.

NodeGroupKeyProperty

Gets or sets the name of the property on node data that specifies the key of the group data that "owns" that node data.

Declaration
public string NodeGroupKeyProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the name "Group", meaning that it expects the data to have a property named "Group" to refer to any containing group.

The value must not be null. If the value is an empty string, GetGroupKeyForNodeData(TNodeData) will return the default TNodeKey for all node data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

See Also

NodeIsGroupProperty

Gets or sets the name of the boolean property on node data that indicates whether the data should be represented as a group of nodes and links or as a simple node.

Declaration
public string NodeIsGroupProperty { get; set; }
Property Value
Type Description
string
Remarks

The default value is the name "IsGroup", meaning that it expects the data to have a property named "IsGroup" on those node data objects that should be represented by Groups.

The value must not be null. If the value is an empty string, IsGroupForNodeData(TNodeData) will return false for all node data objects.

If you want to set this property you must do so before using the model, and especially before you assign Model.

Methods

AddLabelKeyForLinkData(TLinkData, TNodeKey)

Adds a node key value that identifies a node data acting as a new label node on the given link data.

Declaration
public void AddLabelKeyForLinkData(TLinkData linkdata, TNodeKey key)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

TNodeKey key

the key of the new label node.

Remarks

This method only works if LinkLabelKeysProperty has been set to something other than an empty string.

See Also

AddLinkData(TLinkData)

When you want to add a link to the diagram, call this method with a new data object.

Declaration
public void AddLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Remarks

This will add that data to the LinkDataSource and notify all listeners that a new link data object has been inserted into the collection.

Presumably the link data object will already have its "from" and "to" node key references set, but it is also possible to set them after the link data is in the model by calling SetFromKeyForLinkData(TLinkData, TNodeKey) and SetToKeyForLinkData(TLinkData, TNodeKey).

This operation does nothing if the link data is already part of this model's LinkDataSource.

See Also

AddLinkData(IEnumerable<TLinkData>)

Add to this model all of the link data held in a collection of link data objects.

Declaration
public void AddLinkData(IEnumerable<TLinkData> coll)
Parameters
Type Name Description
IEnumerable<TLinkData> coll

a collection of link data objects to add to the LinkDataSource

ApplyIncrementalJson(string)

Modify this model by applying the changes given in an "incremental" model change in JSON format generated by ToIncrementalJson(ChangedEvent).

Declaration
public override void ApplyIncrementalJson(string s)
Parameters
Type Name Description
string s

a string in JSON format containing modifications to be performed to the model

Overrides
Remarks

The expected properties of the argument are described at ToIncrementalJson(ChangedEvent). Incremental changes must be applied in the same order that the changes occurred in the original model.

All of the top-level properties in the JSON, such as NodeKeyProperty, must be the same as for this model. Note that if the model is a GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, you will have to have set LinkKeyProperty to the name of a property, the same both in the Model as well as in the data that you pass to this method.

This conducts a transaction.

ContainsLinkData(TLinkData)

Decide if a given link data object is in this model.

Declaration
public bool ContainsLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
bool
Remarks

If you do not have a reference to the particular data object that is in the LinkDataSource, you may need to search for it by iterating through that collection, or (more likely), by finding the desired Link in a Diagram and getting that link's Data.

See Also

CopyLinkData(TLinkData)

Make a copy of a link data object.

Declaration
public TLinkData CopyLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
TLinkData
Remarks

This uses the value of CopyLinkDataFunction to actually perform the copy, unless it is null, in which case this method just makes a shallow copy of the object.

This does not modify the model -- the returned data object is not added to this model. This assumes that the data's constructor can be called with no arguments. This also makes sure there is no reference to either the "from" or the "to" node of the original data.

See Also

CopyNodeData(TNodeData)

This override also makes sure any copied node data does not have a reference to the containing group.

Declaration
public override TNodeData CopyNodeData(TNodeData nodedata)
Parameters
Type Name Description
TNodeData nodedata

an object represented by a node, group, or non-link.

Returns
Type Description
TNodeData
Overrides
Northwoods.Go.Models.Model<TNodeData, TNodeKey, TSharedData>.CopyNodeData(TNodeData)
See Also
CopyNodeData(TNodeData)

FindLinkDataForKey(TLinkKey)

Given a key, find the link data object in this model that uses the given value as its unique key.

Declaration
public TLinkData FindLinkDataForKey(TLinkKey key)
Parameters
Type Name Description
TLinkKey key

a key.

Returns
Type Description
TLinkData

null if the key is not present in the model.

Remarks

Unless LinkKeyProperty is set to a non-empty string, this model will not automatically assign unique key values for link data objects, and thus this method will always return null.

See Also

GetCategoryForLinkData(TLinkData)

Find the category of a given link data, a string naming the link template that the Diagram should use to represent the link data.

Declaration
public string GetCategoryForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
string
See Also

GetFromKeyForLinkData(TLinkData)

From a link data retrieve a value uniquely identifying the node data from which this link is connected.

Declaration
public TNodeKey GetFromKeyForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
TNodeKey

This may return the default TNodeKey if the link is not coming from any node.

See Also

GetFromPortIdForLinkData(TLinkData)

From a link data retrieve a value identifying the port object of the node from which this link is connected.

Declaration
public TPort GetFromPortIdForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
TPort

This may return the default TPort if there is no particular port parameter information.

See Also

GetGroupKeyForNodeData(TNodeData)

If there is a container group for the given node data, return the group's key.

Declaration
public TNodeKey GetGroupKeyForNodeData(TNodeData nodedata)
Parameters
Type Name Description
TNodeData nodedata

an object represented by a node, group, or non-link.

Returns
Type Description
TNodeKey

This returns the default TNodeKey if there is no containing group data.

See Also

GetKeyForLinkData(TLinkData)

Given a link data object return its unique key.

Declaration
public TLinkKey GetKeyForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link

Returns
Type Description
TLinkKey
Remarks

This returns the default TLinkKey if there is no key value.

It is possible to change the key for a link data object by calling SetKeyForLinkData(TLinkData, TLinkKey).

See Also

GetLabelKeysForLinkData(TLinkData)

Gets a collection of node key values that identify node data acting as labels on the given link data.

Declaration
public ICollection<TNodeKey> GetLabelKeysForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
ICollection<TNodeKey>

a collection of node keys; an empty list if the property was not present.

Remarks

This method only works if LinkLabelKeysProperty has been set to something other than an empty string.

See Also

GetToKeyForLinkData(TLinkData)

From a link data retrieve a value uniquely identifying the node data to which this link is connected.

Declaration
public TNodeKey GetToKeyForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
TNodeKey

This may return the default TNodeKey if the link is not going to any node.

See Also

GetToPortIdForLinkData(TLinkData)

From a link data retrieve a value identifying the port object of the node to which this link is connected.

Declaration
public TPort GetToPortIdForLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Returns
Type Description
TPort

This may return the default TPort if there is no particular port parameter information.

See Also

IsGroupForNodeData(TNodeData)

See if the given node data should be represented as a group or as a simple node.

Declaration
public bool IsGroupForNodeData(TNodeData nodedata)
Parameters
Type Name Description
TNodeData nodedata

an object represented by a node, group, or non-link.

Returns
Type Description
bool
Remarks

This value must not change as long as the node data is part of the model. At the current time there is no SetIsGroupForNodeData method.

See Also

MakeLinkDataKeyUnique(TLinkData)

This method is called when a link data object is added to the model to make sure that GetKeyForLinkData(TLinkData) returns a unique key value.

Declaration
public void MakeLinkDataKeyUnique(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link

Remarks

The key value should be unique within the set of data managed by this model: LinkDataSource. If the key is already in use, this will assign an unused key to the LinkKeyProperty property on the data when possible.

If you want to customize the way in which link data gets a unique key, you can set the MakeUniqueKeyFunction functional property.

If the link data object is already in the model and you want to change its key value, call SetKeyForLinkData(TLinkData, TLinkKey) and give it a new unique key value.

MergeLinkData(IEnumerable<TLinkData>)

Take a collection of link data objects and update LinkDataSource without replacing the collection and without replacing any existing link data objects that are identified by key.

Declaration
public void MergeLinkData(IEnumerable<TLinkData> coll)
Parameters
Type Name Description
IEnumerable<TLinkData> coll
Remarks

This depends on LinkKeyProperty being a non-empty string.

For link data objects that have the same key value, this makes calls to Set(object, string, object) to update the existing link data object. For new keys, this calls the object's clone method to copy the data and then AddLinkData(TLinkData) to add a new link to the model. For existing links that have keys that are not present in the given collection, this calls RemoveLinkData(TLinkData) to remove the existing link from the model.

This method will error if a new key is added and the TLinkData type is not ICloneable.

This method is typically used when GoDiagram is being used within an application that is maintaining state related to the diagram model. When state is updated, this method can be called to keep the GoDiagram model synchronized. Any updates to the data should use new references since this method will use reference equality to check if a link data object needs to be updated.

This method does not conduct a transaction.

RemoveLabelKeyForLinkData(TLinkData, TNodeKey)

Removes a node key value that identifies a node data acting as a former label node on the given link data.

Declaration
public void RemoveLabelKeyForLinkData(TLinkData linkdata, TNodeKey key)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

TNodeKey key

key of the label node being removed from the link.

Remarks

Removing a reference to a node data from the collection of link label keys does not automatically remove any node data from the model.

This method only works if LinkLabelKeysProperty has been set to something other than an empty string.

See Also

RemoveLinkData(TLinkData)

When you want to remove a link from the diagram, call this method with an existing link data object.

Declaration
public void RemoveLinkData(TLinkData linkdata)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

Remarks

This will remove that data object from the LinkDataSource and notify all listeners that a link data object has been removed from the collection.

If you do not have a reference to the particular data object that is in the LinkDataSource, you may need to search for it by iterating through that collection, or (more likely), by finding the desired Link in a Diagram and getting that link's Data.

Removing a link data from a model does not automatically remove any associated label node data from the model.

This operation does nothing if the link data is not present in the LinkDataSource.

See Also

RemoveLinkData(IEnumerable<TLinkData>)

Remove from this model all of the link data held in a collection of link data objects.

Declaration
public void RemoveLinkData(IEnumerable<TLinkData> coll)
Parameters
Type Name Description
IEnumerable<TLinkData> coll

a collection of link data objects to remove from the LinkDataSource

Set(object, string, object)

This override changes the value of some property of a node data, a link data, or an item data, given a string naming the property and the new value, in a manner that can be undone/redone and that automatically updates any bindings.

Declaration
public override void Set(object data, string propname, object val)
Parameters
Type Name Description
object data

an object typically the value of a Data and represented by a Node, Link, Group, simple Part, or item in a ItemList; or this model's SharedData.

string propname

a string that is not null or the empty string.

object val

the new value for the property.

Overrides
Remarks

This override handles link data as well as node data.

This gets the old value of the property; if the value is the same as the new value, no side-effects occur.

See Also

SetCategoryForLinkData(TLinkData, string)

Change the category of a given link data, a string naming the link template that the Diagram should use to represent the link data.

Declaration
public void SetCategoryForLinkData(TLinkData linkdata, string cat)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

string cat

must not be null.

Remarks

Changing the link template for a link data will cause the existing Link to be removed from the Diagram and be replaced with a new Link created by copying the new link template and applying any data-bindings. Note that the new template must be an instance of the same class as the original link. Thus one cannot change the category of a link from an instance of Link to an instance of a subclass of Link, nor vice-versa.

See Also

SetFromKeyForLinkData(TLinkData, TNodeKey)

Change the node key that the given link data references as the source of the link.

Declaration
public void SetFromKeyForLinkData(TLinkData linkdata, TNodeKey key)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

TNodeKey key

This may be the default TNodeKey if the link should no longer come from any node.

See Also

SetFromPortIdForLinkData(TLinkData, TPort)

Change the information that the given link data uses to identify the particular "port" that the link is coming from.

Declaration
public void SetFromPortIdForLinkData(TLinkData linkdata, TPort portid)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

TPort portid

This may be the default TPort if the link should no longer be associated with any particular "port".

See Also

SetGroupKeyForNodeData(TNodeData, TNodeKey)

Change the container group for the given node data, given a key for the new group.

Declaration
public void SetGroupKeyForNodeData(TNodeData nodedata, TNodeKey key)
Parameters
Type Name Description
TNodeData nodedata

an object represented by a node, group, or non-link.

TNodeKey key

This may be the default TNodeKey if there should be no containing group data.

See Also

SetKeyForLinkData(TLinkData, TLinkKey)

Change the unique key of a given link data that is already in this model.

Declaration
public void SetKeyForLinkData(TLinkData linkdata, TLinkKey key)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link

TLinkKey key
Remarks

The new key value must be unique -- i.e. not in use by another link data object. You can call FindLinkDataForKey(TLinkKey) to check if a proposed new key is already in use.

If this is called when LinkKeyProperty is the empty string, this method has no effect. If this is called on a link data object that is not (yet) in this model, this unconditionally modifies the property to the new key value.

See Also

SetLabelKeysForLinkData(TLinkData, ICollection<TNodeKey>)

Replaces an Array of node key values that identify node data acting as labels on the given link data.

Declaration
public void SetLabelKeysForLinkData(TLinkData linkdata, ICollection<TNodeKey> arr)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

ICollection<TNodeKey> arr

a list of node keys

Remarks

This method only works if LinkLabelKeysProperty has been set to something other than an empty string.

See Also

SetToKeyForLinkData(TLinkData, TNodeKey)

Change the node key that the given link data references as the destination of the link.

Declaration
public void SetToKeyForLinkData(TLinkData linkdata, TNodeKey key)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

TNodeKey key

This may be the default TNodeKey if the link should no longer go to any node.

See Also

SetToPortIdForLinkData(TLinkData, TPort)

Change the information that the given link data uses to identify the particular "port" that the link is going to.

Declaration
public void SetToPortIdForLinkData(TLinkData linkdata, TPort portid)
Parameters
Type Name Description
TLinkData linkdata

an object represented by a link.

TPort portid

This may be the default TPort if the link should no longer be associated with any particular "port".

See Also

ToIncrementalData(ChangedEvent)

Produce an object representing the changes in the most recent Transaction.

Declaration
public GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>.IncrementalGLData ToIncrementalData(ChangedEvent e)
Parameters
Type Name Description
ChangedEvent e

a Transaction ChangedEvent for which IsTransactionFinished is true

Returns
Type Description
GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>.IncrementalGLData

returns either null if no changes occurred, or an object containing incremental model changes for the given Transaction

Remarks

The structure of the object follows the same format as the JSON output from ToIncrementalJson(ChangedEvent).

Note that these incremental changes include the results of undo and redo operations.

For GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>s, this method requires that LinkKeyProperty is not an empty string.

Any node or link data objects contained in the "Modified..." properties will be deep copies of the data in the model. When using this method, we suggest all data classes implement a Clone method such that faithful copies are made in the expected manner.

This method is most commonly used when GoDiagram must communicate with some external data source and maintain integrity between the two while avoiding serialization/deserialization.

myDiagram.ModelChanged += (object sender, ChangedEvent e) => {
  if (e.IsTransactionFinished) {
    var dataChanges = e.Model.ToIncrementalData(e);
    ... update application state/save to database ...
  }
};
See Also

ToIncrementalJson(ChangedEvent)

Produce a JSON-format string representing the changes in the most recent Transaction.

Declaration
public string ToIncrementalJson(ChangedEvent e)
Parameters
Type Name Description
ChangedEvent e

a Transaction ChangedEvent for which IsTransactionFinished is true

Returns
Type Description
string
Remarks

This writes out JSON for a model, but recording only changes in the given Transaction. Instead of the "NodeDataSource" property (and "LinkDataSource" property for GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>s), this will have "Inserted...", "Modified...", and "Removed..." properties.

The "ModifiedNodeData" collection holds node data objects. The "InsertedNodeKeys" and "RemovedNodeKeys" collections hold keys of data, not whole objects, that have been added and/or deleted. The "SharedData" property holds the SharedData object, if it was modified.

Note that it is entirely plausible for the same object be in or referenced by all three collections, because a single Transaction can include adding a node, modifying it, and removing it.

The purpose of this method is to make it easier to send incremental changes to the server/database, instead of sending the whole model. Whereas it has always been easy to perform "batch" updates or "file saves":

myDiagram.ModelChanged += (object sender, ChangedEvent e) => {
  if (e.IsTransactionFinished) {
    var json = e.Model.ToJson();
    // save the whole model upon each transaction completion or undo/redo
    ... send to server/database ...
  }
};

You can now easily send "incremental" updates:

myDiagram.ModelChanged += (object sender, ChangedEvent e) => {
  if (e.IsTransactionFinished) {
    var json = e.Model.ToIncrementalJson(e);
    // record each Transaction as a JSON-format string
    ... send to server/database ...
  }
};

Note that these incremental changes include the results of undo and redo operations. Also, when you might call ApplyIncrementalJson(string), you will need to disable your Changed listener, so that it does not send spurious changes to your database during the process of applying incremental changes from the database.

For GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>s, this method requires that LinkKeyProperty is not an empty string. The incremental JSON for GraphLinksModels will include "ModifiedLinkData", "InsertedLinkKeys", and "RemovedLinkKeys" properties.

The same restrictions on data property names and data property values apply to this method as they do to ToJson().

Implements