-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphView.js
769 lines (746 loc) · 24.8 KB
/
GraphView.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
function GraphView(options) {
this.options = options;
this.network = undefined;
}
GraphView.prototype.setDataSource = function (graphDataSource) {
this.graphDataSource = graphDataSource;
};
GraphView.prototype.init = function () {
var self = this;
// bind the event
document.getElementById("setRelationYisheng").onclick = function () {
self.setRelation("yisheng");
};
document.getElementById("setRelationInchai").onclick = function () {
self.setRelation("inchai");
};
document.getElementById("isCgLevel").onchange = function () {
self.handleDisplayLevelChange();
};
document.getElementById("displayJunyiResult").onchange = function () {
self.handleDisplayJunyiResultChange();
};
document.getElementById("displayPath").onchange = function () {
self.handleDisplayPathChange();
};
var dataDropdownElements = document.getElementsByClassName("dataDropdown");
Array.prototype.forEach.call(dataDropdownElements, function (element) {
element.onclick = function () {
self.handleChangeDataButton(this.id);
};
});
// init the graph
var callbackView = function (nodeList, edgeList) {
$("#dropdownNetworkButton").removeAttr("disabled");
$("#editModeBtn").removeAttr("disabled");
self.updateStudentDropdown();
self.updateThemeDropdown();
// create a network
var container = document.getElementById("cg_network");
s_nodes = new vis.DataSet(nodeList);
s_edges = new vis.DataSet(edgeList);
var data = {
nodes: s_nodes,
edges: s_edges,
};
// initialize network
self.network = new vis.Network(container, data, this.options);
self.network.on("initRedraw", function () {
var startPointViewList = self.getStartPoint(
Object.values(self.network.body.data.nodes._data),
Object.values(self.network.body.data.edges._data)
);
self.updateStarPointView(startPointViewList);
});
// handle some event
self.network.on("selectNode", function (object) {
// $("#show_pre_post_network")[0].innerHTML = object;
var subEdgeList = object["edges"].map(function (edgeId) {
return self.network.body.data.edges._data[edgeId];
});
var subNodeIdList = subEdgeList.reduce(function (nodeList, edge) {
var nodeId = edge["from"];
if (nodeList.indexOf(nodeId) === -1) {
nodeList.push(nodeId);
}
nodeId = edge["to"];
if (nodeList.indexOf(nodeId) === -1) {
nodeList.push(nodeId);
}
return nodeList;
}, []);
var subData = {
nodes: new vis.DataSet(
subNodeIdList.map(function (nodeId) {
var nodeData = Object.assign(
{},
self.network.body.data.nodes._data[nodeId]
);
nodeData.level = undefined;
return nodeData;
})
),
edges: new vis.DataSet(subEdgeList),
};
var subOptions = {
nodes: {
color: {
background: "lightgray",
hover: "SILVER",
highlight: "SILVER",
},
borderWidth: 0,
},
edges: {
arrows: "to",
arrowStrikethrough: false,
smooth: false,
},
layout: {
hierarchical: {
enabled: true,
direction: "UD",
edgeMinimization: true,
levelSeparation: 150,
nodeSpacing: 300,
blockShifting: true,
parentCentralization: true,
sortMethod: "directed",
},
},
groups: {
O: {
color: {
background: "lightgreen",
hover: "LIMEGREEN",
highlight: "LIMEGREEN",
},
borderWidth: 3,
},
T: {
color: { background: "yellow", hover: "GOLD", highlight: "GOLD" },
borderWidth: 3,
},
X: {
color: {
background: "pink",
hover: "INDIANRED",
highlight: "INDIANRED",
},
borderWidth: 3,
},
guessO: {
color: {
background: "lawngreen",
hover: "LIMEGREEN",
highlight: "LIMEGREEN",
},
borderWidth: 0,
},
guessT: {
color: { background: "yellow", hover: "GOLD", highlight: "GOLD" },
borderWidth: 0,
},
guessX: {
color: {
background: "lightcoral",
hover: "INDIANRED",
highlight: "INDIANRED",
},
borderWidth: 0,
},
JY: { color: { background: "white" }, borderWidth: 3 },
under5: {
color: { background: "yellow", hover: "GOLD", highlight: "GOLD" },
borderWidth: 3,
},
fit: {
color: {
background: "lightgreen",
hover: "LIMEGREEN",
highlight: "LIMEGREEN",
},
borderWidth: 3,
},
easy: {
color: {
background: "lightgreen",
hover: "LIMEGREEN",
highlight: "LIMEGREEN",
},
borderWidth: 3,
},
not_fit: {
color: {
background: "pink",
hover: "INDIANRED",
highlight: "INDIANRED",
},
borderWidth: 3,
},
unknown: {
color: {
background: "lightgray",
hover: "SILVER",
highlight: "SILVER",
},
borderWidth: 0,
},
conflict: { color: { background: "orange" }, borderWidth: 3 },
},
physics: {
enabled: false,
},
};
self.subNetwork = new vis.Network(
document.getElementById("show_pre_post_network"),
subData,
subOptions
);
});
};
graphDataSource.initialGraphElement(callbackView);
};
GraphView.prototype.redrawNetwork = function () {
var graphElement = this.graphDataSource.getCurGraphElement();
this.network.setData({
nodes: new vis.DataSet(graphElement[0]),
edges: new vis.DataSet(graphElement[1]),
});
this.network.redraw();
};
GraphView.prototype.redrawNetworkByTheme = function (theme) {
var graphElement = this.graphDataSource.getCurGraphElement(theme);
this.network.setData({
nodes: new vis.DataSet(graphElement[0]),
edges: new vis.DataSet(graphElement[1]),
});
this.network.redraw();
};
GraphView.prototype.setRelation = function (relationType) {
this.graphDataSource.setRelation(relationType);
$("#dropdownNetworkButton")[0].innerHTML =
relationType === "yisheng" ? "宜陞" : "因材";
this.redrawNetwork();
};
GraphView.prototype.handleDisplayLevelChange = function () {
var cgLevel = document.getElementById("isCgLevel").checked;
this.graphDataSource.setDisplayLevel(cgLevel);
this.redrawNetwork();
};
GraphView.prototype.handleDisplayJunyiResultChange = function () {
var displayJunyiResult =
document.getElementById("displayJunyiResult").checked;
this.graphDataSource.setDisplayJunyiResult(displayJunyiResult);
this.redrawNetwork();
};
GraphView.prototype.handleDisplayPathChange = function () {
var displayPath = document.getElementById("displayPath").checked;
if (displayPath) {
document.getElementById("recommend-panel-container").style.display =
"block";
} else {
document.getElementById("recommend-panel-container").style.display = "none";
}
};
GraphView.prototype.handleThemeChange = function (theme) {
this.redrawNetworkByTheme(theme);
};
GraphView.prototype.handleChangeDataButton = function (resource) {
var self = this;
this.graphDataSource.resetData();
if (resource === "custom") {
$("#dropdownDataButton")[0].innerHTML = "自行匯入";
$("#submitCustomData").show();
$("#dropdownStudentButton").attr("disabled", true);
$("#dropdownDateButton").attr("disabled", true);
} else {
$("#dropdownDataButton")[0].innerHTML =
resource === "pintong" ? "屏東補救教學" : "歷屆補救教學";
$("#submitCustomData").hide();
var urlListDict = {
pintong: [
"https://dl.dropbox.com/s/j9tcnyrr8b2t16b/pintong_remedial_result.txt",
"https://dl.dropbox.com/s/snfffgshh19hen3/pintong_junyi_result.txt",
],
past_remedial: [
"https://dl.dropbox.com/s/zs8zn93oxqjkwqf/top_result.txt",
"https://dl.dropbox.com/s/wpwpl7g1xyvpyrs/junyi_result.txt",
],
};
$("#dropdownStudentButton").attr("disabled", true);
$("#dropdownNetworkButton").attr("disabled", true);
$("#editModeBtn").attr("disabled", true);
var finishUpdateCallback = function () {
self.redrawNetwork();
self.updateStudentDropdown();
$("#dropdownNetworkButton").removeAttr("disabled");
$("#editModeBtn").removeAttr("disabled");
$("#dropdownStudentButton")[0].innerHTML = "選擇學生";
$("#dropdownDateButton")[0].innerHTML = "選擇時間";
};
this.graphDataSource.updateData(
urlListDict[resource],
finishUpdateCallback
);
}
};
GraphView.prototype.setEmail = function (email) {
$("#dropdownStudentButton")[0].innerHTML = email;
this.graphDataSource.setEmail(email);
this.graphDataSource.setDisplayDate("all");
this.updateDateDropdown();
this.redrawNetwork();
};
GraphView.prototype.setDisplayDate = function (date) {
$("#dropdownDateButton")[0].innerText = date;
this.graphDataSource.setDisplayDate(date);
this.redrawNetwork();
};
GraphView.prototype.updateStudentDropdown = function () {
var self = this;
var studentList = self.graphDataSource.getStudentList();
var studentDropdown = $("#studentDropdownContainer");
studentDropdown[0].innerHTML = "";
for (var i = 0; i < studentList.length; i++) {
var email = studentList[i];
var stuItem = $("<a></a>").text(email);
stuItem.attr("class", "dropdown-item");
stuItem.attr("id", email);
stuItem.on("click", function () {
self.setEmail(this.id);
});
studentDropdown.append(stuItem);
}
$("#dropdownStudentButton").removeAttr("disabled");
$("#dropdownThemeButton").removeAttr("disabled");
$("#dropdownStudentButton")[0].innerHTML = "選擇學生";
$("#dropdownThemeButton")[0].innerHTML = "選擇主題";
};
GraphView.prototype.updateThemeDropdown = function () {
var self = this;
var themeList = self.graphDataSource.getThemeList();
var themeDropdown = $("#themeDropdownContainer");
themeDropdown[0].innerHTML = "";
for (var i = 0; i < themeList.length; i++) {
var theme = themeList[i];
var themeItem = $("<a></a>").text(theme);
themeItem.attr("class", "dropdown-item themeDropdown");
themeItem.attr("id", theme);
themeItem.on("click", function () {
self.handleThemeChange(this.id);
});
themeDropdown.append(themeItem);
}
$("#dropdownThemeButton").removeAttr("disabled");
$("#dropdownThemeButton")[0].innerHTML = "選擇主題";
};
GraphView.prototype.updateDateDropdown = function () {
var self = this;
var dateList = self.graphDataSource.getDateList();
var dateDropdown = $("#dateDropdownContainer");
dateDropdown[0].innerHTML = "";
var createDateItem = function (id) {
if (id === "all") {
var dateItem = $("<a></a>").text("所有時間");
} else {
var dateItem = $("<a></a>").text(id);
}
dateItem.attr("class", "dropdown-item");
dateItem.attr("id", id);
dateItem.on("click", function () {
self.setDisplayDate(this.id);
});
return dateItem;
};
dateDropdown.append(createDateItem("all"));
for (var idx = 0; idx < dateList.length; idx++) {
var date = dateList[idx];
dateDropdown.append(createDateItem(date));
}
$("#dropdownDateButton").removeAttr("disabled");
$("#dropdownDateButton")[0].innerHTML = "所有時間";
};
//////// modify
//view
GraphView.prototype.recursiveFindStartPoint = function (
curStartNodeIdList,
_curNodeList,
_curEdgeList,
statusList,
checkCurNode,
includingLeaf
) {
var matchedNodeList = [];
if (checkCurNode) {
// combine this two for loop later
var curNodeList = curStartNodeIdList.map(function (nodeId) {
return GraphUtil.getNodeById(nodeId, _curNodeList);
});
for (var i = 0; i < curNodeList.length; i++) {
var curNodeObj = curNodeList[i];
if (statusList.indexOf(curNodeObj["group"]) >= 0) {
matchedNodeList.push(curNodeObj);
}
}
if (matchedNodeList.length > 0) {
return matchedNodeList;
}
}
var nextNodeIdList = _curEdgeList.reduce(function (result, edge) {
if (curStartNodeIdList.indexOf(edge["from"]) !== -1) {
result.push(edge["to"]);
}
return result;
}, []);
// make list unique first to reduce the loop
var uniqueObj = {};
for (var i = 0; i < nextNodeIdList.length; i++) {
uniqueObj[nextNodeIdList[i]] = true;
}
nextNodeIdList = Object.keys(uniqueObj);
// combine this two for loop later
var nextNodeList = nextNodeIdList.map(function (nodeId) {
return GraphUtil.getNodeById(nodeId, _curNodeList);
});
for (var i = 0; i < nextNodeList.length; i++) {
var nextNodeObj = nextNodeList[i];
var isLeaf =
GraphUtil.getNextNodeId(nextNodeObj["id"], _curEdgeList).length === 0;
if (statusList.indexOf(nextNodeObj["group"]) >= 0) {
if (includingLeaf || !isLeaf) {
matchedNodeList.push(nextNodeObj);
}
}
}
if (matchedNodeList.length > 0 || nextNodeIdList.length === 0) {
return matchedNodeList;
} else {
return this.recursiveFindStartPoint(
nextNodeIdList,
_curNodeList,
_curEdgeList,
statusList,
false,
includingLeaf
);
}
};
//view
//need to refactor
GraphView.prototype.getStartPoint = function (_curNodeList, _curEdgeList) {
var searchStatusDict = this.graphDataSource.searchStatus;
// combine into one for loop
var correctList = _curNodeList.filter(function (node) {
return searchStatusDict["learned"].indexOf(node["group"]) !== -1;
});
var wrongList = _curNodeList.filter(function (node) {
return searchStatusDict["not_learned"].indexOf(node["group"]) !== -1;
});
var notSureList = _curNodeList.filter(function (node) {
return searchStatusDict["not_sure"].indexOf(node["group"]) !== -1;
});
if (
correctList.length === 0 &&
wrongList.length === 0 &&
notSureList.length === 0
) {
$("#startPointText")[0].innerText = "沒有資料。";
return;
}
// initialize the list
var startPointIdList = [];
var startPointList = [];
var startPointViewList = [];
// If the information is not enough to decide the start point, we set the start point to the begin of the cg
if (
correctList.length === 0 &&
wrongList.length === 0 &&
notSureList.length !== 0
) {
var startNotSureNodeIdList = GraphUtil.getStartNode(
notSureList,
_curEdgeList
).concat(GraphUtil.getSingleNode(notSureList, _curEdgeList));
for (var s_id = 0; s_id < startNotSureNodeIdList.length; s_id++) {
var startNodeId = startNotSureNodeIdList[s_id];
var startNode = GraphUtil.getNodeById(startNodeId, notSureList);
var sameCgNodeList = _curNodeList.filter(function (node) {
return (
node["cg"] === startNode["cg"] &&
searchStatusDict["learned"]
.concat(["guessO"])
.indexOf(node["group"]) === -1
);
});
var startOfCgNodeIdList = GraphUtil.getStartNode(
sameCgNodeList,
_curEdgeList
).concat(GraphUtil.getSingleNode(sameCgNodeList, _curEdgeList));
startPointIdList = startPointIdList.concat(startOfCgNodeIdList);
startPointList = startPointIdList.map(function (node_id) {
return GraphUtil.getNodeById(node_id, sameCgNodeList);
});
startPointViewList.push({
type: "not_enough",
notLearnedPointName: notSureList[0]["id"],
startSection: startOfCgNodeIdList,
});
}
} else if (wrongList.length !== 0) {
// need to refactor
// in this case, we should find the head of the chapter of the cg
var startNodeIdList = GraphUtil.getStartNode(_curNodeList, _curEdgeList);
startNodeIdList = startNodeIdList.concat(
GraphUtil.getSingleNode(_curNodeList, _curEdgeList)
);
startPointListTmp = this.recursiveFindStartPoint(
startNodeIdList,
_curNodeList,
_curEdgeList,
searchStatusDict["not_learned"],
true,
false
);
if (startPointListTmp.length === 0) {
startPointListTmp = this.recursiveFindStartPoint(
startNodeIdList,
_curNodeList,
_curEdgeList,
searchStatusDict["not_learned"],
true,
true
);
}
for (var s_id = 0; s_id < startPointListTmp.length; s_id++) {
var startPointTmp = startPointListTmp[s_id];
var sameCgNodeList = _curNodeList.filter(function (node) {
return (
node["cg"] === startPointTmp["cg"] &&
searchStatusDict["learned"].indexOf(node["group"]) === -1
);
});
var startOfCgNodeIdList = GraphUtil.getStartNode(
sameCgNodeList,
_curEdgeList
).concat(GraphUtil.getSingleNode(sameCgNodeList, _curEdgeList));
for (var i = 0; i < startOfCgNodeIdList.length; i++) {
var startOfCgNode = GraphUtil.getNodeById(
startOfCgNodeIdList[i],
sameCgNodeList
);
var chapterName = startOfCgNode["id"].split("_")[0];
var sameChapterNodeList = _curNodeList.filter(function (node) {
return (
node["id"].split("_")[0] === chapterName &&
searchStatusDict["learned"]
.concat(["guessO"])
.indexOf(node["group"]) === -1
);
});
var startOfChapterNodeIdList = GraphUtil.getStartNode(
sameChapterNodeList,
_curEdgeList
);
if (startOfChapterNodeIdList.length === 0) {
startOfChapterNodeIdList = GraphUtil.getSingleNode(
sameChapterNodeList,
_curEdgeList
); ////////////// need it?
}
startPointIdList = startPointIdList.concat(startOfChapterNodeIdList);
startPointList = startPointIdList.map(function (node_id) {
return GraphUtil.getNodeById(node_id, _curNodeList); //sameChapterNodeList)
});
startPointViewList.push({
type: "not_learned",
notLearnedPointName: startPointTmp["id"],
startSection: startOfChapterNodeIdList,
});
}
}
}
if (startPointList.length === 0) {
$("#startPointText")[0].innerText = "沒有推薦的起始點。";
} else {
var startPointNameList = startPointList.map(function (node) {
return node["name"].replace("\n", " ");
});
$("#startPointText")[0].innerText =
"推薦起始點為:" + startPointNameList.join("、") + "。";
}
return startPointViewList;
};
// use handlebar to improve
GraphView.prototype.updateStarPointView = function (startPointViewList) {
var self = this;
var createLinkElementText = function (relateLink, text) {
return (
'<a target="_blank" href="https://www.junyiacademy.org/' +
relateLink +
'">' +
text +
"</a>"
);
};
var createSectionElement = function (nodeId, additionalClassName) {
// maybe modify to nodeIdList
$("#recommend-container").append(
'<div class="recommendBlockContainer" id="' +
nodeId +
'-container"></div>'
);
var containerSelector = "#" + nodeId + "-container";
if (additionalClassName) {
$(containerSelector).addClass(additionalClassName);
}
var linkElementText = createLinkElementText(
this.graphDataSource.getChapterId(nodeId),
nodeId
);
if (additionalClassName === "startPoint") {
linkElementText = "建議起始點:" + linkElementText;
} else if (additionalClassName === "endPoint") {
linkElementText = "學生尚未學會:" + linkElementText;
} else if (additionalClassName === "prevPoint") {
linkElementText = "起始點的先備:" + linkElementText;
} else if (additionalClassName === "nextPoint") {
linkElementText = "可以繼續學:" + linkElementText;
}
$(containerSelector).append(
'<div class="recommendBlock">' + linkElementText + "</div>"
);
var exerciseList = self.graphDataSource.getExBySection(nodeId);
var exerciseContent = "";
var learnedTime = 0;
var contentList = [];
for (var ex_idx = 0; ex_idx < exerciseList.length; ex_idx++) {
var exercise = exerciseList[ex_idx];
var contentId = exercise["content_id"];
if (contentList.indexOf(contentId) === -1) {
learnedTime += this.graphDataSource.getLearnedTime(contentId);
exerciseContent +=
"<div>" +
createLinkElementText(
"exercise/" + contentId,
exercise["content_title"]
) +
"</div>";
contentList.push(contentId);
}
}
var learnedMin = Math.ceil(learnedTime / 60);
//var learnedSec = learnedTime - learnedMin * 60;
var learnedTimeText = learnedMin + " 分 "; // + learnedSec + " 秒";
$(containerSelector).append(
'<div class="recommendExercise" id="' +
nodeId +
'-recommendExercise">' +
"<div>平均達到等級一時間:" +
learnedTimeText +
"</div>" +
"<hr />" +
exerciseContent +
"</div>"
);
//var containerSelectorElement = getElementById()
$(containerSelector).hover(
function () {
this.lastElementChild.setAttribute("style", "display:block;");
},
function () {
this.lastElementChild.setAttribute("style", "display:none;");
}
);
};
$("#recommend-container")[0].innerHTML = "";
if (!startPointViewList) {
if (!this.graphDataSource.curEmail) {
$("#recommend-container").append(
'<div style="padding-left: 20px;">請先選擇學生,即可看到推薦起始點嘍。</div>'
);
} else {
$("#recommend-container").append(
'<div style="padding-left: 20px;">目前資料不足,無法建議起始點。</div>'
);
}
return;
}
console.log(startPointViewList);
if (startPointViewList.length > 0) {
for (var i = 0; i < startPointViewList.length; i++) {
startPointViewObj = startPointViewList[i];
$("#recommend-container").append(
'<div style="padding-left: 20px;">學生於「' +
startPointViewObj["notLearnedPointName"].split("_")[1] +
"」沒學會可以參考以下學習路徑開始學習</div>"
);
$("#recommend-container").append(
'<h4 style="padding-left: 20px;">學習「' +
startPointViewObj["notLearnedPointName"].split("_")[1] +
"」建議路徑</h4>"
);
for (var j = 0; j < startPointViewObj["startSection"].length; j++) {
var sectionName = startPointViewObj["startSection"][j];
$("#recommend-container").append(
"<h5>從「" + sectionName + "」開始學習</h5>"
);
var path = GraphUtil.getPath(
sectionName,
startPointViewObj["notLearnedPointName"],
this.graphDataSource.curEdgeList
);
var prevNodeIdList = GraphUtil.getPrevNodeId(
path[0],
this.graphDataSource.curEdgeList
);
if (prevNodeIdList.length > 0) {
if (
this.graphDataSource.getExBySection(prevNodeIdList[0]).length === 0
) {
prevNodeIdList = GraphUtil.getPrevNodeId(
prevNodeIdList[0],
this.graphDataSource.curEdgeList
);
}
if (prevNodeIdList.length > 0) {
createSectionElement(prevNodeIdList[0], "prevPoint");
$("#recommend-container").append(
'<div class="recommendArrow">↑</div>'
);
}
}
for (var pathIdx = 0; pathIdx < path.length; pathIdx++) {
var nodeId = path[pathIdx];
if (pathIdx === path.length - 1) {
createSectionElement(nodeId, "endPoint");
} else if (pathIdx === 0) {
createSectionElement(nodeId, "startPoint");
$("#recommend-container").append(
'<div class="recommendArrow">↓</div>'
);
} else {
createSectionElement(nodeId);
$("#recommend-container").append(
'<div class="recommendArrow">↓</div>'
);
}
}
var nextNodeIdList = GraphUtil.getNextNodeId(
path[path.length - 1],
this.graphDataSource.curEdgeList
);
if (nextNodeIdList.length > 0) {
$("#recommend-container").append(
'<div class="recommendArrow">↓</div>'
);
createSectionElement(nextNodeIdList[0], "nextPoint");
}
}
}
} else {
$("#recommend-container").append(
'<div style="padding-left: 20px;">現階段,此學生分數概念已經學到目前的學習階段嘍!</div>'
);
}
};