-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_pay.html
145 lines (141 loc) · 7.85 KB
/
show_pay.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>薪酬管理知识图谱</title>
<script src="static/js/d3.min.js" type="text/javascript"></script>
<script src="static/js/jquery-1.10.2.js"></script>
<style>
*{margin:0;padding:0;}
.tooltip{position: absolute;width: 150;height: auto;
font-family:simsun;font-size: 15px;padding:3px;text-align:center;
border-style: solid; border-width: 1px;
background-color:#F5F5F5;border-radius: 5px;}
</style>
<script type="text/javascript">
var nodes=[], links=[];
window.onload=function(){MyVisual();}
function idIndex(a,id) {for (var i=0;i<a.length;i++) {if (a[i].id == id) return i;}return null;}
function MyD3(nodes,links) {
var width = document.body.scrollWidth, height = document.body.scrollHeight;
var svg = d3.select("body").append("svg").attr("width", width).attr("height", height);
var isNewCircle=new Array(1500);
var isNewLine=new Array(1500);
var zoom = d3.behavior.zoom().scaleExtent([0.4, 2]).on("zoom", zoomed);
var tooltip = d3.select("body").append("div").attr("class","tooltip").style("opacity",0.0);
var force = d3.layout.force().nodes(d3.values(nodes)).links(links).size([width, height])
.linkDistance(300).charge(-800).on("tick", tick).start();
svg.call(zoom).on("dblclick.zoom", null);
var edges_line = svg.append("g").selectAll(".edgepath").data(force.links()).enter().append("path")
.attr({'d': function(d) {return 'M '+d.source.x+' '+d.source.y+' L '+ d.target.x +' '+d.target.y},
'class':'edgepath','id':function(d,i) {return 'edgepath'+i;}})
.style("stroke",function(d){return "#9370DB";}).style("stroke-width",1);
var edges_text = svg.append("g").selectAll(".edgelabel").data(force.links()).enter().append("text")
.attr({ 'class':'edgelabel','id':function(d,i){return 'edgepath'+i;},'dx':80,'dy':0})
.style("font-size",12);
edges_text.append('textPath').attr('xlink:href',function(d,i) {return '#edgepath'+i})
.text(function(d){return d.type;});
var circle = svg.append("g").selectAll("circle").data(force.nodes()).enter().append("circle")
.style("fill",function(node){return "#00BFFF";}).style('stroke',function(node){return "#000080";})
.style("stroke-width",1.5).attr("r", function(node){return 20+set_r(node.id);})
.call(drag()).on("mouseover",function(d){
var str="";str+="name:"+d["name"]+"<br/>";
tooltip.html(str).style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY + 20) + "px")
.style("top", (d3.event.pageY + 20) + "px").style("opacity",1.0);})
.on("mouseout",function(d){tooltip.style("opacity",0.0);}) .on("dblclick.zoom", null)
.on("click",function(node){
for(var i=0;i<isNewCircle.length;i++){
isNewCircle[i]=0;isNewLine[i]=0;}
isNewCircle[node.id]=1;
circle.style('fill',function(d){if(d.id!=node.id&&isOne(d.id,node.id)&&isNewCircle[d.id]==0){
isNewCircle[d.id]=2;}return "#00BFFF";});
circle.style('fill',function(d){
if(isNewCircle[d.id]==2){circle.style('fill',function(d1){
if(isNewCircle[d1.id]==0&&isOne(d1.id,d.id)){isNewCircle[d1.id]=3;}return "#00BFFF";});
}return "#00BFFF";});
circle.style('fill',function(d){
if(isNewCircle[d.id]==3){circle.style('fill',function(d1)
{if(isNewCircle[d1.id]==0&&isOne(d1.id,d.id)){
isNewCircle[d1.id]=4;}return "#00BFFF";});}
return "#00BFFF";});
circle.style('fill',function(d){
if(isNewCircle[d.id]==4){circle.style('fill',function(d1){
if(isNewCircle[d1.id]==0&&isOne(d1.id,d.id)){isNewCircle[d1.id]=5;}
return "#00BFFF";});}return "#00BFFF";});
circle.style('fill',function(d){
if(isNewCircle[d.id]==2||isNewCircle[d.id]==1){return "#FFD700";}else{return "#00BFFF";}
}).transition().delay(200).style('fill',function(d){
if(isNewCircle[d.id]==3){ return "#FFD700";}else{return "#00BFFF";}
}).transition().delay(600).style('fill',function(d){
if(isNewCircle[d.id]==4){ return "#FFD700";}else{return "#00BFFF";}
}).transition().delay(1000).style('fill',function(d){
if(isNewCircle[d.id]==5){ return "#FFD700";}else{return "#00BFFF";}
}).transition().delay(1400).style('fill',"#00BFFF");});
circle.attr("r", function(node){
if(node.名称=="薪酬"||node.名称=="战略"||node.名称=="基本薪酬"||node.名称=="奖金"||node.名称=="福利"||node.名称=="薪酬制度"){
return 60;}else{return 20+set_r(node.id); }});
var text = svg.append("g").selectAll("text").data(force.nodes()).enter().append("text")
.attr("dy", ".35em").attr("text-anchor", "middle").style('fill',function(node){return "#696969";})
.attr('x',function(d){ name=d.name;name=name.toString();
if(name.length<=4){d3.select(this).append('tspan').attr('x',0).attr('y',2).text(function(){return name;});
}else{ var top=name.substring(0,4);
var bot=name.substring(4,name.length);d3.select(this).text(function(){return '';});
d3.select(this).append('tspan').attr('x',0).attr('y',-7).text(function(){return top;});
d3.select(this).append('tspan').attr('x',0).attr('y',10).text(function(){return bot;});}}).
style("font-size",13).on("mouseover",function(d){var str="";str+="name:"+d["name"]+"<br/>";
tooltip.html(str).style("left", (d3.event.pageX) + "px").
style("top", (d3.event.pageY + 20) + "px").
style("top", (d3.event.pageY + 20) + "px").style("opacity",1.0);})
.on("mouseout",function(d){tooltip.style("opacity",0.0);}).call(drag())
.on("dblclick.zoom", null);
function zoomed(){
svg.selectAll("g").attr("transform","translate(" +d3.event.translate + ")scale(" +d3.event.scale + ")"); }
function drag(){//拖拽函数
return force.drag().on("dragstart",function(d){d3.event.sourceEvent.stopPropagation(); }); }
function tick(){
circle.attr("transform", transform1);text.attr("transform", transform2);
edges_line.attr('d', function(d) { var path='M '+d.source.x+' '+d.source.y+' L '+
d.target.x +' '+d.target.y;return path;});
edges_text.attr('transform',function(d,i){if (d.target.x<d.source.x)
{bbox = this.getBBox();rx = bbox.x+bbox.width/2;ry = bbox.y+bbox.height/2;
return 'rotate(180 '+rx+' '+ry+')';}else {return 'rotate(0)';}}); }
function set_r(id){
var r=0;for(var i=0;i<links.length;i++){
if(id == links[i].source.id || id == links[i].target.id){r++; } } return r;}
function isOne(num1,num2){
for(var i=0;i<links.length;i++){
if((num1==links[i].source.id&&num2==links[i].target.id)
||(num2==links[i].source.id&&num1==links[i].target.id)){
return true;} }return false;}
}
function transform1(d) {return "translate(" + d.x + "," + d.y + ")";}
function transform2(d) {return "translate(" + (d.x) + "," + d.y + ")";}
function isObjectValueEqual(a, b) {
var aProps = Object.getOwnPropertyNames(a); var bProps = Object.getOwnPropertyNames(b);
if (aProps.length != bProps.length) { return false; }
for (var i = 0; i < aProps.length; i++) { var propName = aProps[i];
if (a[propName] !== b[propName]) {return false;}}
return true;}
function isInArray(arr,value){
for(var i = 0; i < arr.length; i++){
if(isObjectValueEqual(value,arr[i])){
return true;}}return false;}
function MyVisual(){
$(document).ready(function() {$.ajax({
url : "http://localhost:8080/Salarymanage/Show_pay",
dataType : "json", type : "post",async : true,
success : function(str) {
var count=0;str.results[0].data.forEach(function (row) {
row.graph.nodes.forEach(function (n) {
var obj=new Object();obj["id"]=n.id;obj["label"]=n.labels[0];
for (key in n.properties){obj[key]=n.properties[key];}
if(!isInArray(nodes,obj)){nodes.push(obj);}});
links = links.concat( row.graph.relationships.map(function(r) {
return {source:idIndex(nodes,r.startNode),target:idIndex(nodes,r.endNode),type:r.type}; }));});
MyD3(nodes,links); }})})}
</script>
</head>
<body>
</body>
</html>