1 Star 1 Fork 4

小码农 / D3企业关系图谱

forked from 临月 / D3企业关系图谱 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
relation.min.js 12.54 KB
一键复制 编辑 原始数据 按行查看 历史
临月 提交于 2018-06-05 17:40 . 2018/6/5完成企业关系图
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(){var t=function(t){this.options=$.extend({id:"",spacing:15,nodes:[],edges:[],color:{node:{Person:"#f75000",Company:"#4682b4"},opacityNode:{Person:"#FFCBB3",Company:"#dcecfc"},line:{INVEST:"#fd485e",EMPLOY:"#4ea2f0",LEGAL:"#4ea2f0"},stroke:{Person:"#FF8247",Company:"#6495ED"},opacityStroke:{Person:"#FFE7BA",Company:"#B2DFEE"},main:{node:"#EE3B3B",stroke:"#EE6363",opacityNode:"#FFC1C1",opacityStroke:"#FFE4C4"}}},t);var e=!1;for(var r in this.options)this.isEmpty(this.options[r])&&(e=!0);!e&&this.init()};function e(t,e){for(var r=[],n=0;n<t.length-1;n++)for(var o=n+1;o<t.length;o++)t[o]&&t[n]&&t[n].source===t[o].source&&t[n].target===t[o].target&&(e[o]=t[o],e[o].originalIndex=t[n].index,r.push(o),t[o].isRedundancy=!0);return r}t.prototype.init=function(){var t=this,r=t.options.nodes,n=t.options.edges,o=d3.zoom().on("zoom",function(){u.attr("transform",d3.event.transform)}),i=d3.select("#"+this.options.id),a=+i.attr("width"),s=+i.attr("height"),c=0,l=0,u=i.append("g").attr("transform","translate("+l+", "+c+")"),p=[],d=[],f=[],x={clicked:!1,drag:!1},m="middle",y="top",h="bottom";t.dataSet(n,r);var g=d3.forceSimulation(r).force("charge",d3.forceManyBody().strength(-400)).force("link",d3.forceLink(n).distance(200).strength(2)).force("center",d3.forceCenter(a/2,s/2)).force("collide",d3.forceCollide().radius(function(t){return t.r+50}));t.unique(e(n,p)),t.unique(e(p,d)),t.unique(e(d,f)),t.setIndex(n,p),t.setIndex(d,p),t.setIndex(f,d),t.replaceEmptyItem(n),t.replaceEmptyItem(p),t.replaceEmptyItem(d),t.replaceEmptyItem(f),t.distinctIndex(n,p),t.distinctIndex(p,d),t.distinctIndex(d,f);var k=i.append("defs");for(var b in n)Y("middlePathArrow"+b,n[b].index);for(var v in p)Y("topPathArrow"+v,p[v].index);for(var A in d)Y("bottomPathArrow"+A,d[A].index);var w=_(m,n),C=X(m,n),I=Z(m,n),E=G(y),P=_(y,p),S=X(y,p),L=Z(y,p),B=G(h),M=_(h,d),N=X(h,d),F=Z(h,d),q=u.selectAll(".circle").data(r).enter().append("g").attr("class","gNodes").attr("transform","translate(-9999, -9999)").call(d3.drag().on("start",function(t){if(x.drag=!0,x.clicked)return;lt(t,!1,this)}).on("drag",function(t){if(x.clicked&&"unSelected"===st(t).attr("class"))return;J(t),K(t),d3.select(this).raise(),t.x=d3.event.x,t.y=d3.event.y,d3.select(this).attr("transform",function(e,r){return"translate("+t.x+" ,"+t.y+")"}),ft(ot(".path-middle",t),m,!0),pt(ot(".path-middle-text",t),m),pt(ot(".path-middle-mask-text",t),m),dt(ot(".path-top-rect",t)),ft(ot(".path-top",t),y,!0),pt(ot(".path-top-text",t),y),pt(ot(".path-top-mask-text",t),y),dt(ot(".path-bottom-rect",t)),ft(ot(".path-bottom",t),h,!0),pt(ot(".path-bottom-text",t),h),pt(ot(".path-bottom-mask-text",t),h)}).on("end",function(t){if(x.drag=!1,x.clicked)return;ut(t,!1,this)})),T=q.append("circle").attr("r",function(t){return t.r}).attr("id",function(t){return"circle-"+t.index}).attr("fill",function(t){return t.color}).attr("stroke",function(t){return t.stroke}).style("cursor","pointer"),z=q.append("text").attr("id","text").style("fill","#fff").style("cursor","pointer");function O(t){return{Company:{x:-(t.r/2+5),y:-t.r/2+5,text:t.properties.name.substring(0,4)},Person:{x:-(t.r/2+5),y:5,text:t.properties.name}}}function Y(t,e){k.append("marker").attr("class","arrow").attr("markerUnits","strokeWidth").attr("markerWidth",10).attr("markerHeight",10).attr("refY",3).attr("id","arrow"+e).attr("fill-opacity",.5).append("path").attr("d","M0,1 L0,5 L5,3 z")}z.append("tspan").attr("x",function(t){return O(t)[t.labels[0]].x}).attr("y",function(t){return O(t)[t.labels[0]].y}).text(function(t){if(O(t)[t.labels[0]])return O(t)[t.labels[0]].text}),z.append("tspan").attr("x",function(t){if("Company"===t.labels[0])return O(t)[t.labels[0]].x-8}).attr("y",function(t){if("Company"===t.labels[0])return O(t)[t.labels[0]].y+18}).text(function(t){return t.properties.name.substring(4,9)}),z.append("tspan").attr("x",function(t){if("Company"===t.labels[0])return O(t)[t.labels[0]].x}).attr("y",function(t){if("Company"===t.labels[0])return O(t)[t.labels[0]].y+36}).text(function(t){return t.properties.name.length>13?t.properties.name.substring(9,11)+"...":t.properties.name.substring(9,t.properties.name.length)});var D=d3.scaleLinear();function G(e){"top"===e||t.options.spacing,document.querySelector(".path-middle").getBBox().width;return u.selectAll(".path-rect").data(n).enter().append("rect").attr("fill","none").attr("width",document.querySelector(".path-middle").getBBox().width).attr("height",t.options.spacing)}function V(t,e,r){var n=t+"-path-text",o=u.selectAll(n).data(e).enter().append("text").attr("id",function(e,r){return t+"Text"+r}).attr("dy",3);return r?o.attr("class","path-"+t+"-mask-text"):o.attr("class","path-"+t+"-text"),o}function W(t,e){return e.append("textPath").attr("xlink:href",function(t,e){return"#d"+t.index}).attr("id","text").text(function(t,e){return{EMPLOY:t.properties.role||"任职",LEGAL:"法人",INVEST:"参股"}[t.type]}),e}function X(t,e){var r=V(t,e,!0);return W(0,r).style("stroke","white").style("stroke-width","0.15em"),r}function Z(t,e){var r=V(t,e);return W(0,r),r}function _(t,e){var r="path-"+t,n="."+(t+"Path");return u.selectAll(n).data(e).enter().append("path").attr("class",r).attr("id",function(t){return"d"+t.index})}function j(t,e,r){var n={x:0,y:0},o=r?90-t:t;return o=o*Math.PI/180,n.y=Math.sin(o)*e,n.x=Math.cos(o)*e,n}function H(t,e){t.style("stroke-opacity",function(t){if(t.source===e||t.target===e)return d3.select("#arrow"+t.index).attr("fill-opacity",1),1})}function R(t,e){t.style("stroke-opacity",function(t){if(t.source===e||t.target===e)return d3.select("#arrow"+t.index).attr("fill-opacity",.5),.3})}function U(t){R(w,t),R(P,t),R(M,t)}function J(t){ot(".path-middle",t).raise(),ot(".path-middle-mask-text",t).raise(),ot(".path-middle-text",t).raise(),ot(".path-top",t).raise(),ot(".path-top-mask-text",t).raise(),ot(".path-top-text",t).raise(),ot(".path-bottom",t).raise(),ot(".path-bottom-mask-text",t).raise(),ot(".path-bottom-text",t).raise()}function K(t){T.style("stroke-opacity",function(e){tt(t,e)&&d3.select($("#circle-"+e.index).parent("g")[0]).raise()})}D.domain([0,200]).range([1500,5e3]),setTimeout(function(){$("body").removeClass("loading").addClass("loaded"),q.attr("transform",function(t){return"translate("+t.x+", "+t.y+")"}),ft(w,"middle"),pt(I,"middle"),pt(C,"middle"),dt(E),ft(P,"top"),pt(L,"top"),pt(S,"top"),dt(B),ft(M,"bottom"),pt(F,"bottom"),pt(N,"bottom"),g.stop(),i.call(o)},D(r.length)),q.on("mouseover",function(t){x.clicked||x.drag||(H(w,t),H(P,t),H(M,t))}),q.on("mouseout",function(t){x.clicked||x.drag||U(t)}),q.on("click",function(t){var e=this;d3.selectAll("circle").attr("stroke-width",function(e){return e!==t?"1.5px":"5px"}),J(t),K(t),d3.select(this).raise(),x.clicked?t.selectedNode?lt(t,!0,this):(ut(t,!0,this),x.clicked=!1):(lt(t,!0,this),x.clicked=!0),$(document).click(function(r){"selected"!==r.target.getAttribute("class")&&(d3.selectAll("circle").attr("stroke-width","1.5px"),ut(t,!0,e),U(t),x.clicked=!1)})});var Q={};function tt(t,e){return Q[t.index+","+e.index]||Q[e.index+","+t.index]||t.index===e.index}function et(t,e,r,n,o){r.style("stroke-opacity",function(r,n){if(r.source===e||r.target===e)return 1;var i="end"===o?.5:t;return d3.select("#arrow"+r.index).attr("fill-opacity",i),t})}function rt(t,e,r,n){r.attr("fill-opacity",function(r){return r.source===e||r.target===e?1:t}),n.attr("opacity",function(r){return r.source===e||r.target===e?1:t})}function nt(t,e,r){r.style("fill-opacity",function(r){return tt(e,r)?1:t})}function ot(t,e){return d3.selectAll(t).filter(function(t){return t.source.index===e.index||t.target.index===e.index})}function it(t,e){e.setAttribute("class",t);var r=$(e).next("text")[0];r.setAttribute("class",t),$(r).find("tspan").each(function(e,r){r.setAttribute("class",t)})}function at(e,r){"易关通(广州)网络科技有限公司"===e.properties.name?(r.setAttribute("fill",t.options.color.main.node),r.setAttribute("stroke",t.options.color.main.stroke)):e.color===t.options.color.node.Company?(r.setAttribute("fill",t.options.color.node.Company),r.setAttribute("stroke",t.options.color.stroke.Company)):(r.setAttribute("fill",t.options.color.node.Person),r.setAttribute("stroke",t.options.color.stroke.Person))}function st(t){return $("#circle-"+t.index)}function ct(t,e){var r=st(t),n=r.next("#text");d3.select(r[0]).style("cursor",e),d3.select(n[0]).style("cursor",e)}function lt(e,r,n){T.style("stroke-opacity",function(r){tt(e,r)?(r.selectedNode=!0,at(r,this),it("selected",this),ct(r,"pointer")):(r.properties.name===t.options.dominant?(this.setAttribute("fill",t.options.color.main.opacityNode),this.setAttribute("stroke",t.options.color.main.opacityStroke)):(r.color===t.options.color.node.Company?this.setAttribute("fill",t.options.color.opacityNode.Company):this.setAttribute("fill",t.options.color.opacityNode.Person),r.stroke===t.options.color.stroke.Company?this.setAttribute("stroke",t.options.color.opacityStroke.Company):this.setAttribute("stroke",t.options.color.opacityStroke.Person)),r.selectedNode=!1,it("unSelected",this),ct(r,"default"))}),et(.1,e,w,0,"start"),et(.1,e,P,0,"start"),et(.1,e,M,0,"start"),rt(0,e,I,C),rt(0,e,L,S),rt(0,e,F,N),nt(0,e,z)}function ut(t,e,r){d3.select(r).attr("stroke-width","1.5px"),T.style("stroke-opacity",function(t){ct(t,"pointer"),at(t,this)}),nt(1,t,z),et(.3,t,w,0,"end"),et(.3,t,P,0,"end"),et(.3,t,M,0,"end"),rt(1,t,I,C),rt(1,t,L,S),rt(1,t,F,N)}function pt(t,e){t.attr("x",function(t){return function(e,r){var n=$("#d"+e.index)[0].getTotalLength(),o="middle"===t?2:4,i=0,a=e.properties.role;return a&&(i=a.length>6?26:0),n/o-e.source.r/2-i}}(e)).attr("transform",function(t){return function(e,r){var n=$("#d"+e.index)[0].getBBox(),o=n.x,i=n.y,a="rotate(0, "+(o+n.width/2)+", "+(i+n.height/2)+")",s="rotate(180, "+(o+n.width/2)+", "+(i+n.height/2)+")";return-90<e.x&&e.x<90?"middle"===t?a:s:"middle"===t?s:a}}(e))}function dt(t){t.attr("x",function(t){return t.source.x}).attr("y",function(t){return t.source.y}).attr("transform",function(t,e){return"rotate("+t.x+","+t.source.x+","+t.source.y+")"})}function ft(e,r,n){e.attr("d",function(e,n){return r===y?function(e,r){var n=j(e.x,t.options.spacing,!0).x,o=j(e.x,t.options.spacing,!0).y;return"M"+(e.target.x-n)+" "+(e.target.y+o)+"L"+(e.source.x-n)+" "+(e.source.y+o)+"Z"}(e):r===h?function(e,r){var n=j(e.x,t.options.spacing,!0).x,o=j(e.x,t.options.spacing,!0).y;return"M"+(e.target.x+n)+" "+(e.target.y-o)+"L"+(e.source.x+n)+" "+(e.source.y-o)+"Z"}(e):r===m?function(t,e){var r=t.source.x,n=t.source.y,o=t.target.x,i=t.target.y,a=Math.atan2(i-n,o-r);return a=180*a/Math.PI,t.x=a,p.map(function(e,r){t.index===e.originalIndex&&(e.x=t.x)}),d.map(function(e,r){t.index===e.originalIndex&&(e.x=t.x)}),"M"+r+" "+n+"L"+o+" "+i}(e):void 0}).attr("stroke",function(t){return t.color}).attr("stroke-width",1.5),r!==m?e.attr("marker-end",function(e,r){return d3.select("#arrow"+e.index).attr("fill",t.options.color.line[e.type]).attr("refX",26).attr("orient",e.x),"url(#arrow"+e.index+")"}):e.attr("marker-end",function(e,r){return d3.select("#arrow"+e.index).attr("fill",t.options.color.line[e.type]).attr("refX",28).attr("orient","auto"),"url(#arrow"+e.index+")"})}n.map(function(t){Q[t.source.index+","+t.target.index]=1})},t.prototype.isEmpty=function(t){if(null==t)return!0;if(t.length>0)return!1;if(0===t.length)return!0;for(var e in t)if(hasOwnProperty.call(t,e))return!1;return!1},t.prototype.unique=function(t){var e=new Map;return t.filter(function(t){return!e.has(t)&&e.set(t,1)})},t.prototype.unrepeat=function(t){Array;for(var e in t)"undefined"===e?delete t[e]:"object"==_typeof(t[e])&&this.unrepeat(t[e]);return t},t.prototype.replaceEmptyItem=function(t){for(var e=0,r=t.length;e<r;e++)t[e]&&""!=t[e]||(t.splice(e,1),r--,e--)},t.prototype.distinctIndex=function(t,e){for(var r in t)for(var n in e)t[r].index===e[n].index&&t.splice(r,1)},t.prototype.dataSet=function(t,e){var r=this,n=this;t.map(function(t){t.source=t.startNode,t.target=t.endNode}),t.some(function(t,o){var i=r.options.color.line;t.color=i[t.type],e.some(function(e,r){new{Company:function(){e.r=35,e.stroke=n.options.color.stroke.Company,e.color=n.options.color.node.Company},Person:function(){e.r=25,e.stroke=n.options.color.stroke.Person,e.color=n.options.color.node.Person}}[e.labels[0]],e.properties.name===n.options.dominant&&(e.color=n.options.color.main.node,e.stroke=n.options.color.main.stroke),t.source===e.id&&(t.source=e),t.target===e.id&&(t.target=e)})})},t.prototype.setIndex=function(t,e){t.map(function(t,r){e.map(function(e,r){t.originalIndex===r&&(t.originalIndex=e.originalIndex)})})},window.chart=t}();
JavaScript
1
https://gitee.com/dawangka_admin/relationshipMap.git
git@gitee.com:dawangka_admin/relationshipMap.git
dawangka_admin
relationshipMap
D3企业关系图谱
master

搜索帮助