[solved] error on setting SetValue on edges

Feb 6, 2010 at 9:42 PM

Hi,

See my code below. When I try to set SetValue on the edge, I get an error at this.Controls.Add(host); I tried, setting all different kinds of value, int, doubles, hex, low or high value, nothing works, for no ReservedMetadataKey.

 

        private void cmdGraph_Click(object sender, EventArgs e)
        {
            NodeXLControl ctx = new NodeXLControl();
            ctx.Width = 1024;
            ctx.Height = 786;

            var vertices = from vt in db.vertices select vt;
            var edges = from edg in db.edges select edg;

            prgGraph.Maximum = vertices.Count() + edges.Count();
            prgGraph.Value = 0;

            foreach(vertice vt in vertices)
            {
                Vertex v1 = new Vertex();
                v1.SetValue(ReservedMetadataKeys.PerVertexLabel, vt.email);
                v1.Name = vt.email;
                ctx.Graph.Vertices.Add(v1);
                prgGraph.Value++;
            }

            int maxwidth = (from ew in db.edges orderby ew.count descending select ew.count).First();
            GraphDrawer gd = ctx.GraphDrawer;
            gd.EdgeDrawer.Width = 1;
            foreach (edge ed in edges)
            {
                IVertex v1;
                IVertex v2;
                var edx = ed;
                
                bool res1 = ctx.Graph.Vertices.Find(edx.vertice.email, out v1);
                bool res2 = ctx.Graph.Vertices.Find(edx.vertice1.email, out v2);

                
                Edge e1 = new Edge(v1, v2, true);
                
                e1.SetValue(ReservedMetadataKeys.PerEdgeWidth, edx.count / maxwidth * 10);
                //e1.SetValue(ReservedMetadataKeys.PerAlpha, 55);
                ctx.Graph.Edges.Add(e1);
                prgGraph.Value++;
            }

            ElementHost host = new ElementHost();
            host.Width = 1024;
            host.Height = 786;
            host.Top = 100;
            host.Child = ctx;
            this.Controls.Add(host);
            ctx.DrawGraph(true);


        }

Error: Assertion Failed. at GraphVertexEdgeBase.GetValue

What can be wrong?

 

Feb 7, 2010 at 2:31 PM

Fixed. Used the sourcecode to find out what was wrong. Had to be single value for the width and byte for the alpha. Also my width was under 1 for some values.

Feb 7, 2010 at 5:41 PM
Edited Feb 7, 2010 at 5:43 PM

Please see the ReservedMetadataKeys topic in the NodeXLApi.chm help file, which documents the required type for each key.  For example, the remarks for ReservedMetadataKeys.PerEdgeWidth state that "The key's value is a Single between EdgeDrawer.MinimumWidth and EdgeDrawer.MaximumWidth."

You do not need to look in the source code to determine how to use a particular key.

-- Tony