Graph: Ajout des catégories Semestres

This commit is contained in:
Éric Li 2021-04-30 12:52:14 +02:00
parent bf2074a131
commit 6ddeb10bdc
3 changed files with 62 additions and 30 deletions

View File

@ -207,7 +207,6 @@ def defineSearchTerm(dictio, url, documents):
documents[document["code"]] = document documents[document["code"]] = document
return return
# Créer un fichier contenant la liste des saes # Créer un fichier contenant la liste des saes
datas = {"data" : saes, "title": "SAEs"} # "data" contient un tableau des saes datas = {"data" : saes, "title": "SAEs"} # "data" contient un tableau des saes
template_List.stream(datas).dump(REPERTOIRE_HTML + "/SAE.html") template_List.stream(datas).dump(REPERTOIRE_HTML + "/SAE.html")
@ -248,14 +247,13 @@ for indexSem, sem in enumerate(ressources):
defineSearchTerm(data, url, documents) defineSearchTerm(data, url, documents)
template.stream(datas).dump(REPERTOIRE_HTML + "/" + url) template.stream(datas).dump(REPERTOIRE_HTML + "/" + url)
relations["nodes"].append({"id": data["code"], "type": "Ressource"}) relations["nodes"].append({"id": data["code"], "sem": sem, "type": "Ressource"})
for sae in data["sae"]: for sae in data["sae"]:
if not any(sae in node["id"] for node in relations["nodes"]): relations["nodes"].append({"id": sae, "type": "SAE"}) relations["links"].append({"source": data["code"], "target": sae, "sem": sem, "type": "RessourceToSAE"})
relations["links"].append({"source": data["code"], "target": sae, "type": "RessourceToSAE"})
for rt in data["acs"]: for rt in data["acs"]:
for ac in data["acs"][rt]: for ac in data["acs"][rt]:
if not any(ac in node["id"] for node in relations["nodes"]): relations["nodes"].append({"id": ac, "type": "AC"}) if not any(ac in node["id"] for node in relations["nodes"]): relations["nodes"].append({"id": ac, "sem": 0, "type": "AC"})
relations["links"].append({"source": data["code"], "target": ac, "type": "RessourceToAC"}) relations["links"].append({"source": data["code"], "target": ac, "sem": sem, "type": "RessourceToAC"})
#Créer un fichier contenant la liste des ressources du semestre #Créer un fichier contenant la liste des ressources du semestre
data = {"data" : ressources[sem],"sem" : sem} # "data" contient un tableau des ressources du semestre data = {"data" : ressources[sem],"sem" : sem} # "data" contient un tableau des ressources du semestre
@ -289,8 +287,8 @@ for indexSem, sem in enumerate(ressources):
relations["nodes"].append({"id": data["code"], "type": "SAE"}) relations["nodes"].append({"id": data["code"], "type": "SAE"})
for rt in data["acs"]: for rt in data["acs"]:
for ac in data["acs"][rt]: for ac in data["acs"][rt]:
if not any(ac in node["id"] for node in relations["nodes"]): relations["nodes"].append({"id": ac, "type": "AC"}) if not any(ac in node["id"] for node in relations["nodes"]): relations["nodes"].append({"id": ac, "sem": 0, "type": "AC"})
relations["links"].append({"source": data["code"], "target": ac, "type": "SAEToAC"}) relations["links"].append({"source": data["code"], "target": ac, "sem": sem, "type": "SAEToAC"})
for sae in exemples[sem]: for sae in exemples[sem]:
i = 1 # Nommage des fichiers exemple sae peut être modifier i = 1 # Nommage des fichiers exemple sae peut être modifier

View File

@ -4,6 +4,18 @@
<script src="https://d3js.org/d3.v5.js"></script> <script src="https://d3js.org/d3.v5.js"></script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="field is-horizontal">
<div class="control">
<label class="checkbox">
<input id="Semestre1" class="semestre" value="S1" type="checkbox" checked>
Semestre 1
</label>
<label class="checkbox">
<input id="Semestre2" class="semestre" value="S2" type="checkbox" checked>
Semestre 2
</label>
</div>
</div>
<div class="field is-horizontal"> <div class="field is-horizontal">
<div class="control"> <div class="control">
<label class="checkbox"> <label class="checkbox">

View File

@ -56,18 +56,38 @@ var node = svg.append("g")
redraw(); redraw();
$("document").ready(function() { $("document").ready(function() {
$(".categorie").click(function() { $("input").click(function() {
nodes = []
links = [] var sem = ["default"];
if($("#Ressources").prop("checked")) {graph["nodes"].map(node => {if(node.type == "Ressource"){nodes.push(node);}})} $(".semestre:checked").each(function() { sem.push($(this).val()) });
if($("#SAEs").prop("checked")) {
if (nodes.length != 0) {graph["links"].map(link => {if(link.type == "RessourceToSAE"){links.push(link);}})} var RessourceChecked = $("#Ressources").prop("checked");
nodes.concat(graph["nodes"].map(node => {if(node.type == "SAE"){nodes.push(node);}})); var SAEChecked = $("#SAEs").prop("checked");
var ACChecked = $("#ACs").prop("checked");
nodes = [];
links = [];
if(RessourceChecked) {
graph["nodes"].forEach(node => {
if(node.type == "Ressource" && sem.includes(node.sem)) { nodes.push(node); }
});
} }
if($("#ACs").prop("checked")) {
if($("#Ressources").prop("checked")) {graph["links"].map(link => {if(link.type == "RessourceToAC"){links.push(link);}})} if(SAEChecked) {
if($("#SAEs").prop("checked")) {graph["links"].map(link => {if(link.type == "SAEToAC"){links.push(link);}})} graph["nodes"].forEach(node => {
nodes.concat(graph["nodes"].map(node => {if(node.type == "AC"){nodes.push(node);}})); if(node.type == "SAE") { nodes.push(node); }
});
if (RessourceChecked) {
graph["links"].forEach(link => { if(link.type == "RessourceToSAE" && sem.includes(link.sem)) {links.push(link);} })
}
}
if(ACChecked) {
graph["nodes"].forEach(node => {if(node.type == "AC"){nodes.push(node);}});
if(RessourceChecked) {graph["links"].forEach(link => {if(link.type == "RessourceToAC" && sem.includes(link.sem)){links.push(link);}})}
if(SAEChecked) {graph["links"].forEach(link => {if(link.type == "SAEToAC" && sem.includes(link.sem)){links.push(link);}})}
} }
redraw(); redraw();
}); });
@ -88,19 +108,21 @@ function redraw() {
.call(drag(simulation)) .call(drag(simulation))
node.append("rect") node.append("rect")
.attr("width", 20) .attr("width", 20)
.attr("height", 10) .attr("height", 10)
.attr("x", -10) .attr("x", -10)
.attr("y", -5) .attr("y", -5)
.attr("rx", 5) .attr("rx", 5)
.attr("ry", 5) .attr("ry", 5)
.attr("fill", function(d) { return color(d.type); }) .attr("fill", function(d) { return color(d.type); })
node.append("text") node.append("text")
.attr("style", "user-select: none") .attr("style", "user-select: none")
.text(d => d.id) .attr("dx", 7)
.attr("dx", 7) .attr("dy", 12)
.attr("dy", 12) .append("a")
.attr("href", d => d.id.replace("É", "E") + ".html")
.text(d => d.id)
simulation.nodes(nodes); simulation.nodes(nodes);
simulation.force("links", d3.forceLink(links).id(node => node.id).distance(100)); simulation.force("links", d3.forceLink(links).id(node => node.id).distance(100));