예제 #1
0
        public void Update()
        {
            this.svg.SelectAll("text").Remove();
            this.svg.SelectAll("image").Remove();

            link = link.Data((D3Element)(object)linkData,// null);
                             delegate(D3Element d) {
                string id = ((EntityLink)(object)d).Id;
                return(id);
            });
            node = node.Data((D3Element)(object)nodeData, delegate(D3Element d) {
                string id = ((Entity)(((EntityNode)(object)d).SourceData)).Id;

                return(id);
            });

            link.Enter()
            .Insert("svg:line", ".node")
            .Attr <Func <EntityLink, string> >("id", delegate(EntityLink d)
            {
                return(d.Id);
            })
            .Attr("class", "link");

            node.Enter().Append("svg:g")
            .Attr <Func <EntityNode, string> >("id", delegate(EntityNode d)
            {
                Entity entity = (Entity)d.SourceData;
                return(GetID(entity.Id));
            })
            .Attr("class", "node")
            .Attr("filter", "url(#blur1)")
            .On("click", delegate(D3Element d, int i)
            {
                HighlightNode(d);
                ShowInfoBox(d, true);
            })

            .On("mouseover", delegate(D3Element d, int i)
            {
                HighlightNode(d);
                if (!infoBoxPinned)
                {
                    ShowInfoBox(d, false);
                }
            })

            .On("mouseout", delegate(D3Element d, int i)
            {
                UnHighlightNode(d);
                if (stickyInfoBox || infoBoxPinned)
                {
                    return;
                }
                HideInfoBox();
            })
            .On("dblclick", delegate(D3Element d, int i)
            {
                d.Fixed = false;
                D3.Event.StopPropagation();

                // Expand overflow nodes if there any
                EntityNode entityNode = (EntityNode)(object)d;
                vm.ExpandOverflow(entityNode);
            })
            .Call(dragBehavior);


            node.Append("svg:image")
            .Attr("class", "chromeImage")
            .Attr <Func <EntityNode, string> >("xlink:href", delegate(EntityNode d)
            {
                Entity entity = ((Entity)d.SourceData);
                switch (entity.LogicalName)
                {
                case "account":
                case "contact":
                    return("../images/network.png");

                default:
                    return(null);
                }
            }
                                               )
            .Attr <Func <EntityNode, string> >("x", delegate(EntityNode d) { return(GetXY(d, 1.5)); })
            .Attr <Func <EntityNode, string> >("y", delegate(EntityNode d) { return(GetXY(d, 1.5)); })
            .Attr <Func <EntityNode, string> >("width", delegate(EntityNode d) { return(GetHeightWidth(d, 1.5)); })
            .Attr <Func <EntityNode, string> >("height", delegate(EntityNode d) { return(GetHeightWidth(d, 1.5)); })
            .Attr <Func <EntityNode, string> >("visibility", delegate(EntityNode d)
            {
                Entity entity = ((Entity)d.SourceData);
                switch (entity.LogicalName)
                {
                case "account":
                case "contact":
                    return(null);

                default:
                    return("hidden");
                }
            })
            .Attr <Func <EntityNode, string> >("filter", delegate(EntityNode d)
            {
                return(GetFilter(d));
            });

            node.Append("svg:image")
            .Attr("class", "entityImage")
            .Attr <Func <EntityNode, string> >("xlink:href", delegate(EntityNode d)
            {
                Entity entity = ((Entity)d.SourceData);
                switch (entity.LogicalName)
                {
                case "overflow":
                    return("../images/overflow.png");

                case "account":
                    return("../images/account.png");

                case "contact":
                    return("../images/contact.png");

                case "incident":
                    return("/_imgs/Navbar/ActionImgs/Cases_32.png");

                case "contract":
                    return("/_imgs/Navbar/ActionImgs/Contract_32.png");

                case "opportunity":
                    return("/_imgs/Navbar/ActionImgs/Opportunity_32.png");

                case "lead":
                    return("/_imgs/Navbar/ActionImgs/Lead_32.png");

                case "phonecall":
                    return("/_imgs/Navbar/ActionImgs/PhoneCall_32.png");

                case "email":
                    return("/_imgs/Navbar/ActionImgs/Email_32.png");

                case "task":
                    return("/_imgs/Navbar/ActionImgs/Task_32.png");

                case "appointment":
                    return("/_imgs/Navbar/ActionImgs/Appointment_32.png");

                default:
                    // Custom entity image
                    return("/_imgs/Navbar/ActionImgs/Documents_32.png");
                }
            })
            .Attr <Func <EntityNode, string> >("x", delegate(EntityNode d) { return(GetXY(d, 0.5)); })
            .Attr <Func <EntityNode, string> >("y", delegate(EntityNode d) { return(GetXY(d, 0.5)); })
            .Attr <Func <EntityNode, string> >("width", delegate(EntityNode d) { return(GetHeightWidth(d, 0.5)); })
            .Attr <Func <EntityNode, string> >("height", delegate(EntityNode d) { return(GetHeightWidth(d, 0.5)); })
            .Attr("filter", "url(#blur2)");

            node.Append("svg:text")
            .Attr("class", "nodetext")
            .Attr <Func <EntityNode, int> >("dx", delegate(EntityNode d)
            {
                Entity entity = ((Entity)d.SourceData);
                switch (entity.LogicalName)
                {
                case "overflow":
                    return(-3);

                default:
                    return(-15);
                }
            })
            .Attr <Func <EntityNode, int> >("dy", delegate(EntityNode d)
            {
                Entity entity = ((Entity)d.SourceData);
                switch (entity.LogicalName)
                {
                case "overflow":
                    return(3);

                default:
                    return(-15);
                }
            })
            .Text(delegate(EntityNode d)
            {
                Entity entity = (Entity)d.SourceData;
                if (entity.LogicalName == "overflow")
                {
                    if (d.Children != null)
                    {
                        return(d.Children.Count.ToString());
                    }
                    return("");
                }
                else
                {
                    EntitySetting entitySetting = vm.Config.Entities[entity.LogicalName];
                    // If there is no name attribute setting, we'll use the name attribute so you can add an alias.
                    string name = entity.GetAttributeValueString(entitySetting != null && entitySetting.NameAttribute != null ? entitySetting.NameAttribute : "name");
                    if (name != null && name.Length > 50)
                    {
                        name = name.Substr(0, 50) + "...";
                    }
                    return(name);
                }
            });

            // Exit any old links.
            this.link.Exit().Remove();
            this.node.Exit().Remove();
            force.Start();

            Dictionary <string, string> uniqueKeyCache = new Dictionary <string, string>();

            foreach (EntityLink l in vm.Links)
            {
                string id = l.Id;
                if (uniqueKeyCache.ContainsKey(id))
                {
                    Debug.WriteLine("Duplicate key " + id);
                }
                else
                {
                    uniqueKeyCache[id] = id;
                }
            }

            foreach (EntityNode l in vm.Nodes)
            {
                string id = ((Entity)(((EntityNode)(object)l).SourceData)).Id;

                if (uniqueKeyCache.ContainsKey(id))
                {
                    Debug.WriteLine("Duplicate key " + id);
                }
                else
                {
                    uniqueKeyCache[id] = id;
                }
            }
        }