Graph data and visuals save/load

Saving and loading procedures are using YAXLib( with all of its features and limitations.

To be able to save and load your Graph using GraphArea.SaveToFile and GraphArea.LoadFromFile methods, your code must meet specific conditions:
  • Vertex and Edge data classes must have filled unique positive ID property. Basicaly can be any unique number assigned by some counter. Automatic ID resolving is enabled by default making absent IDs to be filled with unique values (this can be controlled by Area.GenerateGraph() method parameter).
  • Edge and Vertex data classes along with any other used class must implement default parameterless constructor. As reflection is activelyy used in serialization process this is a must.
  • Your data graph class must implement interface IMutableVertexAndEdgeSet<TVertex, TEdge> BidirectionalGraph already implement this by default.

  • There are some possible problems serializing complex type such as BitmapImage. In that cases custom serializers must be coded for each individual type. Look in YAXLib docs for more info.
  • Only properties can be serialized and no fields.
  • All serialized classes must implement parameterless constructors. Workaround in case of generic classes usage can be custom converter or additional serializable property that holds simple value (string or int) that can be used to recreate problematic class on load.
  • Currently it doesn't handle object references creating the same object many times in different address spaces. Such objects must be traced manually (if solid references are needed) for ex. by some internal ids.

Special usage FAQ
For complete usage info look in:
Useful attributes
It is vital to manually exclude some properties from serialization (for ex. get-only props). This can be done by specifying YAXDontSerialize attribute for property.

Custom serializers example
Custom serializers can be specified for any property. This approach made possible end-user customization of default serialization process which is vital in many special cases.

Currently GraphX provides optional custom serializers for:
  • Point (surpasses some weird default deserialization issues)
  • Point[]

Point serializer example which stores point values in a string:
public class YAXPointSerializer: ICustomSerializer<Point>

        private Point Deserialize(string str)
            var res = str.Split(new char[] { '|' });
            if (res.Length == 2) return new Point(Convert.ToDouble(res[0]), Convert.ToDouble(res[1]));
            else return new Point();

        public Point DeserializeFromAttribute(System.Xml.Linq.XAttribute attrib)
            return Deserialize(attrib.Value);

        public Point DeserializeFromElement(System.Xml.Linq.XElement element)
            return Deserialize(element.Value);

        public Point DeserializeFromValue(string value)
            return Deserialize(value);

        public void SerializeToAttribute(Point objectToSerialize, System.Xml.Linq.XAttribute attrToFill)
            attrToFill.Value = String.Format("{0}|{1}", objectToSerialize.X, objectToSerialize.Y);

        public void SerializeToElement(Point objectToSerialize, System.Xml.Linq.XElement elemToFill)
            elemToFill.Value = String.Format("{0}|{1}", objectToSerialize.X, objectToSerialize.Y);

        public string SerializeToValue(Point objectToSerialize)
            return String.Format("{0}|{1}", objectToSerialize.X, objectToSerialize.Y);

Visual graph save/load

GraphArea.SaveVisual and GraphArea.LoadVisual methods are now deprecated.

Last edited Nov 7, 2013 at 5:26 AM by panthernet, version 12