microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.36k stars 304 forks source link

Make SvgGraphWriter extendable #254

Closed MouthlessGames closed 4 years ago

MouthlessGames commented 4 years ago

It would be nice if the consumer of the SvgGraphWriter would be able to customize the rendering of shapes. For example, one would be required to set custom attributes that contain the node's id. Making SvgGraphWrtier extendable would help in doing so.

An example of extending the SvgWriter:

class MySvgGraphWriter : SvgGraphWriter {
        protected override void WriteBox(Node node) {
            WriteStartElement("rect");
            WriteFill(node.Attr);
            WriteStroke(node.Attr);
            var curve = node.GeometryNode.BoundaryCurve;
            WriteAttribute("data-id", node.Id); // custom attribute
            WriteAttribute("x", node.BoundingBox.Left);
            WriteAttribute("y", node.BoundingBox.Bottom);
            WriteAttribute("width", curve.BoundingBox.Width);
            WriteAttribute("height", curve.BoundingBox.Height);
            WriteAttribute("rx", node.Attr.XRadius);
            WriteAttribute("ry", node.Attr.YRadius);
            WriteEndElement();
        }
    }
ghost commented 4 years ago

CLA assistant check
All CLA requirements met.