-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
255 lines (236 loc) · 9.58 KB
/
script.js
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
document.addEventListener("DOMContentLoaded", main);
function main(){
$("#btn-verify").click(verify);
$("#btn-show").click(show_another);
$(".interact-sent").click(example_click);
show_another();
draw_medical_topic();
draw_PICO();
}
var example_data = [
[
["e", "Pain is usually felt over the inflamed site, but referred pain is possible."], ["ne", "The pain is usually felt in the chest wall right over the site of the inflammation or infection that caused the effusion."]],
[
["e", "After an incubation period of about 1 to 12 weeks, a painless, red skin nodule slowly enlarges, becoming a raised, beefy red, moist, smooth, foul-smelling lesion."],
["ne", "Symptoms of granuloma inguinale usually begin 1 to 12 weeks after infection. The first symptom is a painless, red nodule that slowly enlarges into a round, raised, foul-smelling lump."]
],
[
["e", "The lesion slowly enlarges, often ulcerates, and may spread to other skin areas. Lesions heal slowly, with scarring."],
["ne", "The sores slowly enlarge and spread to nearby tissue, causing further damage. Sores heal slowly and may result in permanent scar."]
],
[
["e", "The patients usually feel painful when affected tendons are actively moved or their natural motions are resisted."],
["ne", "People always feel painful when the inflamed tendons are moved or pressed."],
],
[
["e", "Cardiac complications include pericarditis (most commonly),myocarditis,endocardium and coronary artery vasculitis."],
["ne", "People with lupus may have chest pain due to inflammation of the sac around the heart (pericarditis). More serious but rare effects on the heart are inflammation of the walls of the coronary arteries (coronary artery vasculitis), which can lead to angina; the inflammation of the surfaces of the heart valve to thicken or develop lesions (bacterial endocarditis); and inflammation of the heart muscle (myocarditis), which can lead to heart failure."],
]
];
var example_idx = -1;
function verify(){
var sel_st = $(".interact-sent[data-status='select']");
if(sel_st.length==1){
console.log('verify');
var x = sel_st.attr("data-label") == "e"? "an <b>expert</b>": "a <b>layman</b>";
$(".interact-msg span").html(x);
status_show();
}
}
function show_another(){
example_idx = example_idx+1<example_data.length?example_idx+1:0;
$(".interact-sent").attr("data-status", "normal");
$("#int-sent-1 p").text(example_data[example_idx][0][1]);
$("#int-sent-1").attr("data-label", example_data[example_idx][0][0]);
$("#int-sent-2 p").text(example_data[example_idx][1][1]);
$("#int-sent-2").attr("data-label", example_data[example_idx][1][0]);
status_hidden();
}
function example_click(){
if($(this).attr("data-status")=="normal"){
$(this).attr("data-status", "select");
$(this).siblings().attr("data-status", "normal");
verify();
}
else if($(this).attr("data-status")=="select"){
$(this).attr("data-status", "normal");
status_hidden();
}
}
function status_show(){
console.log("show");
console.log($(".interact-msg").css("transition", "0.2s ease-in"));
$(".interact-msg").css("visibility", "visible").css("opacity", 1);
}
function status_hidden(){
$(".interact-msg").css("transition", "0s");
$(".interact-msg").css("visibility", "hidden").css("opacity", 0);
}
function draw_medical_topic(){
var dataset = [96, 76, 70, 59, 51, 46, 38, 33, 31, 26, 26, 23, 23, 20, 57];
var label = [
"Infectious Diseases",
"Pediatrics",
"Gastrointestinal Disorders",
"Musculoskeletal Disorders",
"Neurologic Disorders",
"Gynecology and Obstetrics",
"Pulmonary Disorders",
"Ear, nose, and Throat Disorders",
"Eye Disorders",
"Hepatic and Biliary Disorders",
"Injuries Poisoning",
"Psychiatric Disorders",
"Dermatologic Disorders",
"Genitourinary Disorders",
"Other"];
//var color = d3.scaleOrdinal(d3.schemeCategory10);
var color = d3.quantize(t => d3.interpolateSpectral(t * 0.8 + 0.1), dataset.length).reverse();
var pie = d3.pie().sort(null);
var pie_data = pie(dataset);
var outerRadius = 120;
var innerRadius = 60;
var arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius);
var width = 600;
var height = 400;
var svg = d3.select("#topic_dis")
.attr("width", width)
.attr("height", height);
var arcs = svg.selectAll("g")
.data(pie_data)
.enter()
.append("g")
.attr("transform", `translate(180,${height/2})`);
arcs.append("path")
.attr("fill",function(d,i){
return color[i];
})
.attr("d",function(d){
return arc(d); //调用弧生成器,得到路径值
})
.on("mouseover", function(d, i){
d3.select(this).transition().duration(400).ease(d3.easeQuad)
.attr("transform", function(d){
var xy = arc.centroid(d).map(x=>x/5);
return `translate(${xy})`;
})
})
.on("mouseout", function(d,i){
d3.select(this).transition().duration(400)
.attr("transform", x=>`translate(0,0)`);
});
arcs.append("text")
.attr("transform",function(d, i){
if(i==2) {
var xy = arc.centroid(d).map(x=>x*1.65);
}
else if(i>=1 && i<=5 || i>=6 && i<=13){
var xy = arc.centroid(d).map(x=>x*1.6);
}
else {
var xy = arc.centroid(d).map(x=>x*1.5);
}
return `translate(${xy})`;
})
.attr("text-anchor","middle")
.style("font-family", "cambria")
.text(function(d, i){
var percent = d.data / d3.sum(dataset) * 100;
return `${percent.toFixed(1)}%`;
});
//绘制图例区域
var legendArea = svg.append("g")
.attr("transform", `translate(380,20)`);
//绑定数据,设置每个图例的位置
var legend = legendArea.selectAll("g")
.data(label)
.enter()
.append("g")
.attr("transform", (d,i)=>`translate(0, ${i*25})`);
//添加图例的矩形色块
legend.append("rect")
.attr("width", 40)
.attr("height", 18)
.style("fill", function (d, i) {
return color[i]
});
//添加图例文字
legend.append("text")
.attr("x", 45)
.attr("y", 9)
.attr("dy", ".35em")
.text(function (d, i) {
return d;
})
.style("font-family", "cambria")
.style("font-size", 14);
}
function draw_PICO(){
var dataset = [416, 107, 76, 53, 20, 3];
var label = [
'Symptoms',
'Diagnosis',
'Treatment',
'Etiology',
'Evaluation',
'Prognosis'
];
//var color = d3.scaleOrdinal(d3.schemeCategory10);
var color = d3.quantize(t => d3.interpolateSpectral(t * 0.8 + 0.1), dataset.length).reverse();
var pie = d3.pie().sort(null);
var pie_data = pie(dataset);
var outerRadius = 120;
var innerRadius = 60;
var arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius);
var width = 500;
var height = 350;
var svg = d3.select("#pico_dis")
.attr("width", width)
.attr("height", height);
var arcs = svg.selectAll("g")
.data(pie_data)
.enter()
.append("g")
.attr("transform", `translate(240,220)`);
arcs.append("path")
.attr("fill",function(d,i){
return color[i];
})
.attr("d",function(d){
return arc(d); //调用弧生成器,得到路径值
})
.on("mouseover", function(d, i){
d3.select(this).transition().duration(400).ease(d3.easeQuad)
.attr("transform", function(d){
var xy = arc.centroid(d).map(x=>x/5);
return `translate(${xy})`;
})
})
.on("mouseout", function(d,i){
d3.select(this).transition().duration(400)
.attr("transform", x=>`translate(0,0)`);
});
var text_times = [2.2, 2, 2, 2.05, 1.6, 2.1];
var line_times = [1.9, 1.6, 1.8, 2, 1.6, 2];
arcs.append("text")
.attr("transform",function(d, i){
var xy = arc.centroid(d).map(x=>x * text_times[i]);
return `translate(${xy})`;
})
.attr("text-anchor","middle")
.style("font-family", "cambria")
.text(function(d, i){
var percent = d.data / d3.sum(dataset) * 100;
return `${label[i]} ${percent.toFixed(1)}%`;
});
arcs.append('line')
.attr('stroke', 'black')
.attr('x1', function(d){ return arc.centroid(d)[0] * 4/3; })
.attr('y1', function(d){ return arc.centroid(d)[1] * 4/3; })
.attr('x2', function(d, i){
return arc.centroid(d)[0] * line_times[i];
})
.attr('y2', function(d, i){
return arc.centroid(d)[1] * line_times[i];
});
}