-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.html
204 lines (193 loc) · 6.25 KB
/
template.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Brain viewer</title>
<link rel="stylesheet" type="text/css" href="./style.css"/>
</head>
<body>
<script>
// return zero padded integer
function zeropad(n) {
return ('000' + n).substr(-3)
}
</script>
<div id="images">
<div id="preload"></div>
<!-- below this slices will be inserted -->
<div id="slices">$slices</div>
<!-- below this SVGs will be inserted -->
<div id="svgs">$SVGs</div>
</div>
<div id="app">
<!-- layer selector -->
<div id="layer-control">
<input id="layer-slider" name="layer-slider" type="range" min="0" max="137" v-model.number="goto_layer" v-on:input="refreshLayer"/>
<label for="layer-slider">current layer: <strong>{{zeropad(current_layer+1)}}</strong></label>
<div>current region: <strong>{{region}}</strong></div>
</div>
<div id="info">
<label for="image">select background images</label>
<input type="file" id="image" name="image" accept="image/png, image/jpeg" multiple @change="addedFile">
</div>
<!-- region selector -->
<div id="toggle-region">
<input id="region-input" type="text" v-model="region_on_str" v-on:keyup.enter="parseToggleRegion"/>
<div id="checkboxes">
<div class="checkbox" v-for="(region, index) in Object.entries(region_names)">
<input type="checkbox" :value="region[0]" :name="region[0]" v-model="region_on"/>
<label :for="region[0]"><span v-on:click="gotomiddle(index+1)" class="region-number">{{zeropad(index+1)}}</span> {{region[1]}}</label><br>
</div>
</div>
</div>
</div>
<script>
// the app
var app = new Vue({
el: '#app',
data: {
region_names: {}, // dictionary mapping tag to region name
region_center: {}, // dictionary mapping region number to region center layer
current_layer: 99, // current layer (0 to 137)
goto_layer: 99, // next current layer
region: "--- hover a region ---", // current region name
region_on: [], // list of layers turned on ["x-000", "x-050"..;]
region_on_str: "all", // list of layers turned on (string version)
sheet: undefined, // stylesheet for layers
},
methods: {
// zeropad binding
zeropad: zeropad,
// get region names at the program start
loadRegion: function () {
self = this;
fetch('region-names.json')
.then(function (response) {
return response.json();
})
.then(function (data) {
self.region_names = data
})
.catch(function (err) {
console.log(err);
});
fetch('region-center.json')
.then(function (response) {
return response.json();
})
.then(function (data) {
self.region_center = data.region_center
})
.catch(function (err) {
console.log(err);
});
},
// return tag corresponding to svg layer z (0 to 137)
ztag: function (z) {
return "z-" + zeropad(z);
},
// return tag corresponding to background image layer z (0 to 137)
imgtag: function (z) {
return "img-" + zeropad(z);
},
// return tag corresponding to region x (1 to 294)
xtag: function (x) {
return "x-" + zeropad(x);
},
// toogle visibility of layer z
toggleLayerVisibility: function (z) {
img = document.getElementById(this.imgtag(z));
svg = document.getElementById(this.ztag(z));
img.classList.toggle("visible");
svg.classList.toggle("visible");
},
// switch current view to layer z
seeLayer: function (gotolayer) {
this.toggleLayerVisibility(this.current_layer); // turn of current layer visibility
this.toggleLayerVisibility(gotolayer); // turn on goto layer visibility
this.current_layer = gotolayer; // update current layer with goto layer
},
// callback function for slider
refreshLayer: function () {
this.seeLayer(this.goto_layer);
},
// callback function when clicked on a region
selectRegion: function (xtag) {
this.region = xtag + " " + this.region_names[xtag];
},
// callback function when changed region list
parseToggleRegion: function () {
switch(this.region_on_str) {
case "none": // no region selected
this.region_on = []
break;
case "all": // all regions selected
this.region_on = []
for(i=1;i<=294;i++) {
this.region_on.push("x-" + zeropad(i))
}
break;
case "vestibular":
this.region_on = ["x-015", "x-078", "x-097", "x-098", "x-106", "x-108", "x-109", "x-131", "x-175", "x-201", "x-235", "x-238"]
break;
default:
this.region_on = [] // empty region list
list_str = this.region_on_str.split(" ") // split space separated numbers
list_num = list_str.map(x=>this.region_on.push(this.xtag(Number(x)))) // parse as numbers and put in region_on
break;
}
},
// initialize stylesheet
initStyle: function () {
var style = document.createElement("style")
document.head.appendChild(style)
this.sheet = style.sheet
},
// refresh regions to display
refreshRegionVisibility: function () {
// empty stylesheet
l = this.sheet.rules.length
for(i=0;i<l;i++) {
this.sheet.deleteRule(0)
}
// fill stylesheet
this.region_on.forEach(xtag => {
this.sheet.insertRule("." + xtag + "{display:block}")
});
},
// go to middle of region number n
gotomiddle: function(n) {
this.goto_layer = this.region_center[n]
this.refreshLayer()
},
// when new background images are loaded
addedFile(event) {
files = event.target.files
for(i=0;i<138;i++) {
f = files[i]
img = document.getElementById(this.imgtag(i));
img.src = URL.createObjectURL(f)
}
},
},
watch: {
// when region_on changes, update the stylesheet (TODO optimize this)
region_on: function () {
this.refreshRegionVisibility()
},
},
})
app.loadRegion(); // get region names
app.toggleLayerVisibility(app.current_layer); // initial layer
app.parseToggleRegion(); // set initial region list
app.initStyle(); // initialize stylesheet
// callback function for svg element telling it's tag
function clickedOn(xtag) {
console.log("clicked on " + xtag);
app.selectRegion(xtag)
};
</script>
</body>
</html>