-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfcompare.js
153 lines (133 loc) · 6.68 KB
/
selfcompare.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
if (false){
var bookStructure = [];
var weeks = 3;
//for (var week = 1; week < 4; week++) {
var selfUrl = selfmodels_url+"?usr=" + usr + "&grp=" + grp + "&weeks=" + weeks;
//alert(selfUrl);
$.ajax({
url:selfUrl,
dataType: "json",
async:false,
success:function (result) {
if (result.models.length > 0) {
var progressDiagram = [];
var week = 0;
$.each(result.models, function (i_model, model) {
var smallSunburst = [];
week++;
$.each(model.progress, function (i_progress, progress) {
var theColor = "";
//alert(progress.uprogress);
if (progress.uprogress >= 0.0 && progress.uprogress < 0.1) theColor = colors[0];
if (progress.uprogress >= 0.1 && progress.uprogress < 0.2) theColor = colors[1];
if (progress.uprogress >= 0.2 && progress.uprogress < 0.3) theColor = colors[2];
if (progress.uprogress >= 0.3 && progress.uprogress < 0.4) theColor = colors[3];
if (progress.uprogress >= 0.4 && progress.uprogress < 0.5) theColor = colors[4];
if (progress.uprogress >= 0.5 && progress.uprogress < 0.6) theColor = colors[5];
if (progress.uprogress >= 0.6 && progress.uprogress < 0.7) theColor = colors[6];
if (progress.uprogress >= 0.7 && progress.uprogress < 0.8) theColor = colors[7];
if (progress.uprogress >= 0.8 && progress.uprogress < 0.9) theColor = colors[8];
if (progress.uprogress >= 0.9 && progress.uprogress <= 1) theColor = colors[9];
progressDiagram.push({
diagramColor:theColor
});
smallSunburst.push(theColor);
//alert(theColor);
});
//alert(json_file);
$.ajax({
dataType: "json",
url: json_file,
async:false,
success:function (objcourse) {
var sizes = [];
$.each(objcourse.children, function (i_lecture, lecture) { // lecture
var countLecture = 0;
if (lecture.children.length > 0) {
$.each(lecture.children, function (i_chapter, chapter) { // chapter
if (chapter.children.length > 0) {
$.each(chapter.children, function (i_reading, reading) { // reading
if (reading.children.length > 0) {
countLecture = countLecture + reading.children.length;
} else {
countLecture++;
}
})
} else {
countLecture++;
}
});
} else {
countLecture++;
}
sizes.push(countLecture);
// alert(countLecture);
});
structure = [];
structure["name"] = week + " week ago";
for(var i=0;i<sizes.length;i++){
chapterid = "chapter "+(i+1);
structure[chapterid] = sizes[i];
//alert(sizes[i]);
}
bookStructure.push(structure);
}
});
var width = 100,
height = 150,
radius = Math.min(width, height) / 2.5,
color = d3.scale.category20c();
var radius = 70,
padding = 0;
var color = d3.scale.ordinal()
.range(smallSunburst);
var arc = d3.svg.arc()
.outerRadius(63)// (radius)
.innerRadius(10);//(radius - 30);
var pie = d3.layout.pie()
.sort(null)
.value(function (d) {
return d.population;
});
color.domain(d3.keys(bookStructure[0]).filter(function (key) {
return key !== "name";
}
));
bookStructure.forEach(function (d) {
d.ages = color.domain().map(function (name) {
return {name:name, population:+d[name]};
});
})
var svg = d3.select("#self-comp").selectAll(".pie")
.data(bookStructure)
.enter().append("svg")
.attr("class", "pie")
.attr("width", radius * 2)
.attr("height", radius * 2.5)
.append("g")
.attr("transform", "translate(" + radius + "," + radius + ")");
svg.selectAll(".arc")
.data(function (d) {
return pie(d.ages);
})
.enter().append("path")
.attr("class", function (d) {
return ('arc' + (d.data.name.replace(/ /g, "-")) );
})
.attr("d", arc)
.style("fill", function (d) {
return color(d.data.name);
});
svg.append("text")
.attr("dy", ".35em")
.style("text-anchor", "middle")
.attr("y", "75px")
.text(function (d) {
return d.name;
});
});
}
}
});
//}
}