forked from coldclimate/northeastjobnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold.html
204 lines (170 loc) · 4.4 KB
/
old.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<p>intro copy</p>
<div id="hook"></div>
<style>
.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
.link.resolved {
stroke-dasharray: 0,2 1;
}
circle {
fill: #ccc;
stroke: #333;
stroke-width: 1.5px;
}
text {
font: 10px sans-serif;
pointer-events: none;
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var arrData =
[
{
'companies': [
'Sage',
'CANDDi',
'Memory Merge',
'Wishli.st',
'bGroup',
'Accenture'
],
'colour': 'blue',
'name': 'Oli Wood'
},
{
'companies': [
'CustomerSure',
'bDaily',
'bGroup'
],
'colour': 'green',
'name': 'Chris Stainthorpe'
},
{
'companies': [
'Freelance',
'Memory Merge',
'Creative Nucleus',
'Reflections Interactive'
],
'colour': 'red',
'name': 'James Rutherford'
},
];
var links = [];
var arrCharacters=[];
arrData.forEach(function(set){
var intLength = set.companies.length;
arrCharacters.push(set.name);
for (var i = 0; i < intLength-1; i++) {
objLink = {
source : set.companies[i],
target : set.companies[i+1],
type : set.name.toLowerCase().replace(/\W/g, ''),
colour : set.colour
};
links.push(objLink);
}
});
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
});
var width = window.innerWidth,
height = window.innerHeight;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(60)
.charge(-0.001*(window.innerHeight*window.innerWidth))
.on("tick", tick)
.start();
var svg = d3.select("#hook").append("svg")
.attr("width", width)
.attr("height", height);
console.log(svg);
// Per-type markers, as they don't inherit styles.
svg.append("defs").selectAll("marker")
.data(arrCharacters)
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-5L10,0L0,5");
var path = svg.append("g").selectAll("path")
.data(force.links())
.enter().append("path")
.attr("style", function(d) { console.log(d);return "fill: " + d.colour +";"; })
.attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
var circle = svg.append("g").selectAll("circle")
.data(force.nodes())
.enter().append("circle")
.attr("r", 6)
.call(force.drag);
var text = svg.append("g").selectAll("text")
.data(force.nodes())
.enter().append("text")
.attr("x", 8)
.attr("y", ".31em")
.text(function(d) { return d.name; });
// Use elliptical arc path segments to doubly-encode directionality.
function tick() {
path.attr("d", linkArc);
circle.attr("transform", transform);
text.attr("transform", transform);
}
function linkArc(d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
}
function transform(d) {
return "translate(" + d.x + "," + d.y + ")";
}
var legend = svg.append("g")
.attr("class", "legend")
.attr("x", window.innerWidth - 65)
.attr("y", 25)
.attr("height", 100)
.attr("width", 100);
legend.selectAll('g').data(arrData)
.enter()
.append('g')
.each(function(d, i) {
var g = d3.select(this);
g.append("rect")
.attr("x", 10)
.attr("y", i*25)
.attr("width", 10)
.attr("height", 10)
.style("fill", arrData[i].colour);
g.append("text")
.attr("x", 30)
.attr("y", i * 25 + 8)
.attr("height",30)
.attr("width",100)
.style("fill", arrData[i].colour)
.text(arrData[i].name);
});
</script>
</body>
</html>