-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
209 lines (176 loc) · 7.26 KB
/
index.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
205
206
207
208
209
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.chord path {
fill-opacity: .67;
stroke: #000;
stroke-width: .5px;
}
#tooltip{
visibility: hidden;
position: absolute;
background-color: dodgerblue;
border-radius: 4px;
padding: 5px;
z-index: 10;
color:white;
font-size:14px;
}
</style>
<body>
<div id=tooltip></div>
<div style="color:#0000FF">
<a href="raster.html">
A raster plot of spikes output from a current injection stimulated network.
</a>
<a href="spike distance.html">
A plot of spikes distance.
</a>
</div>
<div style="color:#0000FF">
<a href="force.html">
A force directed layout of the network topology.
</a>
</div>
<div style="color:#0000FF">
<!--Offline -->
<script type="text/javascript" src="d3.v3.min.js"></script>
<!--
Online
<script src="//d3js.org/d3.v3.min.js"></script>
-->
<script>
var hostname = window.location.hostname;
var isDev = (hostname == 'localhost') || (hostname == '127.0.0.1');
var tooltip = d3.select("#tooltip");//The Tooltip plugin is small pop-up box that appears when the user moves the mouse pointer over an element.
d3.json('js/global_whole_network.json', function(error, data){
if (error) throw error;
/*
Written by Dulini Mendis
With comments by Russell Jarvis
*/
var matrix=data[2]; /* adjacency matrix 37 x 37 of all excitatory and inhibitory neurons, although the size of the adjacency
matrix is liable to change with different simulations
*/
var neurons = Object.keys(data[7]).map(function(key){ return data[7][key] }); //object with filenames and whether its excitatory or inhibitory
//Get excitatory and inhibitory neurons indices separately
var neuronType = neurons.map(function(a) {return a[1];});
var neuronInds = neuronType.map(function(a,i){ if(a==0 && i<matrix.length){ return i;} else return null; });//Get the inhibitory neuron types
var inNeuronInds = neuronInds.filter(function(a){return a!=null;}); //remove nulls from the array.
var neuronInds = neuronType.map(function(a,i){ if(a==1 && i<matrix.length){ return i;} else return null; });//Get the excitatory neuron types
var exNeuronInds = neuronInds.filter(function(a){return a!=null;}); //remove nulls from the array.
var sortNeuronInds = exNeuronInds.concat(inNeuronInds); //Extend the excitatory neuron list by concatonating it with inhibitory neuron list. The result is a sorted list called sortNeuronInds
//Sort adjacency matrix
var temp = [];
var vSortRow = [];
var sortMat = [];
//In JS a matrix is emulated by an array of arrays, just like in Java level languages.
for(i=0;i<sortNeuronInds.length;i++){//for every column
temp = matrix[sortNeuronInds[i]];//not a matrix element value at i.
//because matrices are consist of arrays of arrays, indexing into the parent-array simply retrieves a child array.
vSortRow = [];//initialise a new row array.
for(j=0;j<sortNeuronInds.length;j++){//for every row.
vSortRow.push(temp[sortNeuronInds[j]]);//fill up the row array
}
vSortRow.map(function(a){console.log(a);})
sortMat.push(vSortRow.map(function(a){return a;}));
//fill up the parent array (matrix) by appending to it re-sorted row arrays.
}
matrix=sortMat;/*
A substitution of variables for the sake of code convention
and readability.
*/
var chord = d3.layout.chord()
.padding(.05)
.sortSubgroups(d3.descending)
.matrix(matrix);
var width = 800,
height = 600,
innerRadius = Math.min(width, height) * .25,
outerRadius = innerRadius * 1.1;
var fill = d3.scale.ordinal()
.domain(d3.range(4))
.range(["#55ff55","#3366ff","#000000"]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
svg.append("g").selectAll("path")
.data(chord.groups)
.enter().append("path")
.style("fill", function(d,i) { if(i<exNeuronInds.length) return fill(0); else return fill(1) })
.style("stroke", function(d,i) { if(i<exNeuronInds.length) return fill(0); else return fill(1) })
.attr("d", d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius))
.on("mouseover", fade(.05))
.on("mousemove", function(){
tooltip.style("top", (d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px");
})
.on("mouseout", fade(1));
var ticks = svg.append("g").selectAll("g")
.data(chord.groups)
.enter().append("g").selectAll("g")
.data(groupTicks)
.enter().append("g")
.attr("transform", function(d) {
return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")"
+ "translate(" + outerRadius + ",0)";
});
ticks.append("line")
.attr("x1", 1)
.attr("y1", 0)
.attr("x2", 5)
.attr("y2", 0)
.style("stroke", "#000");
ticks.append("text")
.attr("x", 8)
.attr("dy", ".35em")
.attr("transform", function(d) { return d.angle > Math.PI ? "rotate(180)translate(-16)" : null; })
.style("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; })
.text(function(d) { return d.label; });
svg.append("g")
.attr("class", "chord")
.selectAll("path")
.data(chord.chords)
.enter().append("path")
.attr("d", d3.svg.chord().radius(innerRadius))
.style("fill", function(d) {
if(d.target.index<exNeuronInds.length && d.source.index<exNeuronInds.length) return fill(0);
else if(d.target.index>=exNeuronInds.length && d.source.index>=exNeuronInds.length) return fill(1);
else return fill(2);
})
.style("stroke", function(d) {
if(d.target.index<exNeuronInds.length && d.source.index<exNeuronInds.length) return fill(0);
else if(d.target.index>=exNeuronInds.length && d.source.index>=exNeuronInds.length) return fill(1);
else return fill(2);
})
.style("opacity", 1);
// Returns an array of tick angles and labels, given a group.
function groupTicks(d) {
var k = (d.endAngle - d.startAngle) / d.value;
return d3.range(0, d.value, 1000).map(function(v, i) {
return {
angle: v * k + d.startAngle + (d.endAngle-d.startAngle)/2,
label: neurons[sortNeuronInds[d.index]][0]
};
});
}
// Returns an event handler for fading a given chord group.
function fade(opacity) {
return function(g, i) {
svg.selectAll(".chord path")
.filter(function(d) { return d.source.index != i && d.target.index != i; })
.transition()
.style("opacity", opacity);
if(tooltip.style("visibility")=="hidden")
tooltip.style("visibility", "visible").text(neurons[sortNeuronInds[i]]);
else
tooltip.style("visibility", "hidden");
};
}
});
</script>
</div>