(function () {
    function NewGraph(settings) {
        this.opt = $.extend({
            con: "",     //画布的容器id
            width: "",   //画布的宽度
            height: "",  //画布的高度
            linkDistance: 200, //引力中节点连线的距离，但是不唯一确定一条线的距离，线的距离还跟节点间的引力和其他因素有关
            charge: -800, //正数为引力，负数为斥力
            url: "",       //数据接口地址前缀
            nameMap: null,  //实体节点参数映射
            linkMap: null,  //关系的参数映射
            linkRel: null   //节点之间关系类型
        }, settings);
    }

    NewGraph.prototype = {
        para: {
            svg: null,  //svg画布元素
            graph: null,//用来存放关系图
            nodeR: 54,  //关系图中每一个节点的半径
            simulation: null,   //引力
            zoom: null,         //svg触发放大平移操作时执行的函数
            zoomListener: null, //放大平移的监听器
            zoomFactor: {k: 1, tx: 0, ty: 0}, //svg放大的参数用来计算坐标
            data: null,     //关系图中节点和连线数据，格式：{nodes:[],links:[]}
            customData: null,  //用户自定义过的数据（修改过的数据）
            originData: null,  //原始数据
            customBack: {},
            drawRun: null,  //引力设置tick时间为2秒，2秒之后停止刷新。
            timeFilterData: null,   //时间过滤后的数据
            authority: null,//是否有权限
            website: null,  //单个扩展时，判断是哪个页面
            renInjured: false, //人伤
            ruleTel: false,   //专项模型中同一电话规则时，限制展开30个节点，2018-04-23
            //	loop:[],
            //	isHover:false,
            //	type:"",
            nowId: "", //当前查询节点的Id
            ids: [],   //已经查询节点的id集合
            nodeToNode: null, //用来表示两个点是否相连，{ "a-b":1 }表示a节点和b节点相连。
            nodeSelect: {
                Zpress: 0, //为1表示ctrl键被按住，可以进行款选和单击选择节点
                ids: []    //已经选择的节点集合
            },
            rangeSelect: {  //框选时需要用到的参数，用来判断鼠标点击和移动事件。
                isMove: false,        //鼠标是否移动
                isClick: false,       //鼠标是否按下
                isOutRange: false,    //是否超出画布范围
                mouseStartCoor: null, //起始坐标
                mouseCurrCoor: null,  //当前坐标
                mouseEndCoor: null    //结束坐标
            },
            makeMark: {  //新建连线的时候需要用的参数
                isClick: false,        //鼠标是否按下
                isSourceChoose: false, //起点是否选择
                source: null,          //起点节点对象
                target: null			  //终点节点对象
            },
            hightlight: {   //高亮效果时用到的参数
                isEnable: 0,    //是否高亮
                //con:"",   	   //
                autoRun: null,  //自动循环播放高亮效果
                nodes: [],      //高亮的节点
                links: []       //高亮的线段
            },
            operateIndex: -1,
            operateList: [],   //恢复操作列表
            cancelList: [],    //撤销操作列表
            addIndex: 0,  //新家节点的个数，可当做index
            actionEnable: 0,    //为0的时候屏蔽svg的点击和键盘事件
            xhrPool: [],
            infoNodeId: "",
            isCustom: false,
            filterType: [],   //过滤类型的数组
            hotCode: false,
            timeFilter: false,
            maxT: 0,
            minT: 0,
            extendMode: 0,
            menuShow: null,   //右击节点时判断菜单是否显示
            markWeb: null,    //标注时，来源的页面，2018-01-09
            webPosition: null,    //页面所在的位置 ，2018-01-16
            specialModelData: null,  //专项模型列表数据，2018-03-19
            exendBeforeData: null,   //扩展前的数据，2018-04-22
            node: null, // 当前点击的node对象
            firstRender: true
        },
        option: {
            typeData: ['A','B','T','P','L','BUSI','AGE','career','D','C','H','HL','ILL'],
            type: {  //节点的类型简称
                peo: "P",   //人物
                phone: "T", //电话
                order: "C", //案件
                car: "V",   //车辆
                org: "org",
                account: "S", //账户
                baodan: "I",  //保单
                sxclaim: "A",   //寿险案件
                sxpolicy: "B", //寿险保单
                sxpid: "P", //寿险被保人
                sxapid: "T",   //寿险投保人
                sxbenid: "L", //寿险领款人
                sxphone: "D", //寿险电话
                sxclmset: "C", //寿险账户
                sxemp: "BUSI", //寿险业务员
                sxhospital: "H",   //寿险医院
                sxage: "AGE",   // 寿险被保人年龄
                sxhospitalLevel: "HL",   // 寿险案件医院等级
                sxoccupation: "career",   // 寿险被保人职业
                sxseriousillness: "ILL",   // 寿险被保人重疾病类型
            },
            opacity: {
                nodes: {
                    weak: 0.3,
                    strong: 1
                },
                links: {
                    weak: 0.1,
                    strong: 1
                }
            }

        },
        weaverData: null,
        graphweaverIds: null,
        roleProperty: null,
        result: null,
        weaverNode: null,
        weaverEdge: null,
        entityType: null,
        list: { //列表（实体信息等）
            cateCon: null,//接收左侧列表对象
            resultHead: null,//实体信息栏
            resultHead3: null,//统计信息栏
            relation2: null,//风险详情栏
        },
        riskMessage: {
            nodes: new Array(),
            edges: new Array(),
            nodeArr: new Array(),
            edgeArr: new Array(),
        },
        onelink: null,//接收draw中图的数据
        constructor: NewGraph,
        /*
		 *  初始化关系图对象
		 */
        init: function () {
            var self = this;
            //初始化svg画布，添加画布元素，设置高宽
            self.para.svg = d3.select("#" + self.opt.con)
                .append("svg")
                .attr("viewBox", "0 0 " + self.opt.width + " " + self.opt.height)
                .attr("width", self.opt.width)
                .attr("height", self.opt.height)
                .attr("class", "relativeG");
            //设置node，link，linkText的group，注意顺序，后加的位于顶层。
            self.para.graph = self.para.svg.append("g").attr("class", "graph");
            self.para.graph.append("g").attr("class", "markLinks");
            self.para.graph.append("g").attr("class", "links");
            self.para.graph.append("g").attr("class", "linkTexts");
            self.para.graph.append("g").attr("class", "nodes");
            self.para.graph.append("g").attr("class", "nodeLabels");

            //初始化引力
            self.para.simulation = d3.forceSimulation()
            //设置斥力，点的类型为案件的时候斥力较大
                .force("charge", d3.forceManyBody().strength(function (d) {
                    if (d.type == self.option.type.order) {
                        return 10 * self.opt.charge;
                    } else {
                        return 2 * self.opt.charge;
                    }
                }))
                //设置力的中心点
                .force("center", d3.forceCenter(self.opt.width / 2, self.opt.height / 2))
                .force("y", d3.forceY(self.opt.width / 2).strength(0.1))
                .force("x", d3.forceX(self.opt.height / 2).strength(0.1));
            //开启放大平移
            self.zoom(true);
            //事件绑定
            self.bind();
        },
        /*
		 * 事件绑定
		 * */
        bind: function () {
            var self = this;
            //点击svg画布事件
            self.para.svg.on("click", function () {
                self.recover();
                if (self.para.actionEnable == 0) {
                    return;
                }
                //删除功能菜单
                self.clearMenu();
                //self.cancenlHoverLoop();
                /*
				 * 如果被选中的节点数目等于0，清除选中样式，点和线的样式恢复成默认状态；
				 * 如果被选中的节点数目大于0，虚化其他节点，高亮被选中节点和与其相连的节点，并显示连线上的关系。
				 */
                if (self.para.nodeSelect.ids.length == 0) {
                    self.clearSelect(); //清除节点选中样式
                    //self.recover();     //将点、线等样式恢复默认状态
                } else {
                    self.hoverSelectNodes(); //高亮被选中节点和与其相连的节点
                }
            })
            //右键svg画布事件
                .on("contextmenu", function () {
                    ////console.log(self.para.nodeSelect.ids);
                    if (self.para.actionEnable == 0) {
                        return;
                    }
                    var coor = d3.mouse(this); //鼠标点击时的坐标
                    if (self.para.nodeSelect.ids.length > 1) { //如果没有选中的节点，显示圆形菜单
                        //if(!self.para.menuShow){ //右击节点时判断权限是否显示菜单
                        self.showMenu("multi", {x: coor[0], y: coor[1]});
                        //}
                    } else if (self.para.nodeSelect.ids.length == 1) { //如果选中节点数为1，显示环形菜单
                        self.para.graph.selectAll(".node").filter(function (d) {
                            return d.id == self.para.nodeSelect.ids[0];
                        }).each(function (data) {
                            self.moveGraph(data, 0.7);
                            //if(!self.para.menuShow){ //右击节点时判断权限是否显示菜单
                            self.showMenu("single", data, d3.select(this));
                            //}
                        });
                    } else { //如果有选中的节点，显示扇形菜单
                        //if(!self.para.menuShow){ //右击节点时判断权限是否显示菜单
                        self.showMenu("total", {x: coor[0], y: coor[1]});
                        //}
                    }
                    //阻止显示浏览器默认的右键事件
                    d3.event.preventDefault();
                })
                //双击svg画布事件
                .on("dblclick", function () {
                    if (self.para.actionEnable == 0) {
                        return;
                    }
                    //取消选中
                    self.clearSelect();
                    //取消新建连线
                    if (self.para.makeMark.isClick == true) {
                        self.para.graph.select(".markLinks").selectAll("*").remove();
                        self.para.svg.on("mousemove", null);
                        self.para.makeMark.isSourceChoose = false;
                        self.para.makeMark.isClick = false;
                    }
                    //隐藏连线时的提示文字
                    $("#Tip").hide();
                    //取消环
                    self.para.graph.selectAll(".node").selectAll("circle").filter(function (d) {
                        return d.newComing == true && d.markStatus != "10" && d.markStatus != "11" && d.markStatus != "12" && d.searchCase != true;
                    }).attr("stroke-opacity", function (d) {
                        d.newComing = false;
                        return 0;
                    })
                });
            //keyDown事件
            self.para.nodeSelect.Zpress = 0; //默认ctrl按钮没有被按住
            d3.select(document).on("keydown", function () {
                if (self.para.actionEnable == 0 || self.para.makeMark.isClick == true) { //如果actionEnable为0，代表还没有画图，不能触发该事件
                    return;
                }
                if (d3.event.keyCode == 17) {
                    self.para.graph.selectAll(".node").attr("opacity", 1)
                    self.para.graph.selectAll(".link").attr("opacity", 1)
                    self.para.graph.selectAll(".linkText").attr("opacity", 1)
                    self.para.nodeSelect.Zpress = 1;
                    self.zoom(false);
                    self.selectArea(true);
                }
            }).on("keyup", function () {
                ////console.log(self.para.actionEnable);
                if (self.para.actionEnable == 0 || self.para.makeMark.isClick == true) {
                    return;
                }
                if (self.para.hotCode == false) {
                    if (d3.event.shiftKey && d3.event.keyCode == 84) {
                        _.MessageManager.fire("fastTable");
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 49) {
                        self.findLoop();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 27) {
                        $("body #ruleLevel1 [data-id='close']").click();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 86) {
                        self.getForce();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 67) {
                        self.circleLayout([0, 0]);
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 77) {
                        var graph = self.getNewSubGraph();
                        var coorForNode = self.matrixLayoutByType(graph);
                        self.layoutNew(coorForNode);
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 50) { // 2
                        self.getTCDA();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 51) { // 3
                        self.getTDDA();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 52) { // 4
                        self.getYSDQD();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 53) { //5
                        self.getKYPCC();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 54) { // 6
                        self.getTHDA();
                        threeSecond();
                    }
                    if (d3.event.shiftKey && d3.event.keyCode == 55) { // 7
                        self.getKYRW();
                        threeSecond();
                    }
                }

                if (d3.event.keyCode == 17) {
                    //如果提前送掉shift按钮，手动执行mounseup
                    if (self.para.rangeSelect.isClick == true) {
                        self.para.rangeSelect.isClick = false;
                        self.para.rangeSelect.isOutRange = false;
                        self.para.svg.selectAll(".selectArea").remove();
                        self.selectNodes(self.para.rangeSelect.mouseStartCoor, self.para.rangeSelect.mouseCurrCoor, true);
                    }
                    self.para.nodeSelect.Zpress = 0;
                    self.zoom(true);
                    self.selectArea(false);

                    self.mouseoutNode();
                    /*
		    		if(self.para.nodeSelect.ids.length==0){
						self.recover();
					}else{
						self.hoverSelectNodes();
					}
					*/
                }
            });

            function threeSecond() {
                self.para.hotCode = true;
                setTimeout(function () {
                    self.para.hotCode = false;
                }, 1000);
            }

            //回退事件
            _.MessageManager.on("goback", function () {
                if (self.para.operateIndex < self.para.cancelList.length - 1) {
                    self.goback();
                } else {
                    alert("没有操作")
                }
            });
            //撤销事件
            _.MessageManager.on("cancel", function () {
                if (self.para.operateIndex >= 0) {
                    self.undo();
                } else {
                    alert("没有操作")
                }
            });
            //在新建节点的框中，点击不同类型切换不同的详细信息框
            $("body").delegate("#newNodeSel", "change", function () {
                $("#nodeDetailTable").html(self.getNodeTypeStr("newNode", {type: $(this).find("option:selected").data("id")}));

                $(".ui_timepicker").datetimepicker({
                    dateFormat: 'yy-mm-dd',
                    changeMonth: true,
                    changeYear: true,
                    showSecond: true,
                    timeFormat: 'hh:mm:ss'
                });
                $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);

                $("#newNodeCon").perfectScrollbar("update");
            });
            //修改link
            $("body").delegate("[data-id='linkDataLi'] li>p", "click", function () {
                var $p = $(this).parent();
                if ($p.data("detail").attr == undefined || $p.data("detail").attr.length == 0) {
                    alert("没有属性值！");
                    return;
                }
                var isClick = $p.data("isclick");
                var linkId = $p.data("id");
                if (isClick == 0) {
                    var flag = true;
                    $("[data-id='linkDataLi'] li").each(function () {
                        if ($(this).data("isclick") == 1 && $(this).data("ischange") == 1 && linkId != $(this).data("id")) {
                            if (confirm("是否保存当前修改！")) {
                                var isSave = self.linkModifySave($(this).find("[data-btn='save']"));

                                if (!isSave) {
                                    flag = false
                                }
                                return false;
                            } else {
                                flag = false;
                                return false;
                            }
                        }
                    });
                    if (flag) {
                        $("body [data-id='linkDataLi'] li").data("isclick", 0);
                        $p.siblings().find(".relationside").remove();
                        $p.data("isclick", 1);
                        var ht = self.getLinkTable($(this).parent().data("detail"));
                        $(this).parent().append(ht);
                        $(".ui_timepicker").datetimepicker({
                            dateFormat: 'yy-mm-dd',
                            changeMonth: true,
                            changeYear: true,
                            showSecond: true,
                            timeFormat: 'hh:mm:ss'
                        });
                        $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);
                    }
                } else {
                    if ($p.data("ischange") == 1) {
                        alert("请先保存修改信息！");
                    } else {
                        $p.data("isclick", 0);
                        $p.find(".relationside").remove();
                    }
                }
            });
            $("body").delegate("[data-id='linkTable'] button[data-btn='save']", "click", function () {
                self.linkModifySave($(this))
            });

            $("body").delegate("[data-id='linkTable'] button[data-btn='add']", "click", function () {
                var linkData = $(this).parents("li").data("detailmodify");
                var linkType = linkData.source.type + linkData.target.type;
                $(this).siblings("table").find("tbody").append(self.getOneRowForAddLink(linkType, "modify", null));
                $(".ui_timepicker").datetimepicker({
                    dateFormat: 'yy-mm-dd',
                    changeMonth: true,
                    changeYear: true,
                    showSecond: true,
                    timeFormat: 'hh:mm:ss'
                });
                $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);
                linkData.rel.push("empty");
                linkData.attr.push({
                    "type": "empty",
                    "createTime": "",
                    "desc": "",
                    "weight": null
                });
                $(this).parents("li").data("detailmodify", linkData).data("ischange", 1);
            });
            $("body").delegate("[data-id='linkTable'] [data-change='1']", "change", function () {
                $(this).parents("li").data("ischange", 1);
                var name = $(this).attr("name");
                var linkData = $(this).parents("li").data("detailmodify");
                var index = $(this).parent().parent().index();
                for (var prop in linkData.attr[index]) {
                    if (name == prop) {
                        if (prop == "type") {
                            linkData.attr[index][prop] = $(this).find("option:selected").data("id");
                            linkData.rel[index] = $(this).find("option:selected").data("id");
                        } else {
                            linkData.attr[index][prop] = $(this).val();
                        }
                    }
                }
                $(this).parents("li").data("detailmodify", linkData);
            });

            //添加link的关系
            $("body").delegate("#btnAddButton", "click", function () {
                $(".relationside tbody").append(self.getOneRowForAddLink($(this).data("type"), "new", null));
                $(".ui_timepicker").datetimepicker({
                    dateFormat: 'yy-mm-dd',
                    changeMonth: true,
                    changeYear: true,
                    showSecond: true,
                    timeFormat: 'hh:mm:ss'
                });
                $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);
                //$('#linkModify .list').perfectScrollbar("update");
            });
            $("body").delegate(".relationside tr .del", "click", function () {
                if (confirm("确定要删除该关系吗？")) {
                    var $pp = $(this).parent().parent();
                    var index = $pp.index();
                    if ($pp.data("type") == "modify") {
                        var linkData = $pp.parents("li").data("detailmodify");
                        linkData.rel.splice(index, 1);
                        linkData.attr.splice(index, 1);
                        $pp.parents("li").data("detailmodify", linkData);
                        $(this).parents("li").data("ischange", 1);
                    }
                    $pp.remove();
                }
            });

            $("body").delegate("#btnSave", "click", function () {
                var linkId = $("#attribute").find("select option:selected").val();
                $("#btnList li").each(function () {
                    if ($(this).data("type") == linkId) {
                        alert("该关系已经存在！");
                        return false;
                    }
                })
                var hd = '<li style="position:relative;" data-type="' + linkId + '">'
                    + '<p data-type="rel">关系：<span>' + linkId + '</span></p>'
                    + '<p data-type="time">时间：<span>' + $("#detailContent").find("input[name=time]").val() + '</span></p>'
                    + '<p data-type="weight">权重：<span>' + $("#detailContent").find("input[name=weight]").val() + '</span></p>'
                    + '<span data-func="close">X</span>'
                    + '</li>'
                $("#btnList ul").append(hd);
                $("#btnList").perfectScrollbar("update");
                $("#attribute").hide();
            });

            $("body").delegate("#btnList li span[data-func='close']", "click", function () {
                $(this).parent().remove();
            });

            $("body").delegate(".dateClean", "click", function () {
                $(this).siblings("input").datepicker('setDate', null);
                $(this).siblings("input").val("");
            });
        },
        save: function () {
            var self = this;
            if (self.para.operateList.length > 0 && self.para.operateIndex >= 0) {
                var saveData = new Array();
                for (var i = 0; i <= self.para.operateIndex; i++) {
                    if (self.para.operateList[i].operate != "extend") {
                        saveData.push(self.clone(self.para.operateList[i]));
                    }
                }
                for (var i = 0; i < saveData.length; i++) {
                    for (var j = 0; j < saveData[i].data.links.length; j++) {
                        saveData[i].data.links[j].source = self.getLinkSourceId(saveData[i].data.links[j]);
                        saveData[i].data.links[j].target = self.getLinkTargetId(saveData[i].data.links[j]);
                    }
                }
                self.clearXHRPool();
                self.para.xhrPool.push($.ajax({
                    type: "POST",
                    url: self.opt.url + "/graph/saveEntity.do",
                    data: {
                        graph: JSON.stringify(saveData)
                    },
                    dataType: "json",
                    success: function (result) {
                        if (result == "succ") {
                            alert("保存成功！");
                            self.para.operateIndex = -1;
                            self.para.operateList.splice(0, self.para.operateList.length);
                            self.para.cancelList.splice(0, self.para.cancelList.length);
                            self.para.addIndex = 0;
                        } else {
                            alert("保存失败！");
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //console.log([XMLHttpRequest, textStatus, errorThrown]);
                        var status = ["abort", "error"];
                        if (status.indexOf(textStatus) < 0) {
                            alert("保存失败！");
                        }
                    }
                }));
            } else {
                alert("没有改动！");
            }
        },
        getSubGraph: function () {
            if (this.para.nodeSelect.ids.length > 0) {
                var nodeArr = this.getNodes(this.para.nodeSelect.ids);
                var subIds = this.getAllNodeIds(nodeArr);
                var linkArr = [];
                for (var i = 0; i < this.para.data.links.length; i++) {
                    var tmpLink = this.para.data.links[i];
                    var srcId = this.getLinkSourceId(tmpLink);
                    var tarId = this.getLinkTargetId(tmpLink);
                    if (subIds.indexOf(srcId) >= 0 && subIds.indexOf(tarId) >= 0) {
                        linkArr.push(tmpLink);
                    }
                }
                return {nodes: nodeArr, links: linkArr};
            } else {
                if (this.para.timeFilter) {
                    var nodes = [];
                    var links = [];
                    for (var i = 0; i < this.para.data.nodes.length; i++) {
                        if (this.para.data.nodes[i].timeFilter) {
                            nodes.push(this.para.data.nodes[i]);
                        }
                    }
                    for (var i = 0; i < this.para.data.links.length; i++) {
                        if (this.para.data.links[i].timeFilter) {
                            links.push(this.para.data.links[i]);
                        }
                    }
                    return {nodes: nodes, links: links};
                } else {
                    return this.para.data;
                }
            }
        },
        refreshInfoDetail: function (isClick) {
            var self = this;
            var flag = true;
            isClick = isClick == undefined ? true : isClick;
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                if (self.para.infoNodeId == self.para.data.nodes[i].id) {
                    var linkForThisNode = self.getLinkForNode(self.para.infoNodeId);
                    _.MessageManager.fire("infoDetail", {
                        nodeInfo: self.para.data.nodes[i],
                        links: linkForThisNode,
                        isClick: isClick
                    });
                    flag = false;
                    break;
                }
            }
            if (flag) {
                _.MessageManager.fire("clearInfoDetail", {ids: self.para.nodeSelect.ids});
            }
        },
        isCustom: function () {
            var self = this;
            if (!self.para.isCustom) {
                alert("继续修改请先转换为自定义状态！");
                return false;
            } else {
                return true;
            }
        },
        isModify: function () {
            var self = this;
            var flag = false;
            for (var i = 0; i < self.para.operateList.length; i++) {
                if (self.para.operateList[i].operate != "extend") {
                    flag = true;
                    break;
                }
            }
            return flag;
        },
        switchCustomData: function (customData, type) {
            var self = this;
            if (type == "toCustom") {
                self.para.originData = self.clone(self.para.data);
                self.para.customData = self.clone(customData.custom);
                self.switchData(self.para.data, self.para.customData);
                //清空操作序列
                self.para.operateIndex = -1;
                self.para.operateList.splice(0, self.para.operateList.length);
                self.para.cancelList.splice(0, self.para.cancelList.length);
                self.para.addIndex = 0;
                self.refreshInfoDetail();
                //标识自定义状态
                self.para.isCustom = true;
                self.clearMenu();
            } else {
                self.markMatch();
                self.clear();
                self.para.data = self.para.originData;
                self.para.data = self.getOriginFormatData();
                self.refreshInfoDetail();
                self.para.isCustom = false;
            }
            self.para.data = self.filterLinks(self.para.data);
            self.timeFilter(self.para.maxT, self.para.minT);//hyx
            self.filterSameType(self.para.filterType); //过滤类型
            self.draw(self.para.data);
            self.refreshLinkText();
        },
        markMatch: function () {
            var self = this;
            var isMarkStatus = new Object();
            var isMarkMess = new Object();
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                var thisNode = self.para.data.nodes[i];
                isMarkStatus[thisNode.id] = thisNode.markStatus;
                isMarkMess[thisNode.id] = thisNode.markMess;
            }
            for (var i = 0; i < self.para.originData.nodes.length; i++) {
                var thisNode = self.para.originData.nodes[i];
                if (isMarkStatus[thisNode.id] != undefined) {
                    thisNode.markStatus = isMarkStatus[thisNode.id];
                    thisNode.markMess = isMarkMess[thisNode.id];
                }
            }
        },
        refreshLinkText: function () {
            var self = this;
            self.para.graph.selectAll(".linkText").select("text")
                .text(function (d) {
                    if (d.rel.length == 1) {
                        return self.opt.linkMap[d.rel[0]] == undefined ? d.rel[0] : self.opt.linkMap[d.rel[0]].cnName;
                    } else {
                        var relName = [];
                        for (var i = 0; i < d.rel.length; i++) {
                            relName.push(self.opt.linkMap[d.rel[i]] == undefined ? d.rel[i] : self.opt.linkMap[d.rel[i]].cnName);
                        }
                        return relName.join(",");
                    }
                });
        },
        filterLinks: function (data) {
            var self = this;
            var nodeIds = self.getAllNodeIds(data.nodes);
            var delLinkArr = [];
            var newLinks = [];
            for (var i = 0; i < data.links.length; i++) {
                var srcId = self.getLinkSourceId(data.links[i]);
                var tarId = self.getLinkTargetId(data.links[i]);
                if (nodeIds.indexOf(srcId) < 0 || nodeIds.indexOf(tarId) < 0) {
                    if (delLinkArr.indexOf(data.links[i].id) < 0) {
                        delLinkArr.push(data.links[i].id);
                    }
                } else {
                    newLinks.push(data.links[i]);
                }
            }
            data.links = newLinks;
            return data;
        },
        switchData: function (oldData, newData) {
            var self = this;
            for (var i = 0; i < newData.nodes.length; i++) {
                var isNew = true;
                for (var k = 0; k < oldData.nodes.length; k++) {
                    var newD = newData.nodes[i];
                    var oldD = oldData.nodes[k];
                    if (oldD.id == newD.id) {
                        if (newD["delete"] == true) {
                            self.removeNode(oldD.id);//删除数据里面的点
                            self.para.graph.selectAll(".node").filter(function (d) {
                                return d.id == oldD.id;
                            }).remove();
                        } else {
                            self.modifyNode(oldD.id, self.clone(newD));
                        }
                        isNew = false;
                        break;
                    }
                }
                if (isNew && newData.nodes[i]["delete"] != undefined && newData.nodes[i]["delete"] == false) {
                    var newNode = new Object();
                    for (var prop in newData.nodes[i]) {
                        if (prop != "delete") {
                            newNode[prop] = newData.nodes[i][prop];
                        }
                    }
                    oldData.nodes.push(newNode);
                }
            }

            for (var i = 0; i < newData.links.length; i++) {
                var isNew = true;
                for (var k = 0; k < oldData.links.length; k++) {
                    var newD = newData.links[i];
                    var oldD = oldData.links[k];
                    if (oldD.id == newD.id) {
                        if (newD["delete"] == true) {
                            self.removeLink(oldD.id);
                            self.para.graph.selectAll(".linkText").filter(function (d) {
                                return oldD.id == d.id;
                            }).remove();
                            self.para.graph.selectAll(".link").filter(function (d) {
                                return oldD.id == d.id;
                            }).remove();
                        } else {
                            for (var prop in oldD) {
                                if (prop != "source" && prop != "target") {
                                    if (newD[prop] != undefined) {
                                        oldD[prop] = newD[prop];
                                    }
                                }
                            }
                            self.modifyLink(oldD[prop]);
                        }
                        isNew = false;
                        break;
                    }
                }
                var nodeIds = self.getAllNodeIds(self.para.data.nodes);
                if (isNew && nodeIds.indexOf(newData.links[i].source) >= 0 && nodeIds.indexOf(newData.links[i].target) >= 0
                    && newData.links[i]["delete"] != undefined && newData.links[i]["delete"] == false) {
                    oldData.links.push(newData.links[i]);
                }
            }
        },
        linkModifySave: function ($link) {
            //判断输入是否有效
            var rel = [];
            var status = 1;
            var self = this;
            $(".relationside tbody tr").each(function () {
                var linkType = $(this).find("select option:selected").data("id");
                var linkTime = $(this).find("[name='createTime']").val();
                var linkWeight = $(this).find("[name='weight']").val();
                var linkDesc = $(this).find("textarea").val();

                if (linkType == "empty" || linkTime == "" || linkWeight == "" || linkDesc == "") {
                    status = -1;
                    return false;
                }
                if (rel.indexOf(linkType) >= 0) {
                    status = -2;
                    return false;
                }
                rel.push(linkType);
            });
            if (rel.length == 0 && status == 1) {
                status = -3;
            }
            if (status != 1) {
                if (status == -1) {
                    alert("信息填写不完整！");
                } else if (status == -2) {
                    alert("一种类型的边只能存在一条！");
                } else if (status == -3) {
                    alert("至少插入一条关系！");
                }
                return false;
            } else {
                var linkData = $link.parents("li").data("detailmodify");
                $link.parents("li").data("detail", self.clone(linkData));
                $link.parents("li").data("ischange", 0);
                $link.parents("li").data("isclick", 0);
                $link.parents("li").find(".relationside").remove();
                return true;
            }
        },
        getLinkSelectName: function (value) {
            var self = this;
            switch (value) {
                case "empty" :
                    return "-请选择-";
                    break;
                case "other" :
                    return "自定义";
                    break;
                default :
                    return self.opt.linkMap[value] == undefined ? value : self.opt.linkMap[value].cnName;
                    break;
            }
        },
        /*
		 * 获取Group的坐标
		 * */
        coorTransForG: function (translateStr) {
            var translateSubStr = translateStr.substring(translateStr.indexOf("(") + 1, translateStr.indexOf(")"));
            var translate = translateSubStr.split(/[,| ]/);
            for (var i = 0; i < translate.length; i++) {
                translate[i] = parseFloat(translate[i]);
            }
            return translate;
        },
        /*
		 * 获取Group的坐标nodeExtend
		 * */
        getTranslation: function (transform) {
            var g = document.createElementNS("http://www.w3.org/2000/svg", "g");
            g.setAttributeNS(null, "transform", transform);
            var matrix = g.transform.baseVal.consolidate().matrix;
            return [matrix.e, matrix.f];
        },
        /*
		 *  显示环形菜单
		 */
        showMenu: function (type, data, item) {
            var self = this;
            if (self.para.makeMark.isClick) {
                return;
            }
            /*
			self.para.svg.on("dblclick",function(){
				if (d3.event.defaultPrevented) return;
				self.createMenu(d3.mouse(this));
				//self.replace();
			});
			*/
            if (!self.para.menuShow) {
                switch (type) {
                    case "single":
                        self.clearSelect();//清除选中
                        self.para.nodeSelect.ids.push(data.id);
                        item.select("image[data-id='mainImg']").attr("xlink:href", function (d) {
                            console.log("777777777777777777777777777777" + d.type);
                            return self.getImage(d.type, 1);
                        })
                        self.createCircleMenu(data, item);
                        break;
                    case "multi":
                        self.createRingMemu(data);
                        break;
                    case "total":
                        self.clearSelect();
                        self.createMenu(data);
                        break;
                    case "filter":
                        self.clearSelect();//清除选中
                        self.para.nodeSelect.ids.push(data.id);
                        item.select("image[data-id='mainImg']").attr("xlink:href", function (d) {
                            return self.getImage(d.type, 1);
                        })
                        self.createFilterCircleMenu(data, item);
                        break;
                }
            }
        },
        /*
		 *  清除菜单
		 */
        clearMenu: function () {
            var self = this;
            self.para.svg.selectAll(".menu").remove();
            self.para.svg.selectAll(".subMenu").remove();
            self.para.svg.selectAll(".menuCenter").remove();
            self.para.svg.selectAll(".allMenu").remove();
        },
        /*
         * 创建过滤环形菜单
         */
        createFilterCircleMenu: function (nodeData, item) {
            var self = this;
            var data = [{dataValue: 1, name: "相似度过滤", id: "same"}, {
                dataValue: 1,
                name: "过滤2",
                id: "filter2"
            }, {dataValue: 1, name: "过滤3", id: "filter3"}, {
                dataValue: 1,
                name: "过滤4",
                id: "filter4"
            }, {
                dataValue: 1,
                name: "全部",
                id: "all"
            }];
            //删除画布中已有的一级菜单和二级菜单元素
            self.clearMenu();
            var menu = self.createPie(item, 60, 130, 750, data, [0, 0], 0, Math.PI * 2, "menu");
            console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', menu)
            menu.selectAll("*").on("click", function (d) {
                d3.event.stopPropagation();
                self.para.svg.selectAll(".subMenu").remove();
                // var data = {
                //     id: self.para.node.id, //当前查询id
                //     searchType: '',    //当前查询类型
                //     name: self.para.node.name
                // };
                // console.log(data)
                if(d.data.id == 'same' || d.data.id === 'all') {
                    self.extendNodes(false, false, d.data.id)
                }
                self.clearMenu();//删除菜单
                self.clearSelect();//清除选中
            });
        },
        /*
		 * 环形菜单
		 */
        createCircleMenu: function (nodeData, item) {
            var self = this;

            var data;
            if (!self.para.isCustom) {
                data = [{dataValue: 1, name: "新建边", id: "createLink"}, {dataValue: 1, name: "删除", id: "delete"},
                    {dataValue: 1, name: "修改", id: "modify"}, {dataValue: 1, name: "还原数据", id: "origin"},
                    {dataValue: 1, name: "展开", id: "extend"}
                    , {dataValue: 1, name: "标注", id: "mark"}
                ];
            } else {
                data = [{dataValue: 1, name: "新建边", id: "createLink"}, {dataValue: 1, name: "删除", id: "delete"},
                    {dataValue: 1, name: "修改", id: "modify"}, {dataValue: 1, name: "展开", id: "extend"}
                    , {dataValue: 1, name: "标注", id: "mark"}
                ];
            }
            if (nodeData.type == self.option.type.order) {
                data.push({dataValue: 1, name: "图片", id: "pic"});
            }
            /*
			var data = [{dataValue:1,name:"功能",id:"func"},{dataValue:1,name:"编辑",id:"edit"}];
			var subData = {
				"func":[{dataValue:1,name:"新建边",id:"createLink"}],
				"edit":[{dataValue:1,name:"删除",id:"delete"},{dataValue:1,name:"修改",id:"modify"}]
			};
			*/

            //删除画布中已有的一级菜单和二级菜单元素
            self.clearMenu();
            var menu = self.createPie(item, 60, 130, 750, data, [0, 0], 0, Math.PI * 2, "menu");

            menu.selectAll("*").on("click", function (d) {
                d3.event.stopPropagation();
                self.para.svg.selectAll(".subMenu").remove();
                switch (d.data.id) {
                    case "pic":
                        /*
						var url = [01.jpg,02.jpg,03.jpg,04.jpg,05.jpg];
						var str ="<div class='backg' id='CaseImg'>"
								+"<div class='imgCon'><p style='display:inline-block;'>案件的图片显示</p>"
								+"<img src='"+self.opt.url+"/images/indexNew/fulls/02.jpg' style='display:inline-block;'>"
								+"</div></div>";
						$("body").append(str);
						$("#CaseImg").click(function(){
							$(this).remove();
						});
						*/
                        _.MessageManager.fire("getCaseImg", {data: nodeData});
                        break;
                    case "mark":
                        _.MessageManager.fire("showMarkCon", {data: nodeData});
                        break;
                    case "extend":
                        self.extendNodes(true);
                        break;
                    case "origin":
                        self.para.xhrPool.push($.ajax({
                            type: "POST",
                            url: self.opt.url + "/graph/refreshCustomNode.do",
                            data: {nodeid: nodeData.id},
                            dataType: "json", //返回的数据格式
                            success: function (result) {
                                if (result) {
                                    alert("还原成功！");
                                } else {
                                    alert("还原失败！");
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                //console.log([XMLHttpRequest, textStatus, errorThrown]);
                                var status = ["abort", "error"];
                                if (status.indexOf(textStatus) < 0) {
                                    alert("还原失败！");
                                }
                            }
                        }));
                        break;
                    case "delete":
                        //判断是不是自定义状态
                        if (!self.isCustom()) {
                            return;
                        }
                        if (confirm("确定要删除该节点吗？")) {
                            self.para.nodeSelect.ids.push(nodeData.id);
                            var nodes = self.getNodes(self.para.nodeSelect.ids);  //获取删除的nodes对象
                            var links = self.getLinks(self.para.nodeSelect.ids, 1);//获取删除的links对象
                            //记录操作
                            self.recordOperate("delete", "add", {nodes: nodes, links: links}, {
                                nodes: nodes,
                                links: links
                            }, "恢复-删除节点", "撤销-删除节点", "delete");
                            self.deleteNodes(); //删除节点

                            self.refreshInfoDetail();

                            //更新统计信息
                            _.MessageManager.fire("getStatic");
                        }
                        break;
                    case "modify":
                        //判断是不是自定义状态
                        if (!self.isCustom()) {
                            return;
                        }
                        var ht = self.getAlertInfo("modifyNode", nodeData);

                        $.alert({
                            title: "修改节点信息",
                            content: ht,
                            theme: 'blue',
                            closeIcon: true,
                            onOpen: function () {
                                $("#newNodeCon").perfectScrollbar();
                                $(".content").addClass("ml20");
                                $(".ui_timepicker").datetimepicker({
                                    dateFormat: 'yy-mm-dd',
                                    changeMonth: true,
                                    changeYear: true,
                                    showSecond: true,
                                    timeFormat: 'hh:mm:ss'
                                });
                                $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);
                                //$(".Wdate").datepicker({ dateFormat: 'yy-mm-dd',showButtonPanel: true,showClearButton: true,});
                            },
                            confirm: function () {
                                //获取修改节点的数据
//					            	var offerNum=$("input[name='daja#CASE_NOTIFICATIONNO']").val(); //获取"主键"的值
//				            		var caseNum=$("input[name='daja#CASE_CASEFOLDERID']").val();    //获取"显示"的值
                                var flag = true;
                                $("#nodeDetailTable .star").each(function () {
                                    if ($(this).next().val().trim() == '') {
                                        flag = false;
                                    }
                                })
                                if (!flag) {
                                    alert("*为主要信息，请填完整主要信息！");
                                    return false;
                                }
//				            		if(offerNum=='' || caseNum==''){
//				            			alert("请填完整主要信息！");
//				            			return false;
//				            		}
                                //var name=$("#nodeDetailTable input[name='name']").val();
                                var newData = new Object();
                                var name;
                                $("#nodeDetailTable input").each(function () {
                                    newData[$(this).attr("name")] = $(this).val();
                                    if (self.opt.nameMap[nodeData.type].name == $(this).attr("name")) {
                                        name = $(this).val();
                                    }
                                });
                                /*console.log(newData);
									console.log(self.opt.nameMap[nodeData.type].name);*/

                                var tmpData = self.clone(nodeData);//复制原始数据
                                for (var i = 0; i < nodeData.attrs.length; i++) {//修改原始数据
                                    nodeData.attrs[i].value = newData[nodeData.attrs[i].name];
                                }
                                nodeData.name = name == undefined ? nodeData.name : name;
                                nodeData.name = nodeData.name == undefined ? "" : nodeData.name
                                self.recordOperate("modify", "modify", {
                                    nodes: [self.clone(nodeData)],
                                    links: []
                                }, {nodes: [tmpData], links: []}, "恢复-修改节点信息", "撤销-修改节点信息", "modify")

                                self.modifyNode(nodeData.id, self.clone(nodeData));
                                _.MessageManager.fire("refreshCaseList", {list: self.para.data.nodes});
                                self.refreshInfoDetail();
                                self.timeFilter(self.para.maxT, self.para.minT);//hyx
                                self.filterSameType(self.para.filterType); //过滤类型
                                self.mouseoutNode();
                                _.MessageManager.fire("getStatic");
                            }
                        });
                        break
                    case "createLink":
                        //判断是不是自定义状态
                        if (!self.isCustom()) {
                            return;
                        }
                        //停止force
                        self.para.simulation.stop();
                        self.para.makeMark.isClick = true;
                        self.para.makeMark.source = nodeData;
                        self.para.makeMark.isSourceChoose = true;
                        //缩小画布
                        self.moveGraph(nodeData, 0.5);
                        //添加线
                        self.para.graph.select(".markLinks").append("path")
                            .attr("class", "markLine")
                            .attr("stroke-width", 2)
                            .attr("stroke", "#bc8c8f")
                            .attr("opacity", 1)
                            //.attr("marker-end", "url(#C)")
                            .attr("fill", "#bc8c8f");
                        $("#Tip").show();
                        self.para.svg.on("mousemove", function () {
                            self.para.graph.select(".markLine")
                                .attr("d", function () {
                                    //return "M"+self.para.makeMark.source.x+" "+self.para.makeMark.source.y+
                                    //	   " L"+d3.mouse(this)[0]+" "+d3.mouse(this)[1];
                                    var dx = d3.mouse(this)[0] - self.para.makeMark.source.x,
                                        dy = d3.mouse(this)[1] - self.para.makeMark.source.y;

                                    return "M" + self.para.makeMark.source.x + "," + self.para.makeMark.source.y +
                                        "L" + d3.mouse(this)[0] + "," + d3.mouse(this)[1];
                                });
                        });
                        break;
                }
                _.MessageManager.fire("refreshCaseList", {list: self.para.data.nodes});
                self.clearMenu();//删除菜单
                self.clearSelect();//清除选中
            });
        },
        createMenu: function (nodeData) {
            var self = this;
            //移动画布
            //self.moveGraph({x:self.getReverseNodeX(nodeData.x),y:self.getReverseNodeY(nodeData.y)},self.para.zoomFactor.k);
            //右键添加点
            var dataCenter = [{dataValue: 1, name: "", id: "addNode"}];
            //如果是专项模型，就去掉模型的菜单，2018-01-16，JM
            var data = null;
            if (graph.para.webPosition == "special") {
                data = [{dataValue: 1, name: "布局", id: "layout"}];
            } else {
                data = [{dataValue: 1, name: "布局", id: "layout"}, {dataValue: 1, name: "规则", id: "model"}];
            }

            var subData = {
                layout: [
                    {dataValue: 1, name: "力导向", number: "force"},
                    {dataValue: 1, name: "方阵", number: "matrix"},
                    {dataValue: 1, name: "圆形", number: "circle"}
                ],
                model: [
                    {dataValue: 1, name1: "1:同一人", name2: "多案领款", number: "1"},
                    {dataValue: 1, name1: "2:同一电话", name2: "多案领款", number: "2"},
                    /*{dataValue:1,name:"同厂多案",id:"tchda"},*/
                    {dataValue: 1, name1: "3:同一账号", name2: "多案领款", number: "3"},
                    {dataValue: 1, name1: "4:同一被保", name2: "险人一次事", name3: "故多次理赔", number: "4"},
                    {dataValue: 1, name1: "5:同一投保", name2: "人多案出险", number: "5"},
                    {dataValue: 1, name1: "6:同一业务员", name2: "多重疾理赔", number: "6"},
                    {dataValue: 1, name1: "7:同一医院", name2: "多重疾理赔", number: "7"},
                    {dataValue: 1, name1: "8:可疑出", name2: "险时间", number: "8"},
                    {dataValue: 1, name1: "9:集中多", name2: "案理赔", number: "9"},
                    {dataValue: 1, name1: "10:利害关", name2: "系嫌疑", number: "10"},
                ]
            };

            //删除画布中已有的一级菜单和二级菜单元素
            self.clearMenu();
            var allMenu = self.para.svg.append("g").attr("class", "allMenu").attr("transform", "translate(" + nodeData.x + "," + nodeData.y + ")");

            //如果菜单不在虚拟框内，移动到虚拟框内。让菜单完整显示。
            var toX = nodeData.x,
                toY = nodeData.y,
                margin = 180;
            isM = false;
            if (nodeData.x < margin) {
                isM = true;
                toX = margin;
            }
            if (self.opt.width - nodeData.x < margin) {
                isM = true;
                toX = self.opt.width - margin;
            }
            if (nodeData.y < margin) {
                isM = true;
                toY = margin;
            }
            if (self.opt.height - nodeData.y < margin) {
                toY = self.opt.height - margin;
                isM = true;
            }
            if (isM) {
                allMenu.transition()
                    .duration(800)
                    .attr("transform", "translate(" + toX + "," + toY + ")");
            }

            var menuCenter = self.createPie(allMenu, 0, 0, 750, dataCenter, [0, 0], 0, Math.PI * 2, "menuCenter")
                .on("click", function (d) {
                    //判断是不是自定义状态
                    if (!self.isCustom()) {
                        return;
                    }
                    d3.event.stopPropagation();
                    self.para.simulation.stop();//停止力导向
                    //弹窗填写信息
                    var thisD3 = d3.select(this);
                    var thisParent = d3.select(this.parentNode);
                    var ht = self.getAlertInfo("newNode", {type: "C"});
                    $.alert({
                        title: "新建节点",
                        content: ht,
                        theme: 'blue',
                        closeIcon: true,
                        animation: "none",
                        onOpen: function () {
                            $("#newNodeCon").perfectScrollbar();
                            $(".ui_timepicker").datetimepicker({
                                dateFormat: 'yy-mm-dd',
                                changeMonth: true,
                                changeYear: true,
                                showSecond: true,
                                timeFormat: 'hh:mm:ss'
                            });
                            $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);
                            $(".content").addClass("ml20");
                        },
                        confirm: function () {
                            //获取新建节点的数据
                            var flag = true;
                            $("#nodeDetailTable .star").each(function () {
                                if ($(this).next().val().trim() == '') {
                                    flag = false;
                                }
                            })
                            if (!flag) {
                                alert("*为主要信息，请填完整主要信息！");
                                return false;
                            }
                            var type = $(".row .content option:selected").data("id");//新建类型
                            var name;
                            var attrs = new Array();
                            $(".row #nodeDetailTable input").each(function () {

                                attrs.push({
                                    type: $(this).data("type"),
                                    name: $(this).attr("name"),
                                    cnname: $(this).data("cnname"),
                                    value: $(this).val()
                                });
                                if (self.opt.nameMap[type].name == $(this).attr("name")) {
                                    name = $(this).val();
                                }
                            });
                            //var coor = self.coorTransForG(thisParent.attr("transform")); //获取鼠标的位置
                            //var coor = self.getTranslation(thisParent.attr("transform"));
                            var newNodeId = "new" + (++self.para.addIndex); //新节点的id
                            var newNode = {
                                enable: 0,
                                id: type + (new Date().getTime()),
                                name: name,
                                type: type,
                                attrs: self.clone(attrs),
                                vx: 0,
                                vy: 0,
                                x: self.getReverseNodeX(nodeData.x),
                                y: self.getReverseNodeY(nodeData.y)
                            }
                            //新建节点结束
                            self.para.data.nodes.push(newNode);//添加到点数据里面
                            self.recordOperate("add", "delete", {nodes: [newNode], links: []}, {
                                nodes: [newNode],
                                links: []
                            }, "恢复-添加节点", "撤销-添加节点", "add")//记录操作
                            //self.para.nodeToNode[newNodeId+"-"+newNodeId] = 1;//添加相连关系
                            self.getNeighbor();


                            self.para.graph.select(".nodes").append("g").datum(newNode).each(function () {
                                self.createOneNode(d3.select(this));
                                d3.select(this).attr("transform", function (inner) {
                                    return "translate(" + inner.x + "," + inner.y + ")";
                                });
                            });

                            self.nodeDrag("node");//添加拖拽事件
                            _.MessageManager.fire("refreshCaseList", {list: self.para.data.nodes});

                            //更新统计信息
                            _.MessageManager.fire("getStatic");
                            self.timeFilter(self.para.maxT, self.para.minT);//hyx
                            self.filterSameType(self.para.filterType); //过滤类型
                            self.mouseoutNode();
                        }
                    });
                    self.clearMenu();
                    self.clearSelect();//清除选中
                });
            menuCenter.select("text").attr("dy", -10);
            var menu = self.createPie(allMenu, 40, 90, 750, data, [0, 0], 0, Math.PI * 2 / 3, "menu");

            var subMenuAngle = Math.PI * 3 / 10; //一个二级菜单所占的角度
            function jump() {//点击二级菜单后切换左侧列表

                d3.event.stopPropagation();
            }

            //点击一级菜单出现相应的二级菜单
            menu.selectAll("*").on("click", function (d) {
                d3.event.stopPropagation();
                d3.selectAll(".menu").selectAll("path").attr("fill", function (inner) {
                    if (d.data.id == inner.data.id) {
                        return "#2e6dec";
                    } else {
                        return "#4dace9"
                    }
                });
                d3.event.stopPropagation();
                var subMenuNum = subData[d.data.id].length;   //二级菜单个数
                var midAngle = (d.startAngle + d.endAngle) / 2;   //二级菜单中间的角度值
                var angleRange = subMenuAngle * subMenuNum;     //二级菜单的角度范围
                self.para.svg.selectAll(".subMenu").remove(); //删除已有的二级菜单
                var subMenu = self.createPie(allMenu, 95, 210, 750, subData[d.data.id], [0, 0], midAngle - angleRange / 2, midAngle + angleRange / 2, "subMenu");
                //菜单点击事件
                subMenu.on("click", function (d) {
                    var fk = "Shift";
                    switch (d.data.number) {
                        case "1":
                            self.riskData(d.data.number);
                            break;
                        case "2":
                            self.riskData(d.data.number);
                            break;
                        case "3":
                            self.riskData(d.data.number);
                            break;
                        case "4":
                            self.riskData(d.data.number);
                            break;
                        case "5":
                            self.riskData(d.data.number);
                            break;
                        case "6":
                            self.riskData(d.data.number);
                            break;
                        case "7":
                            self.riskData(d.data.number);
                            break;
                        case "8":
                            self.riskData(d.data.number);
                            break;
                        case "9":
                            self.riskData(d.data.number);
                            break;
                        case "10":
                            self.riskData(d.data.number);
                            break;
                        case "force":
                            self.getForce();
                            self.showBoard('快捷键："' + fk + '"+"V"');
                            break;
                        case "matrix":
                            var graph = self.getNewSubGraph();
                            console.log(graph)
                            var coorForNode = self.matrixLayoutByType(graph);
                            console.log(coorForNode)
                            self.layoutNew(coorForNode);
                            self.showBoard('快捷键："' + fk + '"+"M"');
                            break;
                        case "circle":
                            //var coor = self.coorTransForG(d3.select(this).attr("transform"));
                            var coor = self.getTranslation(d3.select(this.parentNode).attr("transform"));
                            self.circleLayout(coor);
                            self.showBoard('快捷键："' + fk + '"+"C"');
                            break;
                        // case "thda": //规则6
                        //     jump();
                        //     self.noRiskData();
                        //     self.getTHDA();
                        //     self.showBoard('快捷键："'+fk+'"+"6"');
                        //     break;
                        // case "kyrw":
                        //     jump();
                        //     self.noRiskData();
                        //     self.showBoard('快捷键："'+fk+'"+"7"');
                        //     self.getKYRW();
                        //     break;
                        // case "tcda": //规则1 好的
                        //     jump();
                        //     self.noRiskData();
                        //     self.getTCDA();
                        //     self.showBoard('快捷键："'+fk+'"+"2"');
                        //     break;
                        // case "tdda": //规则2
                        //     jump();
                        //     self.noRiskData();
                        //     self.getTDDA();
                        //     self.showBoard('快捷键："'+fk+'"+"3"');
                        //     break;
                        // case "ysdqd": //规则4 好的
                        //     self.getYSDQD();
                        //     jump();
                        //     self.noRiskData();
                        //     self.showBoard('快捷键："'+fk+'"+"4"');
                        //     break;
                        // case "kypcc": //规则5 好的
                        //     jump();
                        //     self.noRiskData();
                        //     self.getKYPCC();
                        //     self.showBoard('快捷键："'+fk+'"+"5"');
                        //     break;
                        // case "loop":
                        //     jump();
                        //     self.noRiskData();
                        //     self.findLoop();
                        //     self.showBoard('快捷键："'+fk+'"+"1"');
                        //     break;
                        // case "stoa":
                        //     jump();
                        //     self.noRiskData();
                        //     break;
                        // case "fomc":
                        //     jump();
                        //     self.noRiskData();
                        //     break;
                        // case "soi":
                        //     jump();
                        //     self.noRiskData();
                        //     break;
                    }
                    //删除菜单
                    self.clearMenu();
                });
            });
        },
        //右击风险详情数据展示
        riskData: function (number) {
            var self = this;
            // self.list.resultHead.hide();
            // self.list.resultHead3.hide();
            self.list.relation2.show();
            $(".myNav li:nth-child(4)").attr("style", "background-color:RGB(84,117,172)");
            $(".myNav li:nth-child(3)").removeAttr("style");
            $(".myNav li:nth-child(2)").removeAttr("style");
            var ratio = [0.05, 0.95];
            if ($("#search-Btn").data("search") == 1) {
                var width = $("body").width() - 380 - 70;
            } else {
                var width = $("#relation2").width() - 70;
            }
            $.ajax({
                type: "POST",
                url: self.opt.url + "/graph/hitRule.do",
                data: {number: number, result: JSON.stringify(self.result)},
                // dataType:"json", //返回的数据格式
                success: function (results) {
                    var result = JSON.parse(results);
                    console.log("result", result);
                    $("#tableForlink tbody").empty();
                    self.riskMessage.nodes = new Array();
                    self.riskMessage.edges = new Array();
                    self.riskMessage.nodeArr = new Array();
                    self.riskMessage.edgeArr = new Array();
                    for (var key in result) {
                        if (key == "1") {
                            var data = result[key];
                            for (var i = 0; i < data.length; i++) {
                                var index = i + 1;
                                var tr = $("<tr style='width:98%;'><td style='width:5%;border-top:0;display: inline-block'>" + index + "</td>" + "<td title='" + data[i].message + "' style='display: inline-block;width:95%;white-space: nowrap; ;text-align: left;overflow: hidden; text-overflow: ellipsis;border-top:0 '>" + data[i].message + "</td>"
                                    + "</tr>");
                                $("#tableForlink tbody").append(tr);
                                self.riskMessage.nodeArr.push(data[i].node);
                                self.riskMessage.edgeArr.push(data[i].edge);
                                self.riskMessage.nodes = self.riskMessage.nodes.concat(data[i].node);
                                self.riskMessage.edges = self.riskMessage.edges.concat(data[i].edge);
                                self.hightLightNL(self.riskMessage.nodes, self.riskMessage.edges);
                            }
                        } else if (key == "0") {
                            $("#promptBox").show();
                            var div = $("#promptBox div");
                            div.empty();
                            for (var i = 0; i < result[key].length; i++) {
                                var span = $("<span style='white-space: normal'>" + result[key][i] + "</span>");
                                div.append(span);
                            }
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                    var status = ["abort", "error"];
                    if (status.indexOf(textStatus) < 0) {
                        alert("查询失败！");
                    }
                }
            });
        },
        getForce: function () {
            var self = this;
            self.draw(self.para.data);
            self.para.graph.selectAll(".node").selectAll("circle").each(function (innerD) {
                if (self.para.nodeSelect.ids.indexOf(innerD.id) >= 0) {
                    d3.select(this).attr("fill", "#0080ff");
                }
            });
        },
        getTHDA: function () {
            var self = this;
            var jsonData = JSON.stringify(self.getForFunc());
            ////////console.log(jsonData);
            self.clearXHRPool();
            self.para.xhrPool.push($.ajax({
                type: "POST",
                url: self.opt.url + "/graph/six.do",
                data: {jsonData: jsonData},
                dataType: "json", //返回的数据格式
                success: function (result) {
                    if (result.status != undefined) {
                        alert(result.mess);
                    } else {
                        if (result == null) {
                            alert("没有符合条件的结果")
                        } else {
                            var data = {
                                rule: "rule6",
                                name: "同号多案",
                                list: result.Rule6
                            }
                            _.MessageManager.fire("hoverList2", data);
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                    var status = ["abort", "error"];
                    if (status.indexOf(textStatus) < 0) {
                        alert("查询失败！");
                    }
                }
            }));
        },
        getKYRW: function () {
            var self = this;
            self.clearMenu();
            var tmp = new Object();
            //构建人物-案件关系
            var funcData = self.getForFunc();
            for (var i = 0; i < funcData.links.length; i++) {
                var thisLink = funcData.links[i];
                if (thisLink.source.type == self.option.type.order && thisLink.target.type == self.option.type.peo) {
                    if (tmp[thisLink.target.id] == undefined) {
                        tmp[thisLink.target.id] = new Object();
                        tmp[thisLink.target.id]["name"] = thisLink.target.name || "无记录";
                    }
                    if (tmp[thisLink.target.id][thisLink.source.id] == undefined) {
                        tmp[thisLink.target.id][thisLink.source.id] = new Array();
                    }
                    for (var k = 0; k < thisLink.rel.length; k++) {
                        if (tmp[thisLink.target.id][thisLink.source.id].indexOf(thisLink.rel[k]) < 0) {
                            tmp[thisLink.target.id][thisLink.source.id].push(thisLink.rel[k]);
                        }
                    }
                }
            }
            //挑选出符合条件的人物案件关系
            var peoOb = new Array();
            for (var peoId in tmp) {
                var flag = false;
                var relArr = null;
                var index = 0;
                var caseArr = [];
                var peoName;
                for (var caseId in tmp[peoId]) {
                    if (caseId != "name") {
                        index++;
                        if (relArr == null) {
                            relArr = tmp[peoId][caseId];
                        } else {
                            if (relArr.sort().toString() != tmp[peoId][caseId].sort().toString()) {
                                flag = true;
                            }
                        }
                        caseArr.push(caseId);
                    } else {
                        peoName = tmp[peoId][caseId];
                    }
                }
                if (flag && index > 1) {
                    caseArr.push(peoId);
                    var newTmp = new Object();
                    newTmp.name = peoName;
                    newTmp.cases = caseArr;
                    peoOb.push(newTmp);
                }
            }
            var data = {
                rule: "kyrw",
                name: "可疑人物",
                list: []
            }
            if (peoOb.length > 0) {
                data.list = peoOb;
                _.MessageManager.fire("hoverList2", data);
            } else {
                alert("没有符合条件的结果");
            }
        },
        getTCDA: function () {
            var self = this;
            var jsonData = JSON.stringify(self.getForFunc());
            //////console.log(jsonData);
            self.clearXHRPool();
            var arr = ["C000000001002808299772", "S000000006212262201015288295", "T0000000018689897976"];
            var id1 = ["C000000001002808299772,S000000006212262201015288295", "C000000001002808299772,T0000000018689897976"];
            // self.hightLightNL(arr,id1);
            // self.para.xhrPool.push($.ajax({
            //     type:"POST",
            //     url:self.opt.url+"/graph/tcda.do",
            //     data:{jsonData:jsonData},
            //     dataType:"json",
            //     success:function(result){
            //         if(result.status!=undefined){
            //             alert(result.mess);
            //         }else{
            //             if(result==null){
            //                 alert("没有符合条件的结果");
            //             }else{
            //                 var data = {
            //                     rule:"rule1",
            //                     name:"同车多案",
            //                     // list:result.list
            //                     list:"model1++++"
            //                 }
            //                 _.MessageManager.fire("hoverList2",data);
            //             }
            //         }
            //     },
            //     error:function(XMLHttpRequest, textStatus, errorThrown){
            //         //console.log([XMLHttpRequest, textStatus, errorThrown]);
            //         var status = ["abort","error"];
            //         if(status.indexOf(textStatus)<0){
            //             alert("查询失败！");
            //         }
            //     }
            // }));
        },
        getTDDA: function () {
            var self = this;
            var jsonData = JSON.stringify(self.getForFunc());
            self.clearXHRPool();
            // self.para.xhrPool.push($.ajax({
            //     type:"POST",
            //     url:self.opt.url+"/graph/tdda.do",
            //     //timeout : 1000, //超时时间设置，单位毫秒
            //     data:{jsonData:jsonData},
            //     dataType:"json",
            //     success:function(result){
            //         if(result.status!=undefined){
            //             alert(result.mess);
            //         }else{
            //             if(result==null){
            //                 alert("没有符合条件的结果")
            //             }else{
            //                 var data = {
            //                     rule:"rule2",
            //                     name:'同地多案',
            //                     list:result.Rule2
            //                 }
            //                 _.MessageManager.fire("hoverList2",data);
            //             }
            //         }
            //     },
            //     error:function(XMLHttpRequest, textStatus, errorThrown){
            //         //console.log([XMLHttpRequest, textStatus, errorThrown]);
            //         var status = ["abort","error"];
            //         if(status.indexOf(textStatus)<0){
            //             alert("查询失败！");
            //         }
            //     }
            // }));
        },
        getTCHDA: function () {
            var self = this;
            var jsonData = JSON.stringify(self.getForFunc());
            self.clearXHRPool();
            self.para.xhrPool.push($.ajax({
                type: "POST",
                url: self.opt.url + "/graph/tchda.do",
                data: {jsonData: jsonData},
                dataType: "json",
                success: function (result) {
                    if (result.status != undefined) {
                        alert(result.mess);
                    } else {
                        if (result == null) {
                            alert("没有符合条件的结果")
                        } else {
                            var data = {
                                rule: "rule3",
                                name: '同厂多案',
                                list: result.Rule3
                            }
                            _.MessageManager.fire("hoverList2", data);
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                    var status = ["abort", "error"];
                    if (status.indexOf(textStatus) < 0) {
                        alert("查询失败！");
                    }
                }
            }));
        },
        getYSDQD: function () {
            var self = this;
            var jsonData = JSON.stringify(self.getForFunc());
            self.clearXHRPool();
            self.para.xhrPool.push($.ajax({
                type: "POST",
                url: self.opt.url + "/graph/ysdqd.do",
                data: {jsonData: jsonData},
                dataType: "json",
                success: function (result) {
                    if (result.status != undefined) {
                        alert(result.mess);
                    } else {
                        if (result == null) {
                            alert("没有符合条件的结果")
                        } else {
                            var data = {
                                rule: "rule4",
                                name: '可疑时间',
                                list: result
                            }
                            _.MessageManager.fire("hoverList2", data);
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                    var status = ["abort", "error"];
                    if (status.indexOf(textStatus) < 0) {
                        alert("查询失败！");
                    }
                }
            }));
        },
        getKYPCC: function () {
            var self = this;
            var jsonData = JSON.stringify(self.getForFunc());
            self.clearXHRPool();
            self.para.xhrPool.push($.ajax({
                type: "POST",
                url: self.opt.url + "/graph/kypcc.do",
                data: {jsonData: jsonData},
                dataType: "json",
                success: function (result) {
                    if (result.status != undefined) {
                        alert(result.mess);
                    } else {
                        if (result == null) {
                            alert("没有符合条件的结果")
                        } else {
                            var data = {
                                rule: "rule5",
                                name: '可疑三者',
                                list: result.rule
                            }
                            _.MessageManager.fire("hoverList2", data);
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                    var status = ["abort", "error"];
                    if (status.indexOf(textStatus) < 0) {
                        alert("查询失败！");
                    }
                }
            }));
        },
        getNewSubGraph: function () {
            var self = this;
            var graph = {nodes: [], links: []};
            if (self.para.timeFilter) {
                for (var i = 0; i < self.para.data.nodes.length; i++) {
                    if (self.para.data.nodes[i].timeFilter) {
                        graph.nodes.push(self.para.data.nodes[i]);
                    }
                }
                for (var i = 0; i < self.para.data.links.length; i++) {
                    if (self.para.data.links[i].timeFilter) {
                        graph.links.push(self.para.data.links[i]);
                    }
                }
            } else {
                graph = self.para.data;
            }
            return graph;
        },
        getForFunc: function () {
            var self = this;
            var nodes = [], links = [];
            self.para.graph.selectAll(".node").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            }).each(function (d) {
                if (d3.select(this).attr("opacity") == 1) {
                    nodes.push(d);
                }
            });
            self.para.graph.selectAll(".link").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            }).each(function (d) {
                if (d3.select(this).attr("opacity") == 1) {
                    links.push(d);
                }
            });
            return {nodes: nodes, links: links};
        },
        createRingMemu: function (nodeData) {
            var self = this;
            var data;
            if (!self.para.isCustom && self.para.nodeSelect.ids.length == 2) {
                data = [{dataValue: 1, name: "展开", id: "extend"}, {dataValue: 1, name: "标注", id: "label"},
                    {dataValue: 1, name: "实体删除", id: "delete"}, {dataValue: 1, name: "边删除", id: "deleteL"},
                    {dataValue: 1, name: "边恢复", id: "linkRecover"}];
            } else {
                data = [{dataValue: 1, name: "展开", id: "extend"}, {dataValue: 1, name: "标注", id: "label"},
                    {dataValue: 1, name: "实体删除", id: "delete"}, {dataValue: 1, name: "边删除", id: "deleteL"}];
            }
            //,{dataValue:1,name:"边修改",id:"modifyL"}

            //删除画布中已有的一级菜单和二级菜单元素
            self.clearMenu();
            var menu = self.createPie(self.para.svg, 200, 260, 750, data, [nodeData.x - 60, nodeData.y + 180], 0, Math.PI / 2, "menu");

            //点击一级菜单出现相应的二级菜单
            menu.selectAll("*").on("click", function (d) {
                d3.event.stopPropagation();
                //菜单点击事件
                switch (d.data.id) {
                    case "label":  //框选标注
                        var markSelect = new Array();
                        var seleced_id = self.para.nodeSelect.ids;
                        for (var j = 0; j < seleced_id.length; j++) {
                            for (var i = 0; i < self.para.data.nodes.length; i++) {
                                if (self.para.data.nodes[i].id == seleced_id[j]) {
                                    //self.para.data.nodes[i].markStatus= self.para.data.nodes[i].markStatus || 11;
                                    //self.para.data.nodes[i].markMess= self.para.data.nodes[i].markMess || "可以个体";
                                    markSelect.push(self.para.data.nodes[i]);
                                }
                            }
                        }
                        //console.log(markSelect);
                        _.MessageManager.fire("selectLabel", {markSelect: markSelect});
                        break;
                    case  "linkRecover":
                        self.para.xhrPool.push($.ajax({
                            type: "POST",
                            url: self.opt.url + "/baseInfo/refreshCustomEdge.do",
                            data: {edgeid: self.getLinkIdByNode(self.para.nodeSelect.ids[0], self.para.nodeSelect.ids[1])},
                            dataType: "json", //返回的数据格式
                            success: function (result) {
                                if (result) {
                                    alert("还原成功！");
                                } else {
                                    alert("还原失败！");
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                //console.log([XMLHttpRequest, textStatus, errorThrown]);
                                var status = ["abort", "error"];
                                if (status.indexOf(textStatus) < 0) {
                                    alert("还原失败！");
                                }
                            }
                        }));
                        break;
                    case "extend":
                        self.extendNodes();
                        break;
                    case "delete":
                        //判断是不是自定义状态
                        if (!self.isCustom()) {
                            return;
                        }
                        if (confirm("确定要删除这些节点吗？")) {
                            self.preDeleteNodes();
                            //更新统计信息
                            _.MessageManager.fire("getStatic");
                        }
                        break;
                    case "modifyL":
                        if (self.para.nodeSelect.ids.length < 2) {
                            alert("至少选择两个节点！");
                        } else {
                            //通过所选的节点，记录所选择的边
                            var selectLinks = new Array();
                            for (var i = 0; i < self.para.data.links.length; i++) {
                                if (self.para.nodeSelect.ids.indexOf(self.getLinkSourceId(self.para.data.links[i])) >= 0 &&
                                    self.para.nodeSelect.ids.indexOf(self.getLinkTargetId(self.para.data.links[i])) >= 0) {
                                    selectLinks.push(self.para.data.links[i]);
                                }
                            }
                            if (selectLinks.length <= 0) {
                                alert("选择的节点没有连线！");
                                return
                            }
                            //弹出框修改边的信息
                            htmlStr = "<div data-id='linkDataLi' class='tabMF'><ul>";
                            for (var i = 0; i < selectLinks.length; i++) {
                                htmlStr += "<li data-isclick='0' data-ischange='0' data-id='" + selectLinks[i].id + "'>" +
                                    "<p style='cursor:pointer;'>起始点：" + selectLinks[i].source.name + "  ->  终点：" + selectLinks[i].target.name + "</p></li>";
                            }
                            htmlStr += "</ul></div>";
                            $.alert({
                                title: "边信息修改",
                                content: htmlStr,
                                theme: 'blue',
                                closeIcon: true,
                                onOpen: function () {
                                    //给每个li绑定link数据
                                    $(".content [data-id='linkDataLi'] li").each(function (i) {
                                        $(this).data("detail", self.clone(selectLinks[i]));
                                        $(this).data("detailmodify", self.clone(selectLinks[i]));
                                    });
                                    /*
						            	//改变选择li的高亮状态
						            	$("#linkListForModify li").removeClass("liSel");
						    			$("#linkListForModify li").eq(0).addClass("liSel");
						    			*/
                                    //设置滚动条
                                    $(".content [data-id='linkDataLi']").perfectScrollbar();
                                },
                                confirm: function () {
                                    var flag = true;
                                    $(".content ul li").each(function () {
                                        if ($(this).data("ischange") == 1) {
                                            if (confirm("是否保存已经修改的信息！")) {
                                                var isSave = self.linkModifySave($(this).find("[data-btn='save']"));

                                                if (!isSave) {
                                                    flag = false
                                                }
                                                return false;
                                            } else {
                                                flag = false;
                                            }
                                        }
                                    });
                                    if (flag) {
                                        var oldLinks = new Array();//保存修改之前的数据
                                        var newLinks = new Array();//保存修改之后的数据
                                        //修改边的数据
                                        $(".content ul li").each(function () {
                                            var linkId = $(this).data("id");
                                            for (var i = 0; i < self.para.data.links.length; i++) {
                                                if (linkId == self.para.data.links[i].id) {
                                                    //////console.log([self.para.data.links[i],$(this).data("detail")]);
                                                    oldLinks.push(self.clone(self.para.data.links[i]));
                                                    //self.para.data.links[i].rel = [$(this).find("input[name='rel']").val()];
                                                    var newLink = $(this).data("detail");
                                                    self.para.data.links[i].rel = newLink.rel;
                                                    for (var k = 0; k < newLink.attr.length; k++) {
                                                        newLink.attr[k].weight = parseFloat(newLink.attr[k].weight);
                                                    }
                                                    self.para.data.links[i].attr = newLink.attr;
                                                    newLinks.push(self.clone(self.para.data.links[i]));
                                                    break;
                                                }
                                            }
                                        });
                                        //保存操作数据
                                        self.recordOperate("modify", "modify", {nodes: [], links: newLinks}, {
                                            nodes: [],
                                            links: oldLinks
                                        }, "恢复-修改边信息", "撤销-修改边信息", "modify");
                                        //修改图中的标签
                                        for (var i = 0; i < newLinks.length; i++) {
                                            self.modifyLink(newLinks[i]);
                                        }
                                    } else {
                                        return false;
                                    }
                                }
                            });
                        }
                        break;
                    case "markL":
                        alert("markL");
                        break;
                    case "deleteL":
                        //判断是不是自定义状态
                        if (!self.isCustom()) {
                            return;
                        }
                        var selectLinks = new Array();
                        for (var i = 0; i < self.para.data.links.length; i++) {
                            if (self.para.nodeSelect.ids.indexOf(self.getLinkSourceId(self.para.data.links[i])) >= 0 &&
                                self.para.nodeSelect.ids.indexOf(self.getLinkTargetId(self.para.data.links[i])) >= 0) {
                                selectLinks.push(self.para.data.links[i]);
                            }
                        }
                        if (self.para.nodeSelect.ids.length < 2) {
                            alert("至少选择两个节点！");
                        } else if (selectLinks.length <= 0) {
                            alert("选择的节点没有连线！");
                        } else {
                            if (confirm("确定要删除这些连线吗？")) {
                                var links = self.getLinks(self.para.nodeSelect.ids, 2);
                                self.recordOperate("delete", "add", {nodes: [], links: links}, {
                                    nodes: [],
                                    links: links
                                }, "恢复-删除边", "撤销-删除边", "delete");
                                self.deleteLinks();
                                self.getNeighbor();
                            }
                        }
                        self.refreshInfoDetail();
                        break;
                }
                //删除菜单
                self.clearMenu();
                if (d.data.id != "extend") {
                    self.clearSelect();//清除选中
                }
                _.MessageManager.fire("refreshCaseList", {list: self.para.data.nodes});
            });
        },
        /*
		 *  画饼图
		 *  @param item 饼图父元素
		 *  @param innerR 内半径
		 *  @param outerR 外半径
		 *  @param transitionTime 动画时间
		 *  @param data 数据    例如： [{dataValue:1,name:"编辑",id:"edit"},{dataValue:1,name:"添加",id:"add"},{dataValue:1,name:"删除",id:"delete"}]
		 *  @param coor 圆心坐标
		 *  @param startAngle 开始角度
		 *  @param endAngle 结束角度
		 *  @param className 饼图对应类名
		 *  @return arcs 饼图元素
		 */
        createPie: function (item, innerR, outerR, transitionTime, data, coor, startAngle, endAngle, className) {
            var self = this;
            var pieData = d3.pie()
                .value(function (d) {
                    return d.dataValue;
                })
                .startAngle(startAngle)
                .endAngle(endAngle)(data);
            var arc = d3.arc().innerRadius(innerR).outerRadius(outerR);
            var arcs = item.selectAll("." + className).data(pieData).enter().append("g").attr("class", className).attr("transform", "translate(" + coor[0] + "," + coor[1] + ")");
            arcs.append("path")
                .attr("fill", "#4dace9")//8B8B7A 00b591
                .attr("stroke-width", 2)
                .attr("stroke", "#c8e8fc")
                .attr("opacity", 0.8)
                //.attr("d",function(d){return arc(d);};
                .transition()
                .duration(transitionTime)
                .attrTween("d", function (finish) {
                    var start = {
                        startAngle: 0,
                        endAngle: 0
                    };
                    var i = d3.interpolate(start, finish);
                    return function (d) {
                        return arc(i(d));
                    };
                });

            //等图形变化完成之后才显示数值
            arcs.append("text")
                .attr("transform", function (d) {
                    return "translate(" + arc.centroid(d) + ")";
                })
                .attr("text-anchor", "middle")
                .attr("fill", "#FFFFFF")
                .style("cursor", "pointer")
                .text(function (d) {
                    return d.data.name;
                })
                .attr("opacity", 0)
                .transition()
                .delay(transitionTime / 2)
                .duration(transitionTime)
                .attr("opacity", 1);

            arcs.append("text")
                .attr("transform", function (d) {
                    return "translate(" + arc.centroid(d) + ")";
                })
                // .attr("text-anchor","middle")
                .attr("x", -30)
                .attr("y", -5)
                .attr("fill", "#FFFFFF")
                .style("cursor", "pointer")
                .text(function (d) {
                    return d.data.name1;
                })
                .attr("opacity", 0)
                .transition()
                .delay(transitionTime / 2)
                .duration(transitionTime)
                .attr("opacity", 1);

            arcs.append("text")
                .attr("transform", function (d) {
                    return "translate(" + arc.centroid(d) + ")";
                })
                // .attr("text-anchor","middle")
                .attr("x", -30)
                .attr("y", 15)
                .attr("fill", "#FFFFFF")
                .style("cursor", "pointer")
                .text(function (d) {
                    return d.data.name2;
                })
                .attr("opacity", 0)
                .transition()
                .delay(transitionTime / 2)
                .duration(transitionTime)
                .attr("opacity", 1);
            arcs.append("text")
                .attr("transform", function (d) {
                    return "translate(" + arc.centroid(d) + ")";
                })
                // .attr("text-anchor","middle")
                .attr("x", -30)
                .attr("y", 35)
                .attr("fill", "#FFFFFF")
                .style("cursor", "pointer")
                .text(function (d) {
                    return d.data.name3;
                })
                .attr("opacity", 0)
                .transition()
                .delay(transitionTime / 2)
                .duration(transitionTime)
                .attr("opacity", 1);
            return arcs;
        },
        findLoop: function () {
            var self = this;
            var ids = new Array();
            var funcData = self.getForFunc();
            for (var i = 0; i < funcData.links.length; i++) {
                ids.push(self.getLinkSourceId(funcData.links[i]) + "," + self.getLinkTargetId(funcData.links[i]));
            }
            self.clearXHRPool();
            self.para.xhrPool.push($.ajax({
                type: "POST",
                url: self.opt.url + "/graph/findLoop.do",
                data: {ids: ids.join(";")},
                dataType: "json",
                success: function (result) {
                    if (result.status != undefined) {
                        alert(result.mess);
                    } else {
                        if (result.length == 0) {
                            alert("没有找到可疑的环！");
                            return;
                        }
                        var data = {
                            rule: "loop",
                            name: "找环",
                            list: result
                        };
                        _.MessageManager.fire("hoverList2", data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                    var status = ["abort", "error"];
                    if (status.indexOf(textStatus) < 0) {
                        alert("查询失败！");
                    }
                }
            }));
        },
        /*
		refreshData:function(nodes){
			var self = this;
			if(self.para.nodeSelect.ids.length>0){
				var nodeArr = new Array();
				for(var i=0;i<nodes.length;i++){
					if(self.para.nodeSelect.ids.indexOf(nodes[i].id)>=0){
						nodeArr.push(nodes[i])
					}
				}
				_.MessageManager.fire("refreshCaseList",{list:nodeArr});
			}else{
				_.MessageManager.fire("refreshCaseList",{list:nodes});
			}
		},
		*/
        getLinkIdByNode: function (src, tar) {
            for (var i = 0; i < this.para.data.links.length; i++) {
                var thisLink = this.para.data.links[i]
                var linkSrc = this.getLinkSourceId(thisLink);
                var linkTar = this.getLinkTargetId(thisLink);
                if ((src == linkSrc && tar == linkTar) || (src == linkTar && tar == linkSrc)) {
                    return thisLink.id;
                }
            }
            return "";
        },
        /*
		 * 根据操作和弹框类型拼凑弹框
		 * */
        getAlertInfo: function (type, nodeD) {
            var self = this;
            //构造节点类型下拉选择框
            var option = {C: "案件", V: "车辆", P: "人物", T: "电话", S: "账户", I: "保单"};
            var str = "";
            if (type == "newNode") {
                str += "类型：<select id='newNodeSel'>";
                for (var prop in option) {
                    str += "<option data-id=" + prop + ">" + option[prop] + "</option>";
                }
            } else if (type == "modifyNode") {
                str += "类型：<select id='newNodeSel' disabled='disabled'>";
                str += "<option data-id=" + nodeD.type + ">" + option[nodeD.type] + "</option>";
            }
            str += "</select><div id='newNodeCon'><table class='alertContent' id='nodeDetailTable'>";
            str += self.getNodeTypeStr(type, nodeD);
            str += "</table></div>";
            return str;
        },
        getLinkModifyDiv: function (linkData, index) {
            var str = "";
            str += "<div id='linkData' data-index='" + index + "'><ul>";
            for (var i = 0; i < linkData.rel.length; i++) {
                str += "<li><p data-click='0'>" + linkData.rel[i] + "</p>"
            }
            str += "</ul></div>";
            return str;
        },
        getLinkModifyDiv2: function (linkData, index) {
            var str = "";
            str += '<select><option>请选择</option><option>该保单与车</option></select>'
                + '<div class="detailContent" style="overflow:hidden" data-index="' + index + '">';
            for (var i = 0; i < linkData.rel.length; i++) {
                str += '<span data-val="' + linkData.rel[i] + '">' + linkData.rel[i] + '<i></i></span>';
            }
            str += '</div>'
                + '<div class="detailOther">'
                + '<span>时间：2016-12-20</span>'
                + '</div>';
            return str;
        },
        /*
		 * 根据不同类型和状态（新增或者修改）构造弹框的内容
		 * */
        getNodeTypeStr: function (type, nodeD) {
            console.log(type);
            console.log(nodeD);

            var self = this;
            var data = self.opt.nameMap;
            var str = "";
            if (type == "newNode") {
                for (var i = 0; i < data[nodeD.type].attrs.length; i++) {
                    if (data[nodeD.type].attrs[i].isShow == false) {
                        continue;
                    }
                    if (i % 2 == 0) {
                        str += "<tr>";
                    }
                    if (data[nodeD.type].attrs[i].type == "date") {
                        str += "<td style='position:relative;'><label class='" + (data[nodeD.type].attrs[i]["isNeed"] == true ? "star" : "") + "'>" + data[nodeD.type].attrs[i].cnname + "：</label><input data-cnname='" + data[nodeD.type].attrs[i].cnname + "' data-type='" + data[nodeD.type].attrs[i].type + "'  class='ui_timepicker' type='text' name='" + data[nodeD.type].attrs[i].name + "' value=''  onfocus='' readonly='readonly' maxlength='50'><span class='dateClean' style=''>X</span></td>";
                    } else {
                        str += "<td><label class='" + (data[nodeD.type].attrs[i]["isNeed"] == true ? "star" : "") + "'>" + data[nodeD.type].attrs[i].cnname + "：</label><input data-cnname='" + data[nodeD.type].attrs[i].cnname + "' type='text' data-type='" + data[nodeD.type].attrs[i].type + "' name='" + data[nodeD.type].attrs[i].name + "' value=''  maxlength='50'></td>";
                    }
                    if (i == data[nodeD.type].attrs.length - 1 || i % 2 == 1) {
                        str += "</tr>"
                    }
                }
            } else if (type == "modifyNode") {
                for (var i = 0; i < nodeD.attrs.length; i++) {
                    if (i % 2 == 0) {
                        str += "<tr>";
                    }
                    if (nodeD.attrs[i].type == "date") {
                        str += "<td style='position:relative;'><label class='" + (self.getParaNeed(nodeD.type, nodeD.attrs[i].name) == true ? "star" : "") + "'>" + nodeD.attrs[i].cnname + "：</label><input data-cnname='" + nodeD.attrs[i].cnname + "' data-type='" + nodeD.attrs[i].type + "'  class='ui_timepicker' type='text' name='" + nodeD.attrs[i].name + "' value='" + nodeD.attrs[i].value + "'  onfocus='' readonly='readonly'  maxlength='50'><span class='dateClean' style=''>X</span></td>";
                    }/*else if(nodeD.attrs[i].value=="N"){
						str += "<td><label>"+nodeD.attrs[i].cnname+"：</label><select class='isHarm' style='width:120px;'><option>"+nodeD.attrs[i].value+"</option><option>Y</option></select></td>"
					 }else if(nodeD.attrs[i].value=="Y"){
						str += "<td><label>"+nodeD.attrs[i].cnname+"：</label><select class='isHarm' style='width:120px;'><option>"+nodeD.attrs[i].value+"</option><option>N</option></select></td>"
					 }*/ else {
                        str += "<td><label class='" + (self.getParaNeed(nodeD.type, nodeD.attrs[i].name) == true ? "star" : "") + "'>" + nodeD.attrs[i].cnname + "：</label><input data-cnname='" + nodeD.attrs[i].cnname + "' type='text' name='" + nodeD.attrs[i].name + "' data-type='" + nodeD.attrs[i].type + "' value='" + nodeD.attrs[i].value + "'  maxlength='50'></td>";
                    }
                    if (i == nodeD.attrs.length - 1 || i % 2 == 1) {
                        str += "</tr>"
                    }
                }
            }
            return str;
        },
        getParaNeed: function (type, para) {
            var data = this.opt.nameMap[type].attrs;
            for (var i = 0; i < data.length; i++) {
                if (data[i].name == para) {
                    return data[i].isNeed;
                }
            }
            return false;
        },
        /*
		 * 记录操作
		 * @param
		 */
        recordOperate: function (operate, cancel, data, dataForRecover, operateStr, cancelStr, name) {
            var self = this;
            if (self.para.operateList.length - 1 > self.para.operateIndex) {
                self.para.operateList.splice(self.para.operateIndex + 1, self.para.operateList.length);
                self.para.cancelList.splice(self.para.operateIndex + 1, self.para.cancelList.length);
            }

            self.para.operateIndex++;
            self.para.operateList.push({        //记录添加节点数据
                todo: operate,
                name: operateStr,
                data: data,
                operate: name
            });
            self.para.cancelList.push({        //记录删除节点数据
                todo: cancel,
                name: cancelStr,
                data: dataForRecover,
                operate: name
            });
        },
        showBoard: function (text) {
            var self = this;
            /*悬浮提示框*/
            self.para.svg.select(".broad").remove();
            self.para.svg.append("g").attr("class", "broad")
                .attr("transform", "translate(20,10)")
                .attr("opacity", 1)
                .transition() //设置动画，悬浮框两秒之后透明度为0。
                .duration(3000)
                .attr("opacity", 0);
            self.para.svg.select(".broad").append("rect").attr("x", 0).attr("y", 0)
                .attr("fill", "#23283B").attr("width", 180).attr("height", 28)
                .attr("rx", 5).attr("ry", 5).attr("opacity", 0.8);
            self.para.svg.select(".broad").append("text").attr("dx", 20).attr("dy", 19).attr("fill", "#ffffff")
                .text(function () {
                    return text;
                });
        },
        oneOperate: function (cancelOperate, cancelData) {
            //////console.log(cancelData);
            var self = this;
            self.para.simulation.stop();//停止力导向
            self.showBoard(cancelOperate.name);

            if (cancelOperate.operate == "extend") {
                if (cancelOperate.todo == "add") {
                    for (var i = 0; self.para.data.nodes.length > i; i++) {
                        var thisNode = self.para.data.nodes[i];
                        if (cancelData.extendIds.indexOf(thisNode.id) >= 0) {
                            thisNode.isExtend = 1;
                        }
                    }
                } else {
                    for (var i = 0; self.para.data.nodes.length > i; i++) {
                        var thisNode = self.para.data.nodes[i];
                        if (cancelData.extendIds.indexOf(thisNode.id) >= 0) {
                            thisNode.isExtend = 0;
                        }
                    }
                }
            }

            switch (cancelOperate.todo) {
                case "modify":
                    for (var i = 0; i < cancelData.nodes.length; i++) {
                        self.modifyNode(cancelData.nodes[i].id, cancelData.nodes[i]);
                    }
                    for (var i = 0; i < cancelData.links.length; i++) {
                        //恢复原始数据
                        for (var j = 0; j < self.para.data.links.length; j++) {
                            if (self.para.data.links[j].id == cancelData.links[i].id) {
                                for (var prop in self.para.data.links[j]) {
                                    if (prop != "source" && prop != "target") {
                                        self.para.data.links[j][prop] = cancelData.links[i][prop];
                                    }
                                }
                                //修改图中信息
                                self.modifyLink(self.para.data.links[j]);
                            }
                        }
                    }
                    break;
                case "delete":
                    for (var i = 0; i < cancelData.nodes.length; i++) {
                        self.para.nodeSelect.ids.push(cancelData.nodes[i].id);
                    }
                    self.deleteNodes();
                    for (var i = 0; i < cancelData.links.length; i++) {
                        if (self.para.nodeSelect.ids.indexOf(cancelData.links[i].source.id) < 0) {
                            self.para.nodeSelect.ids.push(cancelData.links[i].source.id);
                        }
                        if (self.para.nodeSelect.ids.indexOf(cancelData.links[i].target.id) < 0) {
                            self.para.nodeSelect.ids.push(cancelData.links[i].target.id);
                        }
                    }
                    self.deleteLinks();
                    break;
                case "add":
                    for (var i = 0; i < cancelData.nodes.length; i++) {
                        self.para.data.nodes.push(cancelData.nodes[i]);
                        //self.para.nodeToNode[cancelData.nodes[i]+"-"+cancelData.nodes[i]] = 1;//添加相连关系
                        self.getNeighbor();

                        self.para.graph.select(".nodes").append("g").datum(cancelData.nodes[i]).each(function () {
                            self.createOneNode(d3.select(this));
                            d3.select(this).attr("transform", function (inner) {
                                return "translate(" + inner.x + "," + inner.y + ")";
                            });
                        });

                        self.nodeDrag("node");//添加拖拽事件
                    }
                    for (var i = 0; i < cancelData.links.length; i++) {
                        self.para.data.links.push(cancelData.links[i]);
                        self.para.graph.select(".links").append("path").datum(cancelData.links[i])
                            .attr("class", "link")
                            .attr("stroke-width", 2)
                            .attr("stroke", "#bc8c8f")
                            .attr("fill", "#bc8c8f")
                            .attr("opacity", 1)
                            .attr("d", function (inner) {
                                var dx = inner.target.x - inner.source.x,
                                    dy = inner.target.y - inner.source.y,
                                    dr = Math.sqrt(dx * dx + dy * dy),
                                    theta = Math.atan2(dy, dx) + Math.PI / 300,
                                    d90 = Math.PI / 2,
                                    dtxs = inner.target.x - 57 * Math.cos(theta),
                                    dtys = inner.target.y - 57 * Math.sin(theta);
                                return "M" + inner.source.x + "," + inner.source.y +
                                    "L" + inner.target.x + "," + inner.target.y +
                                    "M" + dtxs + "," + dtys +
                                    "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                                    "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                                    "z";
                            });
                        self.para.graph.select(".linkTexts").append("g").datum(cancelData.links[i]).attr("class", "linkText")
                            .attr("transform", function (inner) {
                                return "translate(" + ((inner.source.x + inner.target.x) / 2) + "," + ((inner.source.y + inner.target.y) / 2) + ")";
                            })
                            .attr("opacity", 0)
                            .append("text").attr("fill", "#FFFFFF")
                            .style("text-anchor", "middle")
                            .style("cursor", "default")
                            .text(function (inner) {
                                if (inner.rel.length == 1) {
                                    return self.opt.linkMap[inner.rel[0]] == undefined ? inner.rel[0] : self.opt.linkMap[inner.rel[0]].cnName;
                                } else {
                                    var relName = [];
                                    for (var i = 0; i < inner.rel.length; i++) {
                                        relName.push(self.opt.linkMap[inner.rel[i]] == undefined ? inner.rel[i] : self.opt.linkMap[inner.rel[i]].cnName);
                                    }
                                    return relName.join(",");
                                }
                            });
                    }
                    break;
            }
            self.timeFilter(self.para.maxT, self.para.minT);//hyx
            self.filterSameType(self.para.filterType); //过滤类型
            self.getNeighbor();
            _.MessageManager.fire("refreshCaseList", {list: self.para.data.nodes});
            self.cancelHoverFunc();
            _.MessageManager.fire("hoverListClose");
            //更新统计信息
            _.MessageManager.fire("getStatic");

            self.mouseoutNode();
        },
        goback: function () {
            var self = this;
            self.clearSelect();//清除选中
            self.para.operateIndex++;
            var operate = self.para.operateList[self.para.operateIndex];
            var operateData = operate.data;
            self.oneOperate(operate, operateData);
            if (operate.todo == "modify") {
                self.refreshInfoDetail();
            } else {
                self.refreshInfoDetail(false);
            }
        },
        undo: function () {
            var self = this;
            self.clearSelect();//清除选中
            var cancelOperate = self.para.cancelList[self.para.operateIndex];
            var cancelData = cancelOperate.data;
            self.para.operateIndex--;
            self.oneOperate(cancelOperate, cancelData);
            if (cancelOperate.todo == "modify") {
                self.refreshInfoDetail();
            } else {
                self.refreshInfoDetail(false);
            }
        },
        modifyNode: function (id, data) {
            var self = this;
            //修改原始数据
            /*
			for(var i=0;i<self.para.data.nodes.length;i++){
				if(self.para.data.nodes[i].id == id){
					for(var prop in self.para.data.nodes[i]){
						if(data[prop]!=null && data[prop]!=undefined){
							self.para.data.nodes[i][prop] = data[prop];
						}
					}
					//self.para.data.nodes[i] = data;
					break;
				}
			}
			*/
            var noChangePara = ["markMess", "markStatus", "x", "y", "vx", "vy"]
            //改变图中的节点信息
            self.para.graph.select(".nodes").selectAll(".node").filter(function (d) {
                return d.id == id;
            }).select("text").text(function (d) {
                for (var prop in d) {
                    if (data[prop] != null && data[prop] != undefined && noChangePara.indexOf(prop) < 0) {
                        d[prop] = data[prop];
                    }
                }
                //d = data;
                return d.name.length > 20 ? d.name.substring(0, 20) + "..." : d.name;
                ;
            });

            //修改人伤和金额
            if (data.type == self.option.type.order) {
                self.para.graph.selectAll(".node").filter(function (d) {
                    return d.id == id;
                }).each(function (d) {
                    self.createCaseIcon(d3.select(this), d);
                });
            }
        },
        modifyLink: function (data) {
            var self = this;
            self.para.graph.select(".linkTexts").selectAll(".linkText").filter(function (d) {
                return d.id == data.id;
            }).select("text").text(function (d) {
                d.rel = data.rel;
                if (d.rel.length == 1) {
                    return self.opt.linkMap[d.rel[0]] == undefined ? d.rel[0] : self.opt.linkMap[d.rel[0]].cnName;
                } else {
                    var relName = [];
                    for (var i = 0; i < d.rel.length; i++) {
                        relName.push(self.opt.linkMap[d.rel[i]] == undefined ? d.rel[i] : self.opt.linkMap[d.rel[i]].cnName);
                    }
                    return relName.join(",");
                }
                /*
				if(d.rel.length==1){
					 return self.opt.linkMap[d.rel[0]]==undefined?d.rel[0]:self.opt.linkMap[inner.rel[0]];
				}else{
					return "展开";
				}
				*/
                //return d.rel.join(",");
            });
        },
        deleteLinks: function () {
            var self = this;
            //删除相关的线段
            self.para.graph.selectAll(".link").each(function (d) {
                var sourceId = self.getLinkSourceId(d);
                var targetId = self.getLinkTargetId(d);
                if (self.para.nodeSelect.ids.indexOf(sourceId) >= 0 &&
                    self.para.nodeSelect.ids.indexOf(targetId) >= 0) {
                    self.removeLink(d.id);
                    d3.select(this).remove();
                }
            });
            //删除相关linktext
            self.para.graph.selectAll(".linkText").each(function (d) {
                var sourceId = self.getLinkSourceId(d);
                var targetId = self.getLinkTargetId(d);
                if (self.para.nodeSelect.ids.indexOf(sourceId) >= 0 &&
                    self.para.nodeSelect.ids.indexOf(targetId) >= 0) {
                    d3.select(this).remove();
                }
            });
            self.clearSelect();
        },
        /*
		 * 删除 this.para.nodeSelect.ids 里面的节点和对应边
		 */
        deleteNodes: function () {
            var self = this;
            for (var i = 0; i < self.para.nodeSelect.ids.length; i++) {
                //删除相关的节点
                self.removeNode(self.para.nodeSelect.ids[i]);
                self.para.graph.selectAll(".node").each(function (d) {
                    if (d.id == self.para.nodeSelect.ids[i]) {
                        d3.select(this).remove();
                    }
                });
                //删除相关的线段
                self.para.graph.selectAll(".link").each(function (d) {
                    if (self.getLinkSourceId(d) == self.para.nodeSelect.ids[i] ||
                        self.getLinkTargetId(d) == self.para.nodeSelect.ids[i]) {
                        self.removeLink(d.id);
                        d3.select(this).remove();
                    }
                });
                //删除相关linktext
                self.para.graph.selectAll(".linkText").each(function (d) {
                    if (self.getLinkSourceId(d) == self.para.nodeSelect.ids[i] ||
                        self.getLinkTargetId(d) == self.para.nodeSelect.ids[i]) {
                        d3.select(this).remove();
                    }
                });
            }
            self.clearSelect();
            //刷新页面案件列表
            _.MessageManager.fire("refreshCaseList", {list: self.para.data.nodes});
        },
        preDeleteNodes: function () {
            var self = this;
            self.refreshInfoDetail();

            var nodes = self.getNodes(self.para.nodeSelect.ids);
            var links = self.getLinks(self.para.nodeSelect.ids, 1);
            self.recordOperate("delete", "add", {nodes: nodes, links: links}, {
                nodes: nodes,
                links: links
            }, "恢复-删除节点", "撤销-删除节点", "delete");
            self.deleteNodes();
        },
        recordExtend: function (ids) {
            for (var i = 0; i < this.para.data.nodes.length; i++) {
                var thisNode = this.para.data.nodes[i];
                if (ids.indexOf(thisNode.id) >= 0) {
                    thisNode.isExtend = 1;
                }
            }
        },
        extendNodes: function (isFilter, isTable, filterType) {
            var self = this;
            /*//专项模型二次展开，2018-03-20
			if(self.para.renInjured){
				_.MessageManager.fire("extendLoading");
			}*/
            if (self.para.nodeSelect.ids.length <= 0) {
                return;
            }
            var idsLen = self.para.nodeSelect.ids.length;
            var weaverIdArr = [];
            var realId = [];
            var clickNode = [];
            var allIds = [];
            var selectTel = [];
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                var thisNode = self.para.data.nodes[i];
                if (self.para.nodeSelect.ids.indexOf(thisNode.id) >= 0) {
                    weaverIdArr.push(thisNode.weaverId == undefined ? thisNode.id : thisNode.weaverId);
                    realId.push(thisNode.id);
                    clickNode.push(thisNode);
                    //判断展开的是电话，2018-04-23
                    if (thisNode.type == self.option.type.phone) {
                        selectTel.push(thisNode.id);
                    }
                }
                allIds.push(thisNode.id);
            }
            var id = weaverIdArr.join(";");
            //记录图中有所有节点的id
            self.clearXHRPool();
            if (weaverIdArr.length != 1) {
                self.para.xhrPool.push(
                    $.ajax({
                        type: "POST",
                        url: self.opt.url + "/graph/showGraph.do",
                        data: {
                            entityId: id,
                            level: 1,
                            isCustom: self.para.isCustom,
                            isException: self.para.data.isException
                        },
                        dataType: "json",
                        success: function (result) {
                            //$.ajax({type:"POST",url:self.opt.url+"/graph/extendData.do",data:{id:id,level:1},dataType:"json",success:function(result){

                            if (result.status != undefined) {
                                alert(result.mess);
                            } else {
                                self.recordExtend(realId);
                                //专项模型,2018-04-25
                                if (self.para.renInjured && self.para.ruleTel) {
                                    result = self.limitNodes2(realId, result, selectTel);
                                    ; //限制人伤案件，2018-04-20
                                }
                                result = self.filterLinks(result);//过滤多余的边
                                result = self.filterOldData(self.para.data, result);//过滤掉图中已经有的点和线
                                if (result.links.length == 0 && result.nodes.length == 0) {
                                    if (isTable) {
                                        _.MessageManager.fire("showTable");
                                    }
                                    return;
                                }
                                //判断是专项模型不走下面if代码，2018-02-05
                                /*if(self.para.website=='query' || self.para.website=='fraud'){
                                    if(!isTable){
                                        self.getTCDA();//同车多案
                                    }
                                }*/
                                //判断是否需要弹框选择
                                if (isFilter) {
                                    var thisSearchNode = self.getNodes(realId);
                                    if (thisSearchNode.length != 1 || result.links.length == 0) {
                                        return;
                                    }
                                    _.MessageManager.fire("showFilter", {
                                        data: result,
                                        thisNode: thisSearchNode[0],
                                        oldData: self.clone(self.para.data)
                                    });
                                } else {
                                    self.processExtendNodes(result);
                                    /*//专项模型,2018-04-20
                                    if(self.para.renInjured && self.para.ruleTel){
                                        self.limitNodes(realId,self.para.data,selectTel); //限制人伤案件，2018-04-20
                                    }*/
                                    if (isTable) {
                                        _.MessageManager.fire("showTable");
                                    }
                                }
                                /*//专项模型二次展开，2018-03-20
                                if(self.para.renInjured){
                                    self.draw(self.para.data);
                                    self.para.renInjured=false;
                                }
                                _.MessageManager.fire("extendfinish");//专项模型，2018-03-20*/
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            //console.log([XMLHttpRequest, textStatus, errorThrown]);
                            var status = ["abort", "error"];
                            if (status.indexOf(textStatus) < 0) {
                                alert("查询失败！");
                            }
                        }
                    }));
            } else {
                if (self.para.website == 'query') {//查询页
                    //判断是否能展开
                    for (var i = 0; i < clickNode.length; i++) {
                        if (clickNode[i].showOff == false) {
                            alert("你没有操作权限！");
                            return false;
                        }
                    }
                    console.log("js", self.weaverEdge);

                    if ("10487792456" != id && "1375704" != id && "2687336" != id && "1936272" != id && "10487707208" != id && "1422952" != id && "10486992528" != id && "10487403152" != id) {
                        //因为读取只读取json文件的问题，导致去击中规则多次随意点击导致存储的节点问题，
                        self.para.xhrPool.push(
                            $.ajax({
                                type: "POST",
                                url: "/dgt/graph/nodeExtend.do",
                                data: JSON.stringify({
                                    weaverIdList: self.graphweaverIds,
                                    node: self.para.node,
                                    filterType: filterType || ''
                                }),
                                dataType: "json",
                                contentType: "application/json",
                                success: function (result) {
                                    if (result.resultCode != '0000') {
                                        alert(result.message);
                                    } else {
                                        self.recordExtend(realId);
                                        self.weaverData = result.data.graphlist;
                                        self.graphweaverIds = result.data.weaverIdList;
                                        // self.roleProperty = result.rolePropertiesMap;
                                        // self.weaverEdge = result.nodeLinkRelmap;
                                        // self.weaverNode = result.weaverNodeMap;
                                        self.result = result.data;
                                        // 判断节点是否需要过滤, 并返回相应的值
                                        // if(filterType !== 'all') {
                                        //   self.judgeFilter(self.para.data, result.data);
                                        //   self.processExtendNodes(result.data);
                                        // } else {
                                          result = self.filterLinks(result.data);//过滤多余的边
                                          result = self.filterOldData(self.para.data, result);//过滤掉图中已经有的点和线
                                          console.log(result)
                                          if (result.links.length == 0 && result.nodes.length == 0) {
                                              if (isTable) {
                                                  _.MessageManager.fire("showTable");
                                              }
                                              return;
                                          }
                                          //判断是否需要弹框选择
                                          if (isFilter) {
                                              var thisSearchNode = self.getNodes(realId);
                                              if (thisSearchNode.length != 1 || result.links.length == 0) {
                                                  return;
                                              }
                                              _.MessageManager.fire("showFilter", {
                                                  data: result,
                                                  thisNode: thisSearchNode[0],
                                                  oldData: self.clone(self.para.data)
                                              });
                                          } else {
                                              self.processExtendNodes(result);
                                              if (isTable) {
                                                  _.MessageManager.fire("showTable");
                                              }
                                          }
                                        // }

                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    //console.log([XMLHttpRequest, textStatus, errorThrown]);
                                    var status = ["abort", "error"];
                                    if (status.indexOf(textStatus) < 0) {
                                        alert("查询失败！");
                                    }
                                }
                            }));
                    }

                } else {//其他图页面
                    self.para.xhrPool.push(
                        $.ajax({
                            type: "POST",
                            url: self.opt.url + "/graph/expandGraphByTwo.do",
                            data: {
                                entityId: id,
                                level: 1,
                                isCustom: self.para.isCustom,
                                isException: self.para.data.isException
                            },
                            dataType: "json",
                            success: function (result) {
                                //expandGraph.do					//$.ajax({type:"POST",url:self.opt.url+"/graph/extendData.do",data:{id:id,level:1},dataType:"json",success:function(result){
                                if (result.status != undefined) {
                                    alert(result.mess);
                                } else {
                                    self.recordExtend(realId);
                                    //专项模型,2018-04-25
                                    if (self.para.renInjured && self.para.ruleTel) {
                                        result = self.limitNodes2(realId, result, selectTel);
                                        ; //限制人伤案件，2018-04-20
                                    }
                                    result = self.filterLinks(result);//过滤多余的边
                                    result = self.filterOldData(self.para.data, result);//过滤掉图中已经有的点和线
                                    if (result.links.length == 0 && result.nodes.length == 0) {
                                        if (isTable) {
                                            _.MessageManager.fire("showTable");
                                        }
                                        return;
                                    }
                                    //判断是否需要弹框选择
                                    if (isFilter) {
                                        var thisSearchNode = self.getNodes(realId);
                                        if (thisSearchNode.length != 1 || result.links.length == 0) {
                                            return;
                                        }
                                        _.MessageManager.fire("showFilter", {
                                            data: result,
                                            thisNode: thisSearchNode[0],
                                            oldData: self.clone(self.para.data)
                                        });
                                    } else {
                                        self.processExtendNodes(result);
                                        /*//专项模型
                                        if(self.para.renInjured && self.para.ruleTel){
                                            self.limitNodes(realId,self.para.data,selectTel); //限制人伤案件，2018-04-20
                                        }*/
                                        if (isTable) {
                                            _.MessageManager.fire("showTable");
                                        }
                                    }
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                //console.log([XMLHttpRequest, textStatus, errorThrown]);
                                var status = ["abort", "error"];
                                if (status.indexOf(textStatus) < 0) {
                                    alert("查询失败！");
                                }
                            }
                        }));
                }
            }
            self.clearFunc();
            self.mouseoutNode();
        },
        judgeFilter: function(allData, extendData) {
            var allLinkIds = ['h7653558,hlvl7653558', 'A000CHD1830000371321,h7653558','A000CHD1830000371328,h7653558','A000CHD1830000371322,h7653558','A000CHD1830000371329,h7653558','A000CHD1830000371330,h7653558','A000CHD1830000371332,h7653558','A000CHD1830000465868,h7653558','A000CHD1830000371333,h7653558','A000CHD1830000303355,h7653558','A000CHD1830000371334,h7653558','A000CHD1830000371335,h7653558','A000CHD1830000371336,h7653558','A000CHD1830000371337,h7653558','A000CHD1830000375285,h7653558','A000CHD1830000371331,h7653558','A000CHD1830000371338,h7653558','A000CHD1830000371339,h7653558','A000CHD1830000371323,h7653558','A000CHD1830000371340,h7653558','A000CHD1830000371324,h7653558','A000CHD1830000371341,h7653558','A000CHD1830000371325,h7653558','A000CHD1830000371326,h7653558','A000CHD1830000371327,h7653558'];
            var allNodeIds = ['hlvl7653558','A000CHD1830000371332','A000CHD1830000371333','A000CHD1830000371334','A000CHD1830000371323','A000CHD1830000371324','A000CHD1830000371325','A000CHD1830000371326','A000CHD1830000371341','A000CHD1830000371327','A000CHD1830000303355','A000CHD1830000371322','A000CHD1830000371321','A000CHD1830000465868','A000CHD1830000375285','A000CHD1830000371335','h7653558','A000CHD1830000371336','A000CHD1830000371337','A000CHD1830000371328','A000CHD1830000371338','A000CHD1830000371329','A000CHD1830000371339','A000CHD1830000371330','A000CHD1830000371340','A000CHD1830000371331'];
            var linkIds = [],nodeIds = [], self = this;
            for (var i=0;i<extendData.links.length;i++) {
                linkIds.push(extendData.links[i].id)
            }
            for (var i=0;i<extendData.nodes.length;i++) {
                nodeIds.push(extendData.nodes[i].id)
            }
            // 比较两次的id，然后删除两组数据不同的nodeid，linkid
            self.compareArray(linkIds, allLinkIds).forEach(function(item) {
                self.removeLink(item);
            })
            self.compareArray(nodeIds, allNodeIds).forEach(function(item) {
                self.removeNode(item);
            })
            // 重新渲染页面
        },
        compareArray: function(arr1, arr2) {
            arr1.forEach(function(item1) {
               var i = arr2.indexOf(item1);
               if (i > -1) {
                 arr2.splice(i, 1);
               }
            })
            return arr2;
        },
        //电话展开限制30个，人伤优先
        limitNodes2: function (selectIds, result, selectTel) {
            var self = this;
            /*console.log(result);
			console.log(self.para.data);*/
            //图中已有的数据
            var graphData = [];
            self.para.graph.selectAll(".node").each(function (d) {
                graphData.push(d.id);
            });
            //记录新加的节点
            var extendData = new Object();
            var needData = [];  //扩展的的数据被限制后的数据
            if (selectTel.length > 0) {
                for (var k = 0; k < selectTel.length; k++) {
                    extendData[selectTel[k]] = [];
                    for (var i = 0; i < result.links.length; i++) {
                        var thisLink = result.links[i];
                        var srcId = self.getLinkSourceId(thisLink);
                        var tarId = self.getLinkTargetId(thisLink);
                        if (selectTel[k] == srcId) {
                            for (var j = 0; j < result.nodes.length; j++) {
                                var item = result.nodes[j];
                                if (graphData.indexOf(item.id) < 0) {
                                    if (item.id == tarId) {
                                        extendData[selectIds[k]].push(item);
                                    }
                                }
                            }

                        } else if (selectTel[k] == tarId) {
                            for (var j = 0; j < result.nodes.length; j++) {
                                var item = result.nodes[j];
                                if (graphData.indexOf(item.id) < 0) {
                                    if (item.id == srcId) {
                                        extendData[selectIds[k]].push(item);
                                    }
                                }
                            }
                        }
                    }
                }

                //判断人伤数量
                for (var k = 0; k < selectTel.length; k++) {
                    var items = extendData[selectTel[k]];
                    var arrCase = [], arrOther = [], injury = [], noInjury = [], reData = null;
                    var len = 30;  //限制的长度
                    if (items.length > len) {
                        for (var i = 0; i < items.length; i++) {
                            if (items[i].type == self.option.type.order) {
                                arrCase.push(items[i]);
                            } else {
                                arrOther.push(items[i]);
                            }
                        }
                        if (arrCase.length > len) {
                            for (var j = 0; j < arrCase.length; j++) {
                                var isIjury = false;
                                for (var o = 0; o < arrCase[j].attrs.length; o++) {
                                    var inj = arrCase[j].attrs[o];
                                    if (inj.name == "daja#CASE_ISINJURYINVOLVED") {
                                        if (inj.value == "Y") {
                                            injury.push(arrCase[j]);
                                            isIjury = true;
                                        }
                                    }
                                }
                                if (!isIjury) {
                                    noInjury.push(arrCase[j]);
                                }
                            }
                            if (injury.length > len) {
                                reData = injury.slice(0, len)
                            } else {
                                var arr1 = injury;
                                var ln = len - arr1.length
                                if (ln > 0) {
                                    reData = arr1.concat(noInjury.slice(0, ln));
                                }
                            }
                        } else {
                            var ln = len - arrCase.length
                            if (ln > 0) {
                                if (arrOther.length > 0) {
                                    reData = arrCase.concat(arrOther.slice(0, ln));
                                } else {
                                    reData = arrCase;
                                }
                            } else {
                                reData = arrCase;
                            }
                        }
                    } else {
                        reData = items;
                    }
                    needData = needData.concat(reData);//把需要的数据留下
                }
            }
            //取出不是电话的数据
            var notTel = [], Tel = [];
            for (var k = 0; k < selectTel.length; k++) {
                var items = extendData[selectTel[k]];
                Tel = Tel.concat(items);
            }
            for (var i = 0; i < result.nodes.length; i++) {
                var item = result.nodes[i];
                if (Tel.indexOf(item) < 0) {
                    notTel.push(item);
                }
            }
            var data2 = notTel.concat(needData);
            //加入选择的节点
            for (var i = 0; i < result.nodes.length; i++) {
                if (selectIds.indexOf(result.nodes[i].id) >= 0) {
                    data2.push(result.nodes[i]);
                }
            }
            //去重
            var data = [];
            for (var k = 0; k < data2.length; k++) {
                if (data.indexOf(data2[k]) < 0) {
                    data.push(data2[k]);
                }
            }
            result.nodes = data;
            return result;
        },
        //展开限制30个，人伤优先
        limitNodes: function (selectIds, graph, selectTel) {
            var self = this;
            var extendData = new Object();
            var needData = [];  //扩展的的数据被限制后的数据
            var markData = self.para.extendBeforeData;//展开后的数据判断
            for (var k = 0; k < selectIds.length; k++) {
                extendData[selectIds[k]] = [];
                for (var i = 0; i < graph.links.length; i++) {
                    var thisLink = graph.links[i];
                    var srcId = self.getLinkSourceId(thisLink);
                    var tarId = self.getLinkTargetId(thisLink);
                    if (selectIds[k] == srcId) {
                        for (var j = 0; j < markData.nodes.length; j++) {
                            var item = markData.nodes[j];
                            if (graph.nodes[j].id == tarId && item.newComing) {
                                extendData[selectIds[k]].push(item);
                            }
                        }

                    } else if (selectIds[k] == tarId) {
                        for (var j = 0; j < markData.nodes.length; j++) {
                            var item = markData.nodes[j];
                            if (graph.nodes[j].id == srcId && item.newComing) {
                                extendData[selectIds[k]].push(item);
                            }
                        }
                    }
                }
            }
            //判断是否超30个
            for (var k = 0; k < selectIds.length; k++) {
                var items = extendData[selectIds[k]];
                var arrCase = [], arrOther = [], injury = [], noInjury = [], reData = null;
                //电话才限制
                if (selectTel.indexOf(selectIds[k]) >= 0) { //只限制电话
                    var len = 30;  //限制的长度
                    if (items.length > len) {
                        for (var i = 0; i < items.length; i++) {
                            if (items[i].type == self.option.type.order) {
                                arrCase.push(items[i]);
                            } else {
                                arrOther.push(items[i]);
                            }
                        }
                        if (arrCase.length > len) {
                            for (var j = 0; j < arrCase.length; j++) {
                                var isIjury = false;
                                for (var o = 0; o < arrCase[j].attrs.length; o++) {
                                    var inj = arrCase[j].attrs[o];
                                    if (inj.name == "daja#CASE_ISINJURYINVOLVED") {
                                        if (inj.value == "Y") {
                                            injury.push(arrCase[j]);
                                            isIjury = true;
                                        }
                                    }
                                }
                                if (!isIjury) {
                                    noInjury.push(arrCase[j]);
                                }
                            }
                            if (injury.length > len) {
                                reData = injury.slice(0, len)
                            } else {
                                var arr1 = injury;
                                var ln = len - arr1.length
                                if (ln > 0) {
                                    reData = arr1.concat(noInjury.slice(0, ln));
                                }
                            }
                        } else {
                            var ln = len - arrCase.length
                            if (ln > 0) {
                                if (arrOther.length > 0) {
                                    reData = arrCase.concat(arrOther.slice(0, ln));
                                } else {
                                    reData = arrCase;
                                }
                            } else {
                                reData = arrCase;
                            }
                        }
                    } else {
                        reData = items;
                    }
                } else {
                    reData = items;
                }
                needData = needData.concat(reData);
            }
            //重组图中的数据
            var graphNodes = [];
            for (var i = 0; i < markData.nodes.length; i++) {
                var item = markData.nodes[i];
                if (!item.newComing) {
                    graphNodes.push(item);
                }
            }
            graphNodes = graphNodes.concat(needData);
            //去重
            var graphNodes2 = [];
            for (var k = 0; k < graphNodes.length; k++) {
                if (graphNodes2.indexOf(graphNodes[k]) < 0) {
                    graphNodes2.push(graphNodes[k]);
                }
            }
            self.para.data.nodes = graphNodes2;
            self.para.data = self.filterLinks(self.para.data);//过滤多余的边
            self.draw(self.para.data);  //重新画图
            //console.log(self.para.data);
        },
        filterOldData: function (oldData, newData) {
            var self = this;
            var oldNodeIds = self.getAllNodeIds(oldData.nodes);
            var oldLinkIds = self.getAllLinkIds(oldData.links);
            var newNodes = [], newLinks = [], newNodesId = [], newLinksId = [];
            for (var i = 0; i < newData.nodes.length; i++) {
                if (oldNodeIds.indexOf(newData.nodes[i].id) < 0 && newNodesId.indexOf(newData.nodes[i].id) < 0) {
                    newNodes.push(newData.nodes[i]);
                    newNodesId.push(newData.nodes[i].id);
                }
            }
            for (var i = 0; i < newData.links.length; i++) {
                if (oldLinkIds.indexOf(newData.links[i].id) < 0 && newLinksId.indexOf(newData.links[i].id) < 0) {
                    newLinks.push(newData.links[i]);
                    newLinksId.push(newData.links[i].id);
                }
            }
            return {nodes: newNodes, links: newLinks};
        },
        processExtendNodes: function (result) {
            var self = this;
            var loc = self.getGraphLoc();
            /*
			if(self.judgeFormat(result)){
				alert("格式有误！");
				self.clearFunc();
				return;
			}
			*/
            //记录新加的节点
            for (var i = 0; i < result.nodes.length; i++) {
                result.nodes[i]["newComing"] = true;
                result.nodes[i].isExtend == 0;
            }
            //记录已经存在的节点
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                self.para.data.nodes[i]["newComing"] = false;
            }
            self.para.extendBeforeData = self.para.data;  //给新加数据加标识，2018-04-22

            //融合节点
            var mergeData = self.putExtendData(result);

            self.timeFilter(self.para.maxT, self.para.minT);//hyx
            self.filterSameType(self.para.filterType); //过滤类型
            _.MessageManager.fire("hoverListClose");
            self.clearFunc();

            if (self.para.extendMode == 0) {
                self.draw(mergeData, 2);
                _.MessageManager.fire("getStatic");
                _.MessageManager.fire("refreshCaseList", {list: graph.nodes});//更新案件列表信息
                self.mouseoutNode();//更新显隐
            } else {
                result.nodes.sort(function (a, b) {
                    if (a.timeFilter == false && b.timeFilter == true) {
                        return 1;
                    } else if (a.timeFilter == true && b.timeFilter == false) {
                        return -1;
                    } else {
                        return 0;
                    }
                });

                var addNum = result.nodes.length,
                    startX = loc.minX - 200,
                    startY = loc.maxY + 300,
                    circleR = 100,
                    spanCol = circleR + 60,
                    spanRow = circleR + 60;
                startX = (loc.minX + loc.maxX) / 2 - spanCol * addNum / 2;

                var coor = new Object();
                for (var i = 0; i < addNum; i++) {
                    coor[result.nodes[i].id] = [startX + (i) * spanCol, startY + (0) * spanRow];
                }

                self.connectLinkToNode(result, self.para.data.nodes);
                self.checkFormat(self.para.data);

                for (var i = 0; i < result.nodes.length; i++) {
                    result.nodes[i].x = coor[result.nodes[i].id][0];
                    result.nodes[i].y = coor[result.nodes[i].id][1];
                }

                self.moveGraphForLayout(0.3);

                setTimeout(function () {
                    var nodes = self.para.graph.select(".nodes").selectAll(".node").data(self.para.data.nodes, function (d) {
                        return d.id;
                    });
                    nodes.enter().append("g").each(function (d) {
                        self.createOneNode(d3.select(this));
                        //d.x = coor[d.id][0];
                        //d.y = coor[d.id][1];
                        d3.select(this).attr("transform", function (inner) {
                            return "translate(" + inner.x + "," + inner.y + ")";
                        });
                    });
                    var links = self.para.graph.select(".links").selectAll(".link").data(self.para.data.links, function (d) {
                        return d.id;
                    });
                    links.enter().append("path").each(function (d) {
                        self.createOneLink(d3.select(this));
                        d3.select(this).attr("d", function (inner) {
                            return self.linePath(inner.source, inner.target);
                        });
                    });
                    var linkText = self.para.graph.select(".linkTexts").selectAll(".linkText").data(self.para.data.links, function (d) {
                        return d.id;
                    });
                    linkText.enter().append("g").each(function (d) {
                        self.createOneLinkText(d3.select(this));
                        d3.select(this).attr("transform", function (inner) {
                            return "translate(" + ((inner.source.x + inner.target.x) / 2) + "," + ((inner.source.y + inner.target.y) / 2) + ")";
                        });
                    });

                    _.MessageManager.fire("getStatic");
                    self.getNeighbor();//构建相连节点
                    self.nodeDrag("node");//node拖拽事件
                    _.MessageManager.fire("refreshCaseList", {list: graph.nodes});//更新案件列表信息
                    self.mouseoutNode();//更新显隐
                }, 1000)
            }
        },
        connectLinkToNode: function (graph, nodes) {
            var nodeIndex = new Object();
            for (var i = 0; i < nodes.length; i++) {
                nodeIndex[nodes[i].id] = i;
            }
            for (var i = 0; i < graph.links.length; i++) {
                var src = graph.links[i].source;
                var tar = graph.links[i].target;
                graph.links[i].source = nodes[nodeIndex[src]];
                graph.links[i].target = nodes[nodeIndex[tar]];
            }
        },
        clearXHRPool: function () {
            for (var i = 0; i < this.para.xhrPool.length; i++) {
                this.para.xhrPool[i].abort();
            }
        },
        cancelHoverFunc: function () {
            var self = this;
            if (self.para.hightlight.isEnable == 1) {
                self.para.hightlight.isEnable = 0;
                //清除动画
                clearInterval(self.para.hightlight.autoRun);
                self.para.hightlight.autoRun = null;
                //去掉节点高亮效果
                self.para.graph.select(".nodes").selectAll(".node").each(function (innerD) {
                    //if(self.para.hightlight.nodes.indexOf(innerD.id)>=0){
                    var thisNode = d3.select(this);
                    thisNode.select(".outter").remove();
                    self.setCircleStroke(innerD, d3.select(this).select("circle"));
                    //}
                });
                self.para.hightlight.nodes.splice(0, self.para.hightlight.nodes.length);
                self.para.hightlight.links.splice(0, self.para.hightlight.links.length);
            }
            self.mouseoutNode();
        },
        hoverFunc: function (nodeId, lineId) {
            var self = this;
            self.para.hightlight.nodes = self.filterAnaNodes(nodeId);
            self.para.hightlight.links = lineId;
            var linkkkkk = self.getAllLinkIds(self.para.data.links);
            for (var i = 0; i < lineId.length; i++) {
                if (linkkkkk.indexOf(lineId[i]) < 0) {
                    //console.log("noLink:"+lineId[i]);
                }
            }
            //self.layoutForHover(); //找环改变的方法
            setTimeout(function () {
                //如果没有高亮，而且可高亮的links长度大于0
                if (self.para.hightlight.isEnable == 0 && self.para.hightlight.links.length > 0) {
                    self.para.hightlight.isEnable = 1; //高亮状态
                    self.oneMove(self.para.hightlight.links); //第一次动画
                    var outter = null;
                    //添加节点的边框和高亮样式
                    self.para.graph.select(".nodes").selectAll(".node").each(function (innerD) {
                        if (self.para.hightlight.nodes.indexOf(innerD.id) >= 0) {
                            var thisNode = d3.select(this);

                            if (innerD.markStatus != "12" && innerD.markStatus != "11" && innerD.newcoming != true) {
                                thisNode.select("circle").attr("stroke", "#FFFFB7")
                                //.transition().duration(2000)
                                    .attr("stroke-opacity", 1);
                            }

                            var r = d3.select(this).select("circle").attr("r");

                            var outter = thisNode.append("g").attr("class", "outter").attr("opacity", 0);
                            outter.append("circle").attr("fill", "#FFFFB7").attr("r", 5).attr("cx", function () {
                                return 54;
                            })
                                .attr("cy", function () {
                                    return 0;
                                });
                            outter.append("circle").attr("fill", "#FFFFB7").attr("r", 5).attr("cx", function () {
                                return -1 * 54;
                            })
                                .attr("cy", function () {
                                    return 0;
                                });
                        }
                    });
                    //循环播放动画
                    self.para.hightlight.autoRun = setInterval(function () {
                        self.oneMove(self.para.hightlight.links);
                        self.para.graph.selectAll(".outter").attr("opacity", 1).transition()
                            .duration(3000)
                            .ease(d3.easeLinear)
                            .attrTween("transform", function () {
                                return d3.interpolateString("rotate(0)", "rotate(360)");
                            });
                    }, 3000);
                } else {
                    self.cancelHoverFunc();
                }
            }, 0);
        },
        hightLightNL: function (nodes, links) {
            var self = this;
            self.para.graph.selectAll(".node")
                .attr("opacity", function (d) {
                    if (nodes.indexOf(d.id) >= 0) {
                        return 1;
                    } else {
                        return 0.3;
                    }
                });
            self.para.graph.selectAll(".link")
                .attr("opacity", function (d) {
                    // console.log([d.id,links.indexOf(d.id)]);
                    if (links.indexOf(d.id) >= 0) {
                        ////console.log(1);
                        return 1;
                    } else {
                        ////console.log(2);
                        return 0.1;
                    }
                });

            self.para.graph.selectAll(".linkText")
                .attr("opacity", 0);
        },
        filterAnaNodes: function (nodes) {
            var self = this;
            var ids = self.getAllNodeIds(self.para.data.nodes);
            var newNodesIds = new Array();
            for (var i = 0; i < nodes.length; i++) {
                if (ids.indexOf(nodes[i]) >= 0) {
                    newNodesIds.push(nodes[i]);
                } else {
                    //console.log("no："+nodes[i]);
                }
            }
            return newNodesIds;
        },
        oneMove: function (lineId) {
            var self = this;
            self.para.graph.selectAll(".link").each(function (d) {
                if (lineId.indexOf(d.id) < 0) {
                    return;
                }
                var thisLink = d3.select(this),
                    thisLinkPath = thisLink.node();
                thisLinkPathLen = thisLinkPath.getTotalLength(); //path的长度
                self.fadeRoute(d, thisLink, thisLinkPath, thisLinkPathLen, 3000);
            });
        },
        fadeRoute: function (d, thisLink, thisLinkPath, thisLinkPathLen, time) {
            var self = this;
            var sourceR = self.para.nodeR;

            var num = {num: sourceR};
            var tween = new TWEEN.Tween(num)
                .to({num: (thisLinkPathLen - 80)}, time)
                .start();

            function animate() {
                if (self.para.hightlight.isEnable == 0) {
                    return;
                }
                if (num.num >= (thisLinkPathLen - 80)) {
                    return;
                }
                if (self.para.hightlight.links.indexOf(d.id) < 0) {
                    return;
                }
                var tmpPoint = thisLinkPath.getPointAtLength(num.num);
                self.para.graph.append("circle").attr("fill", "#FFFFB7").attr("r", 5)
                    .attr("cx", tmpPoint.x).attr("cy", tmpPoint.y)
                    .transition()
                    .on("end", function () {
                        d3.select(this).remove();
                    })
                    .duration(700)
                    .attrTween("opacity", function (d) {
                        return d3.interpolateNumber(1, 0);
                    });
                requestAnimationFrame(animate);
                TWEEN.update();
            }

            animate();
        },
        getNodeArr: function () {
            if (this.para.nodeSelect.ids.length > 0) {
                var nodeArr = this.getNodes(this.para.nodeSelect.ids);
                return nodeArr;
            } else {
                if (this.para.timeFilter) {
                    var nodes = [];
                    for (var i = 0; i < this.para.data.nodes.length; i++) {
                        if (this.para.data.nodes[i].timeFilter) {
                            nodes.push(this.para.data.nodes[i]);
                        }
                    }
                    return nodes;
                } else {
                    return this.para.data.nodes;
                }
            }
        },
        /*
		 *   加入展开数据
		 * */
        putExtendData: function (data) {
            var self = this;
            var mergeData = self.mergeData(self.para.data, data);
            return mergeData;
        },
        /*
		 * 合并数据
		 * @param newData 图中已有的数据
		 * @param comeData 新来的数据
		 *
		 * */
        mergeData: function (newData, comeData) {
            var self = this;
            var nodeIds = self.getAllNodeIds(newData.nodes);//图中已有的nodes的id
            var linkIds = self.getAllLinkIds(newData.links);//图中已有的links的id
            var tmpData = comeData;
            var addNode = []; //新加的节点
            var addLink = []; //新加的连线
            for (var i = 0; i < tmpData.nodes.length; i++) {
                var nodeId = tmpData.nodes[i].id;
                var nodeIndex = nodeIds.indexOf(nodeId);
                if (nodeIndex < 0) {
                    newData.nodes.push(tmpData.nodes[i]);
                    addNode.push(tmpData.nodes[i]);
                    nodeIds.push(nodeId);
                } else {
                    var preCount = newData.nodes[nodeIndex].count;
                    var newCount = tmpData.nodes[i].count < 0 ? 1 : tmpData.nodes[i].count;
                    newData.nodes[nodeIndex].count = preCount < newCount ? preCount : newCount;
                }
            }
            for (var i = 0; i < tmpData.links.length; i++) {
                var linkId = tmpData.links[i].id;
                var linkIndex = linkIds.indexOf(linkId);
                if (linkIndex < 0) {
                    newData.links.push(tmpData.links[i]);
                    addLink.push(tmpData.links[i])
                    linkIds.push(linkId);
                } else {
                    var preCount = newData.links[linkIndex].count;
                    var newCount = tmpData.links[i].count < 0 ? 1 : tmpData.links[i].count;
                    newData.links[linkIndex].count = preCount < newCount ? preCount : newCount;
                }
            }
            self.recordOperate("add", "delete", {nodes: addNode, links: addLink, extendIds: nodeIds}, {
                nodes: addNode,
                links: addLink,
                extendIds: nodeIds
            }, "恢复-展开", "撤销-展开", "extend");
            return newData;
        },
        makeMark: function () {
            var self = this;
            //停止force
            self.para.simulation.stop();

            var linkObj = {
                source: id,
                target: null,
                id: id + ""
            };
            self.para.graph.select("links").append("line").datum(linkObj)
                .attr("class", "link")
                .attr("stroke-width", 2)
                .attr("data-id", function (d) {
                    return d.id;
                })
                .attr("stroke", function (d) {
                    return "#bc8c8f";
                })
                .attr("opacity", function (d) {
                    return 1;
                })
                .attr("marker-end", function (d) {
                    return "url(#C)";
                });

            self.para.svg.on("mousedown", function () {

            });
        },
        /*
		 * 圆形
		 * */
        circleLayout: function (centerCoor) {
            var self = this;
            var nodeNum = 0;
            if (self.para.timeFilter) {
                for (var i = 0; i < self.para.data.nodes.length; i++) {
                    if (self.para.data.nodes[i].timeFilter) {
                        nodeNum++;
                    }
                }
            } else {
                nodeNum = self.para.data.nodes.length;
            }
            var deg = Math.PI * 2 / nodeNum,
                circleLen = nodeNum * 150,
                circleRadius = circleLen / Math.PI / 2,
                coor = new Array();
            var angle = 0;
            for (var i = 0; i < nodeNum; i++) {
                var x = centerCoor[0] + circleRadius * Math.sin(angle);
                var y = centerCoor[1] + circleRadius * Math.cos(angle);
                coor.push([x, y]);
                angle += deg;
            }
            self.para.simulation.stop();
            self.layout(coor);
        },
        /*
		 * 矩形，根据类型排序
		 * */
        matrixLayoutByType: function (graph) {
            var self = this;
            var num = graph.nodes.length;
            var coor = new Array();
            var col = Math.ceil(Math.sqrt(num)); //每一行的个数
            // var typeSort  = ["C","V","P","S","T","I"];
            var typeSort = self.option.typeData;
            var typeData = new Object();
            var nodeWeight = new Object();

            var nodeIds = self.getAllNodeIds(graph.nodes);
            var linkIds = self.getAllLinkIds(graph.links);

            self.para.graph.selectAll(".link").filter(function (d) {
                return linkIds.indexOf(d.id) >= 0;
            }).each(function (d) {
                var src = self.getLinkSourceId(d);
                var tar = self.getLinkTargetId(d);
                //console.log([src,tar,d])
                if (nodeWeight[src] == undefined) {
                    nodeWeight[src] = 1;
                } else {
                    nodeWeight[src] = nodeWeight[src] + 1;
                }
                if (nodeWeight[tar] == undefined) {
                    nodeWeight[tar] = 1;
                } else {
                    nodeWeight[tar] = nodeWeight[tar] + 1;
                }
            });

            self.para.graph.selectAll(".node").filter(function (d) {
                return nodeIds.indexOf(d.id) >= 0;
            }).each(function (d) {
                var thisNode = d;
                thisNode.weight = nodeWeight[d.id];

                var T = d.type;
                if (typeData[T] == null || typeData[T] == undefined) {
                    typeData[T] = new Object();
                    typeData[T].num = 1;
                    typeData[T].data = new Array();
                    typeData[T].data.push(thisNode);
                } else {
                    typeData[T].num++;
                    typeData[T].data.push(thisNode);
                }
            });

            //每一项根据权重排序
            for (var prop in typeData) {
                typeData[prop].data.sort(function (a, b) {
                    return b.weight - a.weight;
                })
            }
            //console.log("排序后");
            //console.log(typeData);

            //计算坐标
            var coorForNode = new Object(),
                circleR = 100,
                spanCol = circleR + 90,//60
                spanRow = circleR + 90,//60
                nextCoor = [0, 0];
            for (var i = 0; i < typeSort.length; i++) {
                if (typeData[typeSort[i]] == undefined) {
                    continue;
                }
                var thisNodeArr = typeData[typeSort[i]].data;
                var nowCol = 1;
                for (var j = 0; j < thisNodeArr.length; j++) {
                    if (coorForNode[thisNodeArr[j].id] != undefined) {
                        continue;
                    }
                    var x = nextCoor[0] + spanCol;
                    var y = nextCoor[1];
                    nextCoor = [x, y];
                    coorForNode[thisNodeArr[j].id] = nextCoor;
                    nowCol++;
                    if (nowCol > col) {
                        nextCoor = [0, nextCoor[1] + spanRow];
                        nowCol = 1;
                    }
                }
                if (nextCoor[0] != 0) {
                    nextCoor = [0, nextCoor[1] + spanRow];
                }
            }
            return coorForNode;
        },
        layoutNew: function (coor) {
            var self = this;
            self.para.simulation.stop();
            //移动nodes
            self.para.graph.selectAll(".node").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .transition()
                .duration(500)
                .attr("transform", function (d) {
                    var thisCoor = coor[d.id];
                    console.log(thisCoor)
                    d.x = thisCoor[0];
                    d.y = thisCoor[1];
                    return "translate(" + d.x + "," + d.y + ")";
                });
            //修改link的起始点坐标,线的透明度先设为0，延迟750在出现
            self.para.graph.selectAll(".link").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .attr("opacity", 0)
                .attr("d", function (d) {
                    var dx = d.target.x - d.source.x,
                        dy = d.target.y - d.source.y,
                        dr = Math.sqrt(dx * dx + dy * dy),
                        theta = Math.atan2(dy, dx) + Math.PI / 300,
                        d90 = Math.PI / 2,
                        dtxs = d.target.x - 57 * Math.cos(theta),
                        dtys = d.target.y - 57 * Math.sin(theta);
                    return "M" + d.source.x + "," + d.source.y +
                        "L" + d.target.x + "," + d.target.y +
                        "M" + dtxs + "," + dtys +
                        "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                        "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                        "z";
                })
                .transition().delay(500).attr("opacity", 1);
            //修改linkText的位置
            self.para.graph.selectAll(".linkText").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .attr("opacity", 0)
                .attr("transform", function (d) {
                    return "translate(" + (d.source.x + d.target.x) / 2 + "," + (d.source.y + d.target.y) / 2 + ")"
                })
                .transition().delay(500);
            //对画布进行移动和缩放
            setTimeout(function () {
                self.moveGraphForLayout(0.3);
            }, 500)
        },
        /*
		 * 矩形
		 * */
        matrixLayout: function () {
            var self = this;
            var num = self.para.data.nodes.length;
            var coor = new Array();
            var col = Math.ceil(Math.sqrt(num));
            var margin_top = 55,
                margin_left = 10,
                circleR = 100,
                spanCol = circleR + 60,
                spanRow = circleR + 60;
            var colNum = 0;
            while (coor.length < num) {
                for (var i = 0; i < col; i++) {
                    coor.push([margin_left + (i + 1) * spanCol, margin_top + (colNum) * spanRow]);
                }
                colNum++;
            }
            self.para.simulation.stop();
            self.layout(coor);
        },
        layoutForHover: function () {
            var self = this;
            var maxDiameter = self.opt.height < self.opt.width ? self.opt.height - 100 : self.opt.width - 100;
            var scale;

            //被高亮的节点的坐标计算
            var hoverNum = self.para.hightlight.nodes.length,
                deg = Math.PI * 2 / hoverNum,
                circleLen = hoverNum * 350,
                circleRadius = circleLen / (Math.PI * 2),
                coorHover = new Array(),
                angle = 0;
            if (hoverNum > 0) {
                scale = maxDiameter / (2 * circleRadius);
            }
            for (var i = 0; i < hoverNum; i++) {
                var x = self.opt.width / 2 + circleRadius * Math.sin(angle);
                var y = self.opt.height / 2 + circleRadius * Math.cos(angle);
                coorHover.push([x, y]);
                angle += deg;
            }

            //其余节点的坐标计算
            var otherNum = self.para.data.nodes.length - hoverNum,
                deg = Math.PI * 2 / otherNum,
                circleLen = (otherNum * 500 > circleLen * 4 ? otherNum * 500 : circleLen * 4),
                circleRadius = circleLen / Math.PI / 2,
                coorOther = new Array(),
                angle = 0;
            if (hoverNum == 0) {
                scale = maxDiameter / (2 * circleRadius);
            }
            for (var i = 0; i < otherNum; i++) {
                var x = self.opt.width / 2 + circleRadius * Math.sin(angle);
                var y = self.opt.height / 2 + circleRadius * Math.cos(angle);
                coorOther.push([x, y]);
                angle += deg;
            }
            self.para.simulation.stop();
            var hoverIndex = 0;
            var otherIndex = 0;
            var alreadyHover = new Array();
            self.para.graph.selectAll(".node").each(function (d) {
                if (self.para.hightlight.nodes.indexOf(d.id) >= 0 && alreadyHover.indexOf(d.id) < 0) {
                    d.x = coorHover[hoverIndex][0];
                    d.y = coorHover[hoverIndex][1];
                    alreadyHover.push(d.id);
                    hoverIndex++;
                } else {
                    d.x = coorOther[otherIndex][0];
                    d.y = coorOther[otherIndex][1];
                    otherIndex++;
                }
            });
            //移动nodes
            self.para.graph.selectAll(".node")
                .transition()
                .duration(250)
                .attr("transform", function (d, i) {
                    return "translate(" + d.x + "," + d.y + ")";
                })
                .attr("opacity", function (d) {
                    if (self.para.hightlight.nodes.indexOf(d.id) >= 0) {
                        return 1;
                    } else {
                        return 0.3;
                    }
                });
            //修改link的起始点坐标,线的透明度先设为0，延迟750在出现
            self.para.graph.selectAll(".link").attr("opacity", 0)
                .attr("d", function (d) {
                    var dx = d.target.x - d.source.x,
                        dy = d.target.y - d.source.y,
                        dr = Math.sqrt(dx * dx + dy * dy),
                        theta = Math.atan2(dy, dx) + Math.PI / 300,
                        d90 = Math.PI / 2,
                        dtxs = d.target.x - 57 * Math.cos(theta),
                        dtys = d.target.y - 57 * Math.sin(theta);
                    return "M" + d.source.x + "," + d.source.y +
                        "L" + d.target.x + "," + d.target.y +
                        "M" + dtxs + "," + dtys +
                        "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                        "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                        "z";
                })
                .transition().delay(250).attr("opacity", function (d) {
                if (self.para.hightlight.links.indexOf(d.id) >= 0) {
                    return 1;
                } else {
                    return 0.1;
                }
            });
            //修改linkText的位置
            self.para.graph.selectAll(".linkText").attr("opacity", 0)
                .attr("transform", function (d) {
                    return "translate(" + (d.source.x + d.target.x) / 2 + "," + (d.source.y + d.target.y) / 2 + ")"
                })
                .transition().delay(250);
            //对画布进行移动和缩放
            setTimeout(function () {
                self.moveGraphForLayout(scale > 0.7 ? 0.7 : scale, "inside");
            }, 1000);
        },
        layout: function (coor) {
            var self = this;
            //计算每一种类型的数量
            var typeNum = new Object();
            var typeIndex = new Array();
            self.para.graph.selectAll(".node").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .each(function (d, i) {
                    if (typeNum[d.type] == null || typeNum[d.type] == undefined) {
                        typeNum[d.type] = 1;
                        typeIndex.push({type: d.type, index: 0});
                    } else {
                        typeNum[d.type] = typeNum[d.type] + 1;
                    }
                });
            //计算每一种类型的起始index
            var index = 0;
            for (var i = 0; i < typeIndex.length; i++) {
                if (i - 1 >= 0) {
                    index = index + typeNum[typeIndex[i - 1].type];
                }
                typeIndex[i].index = index;
            }
            //给每个点固定坐标
            self.para.graph.selectAll(".node").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .each(function (d) {
                    for (var i = 0; i < typeIndex.length; i++) {
                        if (typeIndex[i].type == d.type) {
                            d.x = coor[typeIndex[i].index][0];
                            d.y = coor[typeIndex[i].index][1];
                            typeIndex[i].index = typeIndex[i].index + 1;
                            break;
                        }
                    }
                });
            //移动nodes
            self.para.graph.selectAll(".node")
                .filter(function (d) {
                    if (self.para.timeFilter) {
                        return d.timeFilter;
                    } else {
                        return true;
                    }
                })
                .transition()
                .duration(500)
                .attr("transform", function (d, i) {
                    return "translate(" + d.x + "," + d.y + ")";
                });
            //修改link的起始点坐标,线的透明度先设为0，延迟750在出现
            self.para.graph.selectAll(".link").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .attr("opacity", 0)
                .attr("d", function (d) {
                    var dx = d.target.x - d.source.x,
                        dy = d.target.y - d.source.y,
                        dr = Math.sqrt(dx * dx + dy * dy),
                        theta = Math.atan2(dy, dx) + Math.PI / 300,
                        d90 = Math.PI / 2,
                        dtxs = d.target.x - 57 * Math.cos(theta),
                        dtys = d.target.y - 57 * Math.sin(theta);
                    return "M" + d.source.x + "," + d.source.y +
                        "L" + d.target.x + "," + d.target.y +
                        "M" + dtxs + "," + dtys +
                        "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                        "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                        "z";
                })
                .transition().delay(500).attr("opacity", 1);
            //修改linkText的位置
            self.para.graph.selectAll(".linkText").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            })
                .attr("opacity", 0)
                .attr("transform", function (d) {
                    return "translate(" + (d.source.x + d.target.x) / 2 + "," + (d.source.y + d.target.y) / 2 + ")"
                })
                .transition().delay(500);
            //对画布进行移动和缩放
            self.moveGraphForLayout(0.3);
        },
        /*
		 * 返回ids所包含的节点
		 */
        getNodes: function (ids) {
            var self = this;
            var nodes = [];
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                if (ids.indexOf(self.para.data.nodes[i].id) >= 0) {
                    nodes.push(self.para.data.nodes[i]);
                }
            }
            return nodes;
        },
        /*
		 *  如果flag为1，返回跟ids所包含节点相连的links；
		 *  如果flag为0，返回ids包含节点之间的连线。
		 */
        getLinks: function (ids, flag) {
            var self = this;
            var links = [];
            for (var i = 0; i < self.para.data.links.length; i++) {
                var sourceId = self.getLinkSourceId(self.para.data.links[i]);
                var targetId = self.getLinkTargetId(self.para.data.links[i]);
                if (flag == 1) {
                    if (ids.indexOf(sourceId) >= 0 || ids.indexOf(targetId) >= 0) {
                        links.push(self.para.data.links[i]);
                    }
                } else {
                    if (ids.indexOf(sourceId) >= 0 && ids.indexOf(targetId) >= 0) {
                        links.push(self.para.data.links[i]);
                    }
                }
            }
            return links;
        },
        /*
		 * 在self.para.data中删除id为传入id的节点
		 */
        removeNode: function (id) {
            var self = this;
            var nodes = self.para.data.nodes;
            for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].id == id) {
                    nodes.splice(i, 1);
                    break;
                }
            }
        },
        /*
		 * 在self.para.data中删除id为传入id的连线
		 */
        removeLink: function (id) {
            var self = this;
            var links = self.para.data.links;
            for (var i = 0; i < links.length; i++) {
                if (links[i].id == id) {
                    links.splice(i, 1);
                    break;
                }
            }
        },
        hoverNodes: function (ids) {
            var self = this;
            self.para.graph.select(".nodes").selectAll(".node").filter(function (d) {
                return ids.indexOf(d.id) >= 0;
            }).select("image[data-id='mainImg']").attr("xlink:href", function (d) {
                console.log("666666666666666666666666" + d.type);
                return self.getImage(d.type, 1);
            });
        },
        /*
		 *  初始化关系图缩放功能
		 *
		 *  放大原理：<x*k + tx , y*k + ty>
		 *  初始值为： k = 1, tx = ty = 0.
		 *  每次放大通过改变k,tx,ty的数值实现元素的缩放，位置改变
		 *
		 *  @param isZoom 为true的时候开启放大，为false的时候关闭放大
		 *
		 */
        zoom: function (isZoom) {
            var self = this;
            self.para.zoom = d3.zoom().scaleExtent([1 / 50, 8]).on("zoom", function () {
                self.para.graph.attr("transform", d3.event.transform);
                //保存放大参数
                self.para.zoomFactor.k = d3.event.transform.k;
                self.para.zoomFactor.tx = d3.event.transform.x;
                self.para.zoomFactor.ty = d3.event.transform.y;
            });
            if (isZoom == true) {
                self.para.zoomListener = self.para.svg.call(self.para.zoom).on("dblclick.zoom", null);
            } else {
                self.para.svg.on(".zoom", null);
            }
        },
        /*
		 *  读取数据
		 *  @param result 画图需要的nodes和links数据
		 *  @data 当前查询节点的类型和id {id:"",type:"" }
		 */
        loadData: function (result, data, isShowInfo) {
            var self = this;
            self.para.nowId = data.id + "";   		//记录当前的id
            self.para.ids.push(data.id + ""); 		//记录图中的根节点id
            self.clearFunc();
            self.preProcess(result, self.para.nowId);
            //self.para.data = self.filterLinks(self.para.data);
            self.timeFilter(self.para.maxT, self.para.minT);//hyx
            self.filterSameType(self.para.filterType); //过滤类型
            self.updateData(self.para.data, isShowInfo, data);
        },
        /*
		 *   预处理新数据，记录每个节点被哪些根节点包含
		 *   @param newData 新数据
		 *   @param newId 新查询的节点
		 * */
        preProcess: function (newData, newId) {
            var self = this;
            if (self.para.data == null) { //如果第一次查询
                for (var i = 0; i < newData.nodes.length; i++) {
                    newData.nodes[i].isExtend == 0;
                }
                self.para.data = newData;//深复制一份新数据保存到本地
                /*
				for(var i=0;i<self.para.data.nodes.length;i++){
					if(!self.para.data.nodes[i].hasOwnProperty("belong")){
						self.para.data.nodes[i].belong = new Array();
					}
					self.para.data.nodes[i].belong.push(newId);
				}
				for(var i=0;i<self.para.data.links.length;i++){
					if(!self.para.data.links[i].hasOwnProperty("belong")){
						self.para.data.links[i].belong = new Array();
					}
					self.para.data.links[i].belong.push(newId);
				}
				*/
            } else {
                var oldData = self.para.data;
                var nodeIds = self.getAllNodeIds(oldData.nodes);
                var linkIds = self.getAllLinkIds(oldData.links);
                for (var i = 0; i < newData.nodes.length; i++) {
                    var index = nodeIds.indexOf(newData.nodes[i].id);
                    if (index >= 0) {
                        //oldData.nodes[index].belong.push(newId);
                    } else {
                        //newData.nodes[i].belong = new Array();
                        //newData.nodes[i].belong.push(newId);
                        newData.nodes[i].isExtend = 0;
                        oldData.nodes.push(newData.nodes[i]);
                        nodeIds.push(newData.nodes[i]);
                    }
                }
                for (var i = 0; i < newData.links.length; i++) {
                    var index = linkIds.indexOf(newData.links[i].id);
                    if (index >= 0) {
                        //oldData.links[index].belong.push(newId);
                    } else {
                        //newData.links[i].belong = new Array();
                        //newData.links[i].belong.push(newId);
                        oldData.links.push(newData.links[i]);
                        linkIds.push(newData.links[i]);
                    }
                }
            }
            //为nodes和links添加status属性
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                self.para.data.nodes[i].status = 1;
            }
            for (var i = 0; i < self.para.data.links.length; i++) {
                self.para.data.links[i].status = 1;
            }
        },
        /*
		 * 删除一条查询记录
		 * */
        /*
		delOne:function(nodeId){
			var self = this;
			var idsIndex = self.para.ids.indexOf(nodeId);
			self.para.ids.splice(idsIndex,1);

			var oldData = self.para.data;
			var delNodeIds = [];
			var delLinkIds = [];
			for(var i=0;i<oldData.nodes.length;i++){
				var tmpBelong = oldData.nodes[i].belong;
				var tmpBelongIndex = tmpBelong.indexOf(nodeId);
				if(tmpBelongIndex>=0){
					tmpBelong.splice(tmpBelongIndex,1);
					if(tmpBelong.length==0){
						delNodeIds.push(oldData.nodes[i].id);
					}
				}
			}
			for(var i=0;i<oldData.links.length;i++){
				var tmpBelong = oldData.links[i].belong;
				var tmpBelongIndex = tmpBelong.indexOf(nodeId);
				if(tmpBelongIndex>=0){
					tmpBelong.splice(tmpBelongIndex,1);
					if(tmpBelong.length==0){
						delLinkIds.push(oldData.links[i].id);
					}
				}
			}
			var newData = {nodes:[],links:[]};
			for(var i=0;i<oldData.nodes.length;i++){
				var index = delNodeIds.indexOf(oldData.nodes[i].id);
				if(index<0){
					newData.nodes.push(oldData.nodes[i]);
				}
			}
			for(var i=0;i<oldData.links.length;i++){
				var index = delLinkIds.indexOf(oldData.links[i].id);
				if(index<0){
					newData.links.push(oldData.links[i]);
				}
			}

			self.para.data = null;
			self.para.data = newData;

			self.updateData(self.para.data);
		},
		*/
        /*
		 *  画布大小调整
		 */
        resize: function (w, h) {
            var self = this;
            self.opt.width = w;
            self.opt.height = h;
            self.para.svg.attr("viewBox", "0 0 " + w + " " + h)
                .attr("width", w)
                .attr("height", h);
            ;
            self.para.simulation.force("center", d3.forceCenter(self.opt.width / 2, self.opt.height / 2));
        },
        /*
		 * 清除节点的选中状态，并且清空选中节点数组
		 */
        clearSelect: function () {
            var self = this;
            self.para.nodeSelect.ids.splice(0, self.para.nodeSelect.ids.length);//清除数组
            self.para.graph.select(".nodes").selectAll("image[data-id='mainImg']") //将图片换成普通状态的图片
                .attr("xlink:href", function (d) {
                    return self.getCommonImage(d.source, d.type, 0);
                });
            // self.mouseoutNode();
            if (self.para.data != null) {
                //更新统计信息
                _.MessageManager.fire("getStatic");
            }
        },
        /*
    		 * 清除节点的高亮状态
    		 */
        clearFunc: function () {
            var self = this;
            self.clearSelect();

            self.para.graph.select(".nodes").selectAll(".node").each(function (innerD) {
                var thisNode = d3.select(this);
                thisNode.select(".outter").remove();
                self.setCircleStroke(innerD, d3.select(this).select("circle"));
            });
            self.para.hightlight.isEnable = 0;
            self.para.hightlight.nodes.splice(0, self.para.hightlight.nodes.length);
            self.para.hightlight.links.splice(0, self.para.hightlight.links.length);
            clearInterval(self.para.hightlight.autoRun);
            self.para.hightlight.autoRun = null;
        },
        clear: function () {
            var self = this;
            self.para.graph.select(".links").selectAll("*").remove();
            self.para.graph.select(".nodes").selectAll("*").remove();
            self.para.graph.select(".linkTexts").selectAll("*").remove();
            //self.para.loop.splice(0,self.para.loop.length);
            self.para.isHover = false;
            self.para.data = null;
            self.para.type = "";
            self.para.nodeSelect.ids.splice(0, self.para.nodeSelect.ids.length);

            self.clearFunc();

            self.para.operateIndex = -1;
            self.para.operateList.splice(0, self.para.operateList.length);
            self.para.cancelList.splice(0, self.para.cancelList.length);
            self.para.addIndex = 0;
            clearTimeout(self.para.drawRun);

            _.MessageManager.fire("hoverListClose");

            self.para.actionEnable = 0;

            self.para.infoNodeId = "";

            self.clearMenu();

            self.clearXHRPool();

            //取消新建连线
            if (self.para.makeMark.isClick == true) {
                self.para.graph.select(".markLinks").selectAll("*").remove();
                self.para.svg.on("mousemove", null);
                self.para.makeMark.isSourceChoose = false;
                self.para.makeMark.isClick = false;
            }
            //隐藏连线时的提示文字
            $("#Tip").hide();
        },
        judgeFormat: function (graph) {
            var self = this;
            var ids = self.getAllNodeIds(graph.nodes);
            for (var i = 0; i < graph.links.length; i++) {
                var srcId = self.getLinkSourceId(graph.links[i]);
                var tarId = self.getLinkTargetId(graph.links[i])
                if (ids.indexOf(srcId) < 0) {
                    console.info([graph.links[i], srcId]);
                    return true;
                }
                if (ids.indexOf(tarId) < 0) {
                    console.info([graph.links[i], tarId]);
                    return true;
                }
            }
            return false;
        },
        updateData: function (graph, isShowInfo, data) {
            var self = this;
            if (self.judgeFormat(graph)) {
                alert("数据格式有误！");
                return;
            } else {
                if (data != undefined) {
                    _.MessageManager.fire("addSearchItem", data)
                }
                self.draw(graph, isShowInfo);
                /*if(!self.para.renInjured){//是否画图

				}*/
            }
        },
        getNodeColor: function (type) {
            return "transparent"

            var self = this;
            if (type == self.option.type.order) {
                return "#c7fa9e";
            } else if (type == self.option.type.car) {
                return "#90fbde";
            } else if (type == self.option.type.phone) {
                return "#00fffc";
            } else if (type == self.option.type.account) {
                return "#fd199a";
            } else if (type == self.option.type.org) {
                return "#0a86fa";
            } else if (type == self.option.type.peo) {
                return "#fbf311";
            } else {
                return "#c7fa9e";
            }
        },
        createOneNode: function (thisNode) {
            var self = this;
            thisNode.attr("class", "node")
                .attr("opacity", 1).attr("cursor", "pointer")
                .attr("data-id", function (d) {
                    return d.id;
                });
            //鼠标移入节点虚化其他节点
            thisNode.on("mouseover", function (d) {
                // console.log('移入节点 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
                self.mouseoverNode(d);
            }).on("mouseout", function (d) {
                self.mouseoutNode(d);
            }).on("dblclick", function (d) {
                // console.log('双击节点 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
                // 保存所选节点
                self.para.node = d;
                d3.event.stopPropagation();
                self.para.nodeSelect.ids.splice(0, self.para.nodeSelect.ids.length);
                self.para.nodeSelect.ids.push(d.id);

                // 如果有限制条件
                if(d.type === 'H') {
                    // 显示过滤扇形
                    self.moveGraph(d, 0.7);
                    //右击节点时判断菜单是否显示
                    if (!self.para.menuShow) {
                        self.showMenu("filter", d, d3.select(this));
                    }
                } else {
                    self.extendNodes();
                }
                /*
				setTimeout(function(){
					self.moveGraph(d,0.7);
				},2100);
				*/
                ////console.log("dblclick");
            }).on("contextmenu", function (data) {
                //handle right click
                self.moveGraph(data, 0.7);
                //右击节点时判断菜单是否显示
                if (!self.para.menuShow) {
                    self.showMenu("single", data, d3.select(this));
                }
                // self.showMenu("single",data,d3.select(this));
                //屏蔽浏览器的右键事件
                d3.event.preventDefault();
                //阻止事件冒泡
                d3.event.stopPropagation();
            }).on("click", function (d) {
                // console.log('单击节点, >>>>>>>>>>>>>>>>>>>>>>>>>>>>', d)
                // 点击调整节点大小
                var $thisDom = d3.select(this);
                $thisDom.attr('transform', function(d) {
                    return "translate(" + d.x + "," + d.y + ")";
                })
                d3.event.stopPropagation();
                if (d._clickid) {
                    clearTimeout(d._clickid);
                    d._clickid = null;
                    $("#resultHead").show();
                    // $("#relation2").hide();
                    // $("#resultHead3").hide();
                    $(".myNav li:nth-child(3)").attr("style", "background-color:RGB(84,117,172);cursor: default;");
                    $(".myNav li:nth-child(2)").removeAttr("style");
                    $(".myNav li:nth-child(4)").removeAttr("style");
                    for (var i = 0; i < self.result.nodes.length; i++) {
                        var type = self.result.nodes[i].type;
                        if (type == "T" || type == "L" || type == "P") {
                            self.roleProperty = self.result.rolePropertiesMap;
                        }
                    }
                } else {
                    d._clickid = setTimeout(function () {
                        // process simple click
                        // ...
                        ////console.log("click");
                        self.clickNode(d, d3.select(this));
                        d._clickid = null;
                    }.bind(this), 350);
                    $("#resultHead").show();
                    // $("#relation2").hide();
                    // $("#resultHead3").hide();
                    $(".myNav li:nth-child(3)").attr("style", "background-color:RGB(84,117,172);cursor: default;");
                    $(".myNav li:nth-child(2)").removeAttr("style");
                    $(".myNav li:nth-child(4)").removeAttr("style");
                    for (var i = 0; i < self.result.nodes.length; i++) {
                        var type = self.result.nodes[i].type;
                        if (type == "T" || type == "L" || type == "P") {
                            self.roleProperty = self.result.rolePropertiesMap;
                        }
                    }
                }
                self.recover();
            });

            thisNode.append("circle").attr("r", function (d) {
                return self.para.nodeR;
            }).attr("fill", function (d) {
                return self.getNodeColor(d.type);
            }).attr("stroke-width", function (d) {
                if (d.searchCase == true) {
                    return 20;
                } else {
                    return 4;
                }
            });

            thisNode.selectAll("circle").each(function (d) {
                var nodeThis = d3.select(this);
                self.setCircleStroke(d, d3.select(this));
            });

            thisNode.append("image")
                .attr("data-id", "mainImg")
                .attr("x", -57) //20
                .attr("y", -57)
                .attr("width", 114) //40
                .attr("height", 114)
                .attr("xlink:href", function (d) {
                    return self.getCommonImage(d.source, d.type, 0);
                });

            thisNode.append("text").text(function (d) {
                return d.name.length > 20 ? d.name.substring(0, 20) + "..." : d.name;
            })
                .attr("fill", "#FFFFFF")
                .attr("font-size", 16)
                .attr("text-anchor", "middle")
                .attr("x", 0).attr("y", function (d) {
                if (d.searchCase == true) {
                    return 80;
                } else {
                    return 70;
                }
            });

            //给案件添加人伤和金额大小信息
            thisNode.each(function (d) {
                if (d.type == self.option.type.order) {
                    self.createCaseIcon(d3.select(this), d);
                }
            });

        },
        createCaseIcon: function (item, d) {
            var self = this;
            item.selectAll("[data-type='inj']").remove();
            item.selectAll("[data-type='moneyIcon']").remove();
            item.selectAll("[data-type='money']").remove();

            for (var i = 0; i < d.attrs.length; i++) {
                if (d.attrs[i].name == "daja#CASE_ISINJURYINVOLVED") {
                    if (d.attrs[i].value == "Y") {
                        item.append("image").attr("data-type", "inj")
                            .attr("opacity", 1)
                            .attr("x", 45)
                            .attr("y", -50)
                            .attr("width", 20)
                            .attr("height", 20)
                            .attr("xlink:href", self.opt.url + '/images/indexNew/wcross.png');
                    }
                }

                if (d.attrs[i].name == "daja#CASE_CLAIMAMOUNT") {
                    var level = 0;
                    var money = parseFloat(d.attrs[i].value);
                    if (isNaN(money)) {
                    } else if (money >= 0 && money < 5000) {
                        level = 1;
                    } else if (money >= 5000 && money < 20000) {
                        level = 2;
                    } else if (money >= 20000) {
                        level = 3;
                    }
                    for (var j = 0; j < level; j++) {
                        item.append("image").attr("data-type", "moneyIcon")
                            .attr("opacity", 1)
                            .attr("x", 50 + 20 * j)
                            .attr("y", -28)
                            .attr("width", 20)
                            .attr("height", 20)
                            .attr("xlink:href", self.opt.url + '/images/indexNew/rmb.png');
                    }

                    item.append("text").attr("data-type", "money")
                        .text(function (d) {
                            if (isNaN(money)) {
                                return "金额未知";
                            } else {
                                return self.strTransform(money);
                            }
                        })
                        .attr("fill", "#fff")
                        .attr("x", function (d) {
                            if (d.searchCase == true) {
                                return 65;
                            } else {
                                return 57;
                            }
                        })
                        .attr("y", 8);
                }
            }
        },
        //23244435.55形式转为23，244，435.55形式
        strTransform: function (strNumber) {
            strNumber += '';
            x = strNumber.split('.');
            x1 = x[0];
            x2 = x.length == 1 ? '' : '.' + x[1];
            var reg = /(\d+)(\d{3})/;
            while (reg.test(x1)) {
                x1 = x1.replace(reg, '$1' + ',' + '$2');
            }
            return x1 + x2;
        },
        createNode: function (item, nodesData) {
            var self = this;

            var nodes = item.selectAll(".node").data(nodesData, function (d) {
                return d.id;
            });

            nodes.exit().remove();//删除已有的线段
            var nodesEnter = nodes.enter().append("g").each(function (d) {
                self.createOneNode(d3.select(this));
            });

            return item;
        },
        createOneLink: function (thisLink) {
            var self = this;
            thisLink.attr("class", "link")
                .attr("stroke-width", 2)
                .attr("data-id", function (d) {
                    return d.id;
                })//自定义属性
                .attr("id", function (d) {
                    return d.id;
                })//自定义属性
                .attr("stroke", function (d) {
                    return "#bc8c8f";
                })
                .attr("opacity", function (d) {
                    return 1;
                })
                .attr("fill", "#bc8c8f");
        },
        createLink: function (item, linksData) {
            var self = this;
            //item.select(".links").selectAll("*").remove();
            var link = item.selectAll(".link").data(linksData, function (d) {
                return d.id;
            });
            link.exit().remove();
            link.enter().append("path").each(function (d) {
                self.createOneLink(d3.select(this));
            });
            return item;
        },
        createOneLinkText: function (thisLinkText) {
            var self = this;
            thisLinkText.attr("class", "linkText").attr("opacity", 0);
            thisLinkText.append("text").attr("fill", "#FFFFFF")
                .style("text-anchor", "middle")
                .style("cursor", "pointer")
                .text(function (d) {
                    if (d.rel.length == 1) {
                        d.rel[0] = d.rel[0].trim();
                        return self.opt.linkMap[d.rel[0]] == undefined ? d.rel[0] : self.opt.linkMap[d.rel[0]].cnName;
                    } else {
                        var relName = [];
                        for (var i = 0; i < d.rel.length; i++) {
                            d.rel[i] = d.rel[i].trim();
                            relName.push(self.opt.linkMap[d.rel[i]] == undefined ? d.rel[i] : self.opt.linkMap[d.rel[i]].cnName);
                        }
                        return relName.join(",");
                    }
                });
        },
        /*
		 *  添加关系标签
		 */
        createLinkText2: function (item, linksData) {
            var self = this;
            var linkText = item.selectAll(".linkText").data(linksData, function (d) {
                return d.id;
            });
            linkText.exit().remove();
            var oneLinkText = linkText.enter().append("g").each(function (d) {
                self.createOneLinkText(d3.select(this));
            });
            return item;
        },
        createLinkText: function (item, linksData) {
            var self = this;
            var linkText = item.selectAll(".linkText").data(linksData, function (d) {
                return d.id;
            });
            linkText.exit().remove();
            var oneLinkText = linkText.enter().append("g").attr("class", "linkText");
            oneLinkText.append("text").attr("fill", "#FFFFFF")
                .style("text-anchor", "middle")
                .style("cursor", "default")
                .text(function (d) {
                    return d.rel.join(",");
                });
            return item;

        },
        mouseoverNode: function (d) {
            var self = this;
            /*
			if(self.para.nodeSelect.Zpress==1){
				return;
			}
			*/
            self.para.graph.selectAll(".node").attr("opacity", function (inner) {
                if (self.para.timeFilter == true) {
                    if (inner.timeFilter == false) {
                        d3.select(this).style("display", "none");
                        return 0;
                    }
                }
                if (self.para.nodeToNode[inner.id + "-" + d.id] == 1) {
                    return 1;
                } else {
                    return 0.3;
                }
            });
            self.para.graph.selectAll(".link").attr("opacity", function (inner) {
                if (self.para.timeFilter == true) {
                    if (inner.timeFilter == false) {
                        d3.select(this).style("display", "none");
                        return 0;
                    }
                }
                if (inner.source.id == d.id || inner.target.id == d.id) {
                    return 1;
                } else {
                    return 0.1;
                }
            });
            self.para.graph.selectAll(".linkText").attr("opacity", function (inner) {
                if (self.para.timeFilter == true) {
                    if (inner.timeFilter == false) {
                        d3.select(this).style("display", "none");
                        return 0;
                    }
                }
                if (inner.source.id == d.id || inner.target.id == d.id) {
                    return 1;
                } else {
                    return 0;
                }
            });
        },
        firstMouseoutNode: function() {
            var self = this;
            if (self.para.nodeSelect.ids.length > 0) {
                self.hoverSelectNodes(); //高亮选中的节点
            } else {
              self.hightLightRiskRelation();
            }
            if (self.para.timeFilter == true) {
                self.para.graph.selectAll(".node").style("display", function (d) {
                    if (d.timeFilter) {
                        return "";
                    } else {
                        return "none";
                    }
                });
                self.para.graph.selectAll(".link").style("display", function (d) {
                    if (d.timeFilter) {
                        return "";
                    } else {
                        return "none";
                    }
                });
                self.para.graph.selectAll(".linkText").style("display", function (d) {
                    if (d.timeFilter) {
                        return "";
                    } else {
                        return "none";
                    }
                });
            }
        },
        mouseoutNode: function (d) {
            var self = this;
            if (self.para.nodeSelect.ids.length > 0) {
                self.hoverSelectNodes(); //高亮选中的节点
            } else if (self.para.hightlight.isEnable == 1) {
                self.hightLightNL(self.para.hightlight.nodes, self.para.hightlight.links);//高亮规则找出的线和节点
            } else if(self.para.firstRender) {
              self.hightLightRiskRelation();
              self.para.firstRender = false;
            }
            /*else if(self.para.filterType.length>0){
      				self.filterSameType(self.para.filterType);
      			}*/
            else {
               // console.log('0000000011111111111')
                self.recover();
            }
            if (self.para.timeFilter == true) {
                self.para.graph.selectAll(".node").style("display", function (d) {
                    if (d.timeFilter) {
                        return "";
                    } else {
                        return "none";
                    }
                });
                self.para.graph.selectAll(".link").style("display", function (d) {
                    if (d.timeFilter) {
                        return "";
                    } else {
                        return "none";
                    }
                });
                self.para.graph.selectAll(".linkText").style("display", function (d) {
                    if (d.timeFilter) {
                        return "";
                    } else {
                        return "none";
                    }
                });

                /*
				self.para.graph.selectAll(".node").filter(function(d){ return !d.timeFilter;}).attr("opacity",0).style("display","none");
				self.para.graph.selectAll(".link").filter(function(d){ return !d.timeFilter;}).attr("opacity",0).style("display","none");
				self.para.graph.selectAll(".linkText").filter(function(d){ return !d.timeFilter;}).attr("opacity",0).style("display","none");
				*/
            }
        },
        recoverTimeFilter: function () {
            this.para.graph.selectAll(".node").style("display", "");
            this.para.graph.selectAll(".link").style("display", "");
            this.para.graph.selectAll(".linkText").style("display", "");
        },
        filterselect: function () {
            var self = this;
            var nodes = [];
            for (var i = 0; i < this.para.data.nodes.length; i++) {
                if (!this.para.data.nodes[i].timeFilter) {
                    nodes.push(this.para.data.nodes[i].id);
                }
            }
            var newSelectNodes = [];
            var oldSelectNodes = this.para.nodeSelect.ids;
            for (var i = 0; i < this.para.nodeSelect.ids.length; i++) {
                if (nodes.indexOf(this.para.nodeSelect.ids[i]) < 0) {
                    newSelectNodes.push(this.para.nodeSelect.ids[i]);
                }
            }
            this.para.nodeSelect.ids = newSelectNodes;
            this.para.graph.selectAll(".node image[data-id='mainImg']").filter(function (d) {
                return oldSelectNodes.indexOf(d.id) >= 0 && newSelectNodes.indexOf(d.id) < 0;
            }).attr("xlink:href", function (d) {
                console.log("5555555555555555555555555555" + d.type);
                return self.getImage(d.type, 0);
            });
        },
        timeFilter: function (maxT, minT) {
            if (maxT == 0 || minT == 0) {
                return;
            }
            var self = this;
            self.para.maxT = maxT;
            self.para.minT = minT;
            var filterNode = [];
            var filterType = [self.option.type.order, self.option.type.baodan];

            var showNode = [];
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                var thisNode = self.para.data.nodes[i];
                if (filterType.indexOf(thisNode.type) >= 0) {
                    if (thisNode.type == self.option.type.order) {
                        var hasTime = false;
                        var key = "daja#CASE_NOTIFICATIONDATE";
                        for (var k = 0; k < thisNode.attrs.length; k++) {
                            if (thisNode.attrs[k].name == key && thisNode.attrs[k].value != "") {
                                hasTime = true;
                                var thisTime = thisNode.attrs[k].value.replace(/^([^-]+)-([^-]+)-([^ ]+)(.*)/i, '$1/$2/$3$4');
                                var caseTime = (new Date(thisTime)).getTime();
                                if (caseTime >= minT && caseTime < maxT) {
                                    thisNode.timeFilter = true;
                                    if (showNode.indexOf(thisNode.id) < 0) {
                                        showNode.push(thisNode.id);
                                    }
                                } else {
                                    thisNode.timeFilter = false;
                                    filterNode.push(thisNode.id);
                                }
                                break;
                            }
                        }
                        if (!hasTime) {
                            thisNode.timeFilter = false;
                            filterNode.push(thisNode.id);
                        }
                    } else if (thisNode.type == self.option.type.baodan) {
                        var hasSTime = false;
                        var hasETime = false;
                        var keyS = "daja#InsuranceProduct_EFFECTIVEDATE";
                        var keyE = "daja#InsuranceProduct_EXPIREDATE";
                        var sTime, eTime;
                        for (var k = 0; k < thisNode.attrs.length; k++) {
                            if (thisNode.attrs[k].name == keyS && thisNode.attrs[k].value != "") {
                                hasSTime = true;
                                var thisTime = thisNode.attrs[k].value.replace(/^([^-]+)-([^-]+)-([^ ]+)(.*)/i, '$1/$2/$3$4');
                                sTime = (new Date(thisTime)).getTime();
                            }
                            if (thisNode.attrs[k].name == keyE && thisNode.attrs[k].value != "") {
                                hasETime = true;
                                var thisTime = thisNode.attrs[k].value.replace(/^([^-]+)-([^-]+)-([^ ]+)(.*)/i, '$1/$2/$3$4');
                                eTime = (new Date(thisTime)).getTime();
                            }
                        }
                        if (!(hasSTime * hasETime)) {
                            thisNode.timeFilter = false;
                            filterNode.push(thisNode.id);
                        } else {
                            if (sTime > maxT || eTime < minT) {
                                thisNode.timeFilter = false;
                                filterNode.push(thisNode.id);
                            } else {
                                thisNode.timeFilter = true;
                                if (showNode.indexOf(thisNode.id) < 0) {
                                    showNode.push(thisNode.id);
                                }
                            }
                        }
                    }
                } else {
                    thisNode.timeFilter = true;
                }
            }

            for (var i = 0; i < self.para.data.links.length; i++) {
                var thisLink = self.para.data.links[i];
                var srcId = self.getLinkSourceId(thisLink);
                var tarId = self.getLinkTargetId(thisLink);
                if (filterNode.indexOf(srcId) < 0 && filterNode.indexOf(tarId) < 0) {
                    if (showNode.indexOf(srcId) < 0) {
                        showNode.push(srcId);
                    }
                    if (showNode.indexOf(tarId) < 0) {
                        showNode.push(tarId);
                    }
                    thisLink.timeFilter = true;
                } else {
                    thisLink.timeFilter = false;
                }
            }
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                var thisNode = self.para.data.nodes[i];
                if (showNode.indexOf(thisNode.id) < 0) {
                    thisNode.timeFilter = false;
                }
            }
            self.para.timeFilterData = self.clone(self.para.data);
            //console.log(self.para.data);
        },
        clearTime: function () {
            var self = this;
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                self.para.data.nodes[i].timeFilter = true;
            }
            for (var i = 0; i < self.para.data.links.length; i++) {
                self.para.data.links[i].timeFilter = true;
            }
        },
        /*过滤类型*/
        filterSameType: function (type) {
            var self = this;
            self.clearType();
            if (self.para.maxT == undefined || self.para.minT == undefined) {
                if (!self.para.timeFilter) {
                    self.para.timeFilter = true;
                    //self.clearType();
                }
            } else if (self.para.maxT == 0 || self.para.minT == 0) {
                if (!self.para.timeFilter) {
                    self.para.timeFilter = true;
                }
            }
            if (type.length > 0) {
                var filterTypeNode = [];
                for (var i = 0; i < self.para.data.nodes.length; i++) {
                    var thisNode = self.para.data.nodes[i];
                    if (thisNode.timeFilter) {
                        for (var j = 0; j < type.length; j++) {
                            if (thisNode.type == type[j]) {
                                thisNode.timeFilter = false;
                                filterTypeNode.push(thisNode.id);
                            } else {
                                thisNode.timeFilter = true;
                            }
                        }
                    } else {
                        filterTypeNode.push(thisNode.id);
                    }
                }

                for (var i = 0; i < self.para.data.links.length; i++) {
                    var thisLink = self.para.data.links[i];
                    var srcId = self.getLinkSourceId(thisLink);
                    var tarId = self.getLinkTargetId(thisLink);
                    if (thisLink.timeFilter) {
                        if (filterTypeNode.indexOf(srcId) < 0 && filterTypeNode.indexOf(tarId) < 0) {
                            thisLink.timeFilter = true;
                        } else {
                            thisLink.timeFilter = false;
                        }
                    }
                }
                for (var i = 0; i < self.para.data.nodes.length; i++) {
                    var thisNode = self.para.data.nodes[i];
                    if (filterTypeNode.indexOf(thisNode.id) < 0) {
                        thisNode.timeFilter = true;
                    } else {
                        thisNode.timeFilter = false;
                    }
                }
            }
            //console.log(self.para.data);
        },
        //清楚类型
        clearType: function () {
            var self = this;
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                self.para.data.nodes[i].timeFilter = true;
            }
            for (var i = 0; i < self.para.data.links.length; i++) {
                self.para.data.links[i].timeFilter = true;
            }
            if (self.para.maxT != undefined || self.para.minT != undefined) {
                self.timeFilter(self.para.maxT, self.para.minT);
            }
        },
        setAttr: function (item, attr, value) {
            item.attr(attr, value);
        },
        clickNode: function (d, thisNode) {
            var self = this;
            var thisNode = thisNode.select("image[data-id='mainImg']");
            if (self.para.nodeSelect.Zpress == 1) {
                var index = self.para.nodeSelect.ids.indexOf(d.id);
                if (index < 0) {
                    self.para.nodeSelect.ids.push(d.id);
                    thisNode.attr("xlink:href", function (d) {
                        console.log("4444444444444444444444" + d.type);
                        return self.getImage(d.type, 1);
                    });
                } else {
                    self.para.nodeSelect.ids.splice(index, 1);
                    thisNode.attr("xlink:href", function (d) {
                        console.log("11111111111111111111111" + d.type);
                        return self.getImage(d.type, 0);
                    });
                }
                //更新统计信息
                _.MessageManager.fire("getStatic");
                self.clearMenu();//清除菜单
            } else if (self.para.makeMark.isClick == true) {
                if (self.para.makeMark.isSourceChoose == true) {
                    self.para.makeMark.target = d;
                    var linkObj = {
                        id: self.para.makeMark.source.id + "," + self.para.makeMark.target.id,
                        source: self.para.makeMark.source,
                        target: self.para.makeMark.target,
                        type: "mark"
                    }

                    //console.log(linkObj.source.type+linkObj.target.type);
                    if (self.opt.linkRel[linkObj.source.type + linkObj.target.type] == undefined) {
                        alert("这两种类型不能相连！");
                        return;
                    }

                    for (var i = 0; i < self.para.data.links.length; i++) {
                        var tmpLink = self.para.data.links[i];
                        if ((self.getLinkSourceId(linkObj) == self.getLinkSourceId(tmpLink) && self.getLinkTargetId(linkObj) == self.getLinkTargetId(tmpLink)) ||
                            (self.getLinkSourceId(linkObj) == self.getLinkTargetId(tmpLink) && self.getLinkTargetId(linkObj) == self.getLinkSourceId(tmpLink))) {
                            alert("两个节点只能有一条连线！");
                            self.para.graph.select(".markLinks").selectAll("*").remove();
                            self.para.svg.on("mousemove", null);
                            self.para.makeMark.isSourceChoose = false;
                            self.para.makeMark.isClick = false;
                            $("#Tip").hide();
                            //flag = false;
                            return;
                        }
                    }

                    //////console.log(linkObj);
                    var typeCouple = self.para.makeMark.source.type + self.para.makeMark.target.type;
                    var ht = '<div class="relationside" >'
                        + '<ul class="relationUL" style="overflow:hidden">'
                        + '<li style="width: 220px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" title="' + linkObj.source.name + '" data-id="' + linkObj.source.id + '">'
                        + '<span>起点：</span>' + (linkObj.source.name == "" ? "无记录" : linkObj.source.name) + '</li>'
                        + '<li style="width: 220px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" title="' + linkObj.target.name + '" data-id="' + linkObj.target.id + '">'
                        + '<span>终点：</span>' + (linkObj.source.name == "" ? "无记录" : linkObj.target.name) + '</li>'
                        + '<li><p style="float:right;cursor: pointer;" data-type="' + typeCouple + '"  id="btnAddButton" class="btnAdd">+</p></li></ul>'
                        + '<div class="tabH"><table border="1">'
                        + '<thead>'
                        + '<tr><th>关系</th><th>日期</th><th>权重</th><th>描述</th><th>操作</th></tr>'
                        + '</thead>'
                        + '<tbody>'
                        + '</tbody>'
                        + '</table></div>'
                        + '</div>'
                    $.alert({
                        title: "边信息",
                        content: ht,
                        onOpen: function () {
                            $(".ui_timepicker").datetimepicker({
                                dateFormat: 'yy-mm-dd',
                                changeMonth: true,
                                changeYear: true,
                                showSecond: true,
                                timeFormat: 'hh:mm:ss'
                            });
                            $.datepicker.setDefaults($.datepicker.regional["zh-CN"]);
                            $(".relationside .tabH").perfectScrollbar();
                        },
                        theme: 'blue',
                        closeIcon: true,
                        confirm: function () {
                            //判断输入是否有效
                            var rel = [];
                            var attr = [];
                            var status = 1;
                            $(".relationside tbody tr").each(function () {
                                var linkType = $(this).find("select option:selected").data("id");
                                var linkTime = $(this).find("[name='createTime']").val();
                                var linkWeight = $(this).find("[name='weight']").val();
                                var linkDesc = $(this).find("textarea").val();

                                if (linkType == "empty" || linkTime == "" || !/^[(-?\d+\.\d+)|(-?\d+)|(-?\.\d+)]+$/.test(linkWeight) || linkDesc.trim() == "") {
                                    status = -1;
                                    return false;
                                }

                                if (rel.indexOf(linkType) >= 0) {
                                    status = -2;
                                    return false;
                                }
                                rel.push(linkType);
                                attr.push({
                                    "type": self.opt.linkMap[linkType].name,
                                    "createTime": linkTime,
                                    "desc": linkDesc,
                                    "weight": linkWeight
                                });

                            });
                            if (rel.length == 0 && status == 1) {
                                status = -3;
                            }
                            if (status != 1) {
                                if (status == -1) {
                                    alert("信息填写不完整！");
                                } else if (status == -2) {
                                    alert("一种类型的边只能存在一条！");
                                } else if (status == -3) {
                                    alert("至少插入一条关系！");
                                }
                                return false;
                            } else {
                                linkObj.rel = rel;
                                linkObj.attr = attr;
                                self.para.data.links.push(linkObj);//将新的link数据合并入原始数据
                                self.recordOperate("add", "delete", {nodes: [], links: [linkObj]}, {
                                    nodes: [],
                                    links: [linkObj]
                                }, "恢复-新建边", "撤销-新建边", "add");//记录操作

                                self.para.graph.select(".links").append("path").datum(linkObj)
                                    .attr("class", "link")
                                    .attr("stroke-width", 2)
                                    .attr("stroke", "#bc8c8f")
                                    .attr("opacity", 1)
                                    .attr("fill", "#bc8c8f")
                                    .attr("d", function (inner) {
                                        //return "M"+inner.source.x+" "+inner.source.y+" L"+inner.target.x+" "+inner.target.y;
                                        var dx = inner.target.x - inner.source.x,
                                            dy = inner.target.y - inner.source.y,
                                            dr = Math.sqrt(dx * dx + dy * dy),
                                            theta = Math.atan2(dy, dx) + Math.PI / 300,
                                            d90 = Math.PI / 2,
                                            dtxs = inner.target.x - 57 * Math.cos(theta),
                                            dtys = inner.target.y - 57 * Math.sin(theta);
                                        return "M" + inner.source.x + "," + inner.source.y +
                                            "L" + inner.target.x + "," + inner.target.y +
                                            "M" + dtxs + "," + dtys +
                                            "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                                            "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                                            "z";
                                    });
                                self.para.graph.select(".linkTexts").append("g").datum(linkObj).attr("class", "linkText")
                                    .attr("transform", function (inner) {
                                        return "translate(" + ((inner.source.x + inner.target.x) / 2) + "," + ((inner.source.y + inner.target.y) / 2) + ")";
                                    })
                                    .append("text").attr("fill", "#FFFFFF")
                                    .style("text-anchor", "middle")
                                    .style("cursor", "default")
                                    .text(function (inner) {
                                        //return inner.rel.join(",");
                                        if (inner.rel.length == 1) {
                                            return self.opt.linkMap[inner.rel[0]] == undefined ? inner.rel[0] : self.opt.linkMap[inner.rel[0]].cnName;
                                        } else {
                                            var relName = [];
                                            for (var i = 0; i < inner.rel.length; i++) {
                                                relName.push(self.opt.linkMap[inner.rel[i]] == undefined ? inner.rel[i] : self.opt.linkMap[inner.rel[i]].cnName);
                                            }
                                            return relName.join(",");
                                        }
                                    });

                                self.para.graph.select(".markLinks").selectAll("*").remove();
                                self.para.svg.on("mousemove", null);
                                self.para.makeMark.isSourceChoose = false;
                                self.para.makeMark.isClick = false;

                                self.getNeighbor();
                                $("#Tip").hide();

                                self.refreshInfoDetail();
                            }
                        }
                    });
                    self.clearSelect();
                }
            } else {
                var linkForThisNode = self.getLinkForNode(d.id);
                self.para.infoNodeId = d.id;
                //authority:self.para.authority
                _.MessageManager.fire("infoDetail", {nodeInfo: d, links: linkForThisNode, isClick: true});
                self.moveGraph(d, 0.7);
            }
        },
        syncNodeAttrs: function (node) {
            var self = this;
            var attrs = node.attrs;
            //var dajaId = (node.weaverId == undefined)? node.id:node.weaverId;
            var dajaId = node.id;
            //console.log(dajaId);
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                if (self.para.data.nodes[i].id == dajaId) {
                    self.para.data.nodes[i].attrs = attrs;
                    break;
                }
            }
            self.para.graph.selectAll(".node").filter(function (d) {
                return d.id == dajaId;
            }).each(function (d) {
                d.attrs = attrs;
            });
        },
        getLinkTable: function (linkData) {
            var self = this;
            var str = "<div data-id='linkTable' style='overflow:hidden;margin-bottom: 5px;' class='relationside'>" +
                "<table>" +
                "<thead><th>关系</th><th>日期</th><th>权重</th><th>描述</th><th>操作</th></tdead>" +
                "<tbody>";
            var typeCouple = linkData.source.type + linkData.target.type;
            for (var i = 0; i < linkData.rel.length; i++) {
                str += self.getOneRowForAddLink(typeCouple, "modify", {rel: linkData.rel[i], attrs: linkData.attr[i]});
            }
            str += "</tbody></table>" +
                "<button data-btn='save' class='btnSave tabBtn'>保存</button><button data-btn='add' class='btnAdd2 tabBtn'>添加</button>"
            "</div>";
            return str;
        },
        getOneRowForAddLink: function (typeCouple, type, linkData) {
            var self = this;
            if (type == "new") {
                return '<tr data-type="new"><td><select name="type" style="width:116px;">' + self.getLinkRelStr(typeCouple) + '</select></td><td style="position:relative"><input name="createTime" style="width:136px;" class="ui_timepicker" type="text" value="" readonly="readonly"  maxlength="50"><span class="dateClean" style="right:15px;top:24px" >X</span></td><td><input name="weight" style="width:30px;" type="number" value=""></td><td><textarea name="desc" style="resize:none"></textarea></td><td><span class="del">删除</span></td></tr>';
            } else {
                if (linkData == null) {
                    return '<tr data-type="modify"><td><select name="type" data-change="1" style="width:116px;">' + self.getLinkRelStr(typeCouple) + '</select></td><td style="position:relative"><input data-change="1" name="createTime" style="width:136px;" data-change="1" class="ui_timepicker" type="text" value="" readonly="readonly"  maxlength="50"><span class="dateClean" style="right:15px;top:24px;">X</span></td><td><input name="weight" data-change="1" style="width:30px;" type="number" value=""></td><td><textarea name="desc" data-change="1" style="resize:none"></textarea></td><td><span class="del">删除</span></td></tr>';
                } else {
                    return '<tr data-type="modify"><td><select name="type" data-id="' + linkData.rel + '" data-change="1" style="width:116px;" disabled="disabled"><option selected="selected" data-id="' + linkData.rel + '">' + self.getLinkSelectName(linkData.rel) + '</option></select></td><td style="position:relative"><input data-change="1" name="createTime" style="width:136px;" data-change="1" class="ui_timepicker" type="text" value="' + linkData.attrs.createTime + '" readonly="readonly"  maxlength="50"><span class="dateClean" style="right:15px;top:24px" >X</span></td><td><input data-change="1" name="weight" style="width:30px;" type="number" value="' + linkData.attrs.weight + '"  maxlength="50"></td><td><textarea name="desc" data-change="1" style="resize:none">' + linkData.attrs.desc + '</textarea></td><td><span class="del">删除</span></td></tr>';
                }
            }

        },
        getLinkRelStr: function (typeCouple) {
            var self = this;
            var optionStr = "";
            optionStr += "<option data-id='empty'>-请选择-</option>";
            if (linkType[typeCouple] != undefined) {
                for (var i = 0; i < linkType[typeCouple].length; i++) {
                    optionStr += "<option data-name='" + self.opt.linkMap[self.opt.linkRel[typeCouple][i]].name + "' data-id='" + self.opt.linkRel[typeCouple][i] + "'>" + self.opt.linkMap[self.opt.linkRel[typeCouple][i]].cnName + "</option>"
                }
            }
            //optionStr += "<option data-id='other'>自定义</option>";
            return optionStr;
        },
        /*
		 * 返回跟这个节点相连的边的集合
		 * @param d node的id
		 */
        getLinkForNode: function (id) {
            var self = this;
            var linkForThisNode = new Array();
            for (var i = 0; i < self.para.data.links.length; i++) {
                var tmpLink = self.para.data.links[i];
                if (self.para.timeFilter) {
                    if (self.para.data.links[i].timeFilter) {
                        if (self.getLinkSourceId(tmpLink) == id || self.getLinkTargetId(tmpLink) == id) {
                            linkForThisNode.push(self.clone(tmpLink));
                        }
                    }
                } else {
                    if (self.getLinkSourceId(tmpLink) == id || self.getLinkTargetId(tmpLink) == id) {
                        linkForThisNode.push(self.clone(tmpLink));
                    }
                }
            }
            return linkForThisNode;
        },
        getGraphLoc: function () {
            var self = this;
            var allWidth = 0, allHeight = 0;
            var maxX = 0, maxY = 0, minX = 0, minY = 0;
            for (var i = 0; i < self.para.data.nodes.length; i++) {
                if (i == 0) {
                    maxX = self.para.data.nodes[i].x;
                    minX = self.para.data.nodes[i].x;
                    maxY = self.para.data.nodes[i].y;
                    minY = self.para.data.nodes[i].y;
                }
                allWidth = allWidth + self.para.data.nodes[i].x;
                allHeight = allHeight + self.para.data.nodes[i].y;
                maxX = maxX < self.para.data.nodes[i].x ? self.para.data.nodes[i].x : maxX;
                minX = minX > self.para.data.nodes[i].x ? self.para.data.nodes[i].x : minX;
                maxY = maxY < self.para.data.nodes[i].y ? self.para.data.nodes[i].y : maxY;
                minY = minY > self.para.data.nodes[i].y ? self.para.data.nodes[i].y : minY;
            }
            var loc = {
                maxX: maxX,
                maxY: maxY,
                minX: minX,
                minY: minY,
                allWidth: allWidth,
                allHeight: allHeight
            }
            return loc;
        },
        moveGraphForLayout: function (scale, type) {
            var self = this;
            var loc = self.getGraphLoc();
            allWidth = loc.allWidth,
                allHeight = loc.allHeight,
                maxX = loc.maxX,
                maxY = loc.maxY,
                minY = loc.minY,
                minX = loc.minX;

            if (type != "inside") {
                var H = maxY - minY;
                scale = (self.opt.height - 150) / H;
                scale = scale > 0.8 ? 0.8 : scale;
                //console.log(scale);
            }
            //对画布进行移动和缩放
            var nodesNum = self.para.data.nodes.length;
            //setTimeout(function(){
            self.moveGraph({x: allWidth / nodesNum, y: allHeight / nodesNum}, scale);
            //},250);
        },
        moveGraph: function (d, scale) {
            var self = this;
            self.zoom(false);
            //移动点击的点到中心
            self.para.zoomFactor.k = scale;
            var x = d.x * -1 * self.para.zoomFactor.k + self.opt.width / 2;
            var y = d.y * -1 * self.para.zoomFactor.k + self.opt.height / 2;
            self.para.graph.transition()
                .duration(800)
                .attr("transform", "translate(" + x + "," + y + ")scale(" + self.para.zoomFactor.k + ")")
                .on("end", function () {
                    self.zoom(true);
                    self.para.zoomListener.call(self.para.zoom.transform, d3.zoomIdentity.translate(x, y).scale(self.para.zoomFactor.k));
                });
        },
        /*
    		 * 将节点、连线、连线的标签的透明度恢复到默认状态
    		 */
        recover: function () {
            var self = this;
            self.para.graph.selectAll(".node").attr("opacity", function (inner) {
                return 1;
            });
            self.para.graph.selectAll(".link").attr("opacity", function (inner) {
                return 1;
            });
            self.para.graph.selectAll(".linkText").attr("opacity", function (inner) {
                return 0;
            });
        },
        /*
		 * 虚化没有跟选中节点直接相连的node、link、linkText。
		 */
        hoverSelectNodes: function () {
            var self = this;
            self.para.graph.selectAll(".node").attr("opacity", function (inner) {
                var flag = false;
                //判断该节点是否与其中一个被选中的节点相连。
                for (var i = 0; i < self.para.nodeSelect.ids.length; i++) {
                    if (self.para.nodeToNode[inner.id + "-" + self.para.nodeSelect.ids[i]] == 1) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    return 1;
                } else {
                    return 0.3;
                }
            });
            self.para.graph.selectAll(".link").attr("opacity", function (inner) {
                var flag = false;
                //判断一条线的起点或者终点是否属于被选中节点
                for (var i = 0; i < self.para.nodeSelect.ids.length; i++) {
                    if (inner.source.id == self.para.nodeSelect.ids[i] || inner.target.id == self.para.nodeSelect.ids[i]) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    return 1;
                } else {
                    return 0.1;
                }
            });
            self.para.graph.selectAll(".linkText").attr("opacity", function (inner) {
                var flag = false;
                //判断一条线的起点或者终点是否属于被选中节点
                for (var i = 0; i < self.para.nodeSelect.ids.length; i++) {
                    if (inner.source.id == self.para.nodeSelect.ids[i] || inner.target.id == self.para.nodeSelect.ids[i]) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    return 1;
                } else {
                    return 0;
                }
            });
        },
        nodeColChange: function (id, col) {
            var self = this;
            self.para.graph.selectAll(".node").each(function (d) {
                if (d.id == id) {
                    d3.select(this).select("circle").attr("fill", col);
                }
            });
        },
        /*
		 *  实现矩形区域选择nodes
		 */
        selectArea: function (flag) {
            var self = this;
            if (flag) {
                self.para.svg.on("mousedown", function () {
                    self.para.rangeSelect.isMove = false;
                    if (self.para.svg.select(".selectArea")._groups[0][0] != null) {
                        self.para.rangeSelect.isClick = true; //之前为false，改成true，不确定对不对
                    } else {
                        self.para.rangeSelect.isClick = true;
                        self.para.rangeSelect.mouseStartCoor = d3.mouse(this);
                        self.para.svg.selectAll(".selectArea").remove();
                        return false;
                    }
                })
                    .on("mousemove", function () {
                        self.para.rangeSelect.isMove = true;
                        if (self.para.rangeSelect.isOutRange) {
                            self.para.rangeSelect.isClick = false;
                            self.para.svg.selectAll(".selectArea").remove();
                            self.selectNodes(self.para.rangeSelect.mouseStartCoor, self.para.rangeSelect.mouseCurrCoor, true);
                            self.para.rangeSelect.isOutRange = false;
                        }
                        if (self.para.rangeSelect.isClick) {
                            self.para.rangeSelect.mouseCurrCoor = d3.mouse(this);
                            var x = self.para.rangeSelect.mouseCurrCoor[0] > self.para.rangeSelect.mouseStartCoor[0] ? self.para.rangeSelect.mouseStartCoor[0] : self.para.rangeSelect.mouseCurrCoor[0];
                            var y = self.para.rangeSelect.mouseCurrCoor[1] > self.para.rangeSelect.mouseStartCoor[1] ? self.para.rangeSelect.mouseStartCoor[1] : self.para.rangeSelect.mouseCurrCoor[1];
                            self.para.svg.selectAll(".selectArea").remove();
                            self.para.svg.append("rect").attr("class", "selectArea")
                                .attr("x", x).attr("y", y)
                                .attr("width", Math.abs(self.para.rangeSelect.mouseCurrCoor[0] - self.para.rangeSelect.mouseStartCoor[0]))
                                .attr("height", Math.abs(self.para.rangeSelect.mouseCurrCoor[1] - self.para.rangeSelect.mouseStartCoor[1]))
                                .attr("opacity", 0.8);
                            self.selectNodes(self.para.rangeSelect.mouseStartCoor, self.para.rangeSelect.mouseCurrCoor, false);
                        }
                    })
                    .on("mouseup", function () { // && self.para.rangeSelect.isOutRange == true
                        ////console.log([self.para.rangeSelect.isClick,self.para.rangeSelect.isOutRange]);
                        if (self.para.rangeSelect.isClick == false) {
                            return false;
                        }
                        self.para.rangeSelect.isClick = false;
                        self.para.rangeSelect.mouseEndCoor = d3.mouse(this);
                        self.para.svg.selectAll(".selectArea").remove();
                        self.selectNodes(self.para.rangeSelect.mouseStartCoor, self.para.rangeSelect.mouseEndCoor, true);

                        self.para.rangeSelect.isOutRange = false;
                        return false;
                    });

                $("body").on("mouseup", function () {
                    if (self.para.rangeSelect.isClick == true) {
                        self.para.rangeSelect.isOutRange = true;
                    }
                });
            } else {
                self.para.rangeSelect.isMove = false;
                self.para.svg.on("mousedown", null);
                self.para.svg.on("mousemove", null);
                //self.para.svg.on("mouseup",null);
                $("body").on("mouseup", null);
            }
        },
        /*
		 *  筛选坐标范围内的nodes
		 *  @param mouseStartCoor 区域开始坐标
		 *  @param mouseEndCoor   区域结束坐标
		 */
        selectNodes: function (mouseStartCoor, mouseEndCoor, flag) {
            var self = this;
            var nodes = self.para.graph.selectAll(".node");
            var tempNode = new Array();
            nodes.select("circle").filter(function (d) {
                if (self.para.timeFilter) {
                    return d.timeFilter;
                } else {
                    return true;
                }
            }).each(function (d) {
                var a = (self.getNodeX(d.x) - mouseStartCoor[0]) * (self.getNodeX(d.x) - mouseEndCoor[0]);
                var b = (self.getNodeY(d.y) - mouseStartCoor[1]) * (self.getNodeY(d.y) - mouseEndCoor[1]);
                if (a < 0 && b < 0) {
                    if (tempNode.indexOf(d.id) < 0) {
                        tempNode.push(d.id);
                    }
                    d3.select(this.parentNode).select("image[data-id='mainImg']")
                        .attr("xlink:href", function (d) {
                            console.log("222222222222222222222222222" + d.type);
                            return self.getImage(d.type, 1);
                        });
                } else {
                    d3.select(this.parentNode).select("image[data-id='mainImg']")
                        .attr("xlink:href", function (d) {
                            console.log("3333333333333333333333333333333" + d.type);
                            return self.getImage(d.type, 0);
                        });
                }
            });
            nodes.select("circle").each(function (d) {
                if (self.para.nodeSelect.ids.indexOf(d.id) >= 0) {
                    //d3.select(this).attr("fill","#0080ff");
                    d3.select(this.parentNode).select("image[data-id='mainImg']")
                        .attr("xlink:href", function (d) {
                            console.log("8888888888888888888888888888" + d.type);
                            return self.getImage(d.type, 1);
                        });
                }
            });
            if (flag) {
                for (var i = 0; i < tempNode.length; i++) {
                    if (self.para.nodeSelect.ids.indexOf(tempNode[i]) < 0) {
                        self.para.nodeSelect.ids.push(tempNode[i]);
                    }
                }
                self.hoverSelectNodes();
            }
            //更新统计信息
            _.MessageManager.fire("getStatic");
            ////////console.log(self.para.nodeSelect);
        },
        getImage: function (type, isHover) {
            var self = this;
            console.log(type, self.option.type)
            if (isHover == 1) {
                if (type == self.option.type.peo) {
                    return self.opt.url + "/images/graph/ren.png";
                } else if (type == self.option.type.sxbenid || type == self.option.type.sxemp) {
                    return self.opt.url + "/images/graph/sxlppeople.png";
                } else if (type == self.option.type.order) {
                    return self.opt.url + "/images/graph/case2.png";
                } else if (type == self.option.type.car) {
                    return self.opt.url + "/images/graph/car2.png";
                } else if (type == self.option.type.phone) {
                    return self.opt.url + "/images/graph/phone2.png";
                } else if (type == self.option.type.account) {
                    return self.opt.url + "/images/graph/account2.png";
                } else if (type == self.option.type.org) {
                    return self.opt.url + "/images/graph/4S.png";
                } else if (type == self.option.type.baodan) {
                    return self.opt.url + "/images/graph/baodanNew2.png";
                } else if (type == self.option.type.sxclaim) {
                    return self.opt.url + "/images/graph/sxlpclaim.png"
                } else if (type == self.option.type.sxpolicy) {
                    return self.opt.url + "/images/graph/sxlppolicy.png"
                } else if (type == self.option.type.sxhospital) {
                    return self.opt.url + "/images/graph/sxlphospital.png"
                } else if (type == self.option.type.sxphone) {
                    return self.opt.url + "/images/graph/sxlpphone.png"
                } else if (type == self.option.type.sxage) {
                    return self.opt.url + "/images/graph/sxlpage.png";
                } else if (type == self.option.type.sxhospitalLevel) {
                    return self.opt.url + "/images/graph/sxlphospitalLvl.png";
                } else if (type == self.option.type.sxoccupation) {
                    return self.opt.url + "/images/graph/sxlpcareer.png";
                } else if (type == self.option.type.sxseriousillness) {
                    return self.opt.url + "/images/graph/sxlpillness.png";
                } else {
                    return self.opt.url + "/images/graph/null.png";
                }
            } else {
                if (type == self.option.type.peo) {
                    return self.opt.url + "/images/graph/ren.png";
                } else if (type == self.option.type.sxbenid) {
                    return self.opt.url + "/images/graph/sxlppeople.png";
                } else if (type == self.option.type.order) {
                    return self.opt.url + "/images/graph/case.png";
                } else if (type == self.option.type.car) {
                    return self.opt.url + "/images/graph/car.png";
                } else if (type == self.option.type.phone) {
                    return self.opt.url + "/images/graph/phone.png";
                } else if (type == self.option.type.account) {
                    return self.opt.url + "/images/graph/account.png";
                } else if (type == self.option.type.org) {
                    return self.opt.url + "/images/graph/4S.png";
                } else if (type == self.option.type.baodan) {
                    return self.opt.url + "/images/graph/baodanNew.png";
                } else if (type == self.option.type.sxage) {
                    return self.opt.url + "/images/graph/sxlpage.png";
                } else if (type == self.option.type.sxhospitalLevel) {
                    return self.opt.url + "/images/graph/sxlphospitalLvl.png";
                } else if (type == self.option.type.sxoccupation) {
                    return self.opt.url + "/images/graph/sxlpcareer.png";
                } else if (type == self.option.type.sxseriousillness) {
                    return self.opt.url + "/images/graph/sxlpillness.png";
                } else {
                    return self.opt.url + "/images/graph/case.png";
                }
            }
        },
        getCommonImage: function (source, type, isHover) {
            var self = this;
            // console.log(type, self.option.type)
            if ("daja" == source) {
                if (isHover == 1) {
                    if (type == self.option.type.peo) {
                        return self.opt.url + "/images/graph/ren2.png";
                    } else if (type == self.option.type.order) {
                        return self.opt.url + "/images/graph/case2.png";
                    } else if (type == self.option.type.car) {
                        return self.opt.url + "/images/graph/car2.png";
                    } else if (type == self.option.type.phone) {
                        return self.opt.url + "/images/graph/phone2.png";
                    } else if (type == self.option.type.account) {
                        return self.opt.url + "/images/graph/account2.png";
                    } else if (type == self.option.type.org) {
                        return self.opt.url + "/images/graph/4S.png";
                    } else if (type == self.option.type.baodan) {
                        return self.opt.url + "/images/graph/baodanNew2.png";
                    } else if (type == self.option.type.sxage) {
                        return self.opt.url + "/images/graph/sxlpage.png";
                    } else if (type == self.option.type.sxhospitalLevel) {
                        return self.opt.url + "/images/graph/sxlphospitalLvl.png";
                    } else if (type == self.option.type.sxoccupation) {
                        return self.opt.url + "/images/graph/sxlpcareer.png";
                    } else if (type == self.option.type.sxseriousillness) {
                        return self.opt.url + "/images/graph/sxlpillness.png";
                    } else {
                        return self.opt.url + "/images/graph/null.png";
                    }
                } else {
                    if (type == self.option.type.peo) {
                        return self.opt.url + "/images/graph/ren.png";
                    } else if (type == self.option.type.order) {
                        return self.opt.url + "/images/graph/case.png";
                    } else if (type == self.option.type.car) {
                        return self.opt.url + "/images/graph/car.png";
                    } else if (type == self.option.type.phone) {
                        return self.opt.url + "/images/graph/phone.png";
                    } else if (type == self.option.type.account) {
                        return self.opt.url + "/images/graph/account.png";
                    } else if (type == self.option.type.org) {
                        return self.opt.url + "/images/graph/4S.png";
                    } else if (type == self.option.type.baodan) {
                        return self.opt.url + "/images/graph/baodanNew.png";
                    } else if (type == self.option.type.sxage) {
                        return self.opt.url + "/images/graph/sxlpage.png";
                    } else if (type == self.option.type.sxhospitalLevel) {
                        return self.opt.url + "/images/graph/sxlphospitalLvl.png";
                    } else if (type == self.option.type.sxoccupation) {
                        return self.opt.url + "/images/graph/sxlpcareer.png";
                    } else if (type == self.option.type.sxseriousillness) {
                        return self.opt.url + "/images/graph/sxlpillness.png";
                    } else {
                        return self.opt.url + "/images/graph/null.png";
                    }
                }
            }

            if ("sxlp" == source) {
                if (isHover == 1) {
                    if (type == self.option.type.sxclaim) {
                        return self.opt.url + "/images/graph/sxlpclaim.png";
                    } else if (type == self.option.type.sxpolicy) {
                        return self.opt.url + "/images/graph/sxlppolicy.png";
                    } else if (type == self.option.type.sxpid) {
                        return self.opt.url + "/images/graph/sxlppeople.png";
                    } else if (type == self.option.type.sxapid) {
                        return self.opt.url + "/images/graph/sxlppeople.png";
                    } else if (type == self.option.type.sxbenid) {
                        return self.opt.url + "/images/graph/sxlppeople.png";
                    } else if (type == self.option.type.sxphone) {
                        return self.opt.url + "/images/graph/sxlpphone.png";
                    } else if (type == self.option.type.sxclmset) {
                        return self.opt.url + "/images/graph/sxlpaccount.png";
                    } else if (type == self.option.type.sxemp) {
                        return self.opt.url + "/images/graph/sxlpsalesman.png";
                    } else if (type == self.option.type.sxhospital) {
                        return self.opt.url + "/images/graph/sxlphospital.png";
                    } else if (type == self.option.type.sxclmset) {
                        return self.opt.url + "/images/graph/sxlpaccount.png";
                    } else if (type == self.option.type.sxage) {
                        return self.opt.url + "/images/graph/sxlpage.png";
                    } else if (type == self.option.type.sxhospitalLevel) {
                        return self.opt.url + "/images/graph/sxlphospitalLvl.png";
                    } else if (type == self.option.type.sxoccupation) {
                        return self.opt.url + "/images/graph/sxlpcareer.png";
                    } else if (type == self.option.type.sxseriousillness) {
                        return self.opt.url + "/images/graph/sxlpillness.png";
                    } else {
                        return self.opt.url + "/images/graph/null.png";
                    }
                } else {
                    if (type == self.option.type.sxclaim) {
                        return self.opt.url + "/images/graph/sxlpclaim.png";
                    } else if (type == self.option.type.sxpolicy) {
                        return self.opt.url + "/images/graph/sxlppolicy.png";
                    } else if (type == self.option.type.sxpid) {
                        return self.opt.url + "/images/graph/sxlppeople.png";
                    } else if (type == self.option.type.sxapid) {
                        return self.opt.url + "/images/graph/sxlppeople.png";
                    } else if (type == self.option.type.sxbenid) {
                        return self.opt.url + "/images/graph/sxlppeople.png";
                    } else if (type == self.option.type.sxphone) {
                        return self.opt.url + "/images/graph/sxlpphone.png";
                    } else if (type == self.option.type.sxclmset) {
                        return self.opt.url + "/images/graph/sxlpaccount.png";
                    } else if (type == self.option.type.sxemp) {
                        return self.opt.url + "/images/graph/sxlpsalesman.png";
                    } else if (type == self.option.type.sxhospital) {
                        return self.opt.url + "/images/graph/sxlphospital.png";
                    } else if (type == self.option.type.sxage) {
                        return self.opt.url + "/images/graph/sxlpage.png";
                    } else if (type == self.option.type.sxhospitalLevel) {
                        return self.opt.url + "/images/graph/sxlphospitalLvl.png";
                    } else if (type == self.option.type.sxoccupation) {
                        return self.opt.url + "/images/graph/sxlpcareer.png";
                    } else if (type == self.option.type.sxseriousillness) {
                        return self.opt.url + "/images/graph/sxlpillness.png";
                    } else {
                        return self.opt.url + "/images/graph/null.png";
                    }
                }
            }
        },
        getNodeX: function (x) {
            var self = this;
            return x * self.para.zoomFactor.k + self.para.zoomFactor.tx;
        },
        getNodeY: function (y) {
            var self = this;
            return y * self.para.zoomFactor.k + self.para.zoomFactor.ty;
        },
        getReverseNodeX: function (x) {
            var self = this;
            return (x - self.para.zoomFactor.tx) / self.para.zoomFactor.k;
        },
        getReverseNodeY: function (y) {
            var self = this;
            return (y - self.para.zoomFactor.ty) / self.para.zoomFactor.k;
        },
        checkFormat: function (graph) {
            //如果node没有attrs属性、link没有attr属性，添加空值
            for (var i = 0; i < graph.nodes.length; i++) {
                if (graph.nodes[i].attrs == undefined) {
                    graph.nodes[i].attrs = new Array();
                }
            }
            for (var i = 0; i < graph.links.length; i++) {
                if (graph.links[i].attr == undefined) {
                    graph.links[i].attr = new Array();
                    for (var j = 0; j < graph.links[i].rel.length; j++) {
                        graph.links[i].attr.push({
                            "type": "",
                            "createTime": "",
                            "desc": "",
                            "weight": 0
                        })
                    }
                }
            }
        },
        draw: function (graph, flag) {
            //console.log(graph);
            //更新统计信息
            _.MessageManager.fire("getStatic");

            flag = flag || 1;
            //////console.log("---draw---")
            var self = this;
            //如果一个节点连接的线太多，融合成一个点
            /*
			var nodeToType = new Object();
			for(var i=0;i<graph.nodes.length;i++){
				nodeToType[graph.nodes[i].id] = graph.nodes[i].type;
			}
			var objLinkNum = new Object();
			var objLinkAll = new Object();

			for(var i=0;i<graph.links.length;i++){
				var srcId = self.getLinkSourceId(graph.links[i]);
				var tarId = self.getLinkTargetId(graph.links[i]);
				if(objLinkNum[srcId]==undefined){
					objLinkNum[srcId] = new Object();
				}
				if(objLinkNum[srcId][nodeToType[tarId]] == undefined){
					objLinkNum[srcId][nodeToType[tarId]] = new Array();
				}
				if(objLinkNum[srcId][nodeToType[tarId]].indexOf(tarId)<0){
					objLinkNum[srcId][nodeToType[tarId]].push(tarId);
				}

				objLinkAll[srcId] = objLinkAll[srcId]==undefined?1:objLinkAll[srcId]+1;

				if(objLinkNum[tarId]==undefined){
					objLinkNum[tarId] = new Object();
				}
				if(objLinkNum[tarId][nodeToType[srcId]] == undefined){
					objLinkNum[tarId][nodeToType[srcId]] = new Array();
				}
				if(objLinkNum[tarId][nodeToType[srcId]].indexOf(srcId)<0){
					objLinkNum[tarId][nodeToType[srcId]].push(srcId);
				}

				objLinkAll[tarId] = objLinkAll[tarId]==undefined?1:objLinkAll[tarId]+1;
			}
			//console.log("num");
			//console.log(objLinkNum);
			//console.log(objLinkAll);

			var bakNode = [];
			for(var prop in objLinkNum){
				for(var type in objLinkNum[prop]){
					if(objLinkNum[prop][type].length>50){
						bakNode.push({id:prop,type:type});
					}
				}
			}
			//console.log(bakNode);

			var delNode = [], delLink = [];
			for(var i=0;i<bakNode.length;i++){
				var tmp = objLinkNum[bakNode[i]["id"]][bakNode[i]["type"]];
				for(var k=0;k<tmp.length;k++){
					if(objLinkAll[tmp[k]]>1){
						if(delLink.indexOf(tmp[k])<0){
							delLink.push([bakNode[i]["id"],tmp[k]]);
						}
					}else{
						if(delNode.indexOf(tmp[k])<0){
							delNode.push(tmp[k]);
							delLink.push([bakNode[i]["id"],tmp[k]]);
						}
					}
				}
			}
			//console.log([delNode,delLink]);

			for(var i=0;i<delNode.length;i++){
				self.removeNode(delNode[i]);
			}
			for(var i=0;i<delLink.length;i++){
				self.removeLink(delLink[i][0]+","+delLink[i][1]);
				self.removeLink(delLink[i][1]+","+delLink[i][0]);
			}
			*/
            self.checkFormat(graph);


            //开启svg事件
            self.para.actionEnable = 1;
            //更新案件列表信息
            _.MessageManager.fire("refreshCaseList", {list: graph.nodes});
            //添加连线
            var links = self.createLink(self.para.graph.select(".links"), graph.links);
            //添加连线label
            var linkTextG = self.createLinkText2(self.para.graph.select(".linkTexts"), graph.links);
            //添加节点
            var nodes = self.createNode(self.para.graph.select(".nodes"), graph.nodes);
            nodes.selectAll("circle").attr("fill", function (d) {
                return self.getNodeColor(d.type);
            })

            //force
            self.para.simulation.nodes(graph.nodes).on("tick", ticked);

            self.para.simulation.force("link", d3.forceLink().id(function (d, i) {
                return d.id;
            }).links(graph.links).distance(self.opt.linkDistance));
            self.para.simulation.force("collide", d3.forceCollide().radius(80).iterations(4));
            self.para.simulation.alpha(1).restart();

            self.para.drawRun = setTimeout(function () {
                self.para.simulation.stop();
                if (self.para.data.nodes.length == 0) {
                    return;
                }
                //对画布进行移动和缩放
                if (flag == 1 || flag == 3) {
                    self.moveGraphForLayout(0.3);
                }
                if (flag == 3) {
                    var linkForThisNode = self.getLinkForNode(self.para.nowId);
                    var thisNode = self.getNodes([self.para.nowId]);
                    self.para.infoNodeId = self.para.nowId;
                    _.MessageManager.fire("infoDetail", {nodeInfo: thisNode[0], links: linkForThisNode, isClick: true});
                }
                if (flag == 4) {
                    for (var i = 0; i < self.para.data.nodes.length; i++) {
                        if (self.para.data.nodes[i].searchCase == true) {
                            self.moveGraph(self.para.data.nodes[i], 0.7);
                            break;
                        }
                    }
                }
            }, 2000);

            //构建相连节点
            self.getNeighbor();

            //node拖拽事件
            self.nodeDrag("node");

            function ticked() {
                nodes.selectAll(".node").attr("transform", function (d) {
                    if (d.size && d.size === 'small') {
                        return "translate(" + d.x + "," + d.y + ") scale(0.5)";
                    }
                    return "translate(" + d.x + "," + d.y + ")";
                });

                //调整link位置
                links.selectAll(".link").attr("d", function (d) {
                    //return "M"+d.source.x+" "+d.source.y+" L"+d.target.x+" "+d.target.y;
                    return self.linePath(d.source, d.target);
                });


                //调整link标签位置
                linkTextG.selectAll(".linkText").each(function (d) {
                    d3.select(this).attr("transform", function () {
                        return "translate(" + ((d.source.x + d.target.x) / 2) + "," + ((d.source.y + d.target.y) / 2) + ")";
                    })
                });

            }
            // self.hightLightRiskRelation();
            //更新显隐
            console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>, 渲染')
            self.firstMouseoutNode();
            // self.mouseoutNode();
        },
        /*
         * 高亮展示高风险关系网
         **/
        hightLightRiskRelation: function() {
            var self = this;
            // 后期 要调接口请求高风险数据
            self.riskMessage.nodes = ["B0002400816027976912","A000CHD1830000303355","pid370704198111050621","A000CHD1830000610289","B000240081602794788","pid370704198107050821","age38","busiCHDVK590","career125545656"];
            self.riskMessage.links = ["A000CHD1830000303355,pid370704198111050621","A000CHD1830000303355,B0002400816027976912","B000240081602794788,busiCHDVK590","A000CHD1830000610289,B000240081602794788","B0002400816027976912,busiCHDVK590","A000CHD1830000610289,pid370704198107050821","pid370704198107050821,age38","pid370704198111050621,age38","pid370704198107050821,career125545656","pid370704198111050621,career125545656"];
            self.hightLightNL(self.riskMessage.nodes, self.riskMessage.links);
        },
        linePath: function (source, target) {
            var dx = target.x - source.x,
                dy = target.y - source.y,
                dr = Math.sqrt(dx * dx + dy * dy),
                theta = Math.atan2(dy, dx) + Math.PI / 300,
                d90 = Math.PI / 2,
                dtxs = target.x - 57 * Math.cos(theta),
                dtys = target.y - 57 * Math.sin(theta);
            return "M" + source.x + "," + source.y +
                "L" + target.x + "," + target.y +
                "M" + dtxs + "," + dtys +
                "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                "z";
        },
        /*
		 * 构建相连节点
		 * */
        getNeighbor: function () {
            var self = this;
            var graph = self.para.data;
            self.para.nodeToNode = null;
            self.para.nodeToNode = new Object();
            for (var i = 0; i < graph.nodes.length; i++) {
                self.para.nodeToNode[graph.nodes[i].id + "-" + graph.nodes[i].id] = 1;
            }
            for (var i = 0; i < graph.links.length; i++) {//marker
                self.para.nodeToNode[self.getLinkSourceId(graph.links[i]) + "-" + self.getLinkTargetId(graph.links[i])] = 1;
                self.para.nodeToNode[self.getLinkTargetId(graph.links[i]) + "-" + self.getLinkSourceId(graph.links[i])] = 1;
            }
        },
        /*
		 * 返回node的指定字段
		 * */
        getNodeDetail: function (nodeArr, id, key) {
            for (var i = 0; i < nodeArr.length; i++) {
                if (nodeArr[i].id == id) {
                    return nodeArr[i][key];
                }
            }
            return null;
        },
        /*
		 *  实现、取消node拖拽
		 */
        nodeDrag: function (className) {
            var self = this;
            var isDrag = true;
            var nodes = self.para.graph.select(".nodes").selectAll("." + className);
            if (isDrag == true) {
                nodes.call(
                    d3.drag().on("start", dragStart)
                        .on("drag", dragged)
                        .on("end", dragEnd)
                );
            } else {
                nodes.on(".start", null);
                nodes.on(".drag", null);
                nodes.on(".end", null);
            }
            var startCoor = null;

            function dragStart(d) {
                startCoor = d3.event;
                self.para.simulation.stop();//停止力导向
            }

            function dragged(d) {
                var nowCoor = d3.event;
                if (self.para.nodeSelect.ids.length > 1 && self.para.nodeSelect.ids.indexOf(d.id) >= 0) {
                    self.para.graph.selectAll(".node").filter(function (innerD) {
                        return (self.para.nodeSelect.ids.indexOf(innerD.id) >= 0);
                    }).each(function (innerD) {
                        self.mytick(innerD, this, nowCoor.x - startCoor.x, nowCoor.y - startCoor.y);
                    })
                } else {
                    self.mytick(d, this, nowCoor.x - startCoor.x, nowCoor.y - startCoor.y);
                }
                startCoor = nowCoor;
            }

            function dragEnd(d) {

            }
        },
        mytick: function (d, thisNode, dx, dy) {
            var self = this;
            var thisNodeCoor = {x: 0, y: 0};
            d3.select(thisNode).attr("transform", function (nodeD) {
                //nodeD.x = d3.event.x;
                //nodeD.y = d3.event.y;
                //return "translate("+d3.event.x+","+d3.event.y+")";
                nodeD.x = nodeD.x + dx;
                nodeD.y = nodeD.y + dy;
                thisNodeCoor.x = nodeD.x;
                thisNodeCoor.y = nodeD.y;
                return "translate(" + nodeD.x + "," + nodeD.y + ")";
            });

            self.para.graph.selectAll(".link").each(function (linkD) {
                if (linkD.source.id == d.id) {
                    d3.select(this).attr("d", function () {
                        //return "M"+d3.event.x+" "+d3.event.y+" L"+linkD.target.x+" "+linkD.target.y;
                        var dx = linkD.target.x - thisNodeCoor.x,
                            dy = linkD.target.y - thisNodeCoor.y,
                            dr = Math.sqrt(dx * dx + dy * dy),
                            theta = Math.atan2(dy, dx) + Math.PI / 300,
                            d90 = Math.PI / 2,
                            dtxs = linkD.target.x - 57 * Math.cos(theta),
                            dtys = linkD.target.y - 57 * Math.sin(theta);
                        return "M" + thisNodeCoor.x + "," + thisNodeCoor.y +
                            "L" + linkD.target.x + "," + linkD.target.y +
                            "M" + dtxs + "," + dtys +
                            "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                            "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                            "z";
                    })
                }
                if (linkD.target.id == d.id) {
                    d3.select(this).attr("d", function () {
                        //return "M"+linkD.source.x+" "+linkD.source.y+" L"+thisNodeCoor.x+" "+thisNodeCoor.y;
                        var dx = thisNodeCoor.x - linkD.source.x,
                            dy = thisNodeCoor.y - linkD.source.y,
                            dr = Math.sqrt(dx * dx + dy * dy),
                            theta = Math.atan2(dy, dx) + Math.PI / 300,
                            d90 = Math.PI / 2,
                            dtxs = thisNodeCoor.x - 57 * Math.cos(theta),
                            dtys = thisNodeCoor.y - 57 * Math.sin(theta);
                        return "M" + linkD.source.x + "," + linkD.source.y +
                            "L" + thisNodeCoor.x + "," + thisNodeCoor.y +
                            "M" + dtxs + "," + dtys +
                            "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                            "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                            "z";
                    })
                }
            });
            //调整link标签位置
            self.para.graph.selectAll(".linkText").each(function (linkD) {
                if (linkD.source.id == d.id) {
                    d3.select(this).attr("transform", function () {
                        return "translate(" + ((thisNodeCoor.x + linkD.target.x) / 2) + "," + ((thisNodeCoor.y + linkD.target.y) / 2) + ")";
                    })
                }
                if (linkD.target.id == d.id) {
                    d3.select(this).attr("transform", function () {
                        return "translate(" + ((thisNodeCoor.x + linkD.source.x) / 2) + "," + ((thisNodeCoor.y + linkD.source.y) / 2) + ")";
                    })
                }
            });

        },
        getLinkSourceId: function (link) {
            var source = link.source;
            if (link.source instanceof Object) {
                source = link.source.id;
            }
            return source;
        },
        getLinkTargetId: function (link) {
            var target = link.target;
            if (link.target instanceof Object) {
                target = link.target.id;
            }
            return target;
        },
        getNodeNameByLink: function (node) {
            var nodeName;
            if (node instanceof Object) {
                nodeName = node.name;
            } else {
                nodeName = this.getNodeDetail(this.para.data.nodes, node, "name");
            }
            return nodeName;
        },
        /*
		 *  获取说有node的id数组
		 *  @param data
		 *  @return ids
		 */
        getAllNodeIds: function (nodes) {
            var ids = [];
            for (var i = 0; i < nodes.length; i++) {
                if (ids.indexOf(nodes[i].id) < 0) {
                    ids.push(nodes[i].id);
                }
            }
            return ids;
        },
        /*
		 *  获取说有node的id数组
		 *  @param data
		 *  @return ids
		 */
        getAllLinkIds: function (links) {
            var ids = [];
            for (var i = 0; i < links.length; i++) {
                if (ids.indexOf(links[i].id) < 0) {
                    ids.push(links[i].id);
                }
            }
            return ids;
        },
        hoverLoop: function (nodes, links) {
            var self = this;
            self.para.isHover = true;
            self.para.graph.selectAll(".node").filter(function (d) {
                return nodes.indexOf(d.id) < 0;
            }).attr("opacity", 0.3);
            self.para.graph.selectAll(".link").filter(function (d) {
                return links.indexOf(d.id) < 0;
            }).attr("opacity", 0.1);
            self.para.graph.selectAll(".linkText").filter(function (d) {
                return links.indexOf(d.id) < 0;
            }).attr("opacity", 0);
        },
        cancenlHoverLoop: function () {
            this.para.isHover = false;
            this.recover();
        },
        /*
		 * 复制
		 * */
        clone: function (obj) {
            var o, i, j, k;
            if (typeof (obj) != "object" || obj === null) return obj;
            if (obj instanceof (Array)) {
                o = [];
                i = 0;
                j = obj.length;
                for (; i < j; i++) {
                    if (typeof (obj[i]) == "object" && obj[i] != null) {
                        o[i] = arguments.callee(obj[i]);
                    } else {
                        o[i] = obj[i];
                    }
                }
            } else {
                o = {};
                for (i in obj) {
                    if (typeof (obj[i]) == "object" && obj[i] != null) {
                        o[i] = arguments.callee(obj[i]);
                    } else {
                        o[i] = obj[i];
                    }
                }
            }
            return o;
        },
        getOriginFormatData: function () {
            var self = this;
            var nowData = self.clone(self.para.data);
            for (var i = 0; i < nowData.links.length; i++) {
                nowData.links[i].source = self.getLinkSourceId(nowData.links[i]);
                nowData.links[i].target = self.getLinkTargetId(nowData.links[i]);
            }
            return nowData;
        },
        markStatus: function (id, type, content) {
            var self = this;
            self.para.graph.selectAll(".node").filter(function (d) {
                return d.id == id;
            }).select("circle").each(function (d) {
                d.markStatus = type;
                d.markMess = content;
                self.setCircleStroke(d, d3.select(this));
            });

            //同步到欺诈检测页面的原始数据
            _.MessageManager.fire("SymMarkStatus", {id: id, type: type, content: content});
        },
        setCircleStroke: function (d, thisNode) {
            //thisNode.attr("stroke","#ffff00").attr("stroke-width",4).attr("stroke-opacity",0);
            if (d.markStatus == "13") {
                thisNode.attr("stroke", "#00b591").attr("stroke-width", 3).attr("stroke-opacity", 1);
            } else if (d.markStatus == "12") {
                thisNode.attr("stroke", "#ff0000").attr("stroke-opacity", 1);
            } else if (d.markStatus == "11") {
                thisNode.attr("stroke", "#ff5809").attr("stroke-opacity", 1);
            } else if (d.markStatus == "10") {
                thisNode.attr("stroke", "#ffffff").attr("stroke-opacity", 1);
            } else if (d.searchCase == true) {
                thisNode.attr("stroke", "#00FF00").attr("stroke-opacity", 1);
            } else if (d.newComing == 1) {
                thisNode.attr("stroke", "#ffff00").attr("stroke-opacity", 1);
            } else {
                thisNode.attr("stroke", "#ffff00").attr("stroke-opacity", 0);
            }
        },
        refreshLinkLoc: function () {
            //调整link位置
            this.para.graph.selectAll(".link").attr("d", function (d) {
                //return "M"+d.source.x+" "+d.source.y+" L"+d.target.x+" "+d.target.y;
                var dx = d.target.x - d.source.x,
                    dy = d.target.y - d.source.y,
                    dr = Math.sqrt(dx * dx + dy * dy),
                    theta = Math.atan2(dy, dx) + Math.PI / 300,
                    d90 = Math.PI / 2,
                    dtxs = d.target.x - 57 * Math.cos(theta),
                    dtys = d.target.y - 57 * Math.sin(theta);
                return "M" + d.source.x + "," + d.source.y +
                    "L" + d.target.x + "," + d.target.y +
                    "M" + dtxs + "," + dtys +
                    "l" + (3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                    "L" + (dtxs - 3.5 * Math.cos(d90 - theta) - 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) - 10 * Math.sin(theta)) +
                    "z";
            });


            //调整link标签位置
            this.para.graph.selectAll(".linkText").attr("transform", function (d) {
                return "translate(" + ((d.source.x + d.target.x) / 2) + "," + ((d.source.y + d.target.y) / 2) + ")";
            });
        },
        extendCase: function () {
            this.showBoard('快捷键："Shift"+"T"');
            if (this.para.nodeSelect.ids.length == 0) {
                this.clearSelect();
                var graph = this.getSubGraph();
                //图转表限制200行，20171016
                var nodeCase = [];
                for (var i = 0; i < graph.nodes.length; i++) {
                    if (graph.nodes[i].type == "C") {
                        nodeCase.push(graph.nodes[i]);
                    }
                }
                if (nodeCase.length > 500) {
                    alert("报案号数量不能大于500个！");
                    return;
                }
                //否时继续，20171016
                var newCase = [];
                for (var j = 0; j < graph.nodes.length; j++) {
                    var thisNode = graph.nodes[j];
                    if (thisNode.type == this.option.type.order && thisNode.isExtend != 1) {
                        newCase.push(thisNode.id);
                    }
                }
                this.para.nodeSelect.ids = newCase;
                if (this.para.nodeSelect.ids.length == 0) {
                    _.MessageManager.fire("showTable");
                } else {
                    this.extendNodes(false, true);
                }
            } else {
                _.MessageManager.fire("showTable");
            }
        },
        refreshIcon: function () {
            var self = this;
            this.para.graph.selectAll(".node").filter(function (d) {
                return d.type == self.option.type.order;
            })
        }
    };
    window.NewGraph = NewGraph;
})()
