-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkAttributes.html
136 lines (107 loc) · 3.41 KB
/
NetworkAttributes.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
<html>
<head>
<script src="./jquery.min.js"></script>
<script src="./scripts.js"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet">
<style type="text/css">
body{font-family: 'open sans condensed', sans-serif;font-size:12px}
.axis path,.axis line {fill: none;stroke:#b6b6b6;shape-rendering: crispEdges;}
/*.tick line{fill:none;stroke:none;}*/
.tick text{fill:#999;}
g.journal.active{cursor:pointer;}
text.label{font-size:16px;font-weight:bold;cursor:pointer}
text.value{font-size:12px;font-weight:bold}
</style>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
function truncate(str, maxLength, suffix) {
if(str.length > maxLength) {
str = str.substring(0, maxLength + 1);
str = str.substring(0, Math.min(str.length, str.lastIndexOf(" ")));
str = str + suffix;
}
return str;
}
var margin = {top: 20, right: 200, bottom: 0, left: 20},
width = 950,
height = 900;
var start_year = 1984,
end_year = 2011;
var c = d3.scale.category20c();
//Create the Scale we will use for the Axis
var x = d3.scale.linear()
.domain([new Date(1984), new Date(2011)])
.range([0, width])
//Create the Axis
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.ticks(27) //this determines how many ticks to display in the x axis
.tickFormat(d3.format("0000"));
//Create the SVG Viewport selection
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style("margin-left", margin.left + "px")
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.json("attData.json", function(data) {
x.domain([start_year, end_year]);
var xScale = d3.scale.linear()
.domain([start_year, end_year])
.range([0, width])
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + 0 + ")")
.call(xAxis);
for (var j = 0; j < data.length; j++) {
var g = svg.append("g")
.attr("class","journal");
var circles = g.selectAll("circle")
.data(data[j]['articles'])
.enter()
.append("circle")
var text = g.selectAll("text")
.data(data[j]['articles'])
.enter()
.append("text")
var rScale = d3.scale.linear()
.domain([0, d3.max(data[j]['articles'], function(d) { return d[1]; })])
.range([2, 10]);
circles
.attr("cx", function(d, i) { return xScale(d[0]); })
.attr("cy", j*35+25)
.attr("r", function(d) { return rScale(d[1])*1.5; })
.style("fill", function(d) { return c(j); });
text
.attr("y", j*35+25)
.attr("x",function(d, i) { return xScale(d[0])-5; })
.attr("class","value")
.text(function(d){ return d[1]; })
.style("fill", function(d) { return c(j); })
.style("display","none");
g.append("text")
.attr("y", j*35+25)
.attr("x",width+50)
.attr("class","label")
.text(truncate(data[j]['name'],60,"..."))
.style("fill", function(d) { return c(j); })
.on("mouseover", mouseover)
.on("mouseout", mouseout);
};
function mouseover(p) {
var g = d3.select(this).node().parentNode;
d3.select(g).selectAll("circle").style("display","none");
d3.select(g).selectAll("text.value").style("display","block");
}
function mouseout(p) {
var g = d3.select(this).node().parentNode;
d3.select(g).selectAll("circle").style("display","block");
d3.select(g).selectAll("text.value").style("display","none");
}
});
</script>
</body>
</html>